git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1531 8e941d3f-bd1b-0410-a28a-d453659cc2b4

This commit is contained in:
yangjixian
2011-03-14 12:34:55 +00:00
parent 1747e6b114
commit 5c694feede
2 changed files with 144 additions and 37 deletions

View File

@ -310,8 +310,8 @@
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="414"/> <TopLine Value="477"/>
<CursorPos X="22" Y="440"/> <CursorPos X="30" Y="493"/>
<UsageCount Value="14"/> <UsageCount Value="14"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit29> </Unit29>
@ -324,7 +324,7 @@
<UsageCount Value="11"/> <UsageCount Value="11"/>
</Unit30> </Unit30>
</Units> </Units>
<JumpHistory Count="29" HistoryIndex="28"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="picturectrls.pas"/> <Filename Value="picturectrls.pas"/>
<Caret Line="333" Column="40" TopLine="314"/> <Caret Line="333" Column="40" TopLine="314"/>
@ -441,6 +441,10 @@
<Filename Value="bmprgbgraph.pas"/> <Filename Value="bmprgbgraph.pas"/>
<Caret Line="392" Column="32" TopLine="378"/> <Caret Line="392" Column="32" TopLine="378"/>
</Position29> </Position29>
<Position30>
<Filename Value="rgbdrawutils.pas"/>
<Caret Line="462" Column="10" TopLine="453"/>
</Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -14,7 +14,7 @@ type
TCustomRGBBitmapCore = class(TBitmap) TCustomRGBBitmapCore = class(TBitmap)
private private
FIntfImg: TLazIntfImage; FIntfImgA: TLazIntfImage;
FFillColor: TColor; FFillColor: TColor;
FOutlineColor: TColor; FOutlineColor: TColor;
FPaperColor: TColor; FPaperColor: TColor;
@ -31,7 +31,8 @@ type
public public
constructor Create; override; constructor Create; override;
destructor Destroy; override; destructor Destroy; override;
procedure SetScanLineValue; procedure OpenScanLine;
procedure CloseScanLine;
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
procedure Clear; virtual; procedure Clear; virtual;
procedure ClearWhite; virtual; procedure ClearWhite; virtual;
@ -41,13 +42,23 @@ type
procedure Rotate90; virtual; procedure Rotate90; virtual;
procedure Rotate180; virtual; procedure Rotate180; virtual;
procedure Rotate270; virtual; procedure Rotate270; virtual;
property ScanLine[Row: integer]: Pointer read GetScanLine;
procedure FillEllipse(X1, Y1, X2, Y2: integer); virtual; procedure FillEllipse(X1, Y1, X2, Y2: integer); virtual;
property FillColor: TColor read GetFillColor write SetFillColor; property FillColor: TColor read GetFillColor write SetFillColor;
property OutlineColor: TColor read GetOutlineColor write SetOutlineColor; property OutlineColor: TColor read GetOutlineColor write SetOutlineColor;
property PaperColor: TColor read GetPaperColor write SetPaperColor; property PaperColor: TColor read GetPaperColor write SetPaperColor;
property ScanLine[Row: integer]: Pointer read GetScanLine;
end; end;
procedure LazBMPRotate90(const aBitmap: TCustomRGBBitmapCore; IsTurnRight: boolean);
procedure BMPRotate90(const Bitmap: TCustomRGBBitmapCore);
procedure DrawSamePixel(ABitmap: TCustomRGBBitmapCore; Value: integer);
procedure BMPRotate180(const Bitmap: TCustomRGBBitmapCore);
procedure BMPRotate270(const Bitmap: TCustomRGBBitmapCore);
function RotateBitmap(Bitmap: TCustomRGBBitmapCore; Angle: integer;
BackColor: TColor): TCustomRGBBitmapCore;
function BitmapFlip(const Vertical: boolean; const Horizontal: boolean;
var BitmapIn: TCustomRGBBitmapCore; out BitmapOut: TCustomRGBBitmapCore): boolean;
implementation implementation
procedure LazBMPRotate90(const aBitmap: TCustomRGBBitmapCore; IsTurnRight: boolean); procedure LazBMPRotate90(const aBitmap: TCustomRGBBitmapCore; IsTurnRight: boolean);
@ -100,7 +111,8 @@ begin
Bmp := TCustomRGBBitmapCore.Create; Bmp := TCustomRGBBitmapCore.Create;
Bmp.Width := Bitmap.Height; Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width; Bmp.Height := Bitmap.Width;
Bmp.PixelFormat := pf24bit; Bmp.OpenScanLine;
Bitmap.OpenScanLine;
Width := Bitmap.Width - 1; Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1; Height := Bitmap.Height - 1;
for j := 0 to Height do for j := 0 to Height do
@ -109,12 +121,11 @@ begin
for i := 0 to Width do for i := 0 to Width do
begin begin
rowOut := Bmp.ScanLine[i]; rowOut := Bmp.ScanLine[i];
// Inc(rowOut, Height - j); rowOut^[Height - j] := rowIn^[i];
rowOut^[j] := rowIn^[i];
// Inc(rowIn);
end; end;
end; end;
Bmp.SetScanLineValue; Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bitmap.Assign(Bmp); Bitmap.Assign(Bmp);
end; end;
@ -131,6 +142,8 @@ begin
Bmp.PixelFormat := pf24bit; Bmp.PixelFormat := pf24bit;
Width := Bitmap.Width - 1; Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1; Height := Bitmap.Height - 1;
Bmp.OpenScanLine;
Bitmap.OpenScanLine;
for j := 0 to Height do for j := 0 to Height do
begin begin
rowIn := Bitmap.ScanLine[j]; rowIn := Bitmap.ScanLine[j];
@ -142,7 +155,8 @@ begin
Inc(rowIn); Inc(rowIn);
end; end;
end; end;
Bmp.SetScanLineValue; Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bitmap.Assign(Bmp); Bitmap.Assign(Bmp);
end; end;
@ -159,6 +173,8 @@ begin
Bmp.PixelFormat := pf24bit; Bmp.PixelFormat := pf24bit;
Width := Bitmap.Width - 1; Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1; Height := Bitmap.Height - 1;
Bmp.OpenScanLine;
Bitmap.OpenScanLine;
for j := 0 to Height do for j := 0 to Height do
begin begin
rowIn := Bitmap.ScanLine[j]; rowIn := Bitmap.ScanLine[j];
@ -170,7 +186,8 @@ begin
Inc(rowIn); Inc(rowIn);
end; end;
end; end;
Bmp.SetScanLineValue; Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bitmap.Assign(Bmp); Bitmap.Assign(Bmp);
end; end;
@ -185,6 +202,8 @@ begin
Result := TCustomRGBBitmapCore.Create; Result := TCustomRGBBitmapCore.Create;
Result.PixelFormat := pf24bit; Result.PixelFormat := pf24bit;
Result.Canvas.Brush.Color := BackColor; Result.Canvas.Brush.Color := BackColor;
Result.OpenScanLine;
Bitmap.OpenScanLine;
Angle := Angle mod 360; Angle := Angle mod 360;
if Angle < 0 then if Angle < 0 then
Angle := 360 - Abs(Angle); Angle := 360 - Abs(Angle);
@ -293,7 +312,8 @@ begin
end; end;
end; end;
end; end;
Result.SetScanLineValue; Result.CloseScanLine;
Bitmap.CloseScanLine;
end; end;
procedure DrawSamePixel(ABitmap: TCustomRGBBitmapCore; Value: integer); procedure DrawSamePixel(ABitmap: TCustomRGBBitmapCore; Value: integer);
@ -303,62 +323,115 @@ var
LScan: PRGBTripleArray; LScan: PRGBTripleArray;
i, j: integer; i, j: integer;
begin begin
aBitmap.OpenScanLine;
for i := 0 to ABitmap.Height - 1 do for i := 0 to ABitmap.Height - 1 do
begin begin
LScan := ABitmap.Scanline[i]; LScan := ABitmap.Scanline[i];
for j := 0 to ABitmap.Width - 1 do for j := 0 to ABitmap.Width - 1 do
begin begin
LNew := LScan^[j]; LNew := LScan^[j];
LScan^[j].rgbtBlue := LNew.rgbtBlue; LScan^[j].rgbtBlue := LScan^[j].rgbtBlue * Value div 100; //Value; //LNew.rgbtBlue;
LScan^[j].rgbtGreen := LNew.rgbtGreen; LScan^[j].rgbtGreen := LScan^[j].rgbtGreen * Value div 100; //LNew.rgbtGreen;
LScan^[j].rgbtRed := LNew.rgbtRed; LScan^[j].rgbtRed := LScan^[j].rgbtRed * Value div 100; //LNew.rgbtRed;
//LScan^[j] := LNew; //LScan^[j] := LNew;
end; end;
end; end;
ABitmap.SetScanLineValue; ABitmap.CloseScanLine;
end;
function BitmapFlip(const Vertical: boolean; const Horizontal: boolean;
var BitmapIn: TCustomRGBBitmapCore; out BitmapOut: TCustomRGBBitmapCore): boolean;
var
DataIn: PRGBTripleArray;
DataOut: PRGBTripleArray;
inRow: integer;
inCol: integer;
begin
Result := False;
try
BitmapIn.OpenScanLine;
BitmapOut.OpenScanLine;
if BitmapIn.PixelFormat <> pf24bit then
Exit;
with BitmapOut do
begin
Width := BitmapIn.Width;
Height := BitmapIn.Height;
PixelFormat := BitmapIn.PixelFormat;
end;
for inRow := 0 to BitmapIn.Height - 1 do
begin
DataIn := BitmapIn.Scanline[inRow];
if Vertical then
begin
DataOut := BitmapOut.ScanLine[BitmapIn.Height - 1 - inRow];
end
else
begin
DataOut := BitmapOut.ScanLine[inRow];
end;
if Horizontal then
begin
for inCol := 0 to BitmapIn.Width - 1 do
DataOut^[inCol] := DataIn^[BitmapIn.Width - 1 - inCol];
end
else
begin
for inCol := 0 to BitmapIn.Width - 1 do
DataOut^[inCol] := DataIn^[inCol];
end;
end;
Result := True;
BitmapIn.CloseScanLine;
BitmapOut.CloseScanLine;
except
end;
end; end;
constructor TCustomRGBBitmapCore.Create; constructor TCustomRGBBitmapCore.Create;
begin begin
inherited; inherited;
PixelFormat := pf24bit; PixelFormat := pf24bit;
FIntfImg := TLazIntfImage.Create(0, 0);
FIntfImg.LoadFromBitmap(Handle, MaskHandle);
end; end;
destructor TCustomRGBBitmapCore.Destroy; destructor TCustomRGBBitmapCore.Destroy;
begin begin
FIntfImg.Free;
inherited; inherited;
end; end;
function TCustomRGBBitmapCore.GetScanLine(Row: integer): Pointer; function TCustomRGBBitmapCore.GetScanLine(Row: integer): Pointer;
var
ImgHandle, ImgMaskHandle: HBitmap;
begin begin
Result := FIntfImg.GetDataLineStart(Row); if FIntfImgA <> nil then
Result := FIntfImgA.GetDataLineStart(Row);
end; end;
procedure TCustomRGBBitmapCore.SetScanLineValue; procedure TCustomRGBBitmapCore.OpenScanLine;
begin
FIntfImgA := TLazIntfImage.Create(0, 0);
FIntfImgA.LoadFromBitmap(Handle, MaskHandle);
end;
procedure TCustomRGBBitmapCore.CloseScanLine;
var var
TmpBmp: TBitmap; TmpBmp: TBitmap;
ImgHandle, ImgMaskHandle: HBitmap; ImgHandle, ImgMaskHandle: HBitmap;
begin begin
TmpBmp := TBitmap.Create; TmpBmp := TBitmap.Create;
TmpBmp.PixelFormat := pf24bit; TmpBmp.PixelFormat := pf24bit;
FIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, False); FIntfImgA.CreateBitmaps(ImgHandle, ImgMaskHandle, True);
TmpBmp.Handle := ImgHandle; TmpBmp.Handle := ImgHandle;
TmpBmp.MaskHandle := ImgMaskHandle; TmpBmp.MaskHandle := ImgMaskHandle;
Empty; Empty;
//Canvas.Draw(0, 0, TmpBmp); Width := TmpBmp.Width;
Assign(TmpBmp); Height := TmpBmp.Height;
Canvas.Draw(0, 0, TmpBmp);
TmpBmp.Free; TmpBmp.Free;
FIntfImgA.Free;
end; end;
procedure TCustomRGBBitmapCore.Assign(Source: TPersistent); procedure TCustomRGBBitmapCore.Assign(Source: TPersistent);
begin begin
inherited; inherited;
FIntfImg.LoadFromBitmap(Handle, MaskHandle);
end; end;
function TCustomRGBBitmapCore.GetFillColor: TColor; function TCustomRGBBitmapCore.GetFillColor: TColor;
@ -394,13 +467,13 @@ end;
procedure TCustomRGBBitmapCore.SetWidth(Value: integer); procedure TCustomRGBBitmapCore.SetWidth(Value: integer);
begin begin
inherited; inherited;
FIntfImg.LoadFromBitmap(Handle, MaskHandle);
end; end;
procedure TCustomRGBBitmapCore.SetHeight(Value: integer); procedure TCustomRGBBitmapCore.SetHeight(Value: integer);
begin begin
inherited; inherited;
FIntfImg.LoadFromBitmap(Handle, MaskHandle);
end; end;
procedure TCustomRGBBitmapCore.Clear; procedure TCustomRGBBitmapCore.Clear;
@ -419,13 +492,41 @@ begin
end; end;
procedure TCustomRGBBitmapCore.FlipHorz; procedure TCustomRGBBitmapCore.FlipHorz;
var
tmp, tmp2: TCustomRGBBitmapCore;
begin begin
tmp := TCustomRGBBitmapCore.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp2:= TCustomRGBBitmapCore.Create;
tmp2.Width := Width;
tmp2.Height := Height;
tmp.PixelFormat := pf24bit;
tmp2.PixelFormat := pf24bit;
tmp.Canvas.Draw(0, 0, Self);
BitmapFlip(False, True, tmp, tmp2);
Canvas.Draw(0, 0, tmp2);
tmp.Free;
tmp2.Free;
end; end;
procedure TCustomRGBBitmapCore.FlipVert; procedure TCustomRGBBitmapCore.FlipVert;
var
tmp, tmp2: TCustomRGBBitmapCore;
begin begin
tmp := TCustomRGBBitmapCore.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp2:= TCustomRGBBitmapCore.Create;
tmp2.Width := Width;
tmp2.Height := Height;
tmp.PixelFormat := pf24bit;
tmp2.PixelFormat := pf24bit;
tmp.Canvas.Draw(0, 0, Self);
BitmapFlip(True, False, tmp, tmp2);
Canvas.Draw(0, 0, tmp2);
tmp.Free;
tmp2.Free;
end; end;
procedure TCustomRGBBitmapCore.Rotate90; procedure TCustomRGBBitmapCore.Rotate90;
@ -436,10 +537,11 @@ begin
tmp.Width := Width; tmp.Width := Width;
tmp.Height := Height; tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self); tmp.Canvas.Draw(0, 0, Self);
LazBMPRotate90(tmp, True); BMPRotate90(Tmp);
Self.Width := tmp.Width; Self.Width := tmp.Width;
Self.Height := tmp.Height; Self.Height := tmp.Height;
Canvas.Draw(0, 0, tmp); Canvas.Draw(0, 0, tmp);
tmp.Free;
end; end;
procedure TCustomRGBBitmapCore.Rotate180; procedure TCustomRGBBitmapCore.Rotate180;
@ -450,11 +552,11 @@ begin
tmp.Width := Width; tmp.Width := Width;
tmp.Height := Height; tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self); tmp.Canvas.Draw(0, 0, Self);
LazBMPRotate90(tmp, True); BMPRotate180(Tmp);
LazBMPRotate90(tmp, True);
Self.Width := tmp.Width; Self.Width := tmp.Width;
Self.Height := tmp.Height; Self.Height := tmp.Height;
Canvas.Draw(0, 0, tmp); Canvas.Draw(0, 0, tmp);
tmp.Free;
end; end;
procedure TCustomRGBBitmapCore.Rotate270; procedure TCustomRGBBitmapCore.Rotate270;
@ -465,10 +567,11 @@ begin
tmp.Width := Width; tmp.Width := Width;
tmp.Height := Height; tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self); tmp.Canvas.Draw(0, 0, Self);
LazBMPRotate90(tmp, False); BMPRotate270(Tmp);
Self.Width := tmp.Width; Self.Width := tmp.Width;
Self.Height := tmp.Height; Self.Height := tmp.Height;
Canvas.Draw(0, 0, tmp); Canvas.Draw(0, 0, tmp);
tmp.Free;
end; end;
procedure TCustomRGBBitmapCore.FillEllipse(X1, Y1, X2, Y2: integer); procedure TCustomRGBBitmapCore.FillEllipse(X1, Y1, X2, Y2: integer);