From cefed8929d734f87c60003818a41280aa6d19ff2 Mon Sep 17 00:00:00 2001 From: Abou Al Montacir Date: Sun, 25 Jun 2023 11:37:37 +0200 Subject: [PATCH] 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. --- .../AggPas_LCLDemo1_example/AggPasInLCLDemo1.lpr | 1 + lcl/interfaces/gtk3/gtk3lclintf.inc | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/aggpas/lazarus/example/AggPas_LCLDemo1_example/AggPasInLCLDemo1.lpr b/components/aggpas/lazarus/example/AggPas_LCLDemo1_example/AggPasInLCLDemo1.lpr index a5bced53cf..a771bc6695 100644 --- a/components/aggpas/lazarus/example/AggPas_LCLDemo1_example/AggPasInLCLDemo1.lpr +++ b/components/aggpas/lazarus/example/AggPas_LCLDemo1_example/AggPasInLCLDemo1.lpr @@ -13,6 +13,7 @@ uses {$R *.res} begin + Application.Title := ''; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; diff --git a/lcl/interfaces/gtk3/gtk3lclintf.inc b/lcl/interfaces/gtk3/gtk3lclintf.inc index 5f0c5d5280..9c5c5a2365 100644 --- a/lcl/interfaces/gtk3/gtk3lclintf.inc +++ b/lcl/interfaces/gtk3/gtk3lclintf.inc @@ -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,