Board index » delphi » Convert BMP of 24 bits to 8 bits

Convert BMP of 24 bits to 8 bits


2006-11-06 07:26:19 PM
delphi35
Hello,
I have a BMP of 24 bits that has a maximum of 32 colors used, how would
like to compress it to a 8 bit bitmap, any tips ?
thanks
John
 
 

Re:Convert BMP of 24 bits to 8 bits

John writes:
Quote
I have a BMP of 24 bits that has a maximum of 32 colors used, how would
like to compress it to a 8 bit bitmap, any tips ?
Since you know that there is <=256 colors, this should be fairly easy.
I'd look at using some sort of hashing structure to store the palette
index for each pixel. Just iterate over the pixels in the image, look up
in the hash table to see if they have been assigned an entry, if not,
allocate one and put back into the table.
Alternatively, if your bitmaps are small or speed is not an issue, you
could just use a 256-entry array and do a linear search for each pixel.
Cheers,
Nicholas Sherlock
--
www.sherlocksoftware.org
 

Re:Convert BMP of 24 bits to 8 bits

Thanks Nicholas!
 

Re:Convert BMP of 24 bits to 8 bits

Just curious ... what happens when you do Bitmap.PixelFormat := pf8bit ?
... you might expect it to do exactly what John wants but it doesn't.
Andrew
 

Re:Convert BMP of 24 bits to 8 bits

Andrew Jameson writes:
Quote
Just curious ... what happens when you do Bitmap.PixelFormat :=
pf8bit ? ... you might expect it to do exactly what John wants but it
doesn't.
Andrew
IIRC, by default it uses the Windows 256 colour palette, and may not give
pleasing results. it is certainly worth a test before writing much
code....
David
 

Re:Convert BMP of 24 bits to 8 bits

John writes:
Quote
I have a BMP of 24 bits that has a maximum of 32 colors used, how would
like to compress it to a 8 bit bitmap, any tips ?
TGifImage.ReduceColors();
 

Re:Convert BMP of 24 bits to 8 bits

John writes:
Quote
Hello,

I have a BMP of 24 bits that has a maximum of 32 colors used, how would
like to compress it to a 8 bit bitmap, any tips ?

thanks

John
Use the below newsgroup algorithm.
www.efg2.com/Lab/Library/UseNet/1999/0801a.txt