forked from micjahn/ZXing.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request micjahn#230 from ghost1face/skia-perf-2
Skia barcode performance
- Loading branch information
Showing
16 changed files
with
417 additions
and
10 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Source/Bindings/Tests/ZXing.SkiaSharp/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("ZXing.SkiaSharp.Test")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("ZXing.SkiaSharp.Test")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
[assembly: ComVisible(false)] | ||
|
||
[assembly: Guid("92327639-ad1c-4671-9ae9-7b39820526f1")] | ||
|
||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
180 changes: 180 additions & 0 deletions
180
Source/Bindings/Tests/ZXing.SkiaSharp/SKBitmapLuminanceSourceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* Copyright 2013 ZXing.Net authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using NUnit.Framework; | ||
using SkiaSharp; | ||
using System.Drawing; | ||
using System.IO; | ||
|
||
namespace ZXing.SkiaSharp.Test | ||
{ | ||
[TestFixture] | ||
public class SKBitmapLuminanceSourceTests | ||
{ | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format1bppIndexed.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format4bppIndexed.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format8bppIndexed.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format16bppRgb565.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format24bppRgb.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format32bppRgb.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format32bppArgb.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format16bppRgb555.bmp", "abc")] | ||
[TestCase("../../../../../test/data/luminance/qr-code-abc-Format16bppArgb1555.bmp", "abc")] | ||
public void Should_Calculate_Luminance_And_Decode(string fileName, string content) | ||
{ | ||
using (var bitmap = LoadSKBitmap(fileName)) | ||
{ | ||
var luminance = new SKBitmapLuminanceSource(bitmap); | ||
var reader = new BarcodeReader(); | ||
var result = reader.Decode(luminance); | ||
Assert.That(result?.Text, Is.EqualTo(content)); | ||
} | ||
} | ||
|
||
[TestCase("../../../../../test/data/blackbox/falsepositives/20.png")] | ||
[TestCase("../../../../../test/data/blackbox/upce-2/36.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-5/15.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-4/05.png")] | ||
[TestCase("../../../../../test/data/blackbox/code128-2/37.png")] | ||
[TestCase("../../../../../test/data/blackbox/partial/16.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-4/25.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-3/33.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-2/19.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpandedstacked-1/45.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-2/35.png")] | ||
[TestCase("../../../../../test/data/blackbox/rss14-2/1.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpandedstacked-1/12.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-2/13.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/49.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpandedstacked-1/39.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-2/28.png")] | ||
[TestCase("../../../../../test/data/blackbox/code39-3/08.png")] | ||
[TestCase("../../../../../test/data/blackbox/upce-2/03.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-5/06.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/18.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-3/28.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-1/10.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/114.png")] | ||
[TestCase("../../../../../test/data/blackbox/pdf417-3/19.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-6/04.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-1/30.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-4/44.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/115.png")] | ||
[TestCase("../../../../../test/data/benchmark/android-2/ean13-1.png")] | ||
[TestCase("../../../../../test/data/blackbox/codabar-1/09.png")] | ||
[TestCase("../../../../../test/data/blackbox/itf-2/08.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-3/23.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-5/03.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-5/02.png")] | ||
[TestCase("../../../../../test/data/blackbox/pdf417-3/04.png")] | ||
[TestCase("../../../../../test/data/blackbox/partial/23.png")] | ||
[TestCase("../../../../../test/data/blackbox/upce-2/21.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-1/31.png")] | ||
[TestCase("../../../../../test/data/blackbox/rss14-1/4.png")] | ||
[TestCase("../../../../../test/data/blackbox/falsepositives/18.png")] | ||
[TestCase("../../../../../test/data/blackbox/datamatrix-2/13.png")] | ||
[TestCase("../../../../../test/data/blackbox/partial/08.png")] | ||
[TestCase("../../../../../test/data/blackbox/code128-2/33.png")] | ||
[TestCase("../../../../../test/data/blackbox/upcean-extension-1/1.png")] | ||
[TestCase("../../../../../test/data/blackbox/aztec-1/lorem-075x075.png")] | ||
[TestCase("../../../../../test/data/blackbox/datamatrix-2/14.png")] | ||
[TestCase("../../../../../test/data/blackbox/codabar-1/02.png")] | ||
[TestCase("../../../../../test/data/blackbox/partial/15.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-2/18.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/25.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-1/13.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-5/13.png")] | ||
[TestCase("../../../../../test/data/blackbox/itf-2/05.png")] | ||
[TestCase("../../../../../test/data/blackbox/imb-1/04.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/106.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-6/05.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-3/10.png")] | ||
[TestCase("../../../../../test/data/benchmark/android-2/fail-2.png")] | ||
[TestCase("../../../../../test/data/blackbox/datamatrix-1/GUID.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-4/5.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-1/29.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-4/14.png")] | ||
[TestCase("../../../../../test/data/blackbox/falsepositives-2/12.png")] | ||
[TestCase("../../../../../test/data/blackbox/upcean-extension-1/2.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-1/3.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-2/23.png")] | ||
[TestCase("../../../../../test/data/blackbox/codabar-1/12.png")] | ||
[TestCase("../../../../../test/data/blackbox/itf-2/10.png")] | ||
[TestCase("../../../../../test/data/blackbox/code128-2/34.png")] | ||
[TestCase("../../../../../test/data/blackbox/datamatrix-2/04.png")] | ||
[TestCase("../../../../../test/data/blackbox/partial/31.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-2/49.png")] | ||
[TestCase("../../../../../test/data/blackbox/rssexpanded-3/102.png")] | ||
[TestCase("../../../../../test/data/blackbox/upca-5/15.png")] | ||
[TestCase("../../../../../test/data/blackbox/imb-1/09.png")] | ||
[TestCase("../../../../../test/data/blackbox/ean13-3/14.png")] | ||
[TestCase("../../../../../test/data/blackbox/pdf417-2/14.png")] | ||
[TestCase("../../../../../test/data/blackbox/qrcode-4/22.png")] | ||
public void Luminance_Is_Within_Margin_Of_Error(string fileName) | ||
{ | ||
byte[] controlLuminanceSourceMatrix; | ||
using (var control = LoadBitmapImage(fileName)) | ||
{ | ||
var bitmapLuminanceSource = new BitmapLuminanceSource(control); | ||
controlLuminanceSourceMatrix = bitmapLuminanceSource.Matrix; | ||
} | ||
|
||
byte[] testLuminanceSourceMatrix; | ||
using (var bitmap = LoadSKBitmap(fileName)) | ||
{ | ||
var skBitmapLuminanceSource = new SKBitmapLuminanceSource(bitmap); | ||
testLuminanceSourceMatrix = skBitmapLuminanceSource.Matrix; | ||
} | ||
|
||
Assert.AreEqual(controlLuminanceSourceMatrix.Length, testLuminanceSourceMatrix.Length); | ||
|
||
for (int index = 0; index < controlLuminanceSourceMatrix.Length; index++) | ||
{ | ||
var controlColor = controlLuminanceSourceMatrix[index]; | ||
var testColor = testLuminanceSourceMatrix[index]; | ||
|
||
Assert.That(testColor, Is.EqualTo(controlColor).Within(3)); | ||
} | ||
} | ||
|
||
private static SKBitmap LoadSKBitmap(string fileName) | ||
{ | ||
string file = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, fileName)); | ||
if (!File.Exists(file)) | ||
{ | ||
// try starting with 'core' since the test base is often given as the project root | ||
file = Path.GetFullPath("..\\..\\..\\Source\\" + fileName); | ||
} | ||
Assert.IsTrue(File.Exists(file), "Please run from the 'core' directory"); | ||
|
||
return SKBitmap.Decode(file); | ||
} | ||
|
||
private static Bitmap LoadBitmapImage(string fileName) | ||
{ | ||
string file = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, fileName)); | ||
if (!File.Exists(file)) | ||
{ | ||
// try starting with 'core' since the test base is often given as the project root | ||
file = Path.GetFullPath("..\\..\\..\\Source\\" + fileName); | ||
} | ||
Assert.IsTrue(File.Exists(file), "Please run from the 'core' directory"); | ||
|
||
return (Bitmap)Image.FromFile(file); | ||
} | ||
|
||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
Source/Bindings/Tests/ZXing.SkiaSharp/ZXing.SkiaSharp.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\..\..\..\packages\NUnit3TestAdapter.3.16.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\..\..\packages\NUnit3TestAdapter.3.16.0\build\net35\NUnit3TestAdapter.props')" /> | ||
<Import Project="..\..\..\..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\..\..\..\packages\NUnit.3.12.0\build\NUnit.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{92327639-AD1C-4671-9AE9-7B39820526F1}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ZXing.SkiaSharp.Test</RootNamespace> | ||
<AssemblyName>ZXing.SkiaSharp.Test</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>Bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>Bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="log4net"> | ||
<HintPath>..\..\..\..\3rdparty\log4net\log4net.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> | ||
<HintPath>..\..\..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="SkiaSharp, Version=1.60.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> | ||
<HintPath>..\..\..\..\packages\SkiaSharp.1.60.0\lib\net45\SkiaSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL"> | ||
<HintPath>..\..\..\..\packages\ZXing.Net.0.16.5\lib\net461\zxing.dll</HintPath> | ||
</Reference> | ||
<Reference Include="zxing.presentation, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL"> | ||
<HintPath>..\..\..\..\packages\ZXing.Net.0.16.5\lib\net461\zxing.presentation.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="SKBitmapLuminanceSourceTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="..\..\..\..\log4net.config"> | ||
<Link>log4net.config</Link> | ||
</None> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\ZXing.SkiaSharp\ZXing.SkiaSharp.csproj"> | ||
<Project>{66f2cf1d-59da-45e6-bb00-ecab29a98a04}</Project> | ||
<Name>ZXing.SkiaSharp</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\..\..\..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\NUnit.3.12.0\build\NUnit.props'))" /> | ||
<Error Condition="!Exists('..\..\..\..\packages\NUnit3TestAdapter.3.16.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\NUnit3TestAdapter.3.16.0\build\net35\NUnit3TestAdapter.props'))" /> | ||
<Error Condition="!Exists('..\..\..\..\packages\SkiaSharp.1.60.0\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\SkiaSharp.1.60.0\build\net45\SkiaSharp.targets'))" /> | ||
</Target> | ||
<PropertyGroup> | ||
<PreBuildEvent>copy "$(MSBuildProjectDirectory)\..\..\..\..\Key\dummy-private.snk" "$(MSBuildProjectDirectory)\..\..\..\..\Key\private.snk"</PreBuildEvent> | ||
</PropertyGroup> | ||
<Import Project="..\..\..\..\packages\SkiaSharp.1.60.0\build\net45\SkiaSharp.targets" Condition="Exists('..\..\..\..\packages\SkiaSharp.1.60.0\build\net45\SkiaSharp.targets')" /> | ||
<!-- <PropertyGroup> | ||
<PreBuildEvent> | ||
echo $sourcePath = [System.IO.Path]::GetFullPath("$(MSBuildProjectDirectory)\..\Common") >> generated.ps1 | ||
echo Copy-Item -Path "$sourcePath\*" -Destination "$(MsBuildProjectDirectory)" -Recurse >> generated.ps1 | ||
echo gci "$(MSBuildProjectDirectory)" *.cs -Recurse ^| ForEach { >> generated.ps1 | ||
echo (Get-Content ^$_ ^| ForEach { ^$_ -replace "$IMAGELIB_TESTCASE_BASECLASS", "SkiaBarcodeBlackBoxTestCase" }) ^| Set-Content ^$_ >> generated.ps1 | ||
echo } >> generated.ps1 | ||
</PreBuildEvent> | ||
</PropertyGroup> --> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit" version="3.12.0" targetFramework="net461" /> | ||
<package id="NUnit3TestAdapter" version="3.16.0" targetFramework="net461" developmentDependency="true" /> | ||
<package id="SkiaSharp" version="1.60.0" targetFramework="net461" /> | ||
<package id="ZXing.Net" version="0.16.5" targetFramework="net461" /> | ||
</packages> |
Oops, something went wrong.