I want to convert a truecolor bitmap with HandleType bmDIB and PixelFormat pf24Bit into a 256 grayscale with PixelFormat pf8Bit.
I have a function for converting a pf24Bit bitmap to grayscale
I want to convert this to a procedure of the form:
procedure ConvertColorToGrayScale(const Bmp24: TBitmap, var Bmp8: TBitmap);
where Bmp8 is the output bitmap in pf8Bit format.
The main question I have is how do I set up the palette for the output bitmap to be a 256 grayscale?
Bob
I have a function for converting a pf24Bit bitmap to grayscale
Code:
procedure ConvertBmpToGrayscale(var Bmp: TBitmap);
const
MaxPixelCount = 32768;
type
pRGBArray = ^TRGBArray;
TRGBArray = ARRAY[0..MaxPixelCount-1] of TRGBTriple;
var
I, J, Lum: Integer;
Row: pRGBArray; // Scanline
begin
for J := 0 to Bmp.Height - 1 do
begin
Row := Bmp.ScanLine[j];
for I := 0 to Bmp.Width - 1 do
begin
Lum := MyRound(0.299 * Row[I].rgbtRed + 0.587 * Row[I].rgbtGreen +
0.114 * Row[I].rgbtBlue);
Row[I].rgbtRed := Lum;
Row[I].rgbtGreen := Lum;
Row[I].rgbtBlue := Lum;
end;
end;
end;
I want to convert this to a procedure of the form:
procedure ConvertColorToGrayScale(const Bmp24: TBitmap, var Bmp8: TBitmap);
where Bmp8 is the output bitmap in pf8Bit format.
The main question I have is how do I set up the palette for the output bitmap to be a 256 grayscale?
Bob