I have a 1280 x 720 pixel .bmp file that I want to load into image2 that is declared like the following:
uint8_t *imageByte=NULL;
image2 is a file named home1.bmp
i want to read the bmp file and convert .bmp image to byte array imageByte which i will use for compare with home.bmp
I relatively new to c programming, so any one can tell me how should I being using to do so? thanks! This a part of my bmp image comparison code which will compare image1 with image2
# define BYTES_PER_PIXEL 4
# define BITMAP_HEADER 54
int temp_width = 1280;
int temp_height = 720;
int temp_x = 0;
int temp_y = 0;
uint8_t k = 0;
char* image1= "E:\\home.bmp";
fp = fopen(image,"rb");
fseek(fp, 0, SEEK_SET);
fseek(fp, BITMAP_HEADER, SEEK_SET);
for(temp_y=0; temp_y<temp_height; temp_y++)
{
temp_x = 0;
for(temp_x=0; temp_x < (temp_width * BYTES_PER_PIXEL); temp_x++)
{
int read_bytes = fread(&k, 1, 1, fp);
if(read_bytes != 0)
{
if(k != imageByte[temp_x])
{
printf("CompareImage :: failed \n");
fclose(fp);
}
}
else
{
printf("CompareImage :: read failed \n");
}
}
}
printf("CompareImage :: passed \n");
As mentioned above, a BMP file starts with 1] A file header that gives information about the file like size ..etc 2] BMP information header that gives more information about the BMP properties These structures are of fixed size
The following link seems to be a perfect reference for you http://paulbourke.net/dataformats/bmp/
You should be able to get rid of byte by bytes comparison which is costly in most of the cases, just by reading the two header structured from the beginning and comparing. Do bytes by byte comparison only of the headers match.
Hope it helps