diff --git a/src/Tesseract.Drawing/Tesseract.Drawing.csproj b/src/Tesseract.Drawing/Tesseract.Drawing.csproj deleted file mode 100644 index 48218f7e..00000000 --- a/src/Tesseract.Drawing/Tesseract.Drawing.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - netstandard2.0 - true - true - Tesseract.Drawing - Charles Weld - - Tesseract.Drawing - Adds support for interop with System.Drawing to Tesseract such as passing Bitmap to Tesseract. - Copyright 2019-2020 Charles Weld - https://github.com/charlesw/tesseract/blob/master/ChangeLog.md - https://github.com/charlesw/tesseract/ - https://github.com/charlesw/tesseract/ - Tesseract Ocr - 4.1.1 - 4.1.1.0 - - Apache-2.0 - Tesseract - - - - NETCORE;NETSTANDARD;NETSTANDARD2_0;SYSTEM_DRAWING_SUPPORT - - - - - - - - - - - - - - - - - - - diff --git a/src/Tesseract.Net45Tests/Tesseract.Net45Tests.csproj b/src/Tesseract.Net45Tests/Tesseract.Net45Tests.csproj deleted file mode 100644 index d8a72cf8..00000000 --- a/src/Tesseract.Net45Tests/Tesseract.Net45Tests.csproj +++ /dev/null @@ -1,210 +0,0 @@ - - - - net45 - - false - NET45;NETFULL - Tesseract.Tests - - - - true - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - - - - \ No newline at end of file diff --git a/src/Tesseract.NetCore2Tests/Tesseract.NetCore31Tests.csproj b/src/Tesseract.NetCore2Tests/Tesseract.NetCore31Tests.csproj deleted file mode 100644 index 86fb0c99..00000000 --- a/src/Tesseract.NetCore2Tests/Tesseract.NetCore31Tests.csproj +++ /dev/null @@ -1,209 +0,0 @@ - - - netcoreapp3.1 - - false - NETCORE;NETSTANDARD;NETSTANDARD2_0 - Tesseract.Tests - - - - true - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - - - - \ No newline at end of file diff --git a/src/Tesseract.Tests/Leptonica/ColorTests.cs b/src/Tesseract.Tests/Leptonica/ColorTests.cs index b7c8b14a..bdfca128 100644 --- a/src/Tesseract.Tests/Leptonica/ColorTests.cs +++ b/src/Tesseract.Tests/Leptonica/ColorTests.cs @@ -10,7 +10,6 @@ namespace Tesseract.Tests.Leptonica [TestFixture] public class ColorTests { -#if NETFULL [TestCase] public void Color_CastColorToNetColor() { @@ -21,7 +20,6 @@ public void Color_CastColorToNetColor() Assert.That(castColor.B, Is.EqualTo(color.Blue)); Assert.That(castColor.A, Is.EqualTo(color.Alpha)); } -#endif [TestCase] public void Color_ConvertColorToNetColor() diff --git a/src/Tesseract.Tests/Leptonica/LeptonicaPerformanceTests.cs b/src/Tesseract.Tests/Leptonica/LeptonicaPerformanceTests.cs index fda42dfa..0c4e5783 100644 --- a/src/Tesseract.Tests/Leptonica/LeptonicaPerformanceTests.cs +++ b/src/Tesseract.Tests/Leptonica/LeptonicaPerformanceTests.cs @@ -1,5 +1,4 @@ -#if NETFULL - + using System; using System.Diagnostics; using System.Drawing; @@ -45,4 +44,3 @@ public void ConvertToBitmap() } } -#endif diff --git a/src/Tesseract.Tests/New Text Document.txt b/src/Tesseract.Tests/New Text Document.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Tesseract.Tests/Properties/AssemblyInfo.cs b/src/Tesseract.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 86ce452b..00000000 --- a/src/Tesseract.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -#region Using directives - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -#endregion - -// This sets the default COM visibility of types in the assembly to invisible. -// If you need to expose a type to COM, use [ComVisible(true)] on that type. -[assembly: ComVisible(false)] - -// Versioning is handled by AssemblyVersionInfo.cs \ No newline at end of file diff --git a/src/Tesseract.Tests/Tesseract.Tests.csproj b/src/Tesseract.Tests/Tesseract.Tests.csproj new file mode 100644 index 00000000..e96d4ea1 --- /dev/null +++ b/src/Tesseract.Tests/Tesseract.Tests.csproj @@ -0,0 +1,223 @@ + + + + net40;net45;net48;netcoreapp3.1;net5.0 + false + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + true + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + diff --git a/src/Tesseract.Tests/UnitTest1.cs b/src/Tesseract.Tests/UnitTest1.cs deleted file mode 100644 index 794c4081..00000000 --- a/src/Tesseract.Tests/UnitTest1.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NUnit.Framework; - -namespace Tests -{ - public class Tests - { - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } - } -} \ No newline at end of file diff --git a/src/Tesseract.Tests/packages.config b/src/Tesseract.Tests/packages.config deleted file mode 100644 index e079d6a7..00000000 --- a/src/Tesseract.Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Tesseract.sln b/src/Tesseract.sln index 012e81e4..b11acc34 100644 --- a/src/Tesseract.sln +++ b/src/Tesseract.sln @@ -10,11 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\ReadMe.md = ..\ReadMe.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesseract.Net45Tests", "Tesseract.Net45Tests\Tesseract.Net45Tests.csproj", "{0B087299-D0A5-47F1-B313-820481F29DA0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesseract.NetCore31Tests", "Tesseract.NetCore2Tests\Tesseract.NetCore31Tests.csproj", "{74F4ACED-886F-4B1B-B524-6DF28A274226}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesseract.Drawing", "Tesseract.Drawing\Tesseract.Drawing.csproj", "{76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tesseract.Tests", "Tesseract.Tests\Tesseract.Tests.csproj", "{4F596876-CA21-45F3-9E8F-AB56420B2DE2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -38,42 +34,18 @@ Global {AB8F7CF1-E75B-4BD3-8853-2348ECDEA969}.Release|x64.Build.0 = Release|Any CPU {AB8F7CF1-E75B-4BD3-8853-2348ECDEA969}.Release|x86.ActiveCfg = Release|Any CPU {AB8F7CF1-E75B-4BD3-8853-2348ECDEA969}.Release|x86.Build.0 = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|x64.ActiveCfg = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|x64.Build.0 = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|x86.ActiveCfg = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Debug|x86.Build.0 = Debug|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|Any CPU.Build.0 = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|x64.ActiveCfg = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|x64.Build.0 = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|x86.ActiveCfg = Release|Any CPU - {0B087299-D0A5-47F1-B313-820481F29DA0}.Release|x86.Build.0 = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|Any CPU.Build.0 = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|x64.ActiveCfg = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|x64.Build.0 = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|x86.ActiveCfg = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Debug|x86.Build.0 = Debug|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|Any CPU.ActiveCfg = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|Any CPU.Build.0 = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|x64.ActiveCfg = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|x64.Build.0 = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|x86.ActiveCfg = Release|Any CPU - {74F4ACED-886F-4B1B-B524-6DF28A274226}.Release|x86.Build.0 = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|x64.ActiveCfg = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|x64.Build.0 = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|x86.ActiveCfg = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Debug|x86.Build.0 = Debug|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|Any CPU.Build.0 = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|x64.ActiveCfg = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|x64.Build.0 = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|x86.ActiveCfg = Release|Any CPU - {76C430BF-86EA-4EE0-8B33-BB4AB5AEABD5}.Release|x86.Build.0 = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|x64.ActiveCfg = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|x64.Build.0 = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|x86.ActiveCfg = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Debug|x86.Build.0 = Debug|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|x64.ActiveCfg = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|x64.Build.0 = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|x86.ActiveCfg = Release|Any CPU + {4F596876-CA21-45F3-9E8F-AB56420B2DE2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Tesseract/BitmapHelper.cs b/src/Tesseract/BitmapHelper.cs index 59ed8e22..aba50314 100644 --- a/src/Tesseract/BitmapHelper.cs +++ b/src/Tesseract/BitmapHelper.cs @@ -4,95 +4,95 @@ namespace Tesseract { - /// - /// Description of BitmapHelper. - /// - public static unsafe class BitmapHelper + /// + /// Description of BitmapHelper. + /// + public static unsafe class BitmapHelper { #region Bitmap Data Access -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static byte GetDataBit(byte* data, int index) - { - return (byte)((*(data + (index >> 3)) >> (index & 0x7)) & 1); - } + { + return (byte)((*(data + (index >> 3)) >> (index & 0x7)) & 1); + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static void SetDataBit(byte* data, int index, byte value) - { - byte* wordPtr = data + (index >> 3); + { + byte* wordPtr = data + (index >> 3); *wordPtr &= (byte)~(0x80 >> (index & 7)); // clear bit, note first pixel in the byte is most significant (1000 0000) *wordPtr |= (byte)((value & 1) << (7 - (index & 7))); // set bit, if value is 1 - } + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static byte GetDataQBit(byte* data, int index) - { + public static byte GetDataQBit(byte* data, int index) + { return (byte)((*(data + (index >> 1)) >> (4 * (index & 1))) & 0xF); - } + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataQBit(byte* data, int index, byte value) - { - byte* wordPtr = data + (index >> 1); + public static void SetDataQBit(byte* data, int index, byte value) + { + byte* wordPtr = data + (index >> 1); *wordPtr &= (byte)~(0xF0 >> (4 * (index & 1))); // clears qbit located at index, note like bit the qbit corresponding to the first pixel is the most significant (0xF0) *wordPtr |= (byte)((value & 0x0F) << (4 - (4 * (index & 1)))); // applys qbit to n - } + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static byte GetDataByte(byte* data, int index) - { - return *(data + index); - } + public static byte GetDataByte(byte* data, int index) + { + return *(data + index); + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataByte(byte* data, int index, byte value) - { - *(data + index) = value; - } + public static void SetDataByte(byte* data, int index, byte value) + { + *(data + index) = value; + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ushort GetDataUInt16(ushort* data, int index) - { - return *(data + index); - } + public static ushort GetDataUInt16(ushort* data, int index) + { + return *(data + index); + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataUInt16(ushort* data, int index, ushort value) - { - *(data + index) = value; - } + public static void SetDataUInt16(ushort* data, int index, ushort value) + { + *(data + index) = value; + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataUInt32(uint* data, int index) - { - return *(data + index); - } + public static uint GetDataUInt32(uint* data, int index) + { + return *(data + index); + } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataUInt32(uint* data, int index, uint value) - { - *(data + index) = value; + public static void SetDataUInt32(uint* data, int index, uint value) + { + *(data + index) = value; } @@ -100,7 +100,7 @@ public static void SetDataUInt32(uint* data, int index, uint value) #region PixelFormat conversion -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static uint ConvertRgb555ToRGBA(uint val) @@ -115,7 +115,7 @@ public static uint ConvertRgb555ToRGBA(uint val) 0xFF; } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static uint ConvertRgb565ToRGBA(uint val) @@ -131,7 +131,7 @@ public static uint ConvertRgb565ToRGBA(uint val) } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static uint ConvertArgb1555ToRGBA(uint val) @@ -147,7 +147,7 @@ public static uint ConvertArgb1555ToRGBA(uint val) ((alpha << 8) - alpha); // effectively alpha * 255, only works as alpha will be either 0 or 1 } -#if Net45 || NETSTANDARD +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static uint EncodeAsRGBA(byte red, byte green, byte blue, byte alpha) @@ -158,6 +158,6 @@ public static uint EncodeAsRGBA(byte red, byte green, byte blue, byte alpha) alpha); } -#endregion + #endregion } } diff --git a/src/Tesseract/BitmapToPixConverter.cs b/src/Tesseract/BitmapToPixConverter.cs index fcf2bc05..8bef09bb 100644 --- a/src/Tesseract/BitmapToPixConverter.cs +++ b/src/Tesseract/BitmapToPixConverter.cs @@ -1,5 +1,4 @@ -#if SYSTEM_DRAWING_SUPPORT - + using System; using System.Drawing; using System.Drawing.Imaging; @@ -195,4 +194,3 @@ private unsafe void TransferDataFormat8bppIndexed(BitmapData imgData, PixData pi } } -#endif \ No newline at end of file diff --git a/src/Tesseract/Internal/InteropDotNet/InteropRuntimeImplementer.cs b/src/Tesseract/Internal/InteropDotNet/InteropRuntimeImplementer.cs index aea578eb..1e2976a1 100644 --- a/src/Tesseract/Internal/InteropDotNet/InteropRuntimeImplementer.cs +++ b/src/Tesseract/Internal/InteropDotNet/InteropRuntimeImplementer.cs @@ -21,10 +21,10 @@ public static T CreateInstance() where T : class throw new Exception(string.Format("The interface {0} should be public", interfaceType.Name)); var assemblyName = GetAssemblyName(interfaceType); -#if NETFULL +#if NET40 var assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.Run); -#elif NETSTANDARD - var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.Run); +#else + var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.Run); #endif var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName); @@ -37,11 +37,10 @@ public static T CreateInstance() where T : class ImplementFields(typeBuilder, methods); ImplementMethods(typeBuilder, methods); ImplementConstructor(typeBuilder, methods); - -#if NETFULL +#if NET40 var implementationType = typeBuilder.CreateType(); return (T)Activator.CreateInstance(implementationType, LibraryLoader.Instance); -#elif NETSTANDARD +#else var implementationType = typeBuilder.CreateTypeInfo(); return (T)Activator.CreateInstance(implementationType, LibraryLoader.Instance); #endif @@ -97,9 +96,9 @@ private static Type ImplementMethodDelegate(string assemblyName, ModuleBuilder m }, new object[] { - importAttribute.CharSet, - importAttribute.BestFitMapping, - importAttribute.ThrowOnUnmappableChar, + importAttribute.CharSet, + importAttribute.BestFitMapping, + importAttribute.ThrowOnUnmappableChar, importAttribute.SetLastError }); delegateBuilder.SetCustomAttribute(attributeBuilder); @@ -129,9 +128,9 @@ private static Type ImplementMethodDelegate(string assemblyName, ModuleBuilder m methodBuilder.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); // Create type -#if NETFULL - return delegateBuilder.CreateType(); -#elif NETSTANDARD +#if NET40 + return delegateBuilder.CreateType(); +#else return delegateBuilder.CreateTypeInfo(); #endif } diff --git a/src/Tesseract/Interop/BaseApi.cs b/src/Tesseract/Interop/BaseApi.cs index 1cb4fc50..110aacf8 100644 --- a/src/Tesseract/Interop/BaseApi.cs +++ b/src/Tesseract/Interop/BaseApi.cs @@ -335,7 +335,7 @@ int BaseApiInit(HandleRef handle, string datapath, string language, int mode, #endregion Renderer API } - internal static class TessApi + public static class TessApi { //XHTML Begin Tag: public const string xhtmlBeginTag = diff --git a/src/Tesseract/Pix.cs b/src/Tesseract/Pix.cs index 26c36ff6..137a136d 100644 --- a/src/Tesseract/Pix.cs +++ b/src/Tesseract/Pix.cs @@ -187,7 +187,7 @@ public int YRes set { Interop.LeptonicaApi.Native.pixSetYRes(this.handle, value); } } - internal HandleRef Handle + public HandleRef Handle { get { return handle; } } diff --git a/src/Tesseract/PixColor.cs b/src/Tesseract/PixColor.cs index 7dc4a912..af7bab7a 100644 --- a/src/Tesseract/PixColor.cs +++ b/src/Tesseract/PixColor.cs @@ -52,7 +52,7 @@ public uint ToRGBA() alpha); } -#if NETFULL + public static explicit operator System.Drawing.Color(PixColor color) { return System.Drawing.Color.FromArgb(color.alpha, color.red, color.green, color.blue); @@ -62,7 +62,6 @@ public static explicit operator PixColor(System.Drawing.Color color) { return new PixColor(color.R, color.G, color.B, color.A); } -#endif #region Equals and GetHashCode implementation diff --git a/src/Tesseract/PixConverter.cs b/src/Tesseract/PixConverter.cs index d1babd6b..949901fe 100644 --- a/src/Tesseract/PixConverter.cs +++ b/src/Tesseract/PixConverter.cs @@ -1,5 +1,4 @@ -#if SYSTEM_DRAWING_SUPPORT - + using System; using System.Collections.Generic; using System.Drawing; @@ -35,6 +34,4 @@ public static Pix ToPix(Bitmap img) return bitmapConverter.Convert(img); } } -} - -#endif \ No newline at end of file +} diff --git a/src/Tesseract/PixData.cs b/src/Tesseract/PixData.cs index f6a1d9ba..9c6d0d12 100644 --- a/src/Tesseract/PixData.cs +++ b/src/Tesseract/PixData.cs @@ -5,27 +5,27 @@ namespace Tesseract { - public unsafe class PixData - { - public Pix Pix { get; private set; } + public unsafe class PixData + { + public Pix Pix { get; private set; } - - internal PixData(Pix pix) - { + + internal PixData(Pix pix) + { Pix = pix; Data = Interop.LeptonicaApi.Native.pixGetData(Pix.Handle); WordsPerLine = Interop.LeptonicaApi.Native.pixGetWpl(Pix.Handle); - } - - /// - /// Pointer to the data. - /// - public IntPtr Data { get; private set; } - - /// - /// Number of 32-bit words per line. - /// - public int WordsPerLine { get; private set; } + } + + /// + /// Pointer to the data. + /// + public IntPtr Data { get; private set; } + + /// + /// Number of 32-bit words per line. + /// + public int WordsPerLine { get; private set; } /// /// Swaps the bytes on little-endian platforms within a word; bytes 0 and 3 swapped, and bytes `1 and 2 are swapped. @@ -39,7 +39,7 @@ public void EndianByteSwap() Interop.LeptonicaApi.Native.pixEndianByteSwap(Pix.Handle); } -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static uint EncodeAsRGBA(byte red, byte green, byte blue, byte alpha) @@ -53,180 +53,180 @@ public static uint EncodeAsRGBA(byte red, byte green, byte blue, byte alpha) /// /// Gets the pixel value for a 1bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataBit(uint* data, int index) - { - return (*(data + ((index) >> 5)) >> (31 - ((index) & 31))) & 1; - } + public static uint GetDataBit(uint* data, int index) + { + return (*(data + ((index) >> 5)) >> (31 - ((index) & 31))) & 1; + } /// /// Sets the pixel value for a 1bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataBit(uint* data, int index, uint value) - { - uint* wordPtr = data + ((index) >> 5); + public static void SetDataBit(uint* data, int index, uint value) + { + uint* wordPtr = data + ((index) >> 5); *wordPtr &= ~(0x80000000 >> ((index) & 31)); - *wordPtr |= (value << (31 - ((index) & 31))); - } + *wordPtr |= (value << (31 - ((index) & 31))); + } /// /// Gets the pixel value for a 2bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataDIBit(uint* data, int index) - { - return (*(data + ((index) >> 4)) >> (2 * (15 - ((index) & 15)))) & 3; - } + public static uint GetDataDIBit(uint* data, int index) + { + return (*(data + ((index) >> 4)) >> (2 * (15 - ((index) & 15)))) & 3; + } /// /// Sets the pixel value for a 2bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataDIBit(uint* data, int index, uint value) - { - uint* wordPtr = data + ((index) >> 4); + public static void SetDataDIBit(uint* data, int index, uint value) + { + uint* wordPtr = data + ((index) >> 4); *wordPtr &= ~(0xc0000000 >> (2 * ((index) & 15))); - *wordPtr |= (((value) & 3) << (30 - 2 * ((index) & 15))); - } + *wordPtr |= (((value) & 3) << (30 - 2 * ((index) & 15))); + } /// /// Gets the pixel value for a 4bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataQBit(uint* data, int index) - { - return (*(data + ((index) >> 3)) >> (4 * (7 - ((index) & 7)))) & 0xf; - } + public static uint GetDataQBit(uint* data, int index) + { + return (*(data + ((index) >> 3)) >> (4 * (7 - ((index) & 7)))) & 0xf; + } /// /// Sets the pixel value for a 4bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataQBit(uint* data, int index, uint value) - { - uint* wordPtr = data + ((index) >> 3); + public static void SetDataQBit(uint* data, int index, uint value) + { + uint* wordPtr = data + ((index) >> 3); *wordPtr &= ~(0xf0000000 >> (4 * ((index) & 7))); - *wordPtr |= (((value) & 15) << (28 - 4 * ((index) & 7))); - } + *wordPtr |= (((value) & 15) << (28 - 4 * ((index) & 7))); + } /// /// Gets the pixel value for a 8bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataByte(uint* data, int index) - { - // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) - if(IntPtr.Size == 8) { - return *((byte*)((ulong)((byte*)data + index) ^ 3)); - } else { - return *((byte*)((uint)((byte*)data + index) ^ 3)); - } - // Architecture types that are NOT little edian are not currently supported + public static uint GetDataByte(uint* data, int index) + { + // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) + if(IntPtr.Size == 8) { + return *((byte*)((ulong)((byte*)data + index) ^ 3)); + } else { + return *((byte*)((uint)((byte*)data + index) ^ 3)); + } + // Architecture types that are NOT little edian are not currently supported //return *((byte*)data + index); - } + } /// /// Sets the pixel value for a 8bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataByte(uint* data, int index, uint value) - { - // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) - if(IntPtr.Size == 8) { - *(byte*)((ulong)((byte*)data + index) ^ 3) = (byte)value; - } else { - *(byte*)((uint)((byte*)data + index) ^ 3) = (byte)value; - } - - // Architecture types that are NOT little edian are not currently supported - // *((byte*)data + index) = (byte)value; - } + public static void SetDataByte(uint* data, int index, uint value) + { + // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) + if(IntPtr.Size == 8) { + *(byte*)((ulong)((byte*)data + index) ^ 3) = (byte)value; + } else { + *(byte*)((uint)((byte*)data + index) ^ 3) = (byte)value; + } + + // Architecture types that are NOT little edian are not currently supported + // *((byte*)data + index) = (byte)value; + } /// /// Gets the pixel value for a 16bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataTwoByte(uint* data, int index) - { - // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) - if(IntPtr.Size == 8) { + public static uint GetDataTwoByte(uint* data, int index) + { + // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) + if(IntPtr.Size == 8) { return *(ushort*)((ulong)((ushort*)data + index) ^ 2); - } else { + } else { return *(ushort*)((uint)((ushort*)data + index) ^ 2); - } - // Architecture types that are NOT little edian are not currently supported + } + // Architecture types that are NOT little edian are not currently supported // return *((ushort*)data + index); - } + } /// /// Sets the pixel value for a 16bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataTwoByte(uint* data, int index, uint value) - { - // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) - if(IntPtr.Size == 8) { - *(ushort*)((ulong)((ushort*)data + index) ^ 2) = (ushort)value; - } else { - *(ushort*)((uint)((ushort*)data + index) ^ 2) = (ushort)value; - } - // Architecture types that are NOT little edian are not currently supported + public static void SetDataTwoByte(uint* data, int index, uint value) + { + // Must do direct size comparison to detect x64 process, since in this will be jited out and results in a lot faster code (e.g. 6x faster for image conversion) + if(IntPtr.Size == 8) { + *(ushort*)((ulong)((ushort*)data + index) ^ 2) = (ushort)value; + } else { + *(ushort*)((uint)((ushort*)data + index) ^ 2) = (ushort)value; + } + // Architecture types that are NOT little edian are not currently supported //*((ushort*)data + index) = (ushort)value; - } + } /// /// Gets the pixel value for a 32bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static uint GetDataFourByte(uint* data, int index) - { - return *(data + index); - } + public static uint GetDataFourByte(uint* data, int index) + { + return *(data + index); + } /// /// Sets the pixel value for a 32bpp image. /// -#if Net45 +#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static void SetDataFourByte(uint* data, int index, uint value) - { - *(data + index) = value; - } - } + public static void SetDataFourByte(uint* data, int index, uint value) + { + *(data + index) = value; + } + } } diff --git a/src/Tesseract/PixToBitmapConverter.cs b/src/Tesseract/PixToBitmapConverter.cs index 526f5edb..9f12b450 100644 --- a/src/Tesseract/PixToBitmapConverter.cs +++ b/src/Tesseract/PixToBitmapConverter.cs @@ -1,5 +1,4 @@ -#if SYSTEM_DRAWING_SUPPORT - + using System; using System.Drawing; using System.Drawing.Imaging; @@ -165,5 +164,3 @@ private PixelFormat GetPixelFormat(Pix pix) } } } - -#endif \ No newline at end of file diff --git a/src/Tesseract/Tesseract.csproj b/src/Tesseract/Tesseract.csproj index 0a5c3afe..6b94f29a 100644 --- a/src/Tesseract/Tesseract.csproj +++ b/src/Tesseract/Tesseract.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net40;net45 + netstandard2.0;net40;net45;net48;netcoreapp3.1;net5.0 true @@ -19,36 +19,15 @@ 4.1.1.0 Apache-2.0 - - - - NET40;NETFULL;SYSTEM_DRAWING_SUPPORT - - - - - NET45;NETFULL;SYSTEM_DRAWING_SUPPORT - - - - - NETCORE;NETSTANDARD;NETSTANDARD2_0 - - .\Tesseract.xml - - .\Tesseract.xml - - - - 4.7.0 + + + 5.0.2 - - - - + + diff --git a/src/Tesseract/TesseractDrawingExtensions.cs b/src/Tesseract/TesseractDrawingExtensions.cs index bc408bf9..9fe1f81f 100644 --- a/src/Tesseract/TesseractDrawingExtensions.cs +++ b/src/Tesseract/TesseractDrawingExtensions.cs @@ -1,5 +1,4 @@ -#if SYSTEM_DRAWING_SUPPORT - + using System; using System.Drawing; @@ -118,4 +117,3 @@ public static int GetBPP(this System.Drawing.Bitmap bitmap) } } -#endif