From fa8e8eeecfdbc16be6a55862af02b39c8b55c492 Mon Sep 17 00:00:00 2001 From: Abou Al Montacir Date: Fri, 24 Nov 2023 19:10:17 +0100 Subject: [PATCH] GTK3: Fixed rendering of images using 24 bits per pixel. Closes: #40374. Thanks To: Anton Kavalenka. When the image is stored in a buffer using 24 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 for 32 bit images. --- lcl/interfaces/gtk3/gtk3lclintf.inc | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lcl/interfaces/gtk3/gtk3lclintf.inc b/lcl/interfaces/gtk3/gtk3lclintf.inc index a116b44f68..e3ba82b7d1 100644 --- a/lcl/interfaces/gtk3/gtk3lclintf.inc +++ b/lcl/interfaces/gtk3/gtk3lclintf.inc @@ -230,6 +230,44 @@ begin GetMem(NewData, ArawImage.DataSize); + if desc.BitsPerPixel = 1 then + begin + DbgS('Bit depth not implemented '+inttostr(desc.BitsPerPixel)); + end + else if desc.BitsPerPixel = 8 then + begin + DbgS('Bit depth not implemented '+inttostr(desc.BitsPerPixel)); + end + else if desc.BitsPerPixel = 16 then + begin + DbgS('Bit depth not implemented '+inttostr(desc.BitsPerPixel)); + end + else if (desc.BitsPerPixel = 24) and ((Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3)) then + begin + // put components in right order + DstRowPtr := NewData; + SrcRowPtr := ArawImage.Data; + y := Desc.Height; + while y > 0 do + begin + Src := SrcRowPtr; + Dst := DstRowPtr; + x := Desc.Width; + while x > 0 do + begin + Dst[0] := Src[Ridx]; + Dst[1] := Src[Gidx]; + Dst[2] := Src[Bidx]; + + Inc(Src, 3); + Inc(Dst, 3); + Dec(x); + end; + Inc(SrcRowPtr, ARowstride); + Inc(DstRowPtr, ARowstride); + Dec(y); + end; + end else if (Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3) then begin // put components in right order