PDA

Click to See Complete Forum and Search --> : Parsing BMP file


sghauri
08-09-2004, 06:53 PM
Hi all


I parsed a BMP file that contained a palette in C. I decoded the image data using the palette and wrote the new data to a new BMP file. Now the original file and the new file should ideally be same but the new image when displayed in a viewer seems to have lost many colours. Any idea why is it so? The routines that I am using for decoding are as below:


void writeImageData(FILE *FpBmp)
{
long i;
char index;

if(containsPalette==1)
{
for(i=0; i<(ImageDataEntries); i++)
{
index=ImageData[i];
fputc((WinColorTable[index].rgbBlue),FpBmp);
fputc((WinColorTable[index].rgbGreen),FpBmp);
fputc((WinColorTable[index].rgbRed),FpBmp);
}
}
else
{
for(i=0; i<(ImageDataEntries); i++)
{
fputc(ImageData[i],FpBmp);
}
}
fclose(FpBmp);
}



ImageData[] contains the image data from the original file in which the image data were merely codes that were basically index into the palette.


Thanks


Samie

PrintDriver
08-10-2004, 02:28 AM
Why do this at all?

PrintDriver is a large format digital print dude. His advice/opinions may not apply to the 4color/offset/web world of printing

sghauri
08-10-2004, 02:19 PM
I am actually writing a device driver for an LCD screen (320x240) that is connected to Leon platform. THe driver will run on eCos. I have decided the specs and expect that the application running on top will pass on the addresses of the palette and the image codes which the driver will then decode and translate them into 24-bit form(i.e. 24 bits for each pixel).


I had to parse the BMP file and write the data back to test and demonstrate that the part of the driver that is translating the 8-bit data into 24-bit data is working fine. I had to do this as the hardware interface to the LCD is not ready yet.


Any suggestions?


Thanks


Samie


PS By the way, the problem that I was facing, I have figured it out. It was just that I was using variable 'index' as char and not unsigned char. Thus for elements with index greater than 127 were being translated by the compiler as 0 and that is why it was not decoding properly. Thanks for your interest in helping me out. :)

Ryan8720
08-10-2004, 10:04 PM
This is really the wrong forum for this type of work. Most of the people here are either graphic designers or printers. There are also some Web designers and Web programmers/scripters.

http://edgewebdesign.org/ryan2.gif (http://www.edgewebdesign.org)

'Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.'
- Albert Einstein