TPortableNetworkGraphic ScanLine property does not correctly work with certain image sizes, also R and B pizels are sometimes s
Original Reporter info from Mantis: sysrpl
-
Reporter name: Anthony Walter
Original Reporter info from Mantis: sysrpl
- Reporter name: Anthony Walter
Description:
When developing my Image Shop example program I have encountered the following bugs with TPortableNetworkGraphic property on Linux using the Gtk2 widgetset.
If you attempt to write pixel values to a 32 bpp TPortableNetworkGraphic on Linux 64 bit with the gtk2 toolkit the colors of the image are corrupted if the image width falls within certain values. In the "Steps To Reproduce" is an example program demonstrating the problem.
When the Width is set to a value of 400, the image appears as fuschia image and is correct.
When the Width is set to a value of 300, the image appears as a series of vertical bars.
See attached screen shot.
https://cache.getlazarus.org/images/png_error.png
Additionally, the red, green, blue and alpha components occasionally swap red and blue components. This problem occurs on various systems without any reason. Sometimes even changing red and blue values on the same computer with no changes to code. This problem can occur without accessing the ScanLine property. Sometimes simple loading and drawing a TPortableNetworkGraphic shows an image with the red and blue components visually reversed.
Steps to reproduce:
unit Unit1;
{$mode delphi}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
{ TForm1 }
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
FImage: TPortableNetworkGraphic;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
type
TPixel = record B, G, R, A: Byte; end;
PPixel = ^TPixel;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
A: PPixel;
I: Integer;
begin
FImage := TPortableNetworkGraphic.Create;
FImage.Width := 300; // works correctly if Width is 400
FImage.Height := 300;
FImage.PixelFormat := pf32bit;
A := FImage.ScanLine[0];
for I := 1 to FImage.Width * FImage.Height do
begin
A.R := $FF;
A.G := 0;
A.B := $FF;
A.A := $FF;
Inc(A);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FImage.Free;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Draw(0, 0, FImage);
end;
end.
Mantis conversion info:
- Mantis ID: 35553
- OS: Ubuntu
- OS Build: 16.04 64bit
- Platform: Linux
- Version: 2.0.2
- Monitored by: » AntonK (Anton Kavalenka)