From 1661d5ff48b2f3f4777479faa9fc50fee88965b0 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Mon, 30 Jun 2025 17:09:25 +0200 Subject: [PATCH] LCL/Graphics: Fix handling of color transparency in TRasterImage and descendants. Issue #41726. --- lcl/graphics.pp | 2 ++ lcl/include/rasterimage.inc | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lcl/graphics.pp b/lcl/graphics.pp index 9d28125358..500cbdf944 100644 --- a/lcl/graphics.pp +++ b/lcl/graphics.pp @@ -1245,6 +1245,7 @@ type FUpdateCount: Integer; FUpdateCanvasOnly: Boolean; FMasked: Boolean; + FTransparentPending: Boolean; procedure CanvasChanging(Sender: TObject); procedure CreateCanvas; @@ -1300,6 +1301,7 @@ type procedure WriteData(Stream: TStream); override; procedure WriteStream(AStream: TMemoryStream); virtual; abstract; function RequestTransparentColor: TColor; + procedure ApplyTransparent; public constructor Create; override; destructor Destroy; override; diff --git a/lcl/include/rasterimage.inc b/lcl/include/rasterimage.inc index 9ff89bead7..b83fa574ca 100644 --- a/lcl/include/rasterimage.inc +++ b/lcl/include/rasterimage.inc @@ -379,9 +379,7 @@ begin then FTransparentMode := tmAuto else FTransparentMode := tmFixed; - if MaskHandleAllocated - then MaskHandle := 0 - else Changed(Self); + ApplyTransparent; end; procedure TRasterImage.Changed(Sender: TObject); @@ -702,9 +700,14 @@ begin if AValue = TransparentMode then exit; FTransparentMode := AValue; - if AValue = tmAuto + if FTransparentColor = clDefault then + FTransparentMode := tmAuto; + + if FTransparentMode = tmAuto then TransparentColor := clDefault else TransparentColor := RequestTransparentColor; + + ApplyTransparent; end; procedure TRasterImage.SetTransparent(AValue: Boolean); @@ -714,8 +717,8 @@ begin lTransparent := GetTransparent(); if AValue = lTransparent then Exit; - // some delphi compatibility, we can only change transparency through the mask. - Masked := AValue; + FTransparentPending := AValue; + ApplyTransparent; end; // release handles without freeing them @@ -976,6 +979,15 @@ begin SetSize(Width, AHeight); end; +procedure TRasterImage.ApplyTransparent; +begin + if MaskHandleAllocated then + MaskHandle := 0; + + // some delphi compatibility, we can only change transparency through the mask. + SetMasked(FTransparentPending); +end; + // included by graphics.pp