Solved

converting 24 bit bitmap into 8 bit bitmap

Posted on 2001-08-12
2
316 Views
Last Modified: 2013-12-03
Hi,

I am looking to convert a 24 bit bitmap to 8 bit bitmap.
Do you know a way to do that without dithering, other than comparing the rgb (finding the minimal sum of diferrences between the red blue and green)?
0
Comment
Question by:yariv_e
2 Comments
 
LVL 5

Expert Comment

by:robpitt
Comment Utility
I'm not 100% sure what you are asking but obviously all colour reduction algorithms attempt to minimising the difference between the 24bit source and 8bit result.

The only question is what quantity they actualy strive to minimise.

Generally it will be a 'sum of differences' or 'root of sum of differences squared' and this will be performed either in RGB or HSV colour space.

In some algorithms the sum is performed on an individual pixel, in others its performed over a group of nearby pixels.
0
 
LVL 3

Accepted Solution

by:
JackThornton earned 100 total points
Comment Utility
With or without dithering, you need to at some point compare your target color against your palette. The process of dithering allows you to disperse errors over a range of pixels so that (thinking of both bitmaps as signals) the average energy of the destination stays as close as possible to the source.

You don't say whether you have to map to a "standard" palette or to different palettes every time. A way to make the problem more tractable, in terms of speed and quality, is to (a) use a standard halftone palette that represents the widest possible range of colors, and (b) generate a lookup table to go along with the standard palette.

To use a lookup table, you peel off low-order bits from R, G and B and "paste together" the high-order bits to create an index. For example, to create a 256-entry table, you might compose an index of rrrgggbb. For a little easier coding (at the expense of filling up a page of RAM!) you can put together a 12-bit index rrrrggggbbbb into a 4096 byte table. If your halftone table favors green and red differences over blue (there are good reasons for this), then you can adjust the index to include more bits of green and red than blue to take advantage of increased green or red resolution of the halftone palette. For best speed, you can drop down into inline assembly; however, 'C' is perfectly adequate (if a bit slower) for doing these kinds of bit manipulations:
e.g.
int index = (blue & 0x0f) | (green & 0xf0) | ((red & 0xf0) << 4);

Even if you have to use different palettes, you can build a lookup table on the fly by doing difference-squared analysis of all possible indices for your selected table size and, if your bitmap is large enough (e.g. more pixels than the size of your table, which isn't too difficult) it will be faster than doing difference-squared analysis on every bloody pixel of the bitmap.

hope this helps

- jack
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now