Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for computeDimension and sizeOfBlackWhiteBlackRunBothWays #169

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions Lib/Classes/2D Barcodes/Detector/ZXing.QrCode.Internal.Detector.pas
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,13 @@ class function TDetector.computeDimension(topLeft: IResultPoint;
((tltrCentersDimension + tlblCentersDimension), 1) + 7;

case (dimension and 3) of
0:
begin
inc(dimension);
end;
2:
begin
dec(dimension);
end;
3:
begin
begin
Result := true;
exit
end
end;
0: inc(dimension); // below a valid dimension
1: ; // exactly on a valid dimension e.g. 21, 25, 29, ..., 177
2: dec(dimension); // above a valid dimension
3: Exit(False); // exactly between two valid dimensions
end;

Result := true;
Result := True;
end;

class function TDetector.createTransform(const topLeft, topRight, bottomLeft,
Expand Down Expand Up @@ -465,34 +454,35 @@ function TDetector.sizeOfBlackWhiteBlackRun(fromX: Integer; fromY: Integer;
function TDetector.sizeOfBlackWhiteBlackRunBothWays(fromX: Integer;
fromY: Integer; toX: Integer; toY: Integer): Single;
var
scale, otherToX, otherToY: Integer;
scale: Double;
otherToX, otherToY: Integer;
begin
Result := self.sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
Result := sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
scale := 1;
otherToX := (fromX - (toX - fromX));
if (otherToX < 0) then
begin
scale := (fromX div (fromX - otherToX));
scale := (fromX / (fromX - otherToX));
otherToX := 0
end
else if (otherToX >= FImage.Width) then
begin
scale := (((FImage.Width - 1) - fromX) div (otherToX - fromX));
scale := (((FImage.Width - 1) - fromX) / (otherToX - fromX));
otherToX := (FImage.Width - 1)
end;
otherToY := (fromY - ((toY - fromY) * scale));
otherToY := Round(fromY - ((toY - fromY) * scale));
scale := 1;
if (otherToY < 0) then
begin
scale := fromY div (fromY - otherToY);
scale := fromY / (fromY - otherToY);
otherToY := 0
end
else if (otherToY >= FImage.Height) then
begin
scale := (((FImage.Height - 1) - fromY) div (otherToY - fromY));
scale := (((FImage.Height - 1) - fromY) / (otherToY - fromY));
otherToY := (FImage.Height - 1)
end;
otherToX := (fromX + (otherToX - fromX) * scale);
otherToX := Round(fromX + (otherToX - fromX) * scale);
Result := Result + self.sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX,
otherToY);

Expand Down