ScanLine likes Delphi's with one line code added to update it.

Multiple images of ICO is back.
Color can be filled in the tools.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1570 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
yangjixian
2011-04-15 16:41:26 +00:00
parent 2b84aaadad
commit fd13bd5514
5 changed files with 270 additions and 233 deletions

View File

@ -64,7 +64,7 @@ type
{ TRGBBitmapCore }
TRGBBitmapCore = class(TCustomRGBBitmapCore)
TRGBBitmapCore = class(TDLBitmap)
private
FSizeOfPixel: integer;
FRowPixelStride: integer;

View File

@ -41,7 +41,7 @@
<PackageName Value="LCL"/>
</Item3>
</RequiredPackages>
<Units Count="33">
<Units Count="35">
<Unit0>
<Filename Value="lazimageeditor.pas"/>
<IsPartOfProject Value="True"/>
@ -49,7 +49,7 @@
<WindowIndex Value="0"/>
<TopLine Value="2"/>
<CursorPos X="11" Y="26"/>
<UsageCount Value="59"/>
<UsageCount Value="61"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
@ -58,23 +58,23 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="1030"/>
<CursorPos X="5" Y="1046"/>
<UsageCount Value="59"/>
<CursorPos X="15" Y="1051"/>
<UsageCount Value="61"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="picturectrls.pas"/>
<UnitName Value="PictureCtrls"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="1157"/>
<CursorPos X="15" Y="1170"/>
<UsageCount Value="26"/>
<TopLine Value="896"/>
<CursorPos X="46" Y="886"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -169,21 +169,19 @@
<Unit12>
<Filename Value="T:\fpclaz\laz\lcl\graphics.pp"/>
<UnitName Value="Graphics"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/>
<TopLine Value="1404"/>
<CursorPos X="27" Y="1404"/>
<TopLine Value="2580"/>
<CursorPos X="9" Y="2592"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
<Filename Value="picturemanager.pas"/>
<UnitName Value="PictureManager"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="233"/>
<CursorPos X="40" Y="250"/>
<UsageCount Value="27"/>
<TopLine Value="1"/>
<CursorPos X="21" Y="268"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
@ -245,10 +243,12 @@
<Unit21>
<Filename Value="bmprgbtypes.pas"/>
<UnitName Value="BmpRGBTypes"/>
<EditorIndex Value="5"/>
<WindowIndex Value="0"/>
<TopLine Value="259"/>
<CursorPos X="20" Y="268"/>
<TopLine Value="559"/>
<CursorPos X="40" Y="567"/>
<UsageCount Value="25"/>
<Loaded Value="True"/>
</Unit21>
<Unit22>
<Filename Value="T:\fpclaz\laz\lcl\include\winapih.inc"/>
@ -276,11 +276,11 @@
<Unit25>
<Filename Value="bmprgbutils.pas"/>
<UnitName Value="BmpRGBUtils"/>
<EditorIndex Value="5"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/>
<TopLine Value="34"/>
<CursorPos X="72" Y="5"/>
<UsageCount Value="22"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit25>
<Unit26>
@ -304,9 +304,9 @@
<UnitName Value="BmpRGBGraph"/>
<EditorIndex Value="6"/>
<WindowIndex Value="0"/>
<TopLine Value="100"/>
<CursorPos X="15" Y="122"/>
<UsageCount Value="18"/>
<TopLine Value="47"/>
<CursorPos X="59" Y="66"/>
<UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit28>
<Unit29>
@ -314,9 +314,9 @@
<UnitName Value="RGBDrawUtils"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="36" Y="15"/>
<UsageCount Value="17"/>
<TopLine Value="636"/>
<CursorPos X="20" Y="669"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit29>
<Unit30>
@ -346,127 +346,142 @@
<CursorPos X="14" Y="607"/>
<UsageCount Value="10"/>
</Unit32>
<Unit33>
<Filename Value="T:\fpclaz\laz\lcl\include\graphic.inc"/>
<WindowIndex Value="0"/>
<TopLine Value="116"/>
<CursorPos X="30" Y="130"/>
<UsageCount Value="10"/>
</Unit33>
<Unit34>
<Filename Value="D:\我的文档\桌面\imgedit\picturemanager.pas"/>
<UnitName Value="PictureManager"/>
<WindowIndex Value="0"/>
<TopLine Value="230"/>
<CursorPos X="28" Y="237"/>
<UsageCount Value="10"/>
</Unit34>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="picturemanager.pas"/>
<Caret Line="108" Column="65" TopLine="82"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="3" Column="98" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="picturemanager.pas"/>
<Caret Line="191" Column="31" TopLine="177"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="111" Column="62" TopLine="79"/>
</Position2>
<Position3>
<Filename Value="picturemanager.pas"/>
<Caret Line="193" Column="38" TopLine="177"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="117" Column="51" TopLine="85"/>
</Position3>
<Position4>
<Filename Value="picturemanager.pas"/>
<Caret Line="277" Column="31" TopLine="263"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="124" Column="10" TopLine="92"/>
</Position4>
<Position5>
<Filename Value="picturemanager.pas"/>
<Caret Line="279" Column="58" TopLine="263"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="125" Column="10" TopLine="93"/>
</Position5>
<Position6>
<Filename Value="picturemanager.pas"/>
<Caret Line="282" Column="31" TopLine="263"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="126" Column="10" TopLine="94"/>
</Position6>
<Position7>
<Filename Value="picturemanager.pas"/>
<Caret Line="287" Column="9" TopLine="263"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="127" Column="15" TopLine="95"/>
</Position7>
<Position8>
<Filename Value="picturemanager.pas"/>
<Caret Line="391" Column="46" TopLine="371"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="143" Column="22" TopLine="111"/>
</Position8>
<Position9>
<Filename Value="picturectrls.pas"/>
<Caret Line="163" Column="26" TopLine="147"/>
<Caret Line="166" Column="24" TopLine="134"/>
</Position9>
<Position10>
<Filename Value="main.pas"/>
<Caret Line="1044" Column="14" TopLine="1032"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="167" Column="28" TopLine="135"/>
</Position10>
<Position11>
<Filename Value="picturemanager.pas"/>
<Caret Line="88" Column="19" TopLine="72"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="205" Column="61" TopLine="173"/>
</Position11>
<Position12>
<Filename Value="picturectrls.pas"/>
<Caret Line="521" Column="33" TopLine="506"/>
<Caret Line="209" Column="72" TopLine="177"/>
</Position12>
<Position13>
<Filename Value="main.pas"/>
<Caret Line="1044" Column="14" TopLine="1032"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="213" Column="82" TopLine="181"/>
</Position13>
<Position14>
<Filename Value="main.pas"/>
<Caret Line="1038" Column="14" TopLine="1030"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="216" Column="60" TopLine="184"/>
</Position14>
<Position15>
<Filename Value="main.pas"/>
<Caret Line="295" Column="28" TopLine="279"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="408" Column="9" TopLine="376"/>
</Position15>
<Position16>
<Filename Value="main.pas"/>
<Caret Line="1038" Column="20" TopLine="1012"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="557" Column="37" TopLine="525"/>
</Position16>
<Position17>
<Filename Value="main.pas"/>
<Caret Line="1046" Column="1" TopLine="1016"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="559" Column="20" TopLine="527"/>
</Position17>
<Position18>
<Filename Value="main.pas"/>
<Caret Line="1229" Column="1" TopLine="1198"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="560" Column="8" TopLine="528"/>
</Position18>
<Position19>
<Filename Value="main.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="596" Column="20" TopLine="573"/>
</Position19>
<Position20>
<Filename Value="main.pas"/>
<Caret Line="295" Column="28" TopLine="269"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="166" Column="24" TopLine="146"/>
</Position20>
<Position21>
<Filename Value="main.pas"/>
<Caret Line="1038" Column="20" TopLine="1012"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="167" Column="28" TopLine="146"/>
</Position21>
<Position22>
<Filename Value="main.pas"/>
<Caret Line="1046" Column="27" TopLine="1016"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="213" Column="82" TopLine="181"/>
</Position22>
<Position23>
<Filename Value="main.pas"/>
<Caret Line="1044" Column="11" TopLine="1028"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="596" Column="25" TopLine="564"/>
</Position23>
<Position24>
<Filename Value="main.pas"/>
<Caret Line="23" Column="77" TopLine="20"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="597" Column="55" TopLine="565"/>
</Position24>
<Position25>
<Filename Value="main.pas"/>
<Caret Line="295" Column="28" TopLine="269"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="641" Column="37" TopLine="609"/>
</Position25>
<Position26>
<Filename Value="main.pas"/>
<Caret Line="1038" Column="20" TopLine="1024"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="658" Column="18" TopLine="626"/>
</Position26>
<Position27>
<Filename Value="main.pas"/>
<Caret Line="1046" Column="23" TopLine="1024"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="703" Column="12" TopLine="671"/>
</Position27>
<Position28>
<Filename Value="main.pas"/>
<Caret Line="1044" Column="24" TopLine="1030"/>
<Filename Value="picturectrls.pas"/>
<Caret Line="766" Column="41" TopLine="743"/>
</Position28>
<Position29>
<Filename Value="picturectrls.pas"/>
<Caret Line="198" Column="22" TopLine="182"/>
<Caret Line="862" Column="23" TopLine="842"/>
</Position29>
<Position30>
<Filename Value="picturectrls.pas"/>
<Caret Line="1170" Column="15" TopLine="1157"/>
<Filename Value="bmprgbtypes.pas"/>
<Caret Line="128" Column="29" TopLine="108"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -521,14 +521,17 @@ begin
end;
procedure TCustomPictureView.SavePicture(const FileName: String);
var Pic: TPicture;
var Pic: TPicture; ExtName: string;
begin
Pic := TPicture.Create;
//Picture.SaveToFile(UTF8Decode(FileName));
Pic.Bitmap.Width := Picture.Width;
Pic.Bitmap.Height := Picture.Height;
Pic.Bitmap.Canvas.Draw(0,0,Picture);
Pic.SaveToFile(FileName);
ExtName := ExtractFileExt(FileName);
// if ExtName = 'PNG' then
// Pic.Graphic.;
Pic.SaveToFile(FileName, ExtName);
Pic.Free;
end;
@ -760,7 +763,7 @@ begin
BeginDraw;
if not (ssLeft in Shift) then Picture.EraseMode := ermErase;
try
Picture.Canvas.FloodFill(X, Y, Picture.Canvas.Brush.Color, fsSurface);
Picture.Canvas.FloodFill(X, Y, FFillColor, fsSurface); //Picture.Canvas.Brush.Color, fsSurface);
finally
Picture.EraseMode := ermNone;
EndDraw;
@ -791,12 +794,14 @@ var
R: TRect;
begin
if Picture = nil then Exit;
BeginDraw;
if ssLeft in Shift then Picture.EraseMode := ermErase;
if ssRight in Shift then Picture.EraseMode := ermReplace;
try
R := Bounds(X - FSize div 2, Y - FSize div 2, FSize, FSize);
Picture.Canvas.Pen.Color:=FPaperColor;
Picture.Canvas.Brush.Color:=FpaperColor;
case Shape of
psRect: Picture.Canvas.FillRect(R.Left, R.Top, R.Right, R.Bottom);
psCircle: Picture.FillEllipse(R.Left, R.Top, R.Right, R.Bottom);
@ -818,6 +823,8 @@ begin
if not (ssLeft in Shift) then Picture.EraseMode := ermErase;
Picture.RandomEnabled := True;
try
Picture.Canvas.Pen.Color:=FFillColor;
Picture.Canvas.Brush.Color:=FFillColor;
R := Bounds(X - FSize div 2, Y - FSize div 2, FSize, FSize);
case Shape of
psRect: Picture.Canvas.FillRect(R.Left, R.Top, R.Right, R.Bottom);
@ -834,7 +841,8 @@ end;
procedure TCustomPictureEdit.Line(X1, Y1, X2, Y2: Integer; Shift: TShiftState);
begin
if Picture = nil then Exit;
Picture.Canvas.Pen.Color:=FOutLineColor;
BeginDraw;
if not (ssLeft in Shift) then Picture.EraseMode := ermErase;
try
@ -854,6 +862,8 @@ begin
BeginDraw;
if not (ssLeft in Shift) then Picture.EraseMode := ermErase;
try
Picture.Canvas.Brush.Color:=FFillColor;
Picture.Canvas.Pen.Color:=FOutlineColor;
if FFuzzy then
begin
Picture.FuzzyRectangle(X1, Y1, X2, Y2);
@ -879,7 +889,8 @@ begin
BeginDraw;
if not (ssLeft in Shift) then Picture.EraseMode := ermErase;
try
Picture.Canvas.Brush.Color:=FFillColor;
Picture.Canvas.Pen.Color:=FOutlineColor;
Picture.Canvas.Ellipse(X1, Y1, X2, Y2);
finally
Picture.EraseMode := ermNone;

View File

@ -235,25 +235,24 @@ end;
procedure TPictureManager.Load(const FileName: String);
var
NewPage: TPicturePage;
Icon: TCustomRGBBitmapCore;
Icon: TIcon;
Bmp: TDLBitmap;
I: Integer;
Pic: TPicture;
begin
//if SameText(ExtractFileExt(FileName), '.ico') then
//begin
Icon := TCustomRGBBitmapCore.Create;
if SameText(ExtractFileExt(FileName), '.ico') then
begin
Icon := TIcon.Create;
try
// First image in std bitmap
// Icon.LoadFromFile(FileName);
Pic := TPicture.Create;
Pic.LoadFromFile(FileName);
Icon.Width:=Pic.Width;
Icon.Height:=Pic.Height;
Icon.Canvas.Draw(0,0,Pic.Graphic);
Icon.LoadFromFile(FileName);
// other images
//for I := 0 to Pred(Icon.Count) do
for I := 0 to Pred(Icon.Count) do
begin
// Icon.Current := I;
Icon.Current := I;
NewPage := CreatePage(Icon);
NewPage.Parent := Self;
ActivePage := NewPage;
@ -262,8 +261,34 @@ begin
end;
finally
Icon.Free;
end;
end
else
begin
Bmp := TDLBitmap.Create;
try
// First image in std bitmap
// Icon.LoadFromFile(FileName);
Pic := TPicture.Create;
Pic.LoadFromFile(FileName);
Bmp.Width:=Pic.Width;
Bmp.Height:=Pic.Height;
Bmp.Canvas.Draw(0,0,Pic.Graphic);
// other images
//for I := 0 to Pred(Icon.Count) do
begin
// Icon.Current := I;
NewPage := CreatePage(Bmp);
NewPage.Parent := Self;
ActivePage := NewPage;
NewPage.Caption := FindNewUniqueName;
Change;
end;
finally
Bmp.Free;
Pic.Free;
end;
end;
{end
else
begin

View File

@ -10,15 +10,15 @@ uses
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
TRGBTripleArray = array[word] of TRGBTriple;
TCustomRGBBitmapCore = class(TBitmap)
TDLBitmap = class(TBitmap)
private
FIntfImgA: TLazIntfImage;
FFillColor: TColor;
FOutlineColor: TColor;
FPaperColor: TColor;
function GetScanline(Row: integer): Pointer;
function GetScanline(Row: integer): pRGBTriple;
function GetFillColor: TColor;
function GetOutlineColor: TColor;
function GetPaperColor: TColor;
@ -28,11 +28,12 @@ type
protected
procedure SetWidth(Value: integer); override;
procedure SetHeight(Value: integer); override;
procedure Changed(Sender: TObject); override;
public
constructor Create; override;
destructor Destroy; override;
procedure OpenScanLine;
procedure CloseScanLine;
procedure ResetScanLine;
procedure InvalidateScanLine;
procedure Assign(Source: TPersistent); override;
procedure Clear; virtual;
procedure ClearWhite; virtual;
@ -43,7 +44,7 @@ type
procedure Rotate90; virtual;
procedure Rotate180; virtual;
procedure Rotate270; virtual;
property ScanLine[Row: integer]: Pointer read GetScanLine;
property ScanLine[Row: integer]: pRGBTriple read GetScanLine;
procedure FillEllipse(X1, Y1, X2, Y2: integer); virtual;
procedure CutToClipboard; virtual;
procedure CopyToClipboard; virtual;
@ -54,29 +55,29 @@ type
property PaperColor: TColor read GetPaperColor write SetPaperColor;
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;
procedure LazBMPRotate90(const aBitmap: TDLBitmap; IsTurnRight: boolean);
procedure BMPRotate90(const Bitmap: TDLBitmap);
procedure DrawSamePixel(ABitmap: TDLBitmap; Value: integer);
procedure BMPRotate180(const Bitmap: TDLBitmap);
procedure BMPRotate270(const Bitmap: TDLBitmap);
function RotateBitmap(Bitmap: TDLBitmap; Angle: integer;
BackColor: TColor): TDLBitmap;
function BitmapFlip(const Vertical: boolean; const Horizontal: boolean;
var BitmapIn: TCustomRGBBitmapCore; out BitmapOut: TCustomRGBBitmapCore): boolean;
procedure InvertBitmap(aBitmap: TCustomRGBBitmapCore);
var BitmapIn: TDLBitmap; out BitmapOut: TDLBitmap): boolean;
procedure InvertBitmap(aBitmap: TDLBitmap);
implementation
procedure LazBMPRotate90(const aBitmap: TCustomRGBBitmapCore; IsTurnRight: boolean);
procedure LazBMPRotate90(const aBitmap: TDLBitmap; IsTurnRight: boolean);
var
i, j: integer;
rowIn, rowOut: PRGBTripleArray;
Bmp: TCustomRGBBitmapCore;
Bmp: TDLBitmap;
Width, Height: integer;
IntfImg1, IntfImg2: TLazIntfImage;
ImgHandle, ImgMaskHandle: HBitmap;
begin
Bmp := TCustomRGBBitmapCore.Create;
Bmp := TDLBitmap.Create;
Bmp.Width := aBitmap.Height;
Bmp.Height := aBitmap.Width;
Bmp.PixelFormat := pf24bit;
@ -107,18 +108,16 @@ begin
Bmp.Free;
end;
procedure BMPRotate90(const Bitmap: TCustomRGBBitmapCore);
procedure BMPRotate90(const Bitmap: TDLBitmap);
var
i, j: integer;
rowIn, rowOut: PRGBTripleArray;
Bmp: TCustomRGBBitmapCore;
rowIn, rowOut: pRGBTriple;
Bmp: TDLBitmap;
Width, Height: integer;
begin
Bmp := TCustomRGBBitmapCore.Create;
Bmp := TDLBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Bmp.OpenScanLine;
Bitmap.OpenScanLine;
Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1;
for j := 0 to Height do
@ -127,29 +126,26 @@ begin
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine[i];
rowOut^[Height - j] := rowIn^[i];
rowOut[Height - j] := rowIn[i];
end;
end;
Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bmp.InvalidateScanLine;
Bitmap.Assign(Bmp);
end;
procedure BMPRotate180(const Bitmap: TCustomRGBBitmapCore);
procedure BMPRotate180(const Bitmap: TDLBitmap);
var
i, j: integer;
rowIn, rowOut: pRGBTriple;
Bmp: TCustomRGBBitmapCore;
Bmp: TDLBitmap;
Width, Height: integer;
begin
Bmp := TCustomRGBBitmapCore.Create;
Bmp := TDLBitmap.Create;
Bmp.Width := Bitmap.Width;
Bmp.Height := Bitmap.Height;
Bmp.PixelFormat := pf24bit;
Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1;
Bmp.OpenScanLine;
Bitmap.OpenScanLine;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
@ -161,26 +157,24 @@ begin
Inc(rowIn);
end;
end;
Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bmp.InvalidateScanLine;
Bitmap.InvalidateScanLine;
Bitmap.Assign(Bmp);
end;
procedure BMPRotate270(const Bitmap: TCustomRGBBitmapCore);
procedure BMPRotate270(const Bitmap: TDLBitmap);
var
i, j: integer;
rowIn, rowOut: pRGBTriple;
Bmp: TCustomRGBBitmapCore;
Bmp: TDLBitmap;
Width, Height: integer;
begin
Bmp := TCustomRGBBitmapCore.Create;
Bmp := TDLBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Bmp.PixelFormat := pf24bit;
Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1;
Bmp.OpenScanLine;
Bitmap.OpenScanLine;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
@ -192,24 +186,21 @@ begin
Inc(rowIn);
end;
end;
Bmp.CloseScanLine;
Bitmap.CloseScanLine;
Bmp.InvalidateScanLine;
Bitmap.Assign(Bmp);
end;
function RotateBitmap(Bitmap: TCustomRGBBitmapCore; Angle: integer;
BackColor: TColor): TCustomRGBBitmapCore;
function RotateBitmap(Bitmap: TDLBitmap; Angle: integer;
BackColor: TColor): TDLBitmap;
var
i, j, iOriginal, jOriginal, CosPoint, SinPoint: integer;
RowOriginal, RowRotated: pRGBTriple;
SinTheta, CosTheta: extended;
AngleAdd: integer;
begin
Result := TCustomRGBBitmapCore.Create;
Result := TDLBitmap.Create;
Result.PixelFormat := pf24bit;
Result.Canvas.Brush.Color := BackColor;
Result.OpenScanLine;
Bitmap.OpenScanLine;
Angle := Angle mod 360;
if Angle < 0 then
Angle := 360 - Abs(Angle);
@ -318,45 +309,42 @@ begin
end;
end;
end;
Result.CloseScanLine;
Bitmap.CloseScanLine;
Result.InvalidateScanLine;
Bitmap.InvalidateScanLine;
end;
procedure DrawSamePixel(ABitmap: TCustomRGBBitmapCore; Value: integer);
procedure DrawSamePixel(ABitmap: TDLBitmap; Value: integer);
var
LNew: TRGBTriple;
LMinusRatio: real;
LScan: PRGBTripleArray;
LScan: pRGBTriple;
i, j: integer;
begin
aBitmap.OpenScanLine;
for i := 0 to ABitmap.Height - 1 do
begin
LScan := ABitmap.Scanline[i];
for j := 0 to ABitmap.Width - 1 do
begin
LNew := LScan^[j];
LScan^[j].rgbtBlue := LScan^[j].rgbtBlue * Value div 100; //Value; //LNew.rgbtBlue;
LScan^[j].rgbtGreen := LScan^[j].rgbtGreen * Value div 100; //LNew.rgbtGreen;
LScan^[j].rgbtRed := LScan^[j].rgbtRed * Value div 100; //LNew.rgbtRed;
//LScan^[j] := LNew;
LNew := LScan[j];
LScan[j].rgbtBlue := LScan[j].rgbtBlue * Value div 100; //Value; //LNew.rgbtBlue;
LScan[j].rgbtGreen := LScan[j].rgbtGreen * Value div 100; //LNew.rgbtGreen;
LScan[j].rgbtRed := LScan[j].rgbtRed * Value div 100; //LNew.rgbtRed;
//LScan[j] := LNew;
end;
end;
ABitmap.CloseScanLine;
ABitmap.InvalidateScanLine;
end;
function BitmapFlip(const Vertical: boolean; const Horizontal: boolean;
var BitmapIn: TCustomRGBBitmapCore; out BitmapOut: TCustomRGBBitmapCore): boolean;
var BitmapIn: TDLBitmap; out BitmapOut: TDLBitmap): boolean;
var
DataIn: PRGBTripleArray;
DataOut: PRGBTripleArray;
DataIn: pRGBTriple;
DataOut: pRGBTriple;
inRow: integer;
inCol: integer;
begin
Result := False;
try
BitmapIn.OpenScanLine;
BitmapOut.OpenScanLine;
if BitmapIn.PixelFormat <> pf24bit then
Exit;
with BitmapOut do
@ -379,90 +367,88 @@ begin
if Horizontal then
begin
for inCol := 0 to BitmapIn.Width - 1 do
DataOut^[inCol] := DataIn^[BitmapIn.Width - 1 - inCol];
DataOut[inCol] := DataIn[BitmapIn.Width - 1 - inCol];
end
else
begin
for inCol := 0 to BitmapIn.Width - 1 do
DataOut^[inCol] := DataIn^[inCol];
DataOut[inCol] := DataIn[inCol];
end;
end;
Result := True;
BitmapIn.CloseScanLine;
BitmapOut.CloseScanLine;
BitmapOut.InvalidateScanLine;
except
end;
end;
procedure InvertBitmap(aBitmap: TCustomRGBBitmapCore);
procedure InvertBitmap(aBitmap: TDLBitmap);
var
LNew: TRGBTriple;
LMinusRatio: real;
LScan: PRGBTripleArray;
LScan: pRGBTriple;
i, j: integer;
begin
aBitmap.OpenScanLine;
for i := 0 to ABitmap.Height - 1 do
begin
LScan := ABitmap.Scanline[i];
for j := 0 to ABitmap.Width - 1 do
begin
LNew := LScan^[j];
LScan^[j].rgbtBlue := not LScan^[j].rgbtBlue;
LScan^[j].rgbtGreen := not LScan^[j].rgbtGreen;
LScan^[j].rgbtRed := not LScan^[j].rgbtRed;
LNew := LScan[j];
LScan[j].rgbtBlue := not LScan[j].rgbtBlue;
LScan[j].rgbtGreen := not LScan[j].rgbtGreen;
LScan[j].rgbtRed := not LScan[j].rgbtRed;
end;
end;
ABitmap.CloseScanLine;
ABitmap.InvalidateScanLine;
end;
procedure ConvertBitmapToGrayScale(const Bitmap: TCustomRGBBitmapCore);
procedure ConvertBitmapToGrayScale(const Bitmap: TDLBitmap);
var
X: integer;
Y: integer;
P: PRGBTripleArray;
P: pRGBTriple;
Gray: byte;
begin
Bitmap.OpenScanLine;
for Y := 0 to (Bitmap.Height - 1) do
begin
P := Bitmap.ScanLine[Y];
for X := 0 to (Bitmap.Width - 1) do
begin
Gray := Round(0.30 * P^[X].rgbtBlue + 0.59 * P^[X].rgbtGreen +
0.11 * P^[X].rgbtRed);
P^[X].rgbtRed := Gray;
P^[X].rgbtGreen := Gray;
P^[X].rgbtBlue := Gray;
Gray := Round(0.30 * P[X].rgbtBlue + 0.59 * P[X].rgbtGreen +
0.11 * P[X].rgbtRed);
P[X].rgbtRed := Gray;
P[X].rgbtGreen := Gray;
P[X].rgbtBlue := Gray;
end;
end;
Bitmap.CloseScanLine;
Bitmap.InvalidateScanLine;
end;
constructor TCustomRGBBitmapCore.Create;
constructor TDLBitmap.Create;
begin
inherited;
PixelFormat := pf24bit;
FIntfImgA := TLazIntfImage.Create(0, 0);
end;
destructor TCustomRGBBitmapCore.Destroy;
destructor TDLBitmap.Destroy;
begin
FIntfImgA.Free;
inherited;
end;
function TCustomRGBBitmapCore.GetScanLine(Row: integer): Pointer;
function TDLBitmap.GetScanLine(Row: integer): pRGBTriple;
begin
if FIntfImgA <> nil then
Result := FIntfImgA.GetDataLineStart(Row);
end;
procedure TCustomRGBBitmapCore.OpenScanLine;
procedure TDLBitmap.ResetScanLine;
begin
FIntfImgA := TLazIntfImage.Create(0, 0);
FIntfImgA.LoadFromBitmap(Handle, MaskHandle);
end;
procedure TCustomRGBBitmapCore.CloseScanLine;
procedure TDLBitmap.InvalidateScanLine;
var
TmpBmp: TBitmap;
ImgHandle, ImgMaskHandle: HBitmap;
@ -477,104 +463,105 @@ begin
Height := TmpBmp.Height;
Canvas.Draw(0, 0, TmpBmp);
TmpBmp.Free;
FIntfImgA.Free;
end;
procedure TCustomRGBBitmapCore.CutToClipboard;
procedure TDLBitmap.CutToClipboard;
begin
CopyToClipboard;
Delete;
end;
procedure TCustomRGBBitmapCore.CopyToClipboard;
procedure TDLBitmap.CopyToClipboard;
begin
ClipBoard.Assign(Self);
end;
procedure TCustomRGBBitmapCore.PasteFromClipboard;
procedure TDLBitmap.PasteFromClipboard;
var
oBmp: TBitmap;
begin
oBmp := TBitmap.Create;
try
oBmp.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfDelphiBitmap));
//Width := oBmp.Width;
//Height := oBmp.Height;
Canvas.Draw(0, 0, oBmp);
finally
oBmp.Free;
end;
end;
procedure TCustomRGBBitmapCore.Delete;
procedure TDLBitmap.Delete;
begin
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := PaperColor;
Canvas.FillRect(0, 0, Width, Height);
end;
procedure TCustomRGBBitmapCore.Assign(Source: TPersistent);
procedure TDLBitmap.Assign(Source: TPersistent);
begin
inherited;
end;
function TCustomRGBBitmapCore.GetFillColor: TColor;
function TDLBitmap.GetFillColor: TColor;
begin
Result := FFillColor;
end;
function TCustomRGBBitmapCore.GetOutlineColor: TColor;
function TDLBitmap.GetOutlineColor: TColor;
begin
Result := FOutlineColor;
end;
function TCustomRGBBitmapCore.GetPaperColor: TColor;
function TDLBitmap.GetPaperColor: TColor;
begin
Result := FPaperColor;
end;
procedure TCustomRGBBitmapCore.SetFillColor(const AValue: TColor);
procedure TDLBitmap.SetFillColor(const AValue: TColor);
begin
FFillColor := AValue;
end;
procedure TCustomRGBBitmapCore.SetOutlineColor(const AValue: TColor);
procedure TDLBitmap.SetOutlineColor(const AValue: TColor);
begin
FOutlineColor := AValue;
end;
procedure TCustomRGBBitmapCore.SetPaperColor(const AValue: TColor);
procedure TDLBitmap.SetPaperColor(const AValue: TColor);
begin
FPaperColor := AValue;
end;
procedure TCustomRGBBitmapCore.SetWidth(Value: integer);
procedure TDLBitmap.SetWidth(Value: integer);
begin
inherited;
end;
procedure TCustomRGBBitmapCore.SetHeight(Value: integer);
procedure TDLBitmap.SetHeight(Value: integer);
begin
inherited;
end;
procedure TCustomRGBBitmapCore.Clear;
procedure TDLBitmap.Changed(Sender: TObject);
begin
inherited;
ResetScanLine;
end;
procedure TDLBitmap.Clear;
begin
end;
procedure TCustomRGBBitmapCore.ClearWhite;
procedure TDLBitmap.ClearWhite;
begin
end;
procedure TCustomRGBBitmapCore.Invert;
procedure TDLBitmap.Invert;
var
tmp: TCustomRGBBitmapCore;
tmp: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self);
@ -583,12 +570,11 @@ begin
tmp.Free;
end;
procedure TCustomRGBBitmapCore.Grayscale;
procedure TDLBitmap.Grayscale;
var
tmp: TCustomRGBBitmapCore;
tmp: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self);
@ -597,14 +583,14 @@ begin
tmp.Free;
end;
procedure TCustomRGBBitmapCore.FlipHorz;
procedure TDLBitmap.FlipHorz;
var
tmp, tmp2: TCustomRGBBitmapCore;
tmp, tmp2: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp2 := TCustomRGBBitmapCore.Create;
tmp2 := TDLBitmap.Create;
tmp2.Width := Width;
tmp2.Height := Height;
tmp.PixelFormat := pf24bit;
@ -616,14 +602,14 @@ begin
tmp2.Free;
end;
procedure TCustomRGBBitmapCore.FlipVert;
procedure TDLBitmap.FlipVert;
var
tmp, tmp2: TCustomRGBBitmapCore;
tmp, tmp2: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp2 := TCustomRGBBitmapCore.Create;
tmp2 := TDLBitmap.Create;
tmp2.Width := Width;
tmp2.Height := Height;
tmp.PixelFormat := pf24bit;
@ -635,11 +621,11 @@ begin
tmp2.Free;
end;
procedure TCustomRGBBitmapCore.Rotate90;
procedure TDLBitmap.Rotate90;
var
tmp: TCustomRGBBitmapCore;
tmp: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self);
@ -650,11 +636,11 @@ begin
tmp.Free;
end;
procedure TCustomRGBBitmapCore.Rotate180;
procedure TDLBitmap.Rotate180;
var
tmp: TCustomRGBBitmapCore;
tmp: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self);
@ -665,11 +651,11 @@ begin
tmp.Free;
end;
procedure TCustomRGBBitmapCore.Rotate270;
procedure TDLBitmap.Rotate270;
var
tmp: TCustomRGBBitmapCore;
tmp: TDLBitmap;
begin
tmp := TCustomRGBBitmapCore.Create;
tmp := TDLBitmap.Create;
tmp.Width := Width;
tmp.Height := Height;
tmp.Canvas.Draw(0, 0, Self);
@ -680,7 +666,7 @@ begin
tmp.Free;
end;
procedure TCustomRGBBitmapCore.FillEllipse(X1, Y1, X2, Y2: integer);
procedure TDLBitmap.FillEllipse(X1, Y1, X2, Y2: integer);
begin
end;