From 9b0d833ee673547a4a06c1dd68405484d39a4cd6 Mon Sep 17 00:00:00 2001 From: yangjixian Date: Wed, 4 May 2011 01:55:49 +0000 Subject: [PATCH] TDLBitmap gets faster. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1608 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazimageeditor/DLBitmap.pas | 38 ++-- applications/lazimageeditor/DLBmpUtils.inc | 36 ++-- applications/lazimageeditor/bmprgbtypes.pas | 2 + .../lazimageeditor/lazimageeditor.lpi | 176 +++++++++--------- 4 files changed, 132 insertions(+), 120 deletions(-) diff --git a/applications/lazimageeditor/DLBitmap.pas b/applications/lazimageeditor/DLBitmap.pas index 660ec3ca8..c8d23b3d8 100644 --- a/applications/lazimageeditor/DLBitmap.pas +++ b/applications/lazimageeditor/DLBitmap.pas @@ -41,9 +41,13 @@ type function GetScanLinePixel(X, Y: Integer): TColor; procedure SetScanLinePixel(X, Y: Integer; Value: TColor); protected + ImgHandle, ImgMaskHandle: HBitmap; procedure SetWidth(Value: integer); override; procedure SetHeight(Value: integer); override; procedure Changed(Sender: TObject); override; + procedure InitializeReader(AImage: TLazIntfImage; AReader: TFPCustomImageReader); override; + procedure InitializeWriter(AImage: TLazIntfImage; AWriter: TFPCustomImageWriter); override; + procedure FinalizeWriter(AWriter: TFPCustomImageWriter); override; public constructor Create; override; destructor Destroy; override; @@ -140,6 +144,7 @@ operator div (const A, B: TRGBATriple): TRGBATriple; function DWordTrans(SrcRow: TRGBATriple): DWORD; function DWordToTriple(SrcRow: DWORD): TRGBATriple; procedure StretchLinear(Dest, Src: TDLBitmap); +procedure StretchDLBMP(Src: TDLBitmap; MultiX, MultiY: integer); implementation @@ -214,25 +219,15 @@ begin end; procedure TDLBitmap.InvalidateScanLine; -var - TmpBmp: TDLBitmap; - ImgHandle, ImgMaskHandle: HBitmap; begin - TmpBmp := TDLBitmap.Create; FIntfImgA.CreateBitmaps(ImgHandle, ImgMaskHandle, True); - TmpBmp.Handle := ImgHandle; - TmpBmp.MaskHandle := ImgMaskHandle; - Empty; - Width := TmpBmp.Width; - Height := TmpBmp.Height; - Canvas.Draw(0, 0, TmpBmp); - TmpBmp.Free; + Handle := ImgHandle; + MaskHandle := ImgMaskHandle; end; procedure TDLBitmap.InvalidateScanLineRect(aRect: TRect); var TmpBmp: TDLBitmap; - ImgHandle, ImgMaskHandle: HBitmap; begin TmpBmp := TDLBitmap.Create; FIntfImgA.CreateBitmaps(ImgHandle, ImgMaskHandle, True); @@ -517,6 +512,22 @@ begin SprayPoints(Self, x, y, radian, PColor); end; +procedure TDLBitmap.InitializeReader(AImage: TLazIntfImage; AReader: TFPCustomImageReader); +begin + inherited; + FIntfImgA := AImage; +end; + +procedure TDLBitmap.InitializeWriter(AImage: TLazIntfImage; AWriter: TFPCustomImageWriter); +begin + inherited; +end; + +procedure TDLBitmap.FinalizeWriter(AWriter: TFPCustomImageWriter); +begin + inherited; +end; + procedure TDLBitmap.FillEllipse(X1, Y1, X2, Y2: integer); begin @@ -659,11 +670,8 @@ begin TextLeft := TextX + IMGCanvas.TextWidth(LeftText); if IMGCanvas = nil then Exit; - //IMGCanvas.TextOut(22, 22, FEdit.Text); IMGCanvas.Brush.Style := bsClear; IMGCanvas.TextOut(TextLeft, TextY, RightText); - //if PositionIndex <> FEdit.SelStart then - // PositionIndex := FEdit.SelStart; PositionIndex := Length(FEdit.Text); end; diff --git a/applications/lazimageeditor/DLBmpUtils.inc b/applications/lazimageeditor/DLBmpUtils.inc index 80694f145..4c8dbe0b1 100644 --- a/applications/lazimageeditor/DLBmpUtils.inc +++ b/applications/lazimageeditor/DLBmpUtils.inc @@ -535,7 +535,7 @@ begin if (a * a + b * b < Sqr(Round(Radian3 * 0.65))) then DLBmp.Pixels[X + a, Y + b] := PColor; end; - DLBmp.InvalidateScanLineRect(Rect(X - Radians, Y - Radians, X + Radians, Y + Radians)); + DLBmp.InvalidateScanLine;//Rect(Rect(X - Radians, Y - Radians, X + Radians, Y + Radians)); end; function GetRColor(const Color: TColor): Byte; @@ -677,24 +677,26 @@ end; procedure StretchDLBMP(Src: TDLBitmap; MultiX, MultiY: integer); var - sw, sh, dw, dh, B, N, x, y, i, j, k, nPixelSize: DWord; + sw, sh, dw, dh, i, j, k, l, nPixelSize: DWord; Dest: TDLBitmap; begin - sw := Src.Width - 1; - sh := Src.Height - 1; - dw := (Src.Width - 1) * MultiX; - dh := (Src.Height - 1) * MultiY; - nPixelSize := 3; - for i := 0 to sh do - begin - for j := 0 to sw do - begin - for k := 0 to nPixelSize - 1 do - begin - - end; - end; - end; + Dest := TDLBitmap.Create; + sw := Src.Width; + sh := Src.Height; + dw := Src.Width * MultiX; + dh := Src.Height * MultiY; + Dest.Width := dw; + Dest.Height := dh; + for i := 0 to sh - 1 do + for j := 0 to sw - 1 do + for k := 0 to MultiY - 1 do + for l := 0 to MultiX - 1 do + Dest.Pixels[j * MultiX + k, i * MultiY + l] := Src.Pixels[j, i]; Dest.InvalidateScanLine; + //Src.Assign(Dest); + Src.Width := dw; + Src.Height := dh; + Src.Canvas.Draw(0, 0, Dest); + Dest.Free; end; diff --git a/applications/lazimageeditor/bmprgbtypes.pas b/applications/lazimageeditor/bmprgbtypes.pas index 758b52299..f6b9b59d7 100644 --- a/applications/lazimageeditor/bmprgbtypes.pas +++ b/applications/lazimageeditor/bmprgbtypes.pas @@ -600,8 +600,10 @@ procedure TRGBBitmapCore.StretchDrawTo(ACanvas: TCanvas; begin if ACanvas <> nil then // ACanvas.StretchDraw(Rect(DstX, DstY, DstWidth, DstHeight), Self); + // StretchDLBMP(Self, 3, 3); begin ACanvas.AntialiasingMode:=amOff; + ACanvas.CopyMode:=cmSrcPaint; ACanvas.CopyRect(Rect(DstX, DstY, DstWidth, DstHeight), Self.Canvas, Rect(0,0,Width,Height)); end; end; diff --git a/applications/lazimageeditor/lazimageeditor.lpi b/applications/lazimageeditor/lazimageeditor.lpi index ce97cdc6c..302521cec 100644 --- a/applications/lazimageeditor/lazimageeditor.lpi +++ b/applications/lazimageeditor/lazimageeditor.lpi @@ -72,7 +72,7 @@ - + @@ -170,8 +170,8 @@ - - + + @@ -242,10 +242,11 @@ + - - + + @@ -359,8 +360,8 @@ - - + + @@ -390,11 +391,10 @@ - - - + + @@ -431,124 +431,124 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - - + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - +