Skip to content

Commit

Permalink
Reverted FRAMEWORK_FMX compile directive and fixed some QR test images.
Browse files Browse the repository at this point in the history
  • Loading branch information
E Spelt committed Mar 16, 2024
1 parent b341faf commit 3eaf161
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 81 deletions.
7 changes: 3 additions & 4 deletions Lib/Classes/Common/ZXing.Common.BitMatrix.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ interface

uses
SysUtils,
{$IFDEF FRAMEWORK_VCL}
VCL.Graphics,
{$ENDIF}
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
FMX.Graphics,
{$ELSE}
VCL.Graphics,
{$ENDIF}
Generics.Collections,
ZXing.Common.BitArray,
Expand Down
9 changes: 4 additions & 5 deletions Lib/Classes/Filtering/ZXing.BaseLuminanceSource.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ interface
uses
System.SysUtils,
System.UITypes,
{$IFDEF FRAMEWORK_VCL}
VCL.Graphics,
{$ENDIF}
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
FMX.Graphics,
{$ELSE}
VCL.Graphics,
{$ENDIF}
ZXing.LuminanceSource,
ZXing.InvertedLuminanceSource;

type
/// <summary>
/// The base class for luminance sources which supports
/// The base class for luminance sources which supports
/// cropping and rotating based upon the luminance values.
/// </summary>
TBaseLuminanceSource = class abstract (TLuminanceSource)
Expand Down
68 changes: 33 additions & 35 deletions Lib/Classes/Filtering/ZXing.RGBLuminanceSource.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ interface
System.SysUtils,
System.UITypes,
System.TypInfo,
{$IFDEF FRAMEWORK_VCL}
{$IFDEF FMX}
FMX.Graphics,
{$ELSE}
Winapi.Windows,
VCL.Graphics,
{$ENDIF}
{$IFDEF FRAMEWORK_FMX}
FMX.Graphics,
{$ENDIF}
ZXing.LuminanceSource,
ZXing.BaseLuminanceSource,
Expand Down Expand Up @@ -159,37 +158,7 @@ constructor TRGBLuminanceSource.Create(const rgbRawBytes: TArray<Byte>;
CalculateLuminance(rgbRawBytes, bitmapFormat);
end;

{$IFDEF FRAMEWORK_VCL}
// VCL TBitmap implementation
constructor TRGBLuminanceSource.CreateFromBitmap(const sourceBitmap: TBitmap; const width, height: Integer);
type
TRGBTripleArray = ARRAY[Word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray; // Use a PByteArray for pf8bit color.

var
x, y,
offset : Integer;
r, g, b : Byte;
P: pRGBTripleArray;

begin
Self.Create(width, height);
sourceBitmap.PixelFormat := pf24bit;
for y := 0 to sourceBitmap.Height - 1 do
begin
offset := y * FWidth;
P := sourceBitmap.ScanLine[y];
for x := 0 to sourceBitmap.Width - 1 do
begin
r := P[x].rgbtRed;
g := P[x].rgbtGreen;
b := P[x].rgbtBlue;
luminances[offset + x] := TMathUtils.Asr(3482*r + 11721*g + 1181*b, 14);
end;
end;
end;
{$ENDIF}
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
// FMX TBitmap implementation
constructor TRGBLuminanceSource.CreateFromBitmap(const sourceBitmap: TBitmap;
const width, height: Integer);
Expand Down Expand Up @@ -226,6 +195,35 @@ constructor TRGBLuminanceSource.CreateFromBitmap(const sourceBitmap: TBitmap;
end;
end;
end;
{$ELSE}
// VCL TBitmap implementation
constructor TRGBLuminanceSource.CreateFromBitmap(const sourceBitmap: TBitmap; const width, height: Integer);
type
TRGBTripleArray = ARRAY[Word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray; // Use a PByteArray for pf8bit color.

var
x, y,
offset : Integer;
r, g, b : Byte;
P: pRGBTripleArray;

begin
Self.Create(width, height);
sourceBitmap.PixelFormat := pf24bit;
for y := 0 to sourceBitmap.Height - 1 do
begin
offset := y * FWidth;
P := sourceBitmap.ScanLine[y];
for x := 0 to sourceBitmap.Width - 1 do
begin
r := P[x].rgbtRed;
g := P[x].rgbtGreen;
b := P[x].rgbtBlue;
luminances[offset + x] := TMathUtils.Asr(3482*r + 11721*g + 1181*b, 14);
end;
end;
end;
{$ENDIF}

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions Lib/Classes/ZXing.ScanManager.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ interface
uses
System.SysUtils,
System.Generics.Collections,
{$IFDEF FRAMEWORK_VCL}
VCL.Graphics,
{$ENDIF}
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
FMX.Graphics,
{$ELSE}
VCL.Graphics,
{$ENDIF}
ZXing.LuminanceSource,
ZXing.RGBLuminanceSource,
Expand Down
Binary file removed MemLeakTest/Leaktest.res
Binary file not shown.
Binary file removed UnitTest/Images/qr-1.png
Binary file not shown.
Binary file removed UnitTest/Images/qr-12.png
Binary file not shown.
Binary file removed UnitTest/Images/qr-1a.png
Binary file not shown.
Binary file removed UnitTest/Images/qr-a1.png
Binary file not shown.
23 changes: 10 additions & 13 deletions UnitTest/Test.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ interface

uses
DUnitX.TestFramework,
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
FMX.Types,
FMX.Graphics,
FMX.Objects,
{$ENDIF}
{$IFDEF FRAMEWORK_VCL}
{$ELSE}
Vcl.Graphics,
Vcl.ExtCtrls,
Vcl.Imaging.jpeg,
Expand Down Expand Up @@ -393,7 +392,7 @@ procedure TZXingDelphiTest.AllQRCode();
end;

try
result := Decode('qr-1.png', TBarcodeFormat.QR_CODE);
result := Decode('qr-1.jpg', TBarcodeFormat.QR_CODE);
Assert.IsNotNull(result, ' Nil result ');
Assert.IsTrue(result.Text.Equals('1'), 'QR code result Text Incorrect: ' + result.Text);

Expand All @@ -402,7 +401,7 @@ procedure TZXingDelphiTest.AllQRCode();
end;

try
result := Decode('qr-a1.png', TBarcodeFormat.QR_CODE);
result := Decode('qr-a1.jpg', TBarcodeFormat.QR_CODE);
Assert.IsNotNull(result, ' Nil result ');
Assert.IsTrue(result.Text.Equals('a1'), 'QR code result Text Incorrect: ' + result.Text);

Expand All @@ -411,7 +410,7 @@ procedure TZXingDelphiTest.AllQRCode();
end;

try
result := Decode('qr-1a.png', TBarcodeFormat.QR_CODE);
result := Decode('qr-1a.jpg', TBarcodeFormat.QR_CODE);
Assert.IsNotNull(result, ' Nil result ');
Assert.IsTrue(result.Text.Equals('1a'), 'QR code result Text Incorrect: ' + result.Text);

Expand All @@ -420,7 +419,7 @@ procedure TZXingDelphiTest.AllQRCode();
end;

try
result := Decode('qr-12.png', TBarcodeFormat.QR_CODE);
result := Decode('qr-12.jpg', TBarcodeFormat.QR_CODE);
Assert.IsNotNull(result, ' Nil result ');
Assert.IsTrue(result.Text.Equals('12'), 'QR code result Text Incorrect: ' + result.Text);

Expand Down Expand Up @@ -1289,17 +1288,15 @@ function TZXingDelphiTest.GetImage(Filename: string): TBitmap;
img := TImage.Create(nil);
try
fs := ExtractFileDir(ParamStr(0)) + '\..\..\images\' + Filename;
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
img.Bitmap.LoadFromFile(fs);
{$ENDIF}
{$IFDEF FRAMEWORK_VCL}
{$ELSE}
img.Picture.LoadFromFile(fs);
{$ENDIF}
result := TBitmap.Create;
{$IFDEF FRAMEWORK_FMX}
{$IFDEF FMX}
result.Assign(img.Bitmap);
{$ENDIF}
{$IFDEF FRAMEWORK_VCL}
{$ELSE}
result.Assign(img.Picture.Graphic);
{$ENDIF}
finally
Expand Down
Binary file modified UnitTest/dUnitXTest.res
Binary file not shown.
Binary file removed demo/aTestApp/FmxTestApp.res
Binary file not shown.
60 changes: 40 additions & 20 deletions demo/vclTestApp/MainForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,74 @@ object mainFrm: TmainFrm
Left = 0
Top = 0
Caption = 'mainFrm'
ClientHeight = 436
ClientWidth = 644
ClientHeight = 872
ClientWidth = 1288
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Height = -22
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
PixelsPerInch = 192
TextHeight = 27
object image: TImage
Left = 0
Top = 0
Width = 453
Height = 395
Width = 906
Height = 790
Margins.Left = 6
Margins.Top = 6
Margins.Right = 6
Margins.Bottom = 6
Align = alClient
AutoSize = True
Center = True
Proportional = True
Stretch = True
end
object Splitter_38A8D14A: TSplitter
Left = 453
Left = 906
Top = 0
Height = 395
Width = 6
Height = 790
Margins.Left = 6
Margins.Top = 6
Margins.Right = 6
Margins.Bottom = 6
Align = alRight
end
object Log: TMemo
Left = 456
Left = 912
Top = 0
Width = 188
Height = 395
Width = 376
Height = 790
Margins.Left = 6
Margins.Top = 6
Margins.Right = 6
Margins.Bottom = 6
Align = alRight
TabOrder = 0
end
object bottomPanel: TPanel
Left = 0
Top = 395
Width = 644
Height = 41
Top = 790
Width = 1288
Height = 82
Margins.Left = 6
Margins.Top = 6
Margins.Right = 6
Margins.Bottom = 6
Align = alBottom
TabOrder = 1
object btnLoadFromFile: TButton
Left = 8
Top = 6
Width = 75
Height = 25
Left = 16
Top = 12
Width = 150
Height = 50
Margins.Left = 6
Margins.Top = 6
Margins.Right = 6
Margins.Bottom = 6
Caption = 'btnLoad'
TabOrder = 0
OnClick = btnLoadFromFileClick
Expand Down
Binary file modified demo/vclTestApp/vclTestApp.res
Binary file not shown.
Binary file removed demo/webcam/Webcam.res
Binary file not shown.
Binary file added unitTest/Images/qr-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unitTest/Images/qr-12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unitTest/Images/qr-1a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unitTest/Images/qr-a1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3eaf161

Please sign in to comment.