From: "Andrew Rybenkov"
To: "Earl F. Glynn"
Subject: ColorQuantizationLibrary: little additions
Date: Mon, 18 Nov 2002 12:19:16 +0300
Hi, Earl.
First of all, maybe you would like to know that I have used the unit in that my Imagizer program.
(release with its implementation will be available in a week).
I made the next changes to it, that you may want to add to your original as well:
1) (changed)
--------------------------------------------------------
PROCEDURE Process24BitDIB;
[...]
BEGIN
Scanline := pRGBArray(DIBSection.dsBm.bmBits);
FOR j := 0 TO DIBSection.dsBmih.biHeight-1 DO
---------------------------------------------------------
FOR j := 0 TO Abs(DIBSection.dsBmih.biHeight)-1 DO
as biHeight can be negative (for top->bottom) bitmaps. Personally I always set negative height of a bitmap.
2) (added implementation of Process32BitDIB by trivial copying of Process24BitDIB routine):
[declairing new type]
---------------------------------------------------------
FUNCTION TColorQuantizer.ProcessImage(CONST Handle: THandle): BOOLEAN;
CONST
MaxPixelCount = 1048576; // 2^20 = 1MB shouldn't be much of a limit here
TYPE
pRGBArray = ^TRGBArray;
TRGBArray = ARRAY[0..MaxPixelCount-1] OF TRGBTriple;
---------------------------------------------------------
pARGBArray = ^TARGBArray;
TARGBArray = ARRAY[0..MaxPixelCount-1] OF TRGBQuad;
and further
PROCEDURE Process32BitDIB;
VAR
i : INTEGER;
j : INTEGER;
ScanLine: pARGBArray;
BEGIN
Scanline := pARGBArray(DIBSection.dsBm.bmBits);
FOR j := 0 TO Abs(DIBSection.dsBmih.biHeight)-1 DO
BEGIN
FOR i := 0 TO DIBSection.dsBmih.biWidth-1 DO
BEGIN
WITH Scanline[i] DO
AddColor(FTree, rgbRed, rgbGreen, rgbBlue,
FColorBits, 0, FLeafCount, FReducibleNodes);
WHILE FLeafCount > FMaxColors DO
ReduceTree(FColorbits, FLeafCount, FReducibleNodes)
END;
ScanLine := pARGBArray(INTEGER(Scanline) + DIBSection.dsBm.bmWidthBytes);
END
END {Process32BitDIB};
Some time later I am going to optimize slightly the unit for speed.
If you have interest in it, please, let me know.
Thanks for great site, and
best wishes,
Andrew Rybenkov.