diff --git a/lcl/graphics.pp b/lcl/graphics.pp index 5245509461..cc4bde84c6 100644 --- a/lcl/graphics.pp +++ b/lcl/graphics.pp @@ -1185,9 +1185,9 @@ type property MaskHandle: HBITMAP read GetMaskHandle write SetMaskHandle; property Monochrome: Boolean read GetMonochrome write SetMonochrome; property PixelFormat: TPixelFormat read FPixelFormat write SetPixelFormat default pfDevice; - // property ScanLine[Row: Integer]: Pointer; // Use TLazIntfImage for such things + // property ScanLine[Row: Integer]: Pointer; -> Use TLazIntfImage for such things property TransparentColor: TColor read FTransparentColor - write FTransparentColor default clNone; + write FTransparentColor default clDefault; property TransparentMode: TTransparentMode read FTransparentMode write SetTransparentMode default tmAuto; end; diff --git a/lcl/include/bitmap.inc b/lcl/include/bitmap.inc index b64811e970..2b53c1b570 100644 --- a/lcl/include/bitmap.inc +++ b/lcl/include/bitmap.inc @@ -126,7 +126,8 @@ begin FPixelFormat := pfDevice; FImage := TBitmapImage.Create; FImage.Reference; - FTransparentColor := clNone; + FTransparentColor := clDefault; // for Delphi compatibility. clDefault means: + // use Left,Bottom pixel as transparent pixel end; destructor TBitMap.Destroy; @@ -814,7 +815,16 @@ end; procedure TBitmap.InitFPImageReader(ImgReader: TFPCustomImageReader); begin - + if ImgReader is TLazReaderBMP then begin + TLazReaderBMP(ImgReader).UseLeftBottomAsTransparent:= + TransparentColor=clDefault; + if (TransparentColor<>clDefault) + and (TransparentColor<>clNone) then + TLazReaderBMP(ImgReader).TransparentColor:= + TColorToFPColor(TransparentColor) + else + TLazReaderBMP(ImgReader).TransparentColor:=colTransparent; + end; end; procedure TBitmap.InitFPImageWriter(ImgWriter: TFPCustomImageWriter); diff --git a/lcl/intfgraphics.pas b/lcl/intfgraphics.pas index 9dedc4744c..4cef22c743 100644 --- a/lcl/intfgraphics.pas +++ b/lcl/intfgraphics.pas @@ -330,6 +330,7 @@ type { This is an imroved FPImage writer for bmp images. } TLazReaderBMP = class (TFPCustomImageReader) Private + FUseLeftBottomAsTransparent: Boolean; Procedure FreeBufs; // Free (and nil) buffers. protected ReadSize: Integer; // Size (in bytes) of 1 scanline. @@ -354,6 +355,9 @@ type public constructor Create; override; destructor Destroy; override; + property TransparentColor: TFPColor read FTransparentColor write FTransparentColor; + property UseLeftBottomAsTransparent: Boolean read FUseLeftBottomAsTransparent + write FUseLeftBottomAsTransparent; end; { TLazReaderPartIcon } @@ -3079,10 +3083,10 @@ end; function TLazReaderBMP.ColorToTrans(const InColor: TFPColor): TFPColor; begin - if InColor = FTransparentColor then - Result := FPImage.colTransparent + if (InColor <> FTransparentColor) then + Result := InColor else - Result := InColor; + Result := FPImage.colTransparent; end; procedure TLazReaderBMP.SetupRead(nPalette, nRowBits: Integer; Stream: TStream; @@ -3215,15 +3219,17 @@ Var procedure SaveTransparentColor; begin - // define transparent color: 1-8 use palette, 15-24 use fixed color - case FBitsPerPixel of - 1 : FPalette[(LineBuf[0] shr 7) and 1] := fpimage.colTransparent; - 4 : FPalette[(LineBuf[0] shr 4) and $f] := fpimage.colTransparent; - 8 : FPalette[LineBuf[0]] := fpimage.colTransparent; - 15: FTransparentColor := Bmp15BitToFPColor(PWord(LineBuf)[0]); - 16: FTransparentColor := Bmp16BitToFPColor(PWord(LineBuf)[0]); - 24: FTransparentColor := BmpRGBToFPColor(PColorRGB(LineBuf)[0]); - 32: ; // BmpRGBA already does transparency + if UseLeftBottomAsTransparent then begin + // define transparent color: 1-8 use palette, 15-24 use fixed color + case FBitsPerPixel of + 1 : FPalette[(LineBuf[0] shr 7) and 1] := fpimage.colTransparent; + 4 : FPalette[(LineBuf[0] shr 4) and $f] := fpimage.colTransparent; + 8 : FPalette[LineBuf[0]] := fpimage.colTransparent; + 15: FTransparentColor := Bmp15BitToFPColor(PWord(LineBuf)[0]); + 16: FTransparentColor := Bmp16BitToFPColor(PWord(LineBuf)[0]); + 24: FTransparentColor := BmpRGBToFPColor(PColorRGB(LineBuf)[0]); + 32: ; // BmpRGBA already does transparency + end; end; end; @@ -3358,6 +3364,7 @@ end; constructor TLazReaderBMP.Create; begin inherited Create; + FTransparentColor:=colTransparent; end; destructor TLazReaderBMP.Destroy;