Solved

converting 24 bit bitmap into 8 bit bitmap

Posted on 2001-08-12
2
317 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
ID: 6377042
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
ID: 6386845
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

15 Experts available now in Live!

Get 1:1 Help Now