diff --git a/lcl/interfaces/gtk/gtkproc.inc b/lcl/interfaces/gtk/gtkproc.inc index b249cab384..07379eef25 100644 --- a/lcl/interfaces/gtk/gtkproc.inc +++ b/lcl/interfaces/gtk/gtkproc.inc @@ -12,7 +12,7 @@ * * * This file is part of the Lazarus Component Library (LCL) * * * - * See the file COPYING.modifiedLGPL.txt, included in this distribution, * + * See the file COPYING.modifiedLGPL.txt, included in this distribution, * * for details about the copyright. * * * * This program is distributed in the hope that it will be useful, * @@ -5526,81 +5526,6 @@ begin FreeMem(ImgData); end; -{ - function GdkPixbufAddBitmapMask - - pixbuf - original pixbuf to mask - mask - mask bitmap - mask_value - bit value that should be masked - - Returns new pixbuf with applied mask -} -function GdkPixbufAddBitmapMask(pixbuf: PGdkPixbuf; mask: PGdkBitmap; mask_value: byte): PGdkPixbuf; -var - i, j, w, h, r, n: integer; - src, dest: Pguchar; - Image: PGdkImage; - s_buf, d_buf: PCardinal; -begin - Result := nil; - - // first check for null images - if (pixbuf = nil) or (mask = nil) then - exit; - - n := gdk_pixbuf_get_n_channels(pixbuf); - gdk_drawable_get_size(mask, @w, @h); - - // second check. we cannot process pixbuf with channels <> 4 - // or with different size that image - if (n <> 4) or (w <> gdk_pixbuf_get_width(pixbuf)) or - (h <> gdk_pixbuf_get_height(pixbuf)) then - exit; - - r := gdk_pixbuf_get_rowstride(pixbuf); - - // we need Image to read pixels - Image := gdk_drawable_get_image(mask, 0, 0, w, h); - - // source pixels of pixbuf - src := gdk_pixbuf_get_pixels(pixbuf); - - // allocate destination buffer for new pixbuf - dest := g_malloc(4 * r * h); - - // to run on buffer we need one more pointer to it - d_buf := PCardinal(dest); - - for i := 0 to h - 1 do - begin - // buffer of source row - s_buf := PCardinal(src + i * r); - for j := 0 to w - 1 do - begin - if gdk_image_get_pixel(Image, j, i) = mask_value then - begin - // if pixel should be masked we fill color with zeros - d_buf^ := 0; - end else - begin - // in other case we copy it from source - d_buf^ := s_buf^; - end; - inc(d_buf); - inc(s_buf); - end; - end; - // image is no more needed, so can be disposed - gdk_image_unref(Image); - - // craete result pixbuf from destination buffer - Result := gdk_pixbuf_new_from_data(dest, GDK_COLORSPACE_RGB, true, 8, w, h, r, nil, nil); - - // if pixbuf is not created, then destination data should be freed - if Result = nil then - g_free(dest); -end; - {------------------------------------------------------------------------------- method CreatePixbufFromDrawable Params: ASource: The source drawable diff --git a/lcl/interfaces/gtk/gtkproc.pp b/lcl/interfaces/gtk/gtkproc.pp index f49918056f..e7d24f89f8 100644 --- a/lcl/interfaces/gtk/gtkproc.pp +++ b/lcl/interfaces/gtk/gtkproc.pp @@ -13,7 +13,7 @@ * * * This file is part of the Lazarus Component Library (LCL) * * * - * See the file COPYING.modifiedLGPL.txt, included in this distribution, * + * See the file COPYING.modifiedLGPL.txt, included in this distribution, * * for details about the copyright. * * * * This program is distributed in the hope that it will be useful, * @@ -609,9 +609,7 @@ procedure LoadPixbufFromLazResource(const ResourceName: string; var Pixbuf: PGdkPixbuf); procedure LoadXPMFromLazResource(const ResourceName: string; Window: PGdkWindow; var PixmapImg, PixmapMask: PGdkPixmap); -function GdkPixbufAddBitmapMask(pixbuf: PGdkPixbuf; mask: - PGdkBitmap; mask_value: byte): PGdkPixbuf; - + function CreatePixbufFromDrawable(ASource: PGdkDrawable; AColorMap:PGdkColormap; AIncludeAplha: Boolean; ASrcX, ASrcY, ADstX, ADstY, AWidth, AHeight :longint): PGdkPixbuf; diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index d3bf238d08..6c9e5ca5a9 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -2482,11 +2482,23 @@ begin {$IFDEF DebugGDKTraps} BeginGDKErrorTrap; {$ENDIF} - if GDIBitmapObject <> nil then - gdk_bitmap_unref(GDIBitmapObject); - If (Visual <> nil) and (not SystemVisual) then + case GDIBitmapType of + gbBitmap: + begin + if GDIBitmapObject <> nil then + gdk_bitmap_unref(GDIBitmapObject); + end; + gbPixmap: + begin + if GDIPixmapObject.Image <> nil then + gdk_pixmap_unref(GDIPixmapObject.Image); + if GDIPixmapObject.Mask <> nil then + gdk_bitmap_unref(GDIPixmapObject.Mask); + end; + end; + if (Visual <> nil) and (not SystemVisual) then gdk_visual_unref(Visual); - If Colormap <> nil then + if Colormap <> nil then gdk_colormap_unref(Colormap); {$IFDEF DebugGDKTraps} EndGDKErrorTrap;