Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!cornell!batcomputer!itsgw!imagine!pawl17.pawl.rpi.edu!kyriazis From: kyriazis@pawl17.pawl.rpi.edu (George Kyriazis) Newsgroups: comp.graphics Subject: Re: The 24-bit question. Message-ID: <512@imagine.PAWL.RPI.EDU> Date: 11 Mar 88 04:10:26 GMT References: <927@xn.LL.MIT.EDU> Sender: news@imagine.PAWL.RPI.EDU Reply-To: kyriazis@pawl17.pawl.rpi.edu (George Kyriazis) Organization: RPI Public Access Workstation Lab - Troy, NY Lines: 36 Keywords: color, colormaps In article <927@xn.LL.MIT.EDU> wjc@XN.LL.MIT.EDU (William J. Chiarchiaro) writes: >Does anyone know of an algorithm for doing the following: > > Take a digitized, color image composed of 24-bit pixels > (8 bits red, 8 bits green, 8 bits blue), and convert it to > an 8-bit-per-pixel color image along with a suitable > 256-entry colormap (each entry has 8 bits of red, 8 of green, > and 8 of blue). > >Thanks, >Bill >(reachable on Internet at wjc@xn.ll.mit.edu) I have written two different programs that do the thing that you ask for. They are written for color SUNs that they have a colormap of 256 entries. The first method is a bit stupid. You define, for example, 3 bits for red, 3 bits for green and 2 bits for blue (unfortunately 256 is 2^8 and not 2^9), take the 3 (or 2) most significant bits of the primary colors, create a byte out of it and index it to the colormap. In other words, the colormap is fixed. The other method is a bit smarter, but it depends on the size and the number of original colors of the image. You start with an empty colormap, and check each incoming pixel if its color is in the colormap. If it is, use that index as its color, else add it to the end of the colormap. Unfortunately for pictures bigger than 128*128 the colormap runs out pretty quickly, so you can try eliminating the 1,2 or how many you want least significant bits of the input data, until everything fits in the colormap. Of course you can elimimate a different number of bits for different primary colors. Hope that I helped you.. ******************************************************* *George C. Kyriazis * Gravity is a myth *userfe0e@mts.rpi.edu or userfe0e@rpitsmts.bitnet * \ / *Electrical and Computer Systems Engineering Dept. * \ / *Rensselear Polytechnic Institute, Troy, NY 12180 * || ******************************************************* Earth sucks.