From b9bf45bc7995ea4280cc9ea80a6df57442d2b7bc Mon Sep 17 00:00:00 2001 From: yangjixian Date: Mon, 2 May 2011 08:07:14 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1606 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazimageeditor/DLBitmap.pas | 52 +++++- applications/lazimageeditor/DLBmpUtils.inc | 66 ++++++- .../lazimageeditor/lazimageeditor.lpi | 162 +++++++++++------- 3 files changed, 216 insertions(+), 64 deletions(-) diff --git a/applications/lazimageeditor/DLBitmap.pas b/applications/lazimageeditor/DLBitmap.pas index c06c1b244..f81aa1f0e 100644 --- a/applications/lazimageeditor/DLBitmap.pas +++ b/applications/lazimageeditor/DLBitmap.pas @@ -75,7 +75,7 @@ type property FillColor: TColor read GetFillColor write SetFillColor; property OutlineColor: TColor read GetOutlineColor write SetOutlineColor; property PaperColor: TColor read GetPaperColor write SetPaperColor; - property ScanLinePixels[X, Y: Integer]: TColor read GetScanLinePixel write SetScanLinePixel; + property Pixels[X, Y: Integer]: TColor read GetScanLinePixel write SetScanLinePixel; end; TTextEditor = class; @@ -133,11 +133,61 @@ function GetGColor(const Color: TColor): byte; function GetBColor(const Color: TColor): byte; procedure SprayPoints(aCanvas: TCanvas; X, Y: integer; Radians: integer; PColor: TColor); procedure DLBMPColorReplace(aBitmap: TDLBitmap; ColorFrom, ColorTo: TColor); +operator + (const A, B: TRGBATriple): TRGBATriple; +operator - (const A, B: TRGBATriple): TRGBATriple; +operator * (const A, B: TRGBATriple): TRGBATriple; +operator div (const A, B: TRGBATriple): TRGBATriple; +function DWordTrans(SrcRow: TRGBATriple): DWORD; +function DWordToTriple(SrcRow: DWORD): TRGBATriple; implementation {$I DLBmpUtils.inc} +operator + (const A, B: TRGBATriple): TRGBATriple; +begin + Result.rgbtBlue := A.rgbtBlue + B.rgbtBlue; + Result.rgbtRed := A.rgbtRed + B.rgbtRed; + Result.rgbtGreen := A.rgbtBlue + B.rgbtGreen; +end; + +operator - (const A, B: TRGBATriple): TRGBATriple; +begin + Result.rgbtBlue := A.rgbtBlue - B.rgbtBlue; + Result.rgbtRed := A.rgbtRed - B.rgbtRed; + Result.rgbtGreen := A.rgbtBlue - B.rgbtGreen; +end; + +operator * (const A, B: TRGBATriple): TRGBATriple; +begin + Result.rgbtBlue := A.rgbtBlue * B.rgbtBlue; + Result.rgbtRed := A.rgbtRed * B.rgbtRed; + Result.rgbtGreen := A.rgbtBlue * B.rgbtGreen; +end; + +operator div (const A, B: TRGBATriple): TRGBATriple; +begin + Result.rgbtBlue := A.rgbtBlue div B.rgbtBlue; + Result.rgbtRed := A.rgbtRed div B.rgbtRed; + Result.rgbtGreen := A.rgbtBlue div B.rgbtGreen; +end; + +function DWordTrans(SrcRow: TRGBATriple): DWORD; +var RR, GG, BB: integer; +begin + RR := SrcRow.rgbtRed; + GG := SrcRow.rgbtGreen; + BB := SrcRow.rgbtBlue; + Result := RR + (GG shl 8) and $FF00 + (BB shl 16) and $FF0000; +end; + +function DWordToTriple(SrcRow: DWORD): TRGBATriple; +begin + Result.rgbtBlue := (SrcRow shr 16) and $FF0000; + Result.rgbtGreen := (SrcRow shr 8) and $FF00; + Result.rgbtRed := SrcRow and $FF; +end; + constructor TDLBitmap.Create; begin inherited; diff --git a/applications/lazimageeditor/DLBmpUtils.inc b/applications/lazimageeditor/DLBmpUtils.inc index 95a56d8ee..ce1aafe45 100644 --- a/applications/lazimageeditor/DLBmpUtils.inc +++ b/applications/lazimageeditor/DLBmpUtils.inc @@ -515,7 +515,7 @@ begin b := Random(Round(Radians * 0.65)); if (temp < 50) then b := 0 - b; if (a * a + b * b < Sqr(Round(Radians * 0.65))) then - DLBmp.ScanLinePixels[X + a, Y + b] := PColor; + DLBmp.Pixels[X + a, Y + b] := PColor; Radian2 := Radians div 3; temp := Random(100); a := Random(Round(Radian2 * 0.65)); @@ -524,7 +524,7 @@ begin b := Random(Round(Radian2 * 0.65)); if (temp < 50) then b := 0 - b; if (a * a + b * b < Sqr(Round(Radian2 * 0.65))) then - DLBmp.ScanLinePixels[X + a, Y + b] := PColor; + DLBmp.Pixels[X + a, Y + b] := PColor; Radian3 := Radians * 2 div 3; temp := Random(100); a := Random(Round(Radian3 * 0.65)); @@ -533,7 +533,7 @@ begin b := Random(Round(Radian3 * 0.65)); if (temp < 50) then b := 0 - b; if (a * a + b * b < Sqr(Round(Radian3 * 0.65))) then - DLBmp.ScanLinePixels[X + a, Y + b] := PColor; + DLBmp.Pixels[X + a, Y + b] := PColor; end; DLBmp.InvalidateScanLineRect(Rect(X - Radians, Y - Radians, X + Radians, Y + Radians)); end; @@ -614,6 +614,64 @@ begin aBitmap.InvalidateScanLine; end; - +procedure StretchLinear(Dest, Src: TDLBitmap); // only for 24bit bitmap +var + sw, sh, dw, dh, B, N, x, y, i, j, k, nPixelSize: DWord; + pLinePrev, pLineNext, pDest, pA, pB, pC, pD: pRGBATriple; +begin + sw := Src.Width - 1; + sh := Src.Height - 1; + dw := Dest.Width - 1; + dh := Dest.Height - 1; + nPixelSize := 3; + for i := 0 to dh do + begin + pDest := Dest.ScanLine[i]; + y := i * sh div dh; + N := dh - i * sh mod dh; + pLinePrev := Src.ScanLine[y]; + Inc(y); + if N = dh then + begin + pLineNext := pLinePrev; + end + else + begin + pLineNext := Src.ScanLine[y]; + end; + for j := 0 to dw do + begin + x := j * sw div dw * nPixelSize; + B := dw - j * sw mod dw; + pA := pLinePrev; + Inc(pA, x); + pB := pA; + Inc(pB, nPixelSize); + pC := pLineNext; + Inc(pC, x); + pD := pC; + Inc(pD, nPixelSize); + if B = dw then + begin + pB := pA; + pD := pC; + end; + for k := 0 to nPixelSize - 1 do + begin + pDest^ := DWordToTriple( + (B * N * DWordTrans(pA^ - pB^ - pC^ + pD^) + + dw * N * DWordTrans(pB^) + + dh * B * DWordTrans(pC^) + (dw * dh - dh * B - dw * N) * + DWordTrans(pD^) + + dw * dh div 2) div (dw * dh)); + Inc(pDest); + Inc(pA); + Inc(pB); + Inc(pC); + Inc(pD); + end; + end; + end; +end; diff --git a/applications/lazimageeditor/lazimageeditor.lpi b/applications/lazimageeditor/lazimageeditor.lpi index 8ccc62f0e..70653a42f 100644 --- a/applications/lazimageeditor/lazimageeditor.lpi +++ b/applications/lazimageeditor/lazimageeditor.lpi @@ -41,7 +41,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -357,8 +357,8 @@ - - + + @@ -391,8 +391,8 @@ - - + + @@ -418,92 +418,136 @@ + + + + + + + + - + - - + + - - + + - - + + - - + + - + - - - - - - - - - - - - - - - - - - + + - - + + - - + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +