Change bitmap color depth

zhaozj2021-02-08  284

Changing Bitmaps Color Depth

This Article WAS Contributed by

Gerd Esser, Germany.

ENVIRONMENT: MSVC 6.0

The basic problem of this code was to decrease a color depth of great bitmaps (like 8000 x 8000 pixels) to - for example - 4 bits per pixel and solving nearly (! See below) the original color palette The first attempt was to use. . the method as shown in DDBtoDIB But such great bitmaps produce an error: They do nothing sencefull in functions like GetDIBits So I handle the bitmap in bands of smaller bitmap data and make direct file reading / saving operations of the bitmaps..

Because of the internal mapping of the color palette to the system palette I got some strange results. Also, by realizing the whole number of really used colors, I ve got another problem with the previous banding of the bitmap, which show me only a small PART of The Second Problem. SO I CREATE A Color Prette by Counting and adding the color.

A small problem still remains:. By mapping the source bitmap into memory, the color palette can not be solved exactly If the color palette can not be mapped into the system palette, the result color palette may differ by a view percent But I did not. Spending more Time To this Fact Because The Present Solution Was Sufficient for me.

The Result Is A Class Bitmaplib with Two (Static) Methods, ChangeColorDepth () and getusedcolors ().

Bool CBitmaplib :: Changecolordepth (CString Const & Stsrcbitmapfile,

CString Const & StdStBitmapFile,

Word const wdstbitPit,

CPROGRESSCTRL * PPROGRESSCTRL = NULL);

ChangeColorDepth () changes a color depth of a file based bitmap and saves the result into a destination file. The operation is done by increasing or decreasing the bits per pixel through the whole range from 1 to 32 (thus converting also from device dependent into device independent or the way back). The progress control is only used if nescessary and showing the work progress (great bitmaps last a few seconds ...) int CBitmapLib :: GetUsedColors (CString const & stSrcBitmapFile,

Rgbquad * pcolortable,

Word Const Wmaxcolortables,

CPROGRESSCTRL * PPROGRESSCTRL = NULL);

INT cBitmaplib :: getusedcolors (BitmapInfo Const * PBMI,

Byte const * PBITS,

Uint const nstartscanline,

Uint const nscanlines,

Rgbquad * pcolortable,

Word Const Wmaxcolortables,

Word & WusedColors;

A byproduct of the operation changecolorDepth () is The method getusedcolors (), Which Count The Really Bused Colors and Products A Color Table of The Used Colors.

Both Methods Abort Its Operation, IF The Destination Color Depth IS Not Sufficient Enough for the number of buy colors in the source bitmap.

Downloads

Download Source - 6 KB

HistoryDate Posted: February 6, 2001

转载请注明原文地址:https://www.9cbs.com/read-2575.html

New Post(0)