Skip to content

Commit

Permalink
New image to string conversion and image_lazbridge unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Aug 30, 2023
1 parent 36a4e57 commit af78f8c
Show file tree
Hide file tree
Showing 20 changed files with 1,297 additions and 682 deletions.
14 changes: 13 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="135">
<Units Count="138">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -952,6 +952,18 @@
<Filename Value="script/imports/simba/simba.import_threading.pas"/>
<IsPartOfProject Value="True"/>
</Unit134>
<Unit135>
<Filename Value="../Third-Party/fpqoi_simba.pas"/>
<IsPartOfProject Value="True"/>
</Unit135>
<Unit136>
<Filename Value="simba.image_lazbridge.pas"/>
<IsPartOfProject Value="True"/>
</Unit136>
<Unit137>
<Filename Value="simba.rgbsumtable.pas"/>
<IsPartOfProject Value="True"/>
</Unit137>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
12 changes: 4 additions & 8 deletions Source/forms/simba.imagetostringform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ implementation
{$R *.lfm}

uses
simba.mufasatypes, simba.bitmap, simba.bitmap_utils, simba.stringbuilder;
simba.mufasatypes, simba.bitmap, simba.image_lazbridge, simba.stringbuilder;

procedure TSimbaImageToStringForm.OpenButtonClick(Sender: TObject);
begin
Expand Down Expand Up @@ -89,7 +89,7 @@ procedure TSimbaImageToStringForm.ToStringButtonClick(Sender: TObject);
begin
if Assigned(ImagePreview.Picture.Bitmap) and (ImagePreview.Picture.Bitmap.Width > 0) and (ImagePreview.Picture.Bitmap.Height > 0) then
begin
with ImagePreview.Picture.Bitmap.ToMufasaBitmap() do
with LazImage_ToSimbaImage(ImagePreview.Picture.Bitmap) do
try
ImageString := SaveToString();
finally
Expand All @@ -98,11 +98,7 @@ procedure TSimbaImageToStringForm.ToStringButtonClick(Sender: TObject);

if PadOutput.Checked then
begin
Builder.Append('Image := TSimbaImage.CreateFromString(');
Builder.Append(IntToStr(ImagePreview.Picture.Bitmap.Width));
Builder.Append(', ');
Builder.Append(IntToStr(ImagePreview.Picture.Bitmap.Height));
Builder.Append(', ');
Builder.Append('Image := TImage.CreateFromString(');
Builder.AppendLine();

while (ImageString <> '') do
Expand All @@ -114,7 +110,7 @@ procedure TSimbaImageToStringForm.ToStringButtonClick(Sender: TObject);

ImageString := Copy(Builder.Str, 1, Builder.Count - Length(LineEnding) - 2) + ');';
end else
ImageString := 'Image := TSimbaImage.CreateFromString(' + IntToStr(ImagePreview.Picture.Bitmap.Width) + ',' + IntToStr(ImagePreview.Picture.Bitmap.Height) + ', ' + #39 + ImageString + #39 + ');';
ImageString := 'Image := TImage.CreateFromString(' + #39 + ImageString + #39 + ');';

try
Clipboard.AsText := ImageString;
Expand Down
12 changes: 6 additions & 6 deletions Source/imagebox/simba.imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ implementation

uses
Math, GraphType, LCLIntf,
simba.finder, simba.bitmap_utils, simba.windowhandle;
simba.finder, simba.image_lazbridge, simba.windowhandle;

procedure TSimbaImageBox_ScrollBox.GetPreferredSize(var PreferredWidth, PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
begin
Expand Down Expand Up @@ -620,7 +620,7 @@ function TSimbaImageBox.FindDTM(DTM: TDTM): TPointArray;
Finder: TSimbaFinder;
Img: TSimbaImage;
begin
Img := FBackground.ToMufasaBitmap();
Img := LazImage_ToSimbaImage(FBackground);
try
Finder.Target.SetImage(Img);

Expand All @@ -635,7 +635,7 @@ function TSimbaImageBox.FindColor(AColor: TColor; Tolerance: Single; ColorSpace:
Finder: TSimbaFinder;
Img: TSimbaImage;
begin
Img := FBackground.ToMufasaBitmap();
Img := LazImage_ToSimbaImage(FBackground);
try
Finder.Target.SetImage(Img);

Expand All @@ -650,7 +650,7 @@ function TSimbaImageBox.MatchColor(AColor: TColor; ColorSpace: EColorSpace; Mult
Finder: TSimbaFinder;
Img: TSimbaImage;
begin
Img := FBackground.ToMufasaBitmap();
Img := LazImage_ToSimbaImage(FBackground);
try
Finder.Target.SetImage(Img);

Expand All @@ -662,7 +662,7 @@ function TSimbaImageBox.MatchColor(AColor: TColor; ColorSpace: EColorSpace; Mult

procedure TSimbaImageBox.SetBackground(Data: PColorBGRA; AWidth, AHeight: Integer);
begin
FBackground.FromData(Data, AWidth, AHeight);
LazImage_FromData(FBackground, Data, AWidth, AHeight);
end;

procedure TSimbaImageBox.SetBackground(FileName: String);
Expand All @@ -672,7 +672,7 @@ procedure TSimbaImageBox.SetBackground(FileName: String);

procedure TSimbaImageBox.SetBackground(Bitmap: TSimbaImage);
begin
FBackground.FromData(Bitmap.Data, Bitmap.Width, Bitmap.Height);
SetBackground(Bitmap.Data, Bitmap.Width, Bitmap.Height);
end;

procedure TSimbaImageBox.SetBackground(Window: TWindowHandle);
Expand Down
5 changes: 2 additions & 3 deletions Source/imagebox/simba.imagebox_bitmap.pas
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ TSimbaImageBoxBitmap = class(TObject)
implementation

uses
simba.bitmap_utils,
simba.singlematrix, simba.integermatrix;
simba.image_lazbridge, simba.singlematrix, simba.integermatrix;

const
HEATMAP_LOOKUP_TABLE: array[0..837] of TColor = (
Expand Down Expand Up @@ -248,7 +247,7 @@ procedure TSimbaImageBoxBitmap.BeginUpdate(Rect: TRect; Width, Height, PixelSize
FBytesPerLine := FBitmap.RawImage.Description.BytesPerLine;
FBytesPerPixel := FBitmap.RawImage.Description.BitsPerPixel shr 3;
FData := FBitmap.RawImage.Data;
FPixelFormat := GetBitmapPixelFormat(FBitmap);
FPixelFormat := LazImage_PixelFormat(FBitmap);
end;

procedure TSimbaImageBoxBitmap.EndUpdate;
Expand Down
12 changes: 6 additions & 6 deletions Source/script/imports/simbaclasses/simba.import_class_bitmap.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,11 @@ procedure _LapeImage_PixelDifferenceToleranceTPA(const Params: PParamArray; cons
(*
TImage.LoadFromString
~~~~~~~~~~~~~~~~~~~~~
> procedure TImage.LoadFromString(AWidth, AHeight: Integer; Str: String);
> procedure TImage.LoadFromString(Str: String);
*)
procedure _LapeImage_LoadFromString(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaImage(Params^[0])^.LoadFromString(PInteger(Params^[1])^, PInteger(Params^[2])^, PString(Params^[3])^);
PSimbaImage(Params^[0])^.LoadFromString(PString(Params^[1])^);
end;

(*
Expand Down Expand Up @@ -1124,11 +1124,11 @@ procedure _LapeImage_CreateFromFile(const Params: PParamArray; const Result: Poi
(*
TImage.CreateFromString
~~~~~~~~~~~~~~~~~~~~~~~
> function TImage.CreateFromString(Width, Height: Integer; Str: String): TImage; static;
> function TImage.CreateFromString(Str: String): TImage; static;
*)
procedure _LapeImage_CreateFromString(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaImage(Result)^ := TSimbaImage.CreateFromString(PInteger(Params^[0])^, PInteger(Params^[1])^, PString(Params^[2])^);
PSimbaImage(Result)^ := TSimbaImage.CreateFromString(PString(Params^[0])^);
end;

(*
Expand Down Expand Up @@ -1300,7 +1300,7 @@ procedure ImportSimbaImage(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function TImage.Create: TImage; static; overload', @_LapeImage_Create);
addGlobalFunc('function TImage.Create(Width, Height: Integer): TImage; static; overload', @_LapeImage_CreateEx);
addGlobalFunc('function TImage.CreateFromFile(FileName: String): TImage; static; overload', @_LapeImage_CreateFromFile);
addGlobalFunc('function TImage.CreateFromString(Width, Height: Integer; Str: String): TImage; static; overload', @_LapeImage_CreateFromString);
addGlobalFunc('function TImage.CreateFromString(Str: String): TImage; static; overload', @_LapeImage_CreateFromString);

addGlobalFunc('function TImage.Equals(Other: TImage): Boolean;', @_LapeImage_Equals);

Expand Down Expand Up @@ -1403,7 +1403,7 @@ procedure ImportSimbaImage(Compiler: TSimbaScript_Compiler);

addGlobalFunc('procedure TImage.LoadFromFile(FileName: String); overload', @_LapeImage_LoadFromFile);
addGlobalFunc('procedure TImage.LoadFromFile(FileName: String; Area: TBox); overload', @_LapeImage_LoadFromFileEx);
addGlobalFunc('procedure TImage.LoadFromString(AWidth, AHeight: Integer; Str: String)', @_LapeImage_LoadFromString);
addGlobalFunc('procedure TImage.LoadFromString(Str: String)', @_LapeImage_LoadFromString);
addGlobalFunc('procedure TImage.LoadFromData(AWidth, AHeight: Integer; AData: PColorBGRA; DataWidth: Integer)', @_LapeImage_LoadFromData);
addGlobalFunc('procedure TImage.LoadFromImage(Image: TImage);', @_LapeImage_LoadFromImage);

Expand Down
7 changes: 7 additions & 0 deletions Source/simba.baseclass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ TSimbaBaseClass = class
constructor Create;
destructor Destroy; override;

function GetSelf: TSimbaBaseClass;

property Name: String read GetName write SetName;
property FreeOnTerminate: Boolean read FFreeOnTerminate write FFreeOnTerminate;
end;
Expand Down Expand Up @@ -83,6 +85,11 @@ destructor TSimbaBaseClass.Destroy;
inherited Destroy();
end;

function TSimbaBaseClass.GetSelf: TSimbaBaseClass;
begin
Result := Self;
end;

procedure TSimbaObjectTracker.Add(Obj: TSimbaBaseClass);
begin
FList.Add(Obj);
Expand Down
Loading

0 comments on commit af78f8c

Please sign in to comment.