Stretch draw issue with TBitmap Canvas (Linux gtk2 only)
- Lazarus/FPC Version: Lazarus 3.99 (rev main_3_99-2316-g00f3d3b397) FPC 3.3.1 x86_64-linux-gtk2
- Operating System: Linux Ubuntu 22.04 64-bit
- CPU / Bitness: x86_64
Preliminary note
This bug only occurs on Linux gtk2, not on qt5, not on Windows. The bug was reproduced by wp in https://forum.lazarus.freepascal.org/index.php/topic,68146.0.html Probably iLya2IK found the reason, why and where the bug occors in reply 7 of this Topic. The code shown by iLya2IK there was added in issue #8553 (closed).
What happens
The attached demo draws something on a TBitmap and then calls 'TPaintBox.Canvas.StretchDraw' to draw this TBitmap on a TPaintBox. If you use 'TBitmap.PixelFormat:=pf32bit' then depending on the Bitmap size this works or works not. Without 'TBitmap.PixelFormat:=pf32bit' this bug does not occur.
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
bmp: TBitmap;
i: integer;
begin
writeln('Event PaintBox1Paint fired');
bmp := TBitmap.Create;
try
bmp.PixelFormat := pf32bit; {only with this line the bug occurs}
i:=1; {'0' causes the bug, '+1' and '-1' work}
bmp.SetSize(1000+i, 1000+i);
bmp.Canvas.Brush.Color := clRed;
bmp.Canvas.FillRect(0, 0, bmp.Width div 2, bmp.Height);
bmp.Canvas.Brush.Color := clYellow;
bmp.Canvas.FillRect(bmp.Width div 2, 0, bmp.Width, bmp.Height);
Caption := FormatFloat('0.000', bmp.RawImage.DataSize/bmp.RawImage.MaskSize);
Paintbox1.Canvas.StretchDraw(Rect(0, 0, Paintbox1.Width, Paintbox1.Height), bmp);
finally
bmp.Free;
end;
end;
What did you expect
The attached demo should also work with TBitmap.PixelFormat:=pf32bit;
Steps to reproduce
- compile and run the attached project
- result: you see a TPaintBox which is half red and yellow (the bug did NOT occur)
- edit line 41 (of the attached project) to be 'i:=0' instead of 'i:=1'
- compile and run the project
- result: you see a TPaintBox which is completely gray (the bug occured)
- insert '//' in front of line 40 to deactivate 'bmp.PixelFormat:=pf32bit'
- compile and run the project
- result: you see the TPaintBox which is again half red and yellow (the bug disappeared)