implemented TBitmap.TransparentColor, set to clNone to load a bmp without transparency

git-svn-id: trunk@8221 -
This commit is contained in:
mattias 2005-11-24 22:19:12 +00:00
parent 1a223037c8
commit cbe200a355
3 changed files with 33 additions and 16 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;