Jump to content
  • Advertisement

Archived

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

Viperxxy

Convert 24Bit to 8Bit

This topic is 5585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, it may sound stupid but I can''t figure out how to convert an 24Bit-RGB pixel to 8 Bit. Hope someone can help me, please.

Share this post


Link to post
Share on other sites
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!