I have a test bench for a Sobel filter in Vitis HLS
. This test bench is reading an image via
if(Bitmap_Reader_Open("Test.bmp", &Width, &Height, &Bits) == -1)
{
printf("Can not open input image!\n\r");
return -1;
}
int Bitmap_Reader_Open(char* p_Path, uint32_t* p_Width, uint32_t* p_Height, uint8_t* p_Bits)
{
Bitmap_BMP_Header_t Header;
Bitmap_DIB_Header_t InfoHeader;
if((p_Path == NULL) || (p_Width == NULL) || (p_Height == NULL) || (p_Bits == NULL))
{
return -1;
}
_Reader_Bitmap = fopen(p_Path, "rb");
if(_Reader_Bitmap == NULL)
{
return -1;
}
fread(&Header, 1, sizeof(Header), _Reader_Bitmap);
printf("Read file header...\n\r");
printf(" bType: 0x%X\n\r", Header.bType);
printf(" bfSize: %u\n\r", Header.bfSize);
printf(" bfOffBits: 0x%X\n\r", Header.bfOffBits);
fread(&InfoHeader, 1, sizeof(InfoHeader), _Reader_Bitmap);
printf("Read file info header...\n\r");
printf(" biSize: %u\n\r", InfoHeader.biSize);
printf(" biWidth: %u\n\r", InfoHeader.biWidth);
printf(" biHeight: %u\n\r", InfoHeader.biHeight);
printf(" biPlanes: %u\n\r", InfoHeader.biPlanes);
printf(" biBitCount: %u\n\r", InfoHeader.biBitCount);
printf(" biCompression: %u\n\r", InfoHeader.biCompression);
printf(" biSizeImage: %u\n\r", InfoHeader.biSizeImage);
printf(" biXPelsPerMeter: %u\n\r", InfoHeader.biXPelsPerMeter);
printf(" biYPelsPerMeter: %u\n\r", InfoHeader.biYPelsPerMeter);
printf(" biClrUsed: %u\n\r", InfoHeader.biClrUsed);
printf(" biClrImportant: %u\n\r", InfoHeader.biClrImportant);
if(InfoHeader.biCompression != BITMAP_COMP_RGB)
{
return -1;
}
*p_Width = InfoHeader.biWidth;
*p_Height = InfoHeader.biHeight;
*p_Bits = InfoHeader.biBitCount;
return 0;
}
Both headers are defined as follows:
/** @brief Bitmap file header.
* NOTE: Please check https://en.wikipedia.org/wiki/BMP_file_format if you need additional information.
*/
typedef struct
{
uint16_t bType; /**< Contains the characters "BM". */
uint32_t bfSize; /**< Size of the bitmap in bytes. */
uint16_t bReserved; /**< Reserved. Default 0. */
uint16_t bReserved1; /**< Reserved. Default 0. */
uint32_t bfOffBits; /**< Image data offset. */
} __attribute__((packed)) Bitmap_BMP_Header_t;
/** @brief Bitmap information header.
* NOTE: Please check https://en.wikipedia.org/wiki/BMP_file_format if you need additional information.
*/
typedef struct
{
uint32_t biSize; /**< Size of the \ref Bitmap_DIB_Header_t in bytes. */
int32_t biWidth; /**< Width of the bitmap in pixel. The first byte contains the LSB, the last byte contains the MSB. */
int32_t biHeight; /**< Height of the bitmap in pixel. The first byte contains the LSB, the last byte contains the MSB.
- Positive value: The image data start with the bottom row (bottom-up).
- Negative value: The image data start with the top row (top-down). */
uint16_t biPlanes; /**< Always 1. */
uint16_t biBitCount; /**< Color depth of the bitmap in bpp. */
uint32_t biCompression; /**< Bitmap compression. See \ref Bitmap_Compression_t for more information. */
uint32_t biSizeImage; /**< When \ref Bitmap_DIB_Header_t.biBitCount = BI_RGB: 0 or image size in bytes.
Else: Image size in bytes. */
int32_t biXPelsPerMeter; /**< Horizontal resolution of the target output device. Is set to 0 mostly. */
int32_t biYPelsPerMeter; /**< Vertical resolution of the target output device. Is set to 0 mostly. */
uint32_t biClrUsed; /**< When \ref Bitmap_DIB_Header_t.biBitCount = 1: 0.
When \ref Bitmap_DIB_Header_t.biBitCount = 4 or 8: Color table entry count. If value is 0 the maximum count (2, 16 or 256) is used.
Else: Color table entry count (0 = no color table). */
uint32_t biClrImportant; /**< When \ref Bitmap_DIB_Header_t.biBitCount = 1, 4 or 8: Number of colors used in the image. All colors of the color table when 0.
Else: When: Number of colors when a color table with all used colors is available.
Else: 0. */
} __attribute__((packed)) Bitmap_DIB_Header_t;
But the output doesn´t fit to my expectations, because bfOffBits
is wrong.
Read file header...
bType: 0x4D42
bfSize: 36
bfOffBits: 0x0
Read file info header...
biSize: 40
biWidth: 640
biHeight: 480
biPlanes: 1
biBitCount: 24
biCompression: 0
biSizeImage: 2359296
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
I opened the image in HxD to check the headers and the program gives me the following output:
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 42 4D 36 00 24 00 00 00 00 00 36 00 00 00 28 00 BM6.$.....6...(.
00000010 00 00 80 02 00 00 E0 01 00 00 01 00 18 00 00 00 ..€...à.........
00000020 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 ....$...........
00000030 00 00 00 00 00 00 40 80 80 38 7C 80 40 80 80 40 ......@€€8|€@€€@
00000040 80 80 40 7C 80 40 78 80 40 70 88 40 70 88 38 74 €€@|€@x€@pˆ@pˆ8t
00000050 88 38 70 88 38 74 80 38 74 80 38 74 88 38 74 80 ˆ8pˆ8t€8t€8tˆ8t€
...