GTK3: Fixed rendering of images using 32 bits per pixel.

Closes: #40337. Thanks To: Anton Kavalenka.

When the image is stored in a buffer using 32 bits per pixel, we don't
need to copy pixel by pixel unless the components order is wrong.
We can use `System.move` in this case.
This is the same thing that is used in GTK2.
This commit is contained in:
Abou Al Montacir 2023-06-25 11:37:37 +02:00 committed by Maxim Ganetsky
parent 45f3de24a3
commit cefed8929d
2 changed files with 9 additions and 5 deletions

View File

@ -13,6 +13,7 @@ uses
{$R *.res}
begin
Application.Title := '';
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;

View File

@ -230,8 +230,7 @@ begin
GetMem(NewData, ArawImage.DataSize);
//if (Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3) then
if desc.Depth=32 then
if (Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3) then
begin
// put components in right order
@ -258,6 +257,8 @@ begin
Inc(DstRowPtr, ARowstride);
Dec(y);
end;
end else begin
System.Move(ArawImage.Data^, NewData^, ArawImage.DataSize);
end;
end
@ -265,11 +266,13 @@ begin
NewData := nil;
// this is only a rough implementation, there is no check against bitsperpixel
case Desc.Depth of
case Desc.BitsPerPixel of
1: ImageFormat := CAIRO_FORMAT_A1;
8: ImageFormat := CAIRO_FORMAT_A8;
else
ImageFormat := CAIRO_FORMAT_ARGB32;
24: ImageFormat := CAIRO_FORMAT_RGB24;
32: ImageFormat := CAIRO_FORMAT_ARGB32;
else
Exit(False);
end;
ARowStride := GetBytesPerLine(Desc.Width, Desc.BitsPerPixel, rileDWordBoundary);
ABitmap := HBitmap(TGtk3Image.Create(NewData, Desc.Width, Desc.Height, ARowStride, ImageFormat,