Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

converting 24 bit bitmap into 8 bit bitmap

Posted on 2001-08-12
2
Medium Priority
?
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 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