Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert pf24Bit truecolor bitmap to pf8Bit grayscale

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
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

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top