mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-05 07:58:16 +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 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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user