Solved

converting 24 bit bitmap into 8 bit bitmap

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Event ID 10010 3 60
How to use Dotfuscator CE with Visual Studio 2010 Installer? 4 295
Clean Uninstall of VS Professional 2015 5 52
T-SQL Debugging - Temp Object Content 2 54
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

809 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