i have the code bellow :
FILE *inFile;
BmpHeader header;
BmpImageInfo info;
Rgb *palette;
int i = 0;
inFile = fopen( "red.bmp", "rb" );
fread(&header, 1, sizeof(BmpHeader), inFile);
fread(&info, 1, sizeof(BmpImageInfo), inFile);
palette = (Rgb*)malloc(sizeof(Rgb) * info.numColors);
fread(palette, sizeof(Rgb), info.numColors, inFile);
unsigned char buffer[info.width*info.height];
FILE *outFile = fopen( "red.a", "wb" );
Rgb *pixel = (Rgb*) malloc( sizeof(Rgb) );
int read, j;
for( j=info.height; j>0; j-- )
{
for( i=0; i<info.width; i++ )
{
fread(pixel, 1, sizeof(Rgb), inFile);
buffer[i] = ARGB16(0, pixel->red, pixel->green, pixel->blue);
}
}
fwrite(buffer, 1, sizeof(buffer), outFile);
and i am reading a red image(255 0 0), and i am using the function defined by you above(#define ARGB16(a, r, g, b) ( ((a) << 15) | (r>>3)|((g>>3)<<5)|((b>>3)<<10))
), but the output file shows me : 1F 1F 1F when i am opening the file with a hexaeditor instead of 7C00 ..