mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 06:20:17 +02:00
implemented TBitmap.TransparentColor, set to clNone to load a bmp without transparency
git-svn-id: trunk@8221 -
This commit is contained in:
parent
1a223037c8
commit
cbe200a355
@ -1185,9 +1185,9 @@ type
|
|||||||
property MaskHandle: HBITMAP read GetMaskHandle write SetMaskHandle;
|
property MaskHandle: HBITMAP read GetMaskHandle write SetMaskHandle;
|
||||||
property Monochrome: Boolean read GetMonochrome write SetMonochrome;
|
property Monochrome: Boolean read GetMonochrome write SetMonochrome;
|
||||||
property PixelFormat: TPixelFormat read FPixelFormat write SetPixelFormat default pfDevice;
|
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
|
property TransparentColor: TColor read FTransparentColor
|
||||||
write FTransparentColor default clNone;
|
write FTransparentColor default clDefault;
|
||||||
property TransparentMode: TTransparentMode read FTransparentMode
|
property TransparentMode: TTransparentMode read FTransparentMode
|
||||||
write SetTransparentMode default tmAuto;
|
write SetTransparentMode default tmAuto;
|
||||||
end;
|
end;
|
||||||
|
@ -126,7 +126,8 @@ begin
|
|||||||
FPixelFormat := pfDevice;
|
FPixelFormat := pfDevice;
|
||||||
FImage := TBitmapImage.Create;
|
FImage := TBitmapImage.Create;
|
||||||
FImage.Reference;
|
FImage.Reference;
|
||||||
FTransparentColor := clNone;
|
FTransparentColor := clDefault; // for Delphi compatibility. clDefault means:
|
||||||
|
// use Left,Bottom pixel as transparent pixel
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TBitMap.Destroy;
|
destructor TBitMap.Destroy;
|
||||||
@ -814,7 +815,16 @@ end;
|
|||||||
|
|
||||||
procedure TBitmap.InitFPImageReader(ImgReader: TFPCustomImageReader);
|
procedure TBitmap.InitFPImageReader(ImgReader: TFPCustomImageReader);
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
procedure TBitmap.InitFPImageWriter(ImgWriter: TFPCustomImageWriter);
|
procedure TBitmap.InitFPImageWriter(ImgWriter: TFPCustomImageWriter);
|
||||||
|
@ -330,6 +330,7 @@ type
|
|||||||
{ This is an imroved FPImage writer for bmp images. }
|
{ This is an imroved FPImage writer for bmp images. }
|
||||||
TLazReaderBMP = class (TFPCustomImageReader)
|
TLazReaderBMP = class (TFPCustomImageReader)
|
||||||
Private
|
Private
|
||||||
|
FUseLeftBottomAsTransparent: Boolean;
|
||||||
Procedure FreeBufs; // Free (and nil) buffers.
|
Procedure FreeBufs; // Free (and nil) buffers.
|
||||||
protected
|
protected
|
||||||
ReadSize: Integer; // Size (in bytes) of 1 scanline.
|
ReadSize: Integer; // Size (in bytes) of 1 scanline.
|
||||||
@ -354,6 +355,9 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
property TransparentColor: TFPColor read FTransparentColor write FTransparentColor;
|
||||||
|
property UseLeftBottomAsTransparent: Boolean read FUseLeftBottomAsTransparent
|
||||||
|
write FUseLeftBottomAsTransparent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLazReaderPartIcon }
|
{ TLazReaderPartIcon }
|
||||||
@ -3079,10 +3083,10 @@ end;
|
|||||||
|
|
||||||
function TLazReaderBMP.ColorToTrans(const InColor: TFPColor): TFPColor;
|
function TLazReaderBMP.ColorToTrans(const InColor: TFPColor): TFPColor;
|
||||||
begin
|
begin
|
||||||
if InColor = FTransparentColor then
|
if (InColor <> FTransparentColor) then
|
||||||
Result := FPImage.colTransparent
|
Result := InColor
|
||||||
else
|
else
|
||||||
Result := InColor;
|
Result := FPImage.colTransparent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazReaderBMP.SetupRead(nPalette, nRowBits: Integer; Stream: TStream;
|
procedure TLazReaderBMP.SetupRead(nPalette, nRowBits: Integer; Stream: TStream;
|
||||||
@ -3215,6 +3219,7 @@ Var
|
|||||||
|
|
||||||
procedure SaveTransparentColor;
|
procedure SaveTransparentColor;
|
||||||
begin
|
begin
|
||||||
|
if UseLeftBottomAsTransparent then begin
|
||||||
// define transparent color: 1-8 use palette, 15-24 use fixed color
|
// define transparent color: 1-8 use palette, 15-24 use fixed color
|
||||||
case FBitsPerPixel of
|
case FBitsPerPixel of
|
||||||
1 : FPalette[(LineBuf[0] shr 7) and 1] := fpimage.colTransparent;
|
1 : FPalette[(LineBuf[0] shr 7) and 1] := fpimage.colTransparent;
|
||||||
@ -3226,6 +3231,7 @@ Var
|
|||||||
32: ; // BmpRGBA already does transparency
|
32: ; // BmpRGBA already does transparency
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ This will move past any junk after the BFI header }
|
{ This will move past any junk after the BFI header }
|
||||||
@ -3358,6 +3364,7 @@ end;
|
|||||||
constructor TLazReaderBMP.Create;
|
constructor TLazReaderBMP.Create;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
FTransparentColor:=colTransparent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TLazReaderBMP.Destroy;
|
destructor TLazReaderBMP.Destroy;
|
||||||
|
Loading…
Reference in New Issue
Block a user