Archived

This topic is now archived and is closed to further replies.

Viperxxy

Convert 24Bit to 8Bit

Recommended Posts

Mihail121    100
Ok here is the help:

the convertion depends on your needs.If you need grayscale data simply loop through all RGB tripples and find their average.Here is sample code:



long stride = width * 3;

for(int i = 0;i < height;i++)
{
for(int j = 0;j < width;j++)
{
new_data[i*width+j] = rgb_data[i*width+(j*3+0)] +
rgb_data[i*width+(j*3+1)] +
rgb_data[i*width+(j*3+2)]);
new_data[i*width+j] /= 3;
}
}



If you want paletted 8 bit data the stuff gets complicated.You must make a table with 256 indices where u''ll have to store the most important RGB tripplets of the RGB data.Of the rules will be to store the to store tripplets with big difference.I.E u shoudn''t store RGB(255,0,0) and RGB(254,0,0) if there is RGB(253,0,0).

"Tonight we strike,there is thunder in the sky,together we''ll fight,some of us will die,but they''ll always remember that we''ve made a stand and many will die by hand!" - ManOwaR

Share this post


Link to post
Share on other sites
Zipster    2359
NeuQuant. One of the best color quantization algorithms out there, used to create a full 8-bit palette from a 24-bit image. I''ve used it with great success. Best of all, source code included

Otherwise if you already have the palette and are looking for the closes index, imagine each RGB values as being XYZ coordinates and find the index with the smallest 3D distance from the color you have.

Share this post


Link to post
Share on other sites