Thread: Trouble converting 24 bit image to 8 bit image...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    Exclamation Trouble converting 24 bit image to 8 bit image...

    I can read and write the bitmap files just fine, but say I have now a large array of dwords (the dib's pixels) and I need to figure out what 256 colors I can use out of how ever many the 24-bit image has.

    I made an algorithim that uses the colors that occure most often in the bitmap. But I quickly learned that it's not good enough.

    I would link to make my program capable of acceptable 24 to 8 bit coversion. Like Corel Photo-Paint can do. Does anyone know how to make an algorithim that can do this good? I have done alot of googling, but I can't find anything.

    Please help.
    Yarin.

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    If you want to convert the bmp without a pallette this is pretty easy. Basically each byte would then hold the complete rbg value. the high 2 bits would be red, middle three green and the last two bits blue.

    I'm not sure how coral paint make 8 bit bitmaps but if you are using a palette png format would be better.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    It's no easy task.

    If I remember correctly, Adobe photoshop, has 3 separate algorithms, for choosing a pallette, not inclding the predefined pallettes.

    Really, you should get an image editor to do this properly for you.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What you want to Google is "dither algorithm".

    gg

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This is an absolutely fantastic article on dithering and colour palette reduction:
    http://en.wikipedia.org/wiki/Dither

    I believe the thing you asked about however is colour quantization, for which I'll point you at the folowing equally fantastic link:
    http://en.wikipedia.org/wiki/Color_quantization

    I highly suggest reading both!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Pallette optimization is a quite interesting field. You need to choose between speed and quality, as the best algorithms usually take the longest time. Its also easier to optimize a high resolution image than a low resolution one.

  7. #7
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Thanks for the replys, but I already found out what to do. I created my own version of the Octree Quantization method, and it works sweet! Almost as good as Corel PP in fact.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, how to convert a grayscale image into 8 bit image?
    By Alexanderbinich in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2005, 07:50 PM
  2. Replies: 6
    Last Post: 03-03-2005, 03:52 AM
  3. having a bit of trouble
    By principii in forum C Programming
    Replies: 3
    Last Post: 09-15-2004, 02:19 PM
  4. Please help with my game
    By jjj93421 in forum Game Programming
    Replies: 10
    Last Post: 04-12-2004, 11:38 PM