Skip to content

Commit

Permalink
Move integer & single matrix to units
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 1, 2023
1 parent 2aa7183 commit ff89d34
Show file tree
Hide file tree
Showing 21 changed files with 786 additions and 184 deletions.
10 changes: 9 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="172">
<Units Count="174">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -1072,6 +1072,14 @@
<Filename Value="components/simba.component_scrollbar.pas"/>
<IsPartOfProject Value="True"/>
</Unit171>
<Unit172>
<Filename Value="simba.singlematrix.pas"/>
<IsPartOfProject Value="True"/>
</Unit172>
<Unit173>
<Filename Value="simba.integermatrix.pas"/>
<IsPartOfProject Value="True"/>
</Unit173>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2 changes: 1 addition & 1 deletion Source/finders/simba.finder_color.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function MatchColorsOnTarget(Target: TSimbaTarget; Bounds: TBox;
implementation

uses
simba.overallocatearray, simba.colormath_distance_unrolled, simba.threadpool, simba.atpa, simba.datetime;
simba.overallocatearray, simba.colormath_distance_unrolled, simba.threadpool, simba.atpa, simba.datetime, simba.singlematrix;

// How much to "Slice" (vertically) the image up for multithreading.
function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.aca.pas
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ implementation

uses
Clipbrd, TypInfo, LCLType,
simba.windowhandle, simba.bitmap, simba.colormath_aca;
simba.windowhandle, simba.bitmap, simba.colormath_aca, simba.singlematrix;

procedure TSimbaACAForm.ClientImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
Expand Down
3 changes: 2 additions & 1 deletion Source/imagebox/simba.imagebox_bitmap.pas
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ TSimbaImageBoxBitmap = class(TObject)
implementation

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

const
HEATMAP_LOOKUP_TABLE: array[0..837] of TColor = (
Expand Down
28 changes: 13 additions & 15 deletions Source/matchtemplate/simba.matchtemplate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ interface

uses
Classes, SysUtils,
simba.mufasatypes, simba.baseclass, simba.bitmap;
simba.mufasatypes, simba.baseclass;

type
PTMFormula = ^ETMFormula;
ETMFormula = (
TM_CCORR,
TM_CCORR_NORMED,
TM_CCOEFF,
TM_CCOEFF_NORMED,
TM_SQDIFF,
TM_SQDIFF_NORMED
);

PMatchTemplateCacheBase = ^TMatchTemplateCacheBase;
TMatchTemplateCacheBase = class(TSimbaBaseClass)
public
Expand All @@ -34,11 +44,8 @@ TMatchTemplateCacheBase = class(TSimbaBaseClass)
end;

function MatchTemplateCache(Image, Template: TIntegerMatrix; Formula: ETMFormula): TMatchTemplateCacheBase; overload;
function MatchTemplateCache(Image, Template: TMufasaBitmap; Formula: ETMFormula): TMatchTemplateCacheBase; overload;
function MatchTemplateMask(Cache: TMatchTemplateCacheBase; Template: TIntegerMatrix; Formula: ETMFormula): TSingleMatrix; overload;
function MatchTemplateMask(Cache: TMatchTemplateCacheBase; Template: TMufasaBitmap; Formula: ETMFormula): TSingleMatrix; overload;
function MatchTemplateMask(Image, Template: TIntegerMatrix; Formula: ETMFormula): TSingleMatrix; overload;

function MatchTemplate(Image, Template: TIntegerMatrix; Formula: ETMFormula): TSingleMatrix;

function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
Expand All @@ -57,7 +64,8 @@ implementation

uses
simba.matchtemplate_ccorr, simba.matchtemplate_sqdiff, simba.matchtemplate_ccoeff,
simba.threadpool;
simba.threadpool,
simba.singlematrix, simba.integermatrix;

// How much to "Slice" (vertically) the image up for multithreading.
function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
Expand Down Expand Up @@ -124,11 +132,6 @@ function MatchTemplateCache(Image, Template: TIntegerMatrix; Formula: ETMFormula
end;
end;

function MatchTemplateCache(Image, Template: TMufasaBitmap; Formula: ETMFormula): TMatchTemplateCacheBase;
begin
Result := MatchTemplateCache(Image.ToMatrixBGR(), Template.ToMatrixBGR(), Formula);
end;

function MatchTemplateMask(Cache: TMatchTemplateCacheBase; Template: TIntegerMatrix; Formula: ETMFormula): TSingleMatrix;
begin
Validate(Cache.Width, Cache.Height, Template.Width, Template.Height);
Expand All @@ -143,11 +146,6 @@ function MatchTemplateMask(Cache: TMatchTemplateCacheBase; Template: TIntegerMat
end;
end;

function MatchTemplateMask(Cache: TMatchTemplateCacheBase; Template: TMufasaBitmap; Formula: ETMFormula): TSingleMatrix;
begin
Result := MatchTemplateMask(Cache, Template.ToMatrixBGR(), Formula);
end;

function MatchTemplateMask(Image, Template: TIntegerMatrix; Formula: ETMFormula): TSingleMatrix;
begin
Validate(Image.Width, Image.Height, Template.Width, Template.Height);
Expand Down
3 changes: 2 additions & 1 deletion Source/matchtemplate/simba.matchtemplate_ccoeff.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function MatchTemplateMask_CCOEFF_Cache(ACache: TMatchTemplateCacheBase; Templat
implementation

uses
simba.threadpool, simba.simplelock;
simba.threadpool, simba.simplelock,
simba.singlematrix, simba.integermatrix;

// MatchTemplate_CCOEFF
function __MatchTemplate_CCOEFF(Image, Template: TIntegerMatrix; Normed: Boolean): TSingleMatrix;
Expand Down
3 changes: 2 additions & 1 deletion Source/matchtemplate/simba.matchtemplate_ccorr.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function MatchTemplateMask_CCORR_Cache(ACache: TMatchTemplateCacheBase; Template
implementation

uses
simba.threadpool, simba.simplelock;
simba.threadpool, simba.simplelock,
simba.singlematrix, simba.integermatrix;

// MatchTemplate_CCORR
function __MatchTemplate_CCORR(Image, Templ: TIntegerMatrix; Normed: Boolean): TSingleMatrix;
Expand Down
3 changes: 2 additions & 1 deletion Source/matchtemplate/simba.matchtemplate_helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function CrossCorrRGB(Image: TRGBComplexMatrix; Templ: TRGBMatrix): TRGBMatrix;
implementation

uses
simba.FFTPACK4, simba.threadpool;
simba.FFTPACK4, simba.threadpool,
simba.singlematrix, simba.integermatrix;

function DoFFT2(const Matrix: TSingleMatrix; const outW, outH: Integer): TComplexMatrix;
var
Expand Down
40 changes: 5 additions & 35 deletions Source/matchtemplate/simba.matchtemplate_matrix.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,18 @@
See the License for the specific language governing permissions and
limitations under the License.
[==============================================================================}
{$DEFINE SIMBA_MAX_OPTIMIZATION}
{$i simba.inc}

{$IFOPT D-}
{$OPTIMIZATION LEVEL4}
{$ENDIF}

{$MODESWITCH ARRAYOPERATORS OFF}

interface

uses
classes, sysutils,
Classes, SysUtils,
simba.mufasatypes;

type
TComplex = record
Re, Im: Single;
end;
TComplexArray = array of TComplex;
TComplexMatrix = array of TComplexArray;
TComplexMatrixHelper = type helper for TComplexMatrix
public
procedure SetSize(AWidth, AHeight: Integer);
function Width: Integer;
function Height: Integer;
end;

TRGBComplexMatrix = record
Width: Integer;
Height: Integer;
Expand Down Expand Up @@ -84,6 +69,9 @@ function Rot90(const Matrix: TComplexMatrix): TComplexMatrix;

implementation

uses
simba.singlematrix;

function SumsPd(const Matrix: TSingleMatrix; out Square: TDoubleMatrix): TDoubleMatrix;
var
x,y,W,H: Integer;
Expand Down Expand Up @@ -429,24 +417,6 @@ function Norm(const Matrix: TRGBMatrix): Double;
Result[Y, X] := Left[Y, X] / Right[Y, X];
end;

procedure TComplexMatrixHelper.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self, AHeight, AWidth);
end;

function TComplexMatrixHelper.Width: Integer;
begin
if (Length(Self) > 0) then
Result := Length(Self[0])
else
Result := 0;
end;

function TComplexMatrixHelper.Height: Integer;
begin
Result := Length(Self);
end;

procedure TRGBMatrix.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self.R, AHeight, AWidth);
Expand Down
3 changes: 2 additions & 1 deletion Source/matchtemplate/simba.matchtemplate_sqdiff.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function MatchTemplateMask_SQDIFF_Cache(ACache: TMatchTemplateCacheBase; Templat
implementation

uses
simba.threadpool, simba.simplelock;
simba.threadpool, simba.simplelock,
simba.singlematrix, simba.integermatrix;

// MatchTemplate_SQDIFF
function __MatchTemplate_SQDIFF(Image, Templ: TIntegerMatrix; Normed: Boolean): TSingleMatrix;
Expand Down
97 changes: 6 additions & 91 deletions Source/matrix.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@

{$IFDEF HEADER}
type
TDoubleMatrixHelper = type helper for TDoubleMatrix
public
function Width: Integer;
function Height: Integer;
function Area: Integer;
function GetSize(out AWidth, AHeight: Integer): Boolean;
procedure SetSize(AWidth, AHeight: Integer);
end;

TByteMatrixHelper = type helper for TByteMatrix
public
function Width: Integer;
function Height: Integer;
function Area: Integer;
function GetSize(out AWidth, AHeight: Integer): Boolean;
procedure SetSize(AWidth, AHeight: Integer);
end;

TBooleanMatrixHelper = type helper for TBooleanMatrix
public
MACRO_HELPER_NAME = type helper for MACRO_MATRIX_NAME
function Width: Integer;
function Height: Integer;
function Area: Integer;
Expand All @@ -31,100 +12,34 @@ type
{$ENDIF}

{$IFDEF BODY}
function TDoubleMatrixHelper.Width: Integer;
begin
if (Length(Self) > 0) then
Result := Length(Self[0])
else
Result := 0;
end;

function TDoubleMatrixHelper.Height: Integer;
begin
Result := Length(Self);
end;

function TDoubleMatrixHelper.Area: Integer;
begin
Result := Width * Height;
end;

function TDoubleMatrixHelper.GetSize(out AWidth, AHeight: Integer): Boolean;
begin
AWidth := Width;
AHeight := Height;

Result := (AWidth > 0) and (AHeight > 0);
end;

procedure TDoubleMatrixHelper.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self, AHeight, AWidth);
end;

function TByteMatrixHelper.Width: Integer;
function MACRO_HELPER_NAME.Width: Integer;
begin
if (Length(Self) > 0) then
Result := Length(Self[0])
else
Result := 0;
end;

function TByteMatrixHelper.Height: Integer;
function MACRO_HELPER_NAME.Height: Integer;
begin
Result := Length(Self);
end;

function TByteMatrixHelper.Area: Integer;
function MACRO_HELPER_NAME.Area: Integer;
begin
Result := Width * Height;
end;

function TByteMatrixHelper.GetSize(out AWidth, AHeight: Integer): Boolean;
function MACRO_HELPER_NAME.GetSize(out AWidth, AHeight: Integer): Boolean;
begin
AWidth := Width;
AHeight := Height;

Result := (AWidth > 0) and (AHeight > 0);
end;

procedure TByteMatrixHelper.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self, AHeight, AWidth);
end;

function TBooleanMatrixHelper.Width: Integer;
begin
if (Length(Self) > 0) then
Result := Length(Self[0])
else
Result := 0;
end;

function TBooleanMatrixHelper.Height: Integer;
begin
Result := Length(Self);
end;

function TBooleanMatrixHelper.Area: Integer;
begin
Result := Width * Height;
end;

function TBooleanMatrixHelper.GetSize(out AWidth, AHeight: Integer): Boolean;
begin
AWidth := Width;
AHeight := Height;

Result := (AWidth > 0) and (AHeight > 0);
end;

procedure TBooleanMatrixHelper.SetSize(AWidth, AHeight: Integer);
procedure MACRO_HELPER_NAME.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self, AHeight, AWidth);
end;
{$ENDIF}




4 changes: 2 additions & 2 deletions Source/script/imports/simba/simba.import_matchtemplate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ procedure _LapeMatchTemplateCache_Create(const Params: PParamArray; const Result

procedure _LapeMatchTemplateCache_CreateEx(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PMatchTemplateCacheBase(Result)^ := MatchTemplateCache(PMufasaBitmap(Params^[0])^, PMufasaBitmap(Params^[1])^, PTMFormula(Params^[2])^);
PMatchTemplateCacheBase(Result)^ := MatchTemplateCache(PMufasaBitmap(Params^[0])^.ToMatrixBGR(), PMufasaBitmap(Params^[1])^.ToMatrixBGR(), PTMFormula(Params^[2])^);
end;

procedure _LapeMatchTemplateCache_FreeOnTerminate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
Expand All @@ -37,7 +37,7 @@ procedure _LapeMatchTemplateMaskCache(const Params: PParamArray; const Result: P

procedure _LapeMatchTemplateMaskCacheEx(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PSingleMatrix(Result)^ := MatchTemplateMask(PMatchTemplateCacheBase(Params^[0])^, PMufasaBitmap(Params^[1])^, PTMFormula(Params^[2])^);
PSingleMatrix(Result)^ := MatchTemplateMask(PMatchTemplateCacheBase(Params^[0])^, PMufasaBitmap(Params^[1])^.ToMatrixBGR(), PTMFormula(Params^[2])^);
end;

procedure _LapeMatchTemplateMask(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand Down
Loading

0 comments on commit ff89d34

Please sign in to comment.