diff --git a/src/Tesseract.Tests/BaseApiTests.cs b/src/Tesseract.Tests/BaseApiTests.cs
index 8fa602b3..73e6d627 100644
--- a/src/Tesseract.Tests/BaseApiTests.cs
+++ b/src/Tesseract.Tests/BaseApiTests.cs
@@ -11,7 +11,7 @@ public class BaseApiTests
[Test]
public void GetVersion_Is302()
{
- var version = Interop.TessApi.GetVersion();
+ var version = Interop.TessApi.Native.GetVersion();
Assert.That(version, Is.EqualTo("3.02"));
}
}
diff --git a/src/Tesseract/Interop/BaseApi.cs b/src/Tesseract/Interop/BaseApi.cs
index 0a6e8198..6ecd9ffb 100644
--- a/src/Tesseract/Interop/BaseApi.cs
+++ b/src/Tesseract/Interop/BaseApi.cs
@@ -1,12 +1,172 @@
-
-using System;
+using System;
using System.Runtime.InteropServices;
using System.Text;
+using InteropDotNet;
namespace Tesseract.Interop
{
- public static class TessApi
- {
+ public interface ITessApiSignatures
+ {
+ // Helper functions
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessVersion")]
+ string GetVersion();
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessDeleteText")]
+ void DeleteText(IntPtr textPtr);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessDeleteTextArray")]
+ void DeleteTextArray(IntPtr arr);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessDeleteIntArray")]
+ void DeleteIntArray(IntPtr arr);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessDeleteBlockList")]
+ void DeleteBlockList(IntPtr arr);
+
+ // Base API
+
+ ///
+ /// Creates a new BaseAPI instance
+ ///
+ ///
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPICreate")]
+ IntPtr BaseApiCreate();
+
+
+ ///
+ /// Deletes a base api instance.
+ ///
+ ///
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIDelete")]
+ void BaseApiDelete(HandleRef ptr);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIInit1")]
+ int BaseApiInit(HandleRef handle,
+ string datapath,
+ string language,
+ int mode,
+ IntPtr configs, int configs_size,
+ IntPtr vars_vec, int vars_vec_size,
+ IntPtr vars_values, int vars_values_size);
+
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetVariable")]
+ int BaseApiSetVariable(HandleRef handle, string name, string value);
+
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetDebugVariable")]
+ int BaseApiSetDebugVariable(HandleRef handle, string name, string value);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetIntVariable")]
+ int BaseApiGetIntVariable(HandleRef handle, string name, out int value);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetBoolVariable")]
+ int BaseApiGetBoolVariable(HandleRef handle, string name, out int value);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetDoubleVariable")]
+ int BaseApiGetDoubleVariable(HandleRef handle, string name, out double value);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetStringVariable")]
+ IntPtr BaseApiGetStringVariableInternal(HandleRef handle, string name);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetPageSegMode")]
+ void BaseAPISetPageSegMode(HandleRef handle, PageSegMode mode);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetPageSegMode")]
+ PageSegMode BaseAPIGetPageSegMode(HandleRef handle);
+
+ // image analysis
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetImage2")]
+ void BaseApiSetImage(HandleRef handle, HandleRef pixHandle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetInputName")]
+ void BaseApiSetInputName(HandleRef handle, string value);
+
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPISetRectangle")]
+ void BaseApiSetRectangle(HandleRef handle, int left, int top, int width, int height);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIRecognize")]
+ int BaseApiRecognize(HandleRef handle, HandleRef monitor);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIAnalyseLayout")]
+ IntPtr BaseAPIAnalyseLayout(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetIterator")]
+ IntPtr BaseApiGetIterator(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetUTF8Text")]
+ IntPtr BaseAPIGetUTF8TextInternal(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIGetHOCRText")]
+ IntPtr BaseAPIGetHOCRTextInternal(HandleRef handle, int pageNum);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIMeanTextConf")]
+ int BaseAPIMeanTextConf(HandleRef handle);
+
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessBaseAPIClear")]
+ void BaseAPIClear(HandleRef handle);
+
+ // result iterator
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessResultIteratorDelete")]
+ void ResultIteratorDelete(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessResultIteratorCopy")]
+ IntPtr ResultIteratorCopy(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessResultIteratorGetPageIterator")]
+ IntPtr ResultIteratorGetPageIterator(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessResultIteratorGetUTF8Text")]
+ IntPtr ResultIteratorGetUTF8TextInternal(HandleRef handle, PageIteratorLevel level);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessResultIteratorConfidence")]
+ float ResultIteratorGetConfidence(HandleRef handle, PageIteratorLevel level);
+
+ // page iterator
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorDelete")]
+ void PageIteratorDelete(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorCopy")]
+ IntPtr PageIteratorCopy(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorBegin")]
+ void PageIteratorBegin(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorNext")]
+ int PageIteratorNext(HandleRef handle, PageIteratorLevel level);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorIsAtBeginningOf")]
+ int PageIteratorIsAtBeginningOf(HandleRef handle, PageIteratorLevel level);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorIsAtFinalElement")]
+ int PageIteratorIsAtFinalElement(HandleRef handle, PageIteratorLevel level, PageIteratorLevel element);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorBoundingBox")]
+ int PageIteratorBoundingBox(HandleRef handle, PageIteratorLevel level, out int left, out int top, out int right, out int bottom);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorBlockType")]
+ PolyBlockType PageIteratorBlockType(HandleRef handle);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorGetBinaryImage")]
+ IntPtr PageIteratorGetBinaryImage(HandleRef handle, PageIteratorLevel level);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorGetImage")]
+ IntPtr PageIteratorGetImage(HandleRef handle, PageIteratorLevel level, int padding, out int left, out int top);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorBaseline")]
+ int PageIteratorBaseline(HandleRef handle, PageIteratorLevel level, out int x1, out int y1, out int x2, out int y2);
+
+ [RuntimeDllImport(Constants.TesseractDllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TessPageIteratorOrientation")]
+ void PageIteratorOrientation(HandleRef handle, out Orientation orientation, out WritingDirection writing_direction, out TextLineOrder textLineOrder, out float deskew_angle);
+ }
+
+ public static class TessApi
+ {
+
public const string htmlBeginTag =
"\n"
@@ -17,128 +177,56 @@ public static class TessApi
public const string htmlEndTag = "