From 0e876bd527f765ef95f929f84b38ea45651826b9 Mon Sep 17 00:00:00 2001 From: zeljko Date: Mon, 6 Feb 2012 11:17:02 +0000 Subject: [PATCH] Gtk, Gtk2: fixed drawing bitmaps with pf32bit. issue #8553 git-svn-id: trunk@35177 - --- lcl/interfaces/gtk/gtklclintf.inc | 15 ++++++++++++++- lcl/interfaces/gtk2/gtk2lclintf.inc | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lcl/interfaces/gtk/gtklclintf.inc b/lcl/interfaces/gtk/gtklclintf.inc index 6f57392e28..31f4be52a2 100644 --- a/lcl/interfaces/gtk/gtklclintf.inc +++ b/lcl/interfaces/gtk/gtklclintf.inc @@ -250,10 +250,12 @@ var Data: Pointer; Src, Dst, SrcRowPtr, DstRowPtr: PByte; x, y: Cardinal; + CreateWithAlpha: boolean; begin Result := False; ABitmap := 0; AMask := 0; + CreateWithAlpha := True; if ImgWidth = 0 then Exit; if ImgHeight = 0 then Exit; @@ -343,10 +345,21 @@ begin end else begin // components are in place + + // gtkPixbuf doesn't like invalid dataSize/MaskSize < 32. issue #8553. + if (ARawImage.MaskSize > 0) and (ImgDepth = 32) then + begin + CreateWithAlpha := Trunc(ARawImage.DataSize / ARawImage.MaskSize) = 32; + {$IFDEF VerboseRawImage} + if not CreateWithAlpha then + DebugLn('TGtkWidgetSet.CreateBitmapFromRawImage B WARNING: This image have invalid DataSize / MaskSize.'); + {$ENDIF} + end; Data := ImgData; end; - TmpPixBuf := gdk_pixbuf_new_from_data(Data, GDK_COLORSPACE_RGB, True, 8, ImgWidth, ImgHeight, RowStride, nil, nil); + TmpPixBuf := gdk_pixbuf_new_from_data(Data, GDK_COLORSPACE_RGB, CreateWithAlpha, + 8, ImgWidth, ImgHeight, RowStride, nil, nil); // we need to copy our pixbuf into a new one to allow data deallocation Pixbuf := gdk_pixbuf_copy(TmpPixBuf); gdk_pixbuf_unref(TmpPixBuf); diff --git a/lcl/interfaces/gtk2/gtk2lclintf.inc b/lcl/interfaces/gtk2/gtk2lclintf.inc index ea3b8fbc7a..05dab26ce2 100644 --- a/lcl/interfaces/gtk2/gtk2lclintf.inc +++ b/lcl/interfaces/gtk2/gtk2lclintf.inc @@ -265,6 +265,7 @@ var Data: Pointer; Src, Dst, SrcRowPtr, DstRowPtr: PByte; x, y: Cardinal; + CreateWithAlpha: boolean; begin Result := False; ABitmap := 0; @@ -273,6 +274,7 @@ begin if ImgWidth = 0 then Exit; if ImgHeight = 0 then Exit; + CreateWithAlpha := True; try {$IFDEF VerboseRawImage} DebugLn('TGtk2WidgetSet.CreateBitmapFromRawImage A ', @@ -328,8 +330,8 @@ begin // check if the pixels are in order, pixbuf expects them in R-G-B-A Desc.GetRGBIndices(Ridx, Gidx, Bidx, AIdx); - if (Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3) - then begin + if (Ridx <> 0) or (Gidx <> 1) or (Bidx <> 2) or (AIdx <> 3) then + begin // put components in right order GetMem(Data, ImgDataSize); DstRowPtr := Data; @@ -358,10 +360,22 @@ begin end else begin // components are in place + + // gtkPixbuf doesn't like invalid dataSize/MaskSize < 32. issue #8553. + if (ARawImage.MaskSize > 0) and (ImgDepth = 32) then + begin + CreateWithAlpha := Trunc(ARawImage.DataSize / ARawImage.MaskSize) = 32; + {$IFDEF VerboseRawImage} + if not CreateWithAlpha then + DebugLn('TGtk2WidgetSet.CreateBitmapFromRawImage B WARNING: This image have invalid DataSize / MaskSize.'); + {$ENDIF} + end; Data := ImgData; end; - TmpPixBuf := gdk_pixbuf_new_from_data(Data, GDK_COLORSPACE_RGB, True, 8, ImgWidth, ImgHeight, RowStride, nil, nil); + TmpPixBuf := gdk_pixbuf_new_from_data(Data, GDK_COLORSPACE_RGB, CreateWithAlpha, + 8, ImgWidth, ImgHeight, RowStride, nil, nil); + // we need to copy our pixbuf into a new one to allow data deallocation Pixbuf := gdk_pixbuf_copy(TmpPixBuf); gdk_pixbuf_unref(TmpPixBuf);