Skip to content

Commit

Permalink
GetColor functions shouldn't return alpha channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jan 3, 2024
1 parent 4c2c155 commit 04bc741
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 0 additions & 5 deletions Source/colormath/simba.colormath_conversion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
}
unit simba.colormath_conversion;

{$DEFINE B_BIT := 16}
{$DEFINE G_BIT := 8}
{$DEFINE R_BIT := 0}
{$DEFINE A_BIT := 24}

{$DEFINE SIMBA_MAX_OPTIMIZATION}

{$i simba.inc}
Expand Down
22 changes: 14 additions & 8 deletions Source/simba.finder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ interface

uses
Classes, SysUtils, Graphics,
simba.mufasatypes, simba.colormath, simba.colormath_distance, simba.image,
simba.dtm, simba.target;
simba.mufasatypes,
simba.colormath, simba.colormath_distance, simba.colormath_conversion,
simba.image, simba.dtm, simba.target;

type
PColorTolerance = ^TColorTolerance;
Expand Down Expand Up @@ -212,7 +213,7 @@ function TSimbaFinder.GetColor(X, Y: Integer): TColor;

if FTarget.GetImageData(B, Data, DataWidth) then
try
Result := Data^.ToColor()
Result := Data^.R or Data^.G shl G_BIT or Data^.B shl B_BIT;
finally
FTarget.FreeImageData(Data);
end;
Expand All @@ -223,7 +224,8 @@ function TSimbaFinder.GetColors(Points: TPointArray): TColorArray;
B: TBox;
Data: PColorBGRA;
DataWidth: Integer;
I, X, Y, Count: Integer;
I, Count: Integer;
Pixel: TColorBGRA;
begin
Result := nil;

Expand All @@ -235,10 +237,9 @@ function TSimbaFinder.GetColors(Points: TPointArray): TColorArray;
Count := 0;
for I := 0 to High(Points) do
begin
X := Points[I].X - B.X1;
Y := Points[I].Y - B.Y1;
Pixel := Data[(Points[I].Y - B.Y1) * DataWidth + (Points[I].X - B.X1)];

Result[Count] := Data[Y * DataWidth + X].ToColor();
Result[Count] := Pixel.R or Pixel.G shl G_BIT or Pixel.B shl B_BIT;
Inc(Count);
end;
SetLength(Result, Count);
Expand All @@ -252,6 +253,7 @@ function TSimbaFinder.GetColorsMatrix(Bounds: TBox): TIntegerMatrix;
Data: PColorBGRA;
DataWidth: Integer;
Width, Height, X, Y: Integer;
Pixel: TColorBGRA;
begin
Result := nil;

Expand All @@ -264,7 +266,11 @@ function TSimbaFinder.GetColorsMatrix(Bounds: TBox): TIntegerMatrix;

for Y := 0 to Height do
for X := 0 to Width do
Result[Y, X] := Data[Y * DataWidth + X].ToColor();
begin
Pixel := Data[Y * DataWidth + X];

Result[Y, X] := Pixel.R or Pixel.G shl G_BIT or Pixel.B shl B_BIT;
end;
finally
FTarget.FreeImageData(Data);
end;
Expand Down
6 changes: 6 additions & 0 deletions Source/simba.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
{$DEFINE LAPE_WRAPPER_CALLING_CONV := cdecl;}
{$ENDIF}

// bitshifts for color channels
{$DEFINE A_BIT := 24}
{$DEFINE B_BIT := 16}
{$DEFINE G_BIT := 8}
{$DEFINE R_BIT := 0}

{.$DEFINE PARSER_BENCHMARK}
{.$DEFINE PARSER_CACHE_DEBUG}
{.$DEFINE PARSER_LEAK_CHECKS}
Expand Down

0 comments on commit 04bc741

Please sign in to comment.