🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.misc
Article #122

Re: Reduce number of colors of a bitmap

#122
From: Earl F. Glynn
Date: Sun, 06 Dec 1998 00:00
40 lines
2866 bytes
Stefan Cruysberghs wrote in message <74btm3$lop$1@xenon.inbe.net>...
>Where can I find some routines to reduce the number of colors of a bitmap ?
>I want to convert a 24bit bitmap to 256 color or 16 colors bitmap.


The "Show Demo One" Lab Report in my Computer Lab shows how to compute the "optimal" palette for  a single 24 bit bitmap for display
in 256 color mode.
www.efg2.com/lab/Graphics/Colors/ShowDemoOne.htm

The "Show Demo Many" Lab Report shows how to compute the "optimal" palette for a displaying a number of 24 bit bitmaps on a single
form in 256 color mode.
www.efg2.com/lab/Graphics/Colors/ShowDemoMany.htm

Both of the Lab Reports have the complete Delphi source code.

While these palettes are called "optimal" they are really just derived using some good heuristics that seem to work well for many
images.  Please understand that this can be quite a challenge.  A single image can have thousands of colors.  The well-known
"Mandrill Monkey" image has 230,427 unique colors  when the image only contains 262,144 pixels!  Picking the "best" 236 colors
(since Windows reserves 20) for display in 256 color mode can be quite a challenge.  (The Show Image Lab Report has a program
including source code that counts the unique RGB colors in an image:
www.efg2.com/lab/Graphics/Colors/ShowImage.htm )  You best bet is to use high color (15/16-bit) or true color (24-bit) display
modes -- then you never need to worry about palettes.

While the "Show Demo" examples compute an "optimal" palette for display, these programs do not take the final step of converting the
pf24bit scanlines into pf8bit scanlines where each pixel is an index into the "optimal" palette.  Several have requested this
addition, but I just haven't had the time to get to it yet.

There is a great deal of Color Quantization information in Section B of the page
www.efg2.com/lab/Library/Color.htm

In particular the "Octree Color Quantization" code by I. Ashdown (but in C++) shows how to reduce a pf24bit bitmap to a pf8bit
bitmap.

efg
_________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGlynn@att.net
Overland Park, KS  USA
Technical Details
Message-ID: <74d2vg$p8q@bgtnsc02.worldnet.att.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <74btm3$lop$1@xenon.inbe.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10a296,c092edb04936f86f,start
X-Google-Attributes: gid10a296,public
X-Google-Thread: 10baee,9f2025fdc5a29c82
X-Google-Attributes: gid10baee,public
From: "Earl F. Glynn" <EarlGlynn@att.net>
Subject: Re: Reduce number of colors of a bitmap
Date: 1998/12/06
Message-ID: <74d2vg$p8q@bgtnsc02.worldnet.att.net>
X-Deja-AN: 419136836
References: <74btm3$lop$1@xenon.inbe.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
Organization: AT&T WorldNet Services
Newsgroups: comp.lang.pascal.delphi.misc,borland.public.delphi.graphics