Solved

converting 24 bit bitmap into 8 bit bitmap

Posted on 2001-08-12
2
319 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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