Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-04

TImageList.AddMasked not working with TBitmap.PixelFormat := pf32bit

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Boian Mitov

Hi Folks,

I am testing the:
Lazarus-0.9.27-19324-fpc-2.2.5-20090411-win32.exe
snapshot. I have had a bug that has been around for many months, and finally had time to investigate it in this snapshot.

The TImageList.AddMasked does not work correctly with TBitmap.PixelFormat := pf32bit; . It works with pf24bit but not with pf32bit.

Here is a demo code that shows the bug:

procedure TForm1.PaintBox2Paint(Sender: TObject);
var
  ABitmap : TBitmap;
  AImgeList : TImageList;
begin
  AImgeList := TImageList.Create( NIL );
  AImgeList.Width := 16;
  AImgeList.Height := 16;
  ABitmap := TBitmap.Create();
  ABitmap.Width := 16;
  ABitmap.Height := 16;
  ABitmap.PixelFormat := pf32bit;
//  ABitmap.PixelFormat := pf24bit;
  ABitmap.Canvas.Brush.Color:= clRed;
  ABitmap.Canvas.FillRect( 0, 0, 16, 16 );
  ABitmap.Canvas.Brush.Color:= clBlue;
  ABitmap.Canvas.Ellipse( 0, 0, 16, 16 );
  AImgeList.AddMasked( ABitmap, clRed );
  AImgeList.Draw( PaintBox2.Canvas, 10, 10, 0, True );
  ABitmap.Free();
  AImgeList.Free();
end;
Even worse, after ABitmap is drawn, I can't set the ABitmap.PixelFormat := pf24bit; . If I do that the image gets erased. It is not converted. The only workaround I have found is using a temporary bitmap to draw on and then use that one to populate the ImageList.

With best regards,
Boian Mitov

------------------------------------------------------- Mitov Software
www.mitov.com
------------------------------------------------------- -------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090412/9f09a41b/attachment.html

Reply by email

Marc Weustink
to Boian Mitov
Boian Mitov wrote 10 lines
Hi Folks, I am testing the: Lazarus-0.9.27-19324-fpc-2.2.5-20090411-win32.exe snapshot. I have had a bug that has been around for many months, and finally had time to investigate it in this snapshot. The TImageList.AddMasked does not work correctly with TBitmap.PixelFormat := pf32bit; . It works with pf24bit but not with pf32bit.

there is not a good reason to add a 32bit alpha image using a mask. Anyway, in the current implementation, the added images are converted first. This is still a todo to fix.

Marc

Reply by email

Boian Mitov
to Marc Weustink

Hi Mark,

Thank you!
The reason I need to use pf32bit is that I manipulate the raw image, and I access the pixels as integers. I can't do that if the image is 24 bit. I actually don't care about the Alpha channel in this case.

  AScanLineImage:=TLazIntfImage.Create(0,0);
  AImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB(Images.Width,Images.Height);
  AScanLineImage.DataDescription := AImgFormatDescription;
    for Y :=0 to AScanLineImage.Height-1 do
      begin
      Ptr := AScanLineImage.GetDataLineStart( Y );
      for X := 0 to AScanLineImage.Width-1 do
        begin
        AColor := TColor( Ptr^ and $FFFFFF );
         if( AColor = clWhite ) then
          Ptr^ := AGlyphColor
        else if( AColor = clGray ) then
          Ptr^ := ABorderColor
        else if( ASecondaryArea and ( AColor = clRed )) then
          Ptr^ := ABorderColor
        else if( AColor = clLtGray ) then
          Ptr^ := AHalfToneColor
        else if( AColor = clBlack ) then
          Ptr^ := AButtonColor
   ....
   ....
    AIntfImage.CopyPixels( AScanLineImage );
    ABitmap.LoadFromIntfImage( AIntfImage );
    Images.ReplaceMasked( ImageIndex, ABitmap, InvertColor( AUniqueColor ));

As you can see I need this so I can access the pixels fast as a raw image, and need to get the image back. This is significantly more complex in 24 bit image, so the need for 32 bit image being added as masked is obvious.

With best regards,
Boian Mitov

------------------------------------------------------- Mitov Software
www.mitov.com
-------------------------------------------------------

Earlier message 11 lines
----- Original Message ----- From: "Marc Weustink" To: "General mailing list" Sent: Tuesday, April 14, 2009 1:29 AM Subject: Re: [Lazarus] TImageList.AddMasked not working with TBitmap.PixelFormat := pf32bit > there is not a good reason to add a 32bit alpha image using a mask. > Anyway, in the current implementation, the added images are converted > first. This is still a todo to fix.

Reply by email