*****************************************************} { } { Delphi VCL Extensions (RX) } { } { Copyright (c) 1997 Master-Bank } { } {
BitmapToMemory - !!!
BitmapToMemoryStream - Change bits per pixel in a General Bitmap
GetBitmapPixelFormat -
GetPaletteBitmapFormat - expand to 24 bits-per-pixel } (*
procedure ExpandTo24Bit(const Header: TBitmapInfoHeader; Colors: TRGBPalette;
Data, NewData: Pointer);
var
Scanline, NewScanline: Longint;
Y, X: Integer;
Src, Dest: Pointer;
C: Byte;
begin
if Header.
GrayscaleBitmap -
SaveBitmapToFile -
ScreenColorCount -
ScreenPixelFormat -
SetBitmapPixelFormat -
TMappingMethod
TPixelFormat
DefaultMappingMethod
function BitmapToMemory(Bitmap: TBitmap; Colors: Integer): TStream;
!!!
function BitmapToMemoryStream(Bitmap: TBitmap; PixelFormat: TPixelFormat;
Method: TMappingMethod): TMemoryStream;
Change bits per pixel in a General Bitmap
function GetBitmapPixelFormat(Bitmap: TBitmap): TPixelFormat;
function GetPaletteBitmapFormat(Bitmap: TBitmap): TPixelFormat;
expand to 24 bits-per-pixel } (*
procedure ExpandTo24Bit(const Header: TBitmapInfoHeader; Colors: TRGBPalette;
Data, NewData: Pointer);
var
Scanline, NewScanline: Longint;
Y, X: Integer;
Src, Dest: Pointer;
C: Byte;
begin
if Header.biBitCount = 24 then begin
Exit;
end;
Scanline := ((Header.biWidth * Header.biBitCount + 31) div 32) * 4;
NewScanline := ((Header.biWidth * 3 + 3) and not 3);
for Y := 0 to Header.biHeight - 1 do begin
Src := HugeOffset(Data, Y * Scanline);
Dest := HugeOffset(NewData, Y * NewScanline);
case Header.biBitCount of
1:
begin
C := 0;
for X := 0 to Header.biWidth - 1 do begin
if (X and 7) = 0 then begin
C := Byte(Src^);
Src := HugeOffset(Src, 1);
end
else C := C shl 1;
PByte(Dest)^ := Colors[C shr 7].rgbBlue;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 7].rgbGreen;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 7].rgbRed;
Dest := HugeOffset(Dest, 1);
end;
end;
4:
begin
X := 0;
while X < Header.biWidth - 1 do begin
C := Byte(Src^);
Src := HugeOffset(Src, 1);
PByte(Dest)^ := Colors[C shr 4].rgbBlue;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 4].rgbGreen;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 4].rgbRed;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C and 15].rgbBlue;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C and 15].rgbGreen;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C and 15].rgbRed;
Dest := HugeOffset(Dest, 1);
Inc(X, 2);
end;
if X < Header.biWidth then begin
C := Byte(Src^);
PByte(Dest)^ := Colors[C shr 4].rgbBlue;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 4].rgbGreen;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C shr 4].rgbRed;
{Dest := HugeOffset(Dest, 1);}
end;
end;
8:
begin
for X := 0 to Header.biWidth - 1 do begin
C := Byte(Src^);
Src := HugeOffset(Src, 1);
PByte(Dest)^ := Colors[C].rgbBlue;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C].rgbGreen;
Dest := HugeOffset(Dest, 1);
PByte(Dest)^ := Colors[C].rgbRed;
Dest := HugeOffset(Dest, 1);
end;
end;
end;
end;
end;
*) { DIB utility routines
procedure GrayscaleBitmap(Bitmap: TBitmap);
procedure SaveBitmapToFile(const Filename: string; Bitmap: TBitmap;
Colors: Integer);
function ScreenColorCount: Integer;
function ScreenPixelFormat: TPixelFormat;
procedure SetBitmapPixelFormat(Bitmap: TBitmap; PixelFormat: TPixelFormat;
Method: TMappingMethod);
TMappingMethod = (mmHistogram, mmQuantize, mmTrunc784, mmTrunc666,
mmTripel, mmGrayscale);
TPixelFormat = (pfDevice, pf1bit, pf4bit, pf8bit, pf24bit);
DefaultMappingMethod = mmHistogram