I need to work with .bmp
type of images.
The format for it is:
struct bmp_fileheader
{
unsigned char fileMarker1; /* 'B' */
unsigned char fileMarker2; /* 'M' */
unsigned int bfSize; /* File's size */
unsigned short unused1; /* Aplication specific */
unsigned short unused2; /* Aplication specific */
unsigned int imageDataOffset; /* Offset to the start of image data */
};
struct bmp_infoheader
{
unsigned int biSize; /* Size of the info header - 40 bytes */
signed int width; /* Width of the image */
signed int height; /* Height of the image */
unsigned short planes;
unsigned short bitPix; /* Number of bits per pixel = 3 * 8 (for each channel R, G, B we need 8 bits */
unsigned int biCompression; /* Type of compression */
unsigned int biSizeImage; /* Size of the image data */
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
};
typedef struct pi {
unsigned char r;
unsigned char g;
unsigned char b;
}Pixel;
struct bmp_image {
struct bmp_fileheader file_header;
struct bmp_infoheader info_header;
Pixel ** pixel;
};
struct bmp_image image;
So, an image contains a header and a matrix(height * width
) of pixels.
I read the image from a file :
FILE *image_file = fopen("path.bmp", "rb");
After that, I read all the variables of the header and then the matrix of pixels. I need to make some changes on the image in order to create another image that is the black_and_white format from the initial image.
The algorithm to do that is to change the (X, Y, Z) pixel with (B, B, B), where B = (X + Y + Z) / 3;
. I create the black_and_white image just fine.
The problem shows when I try to compare my black_and_white image with a black_and_white image made by a paint program.
cmp -lb airplane_black_white.bmp ref/airplane_black_white.bmp
cmp: EOF on airplane_black_white.bmp