-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,538 additions
and
0 deletions.
There are no files selected for viewing
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,90 @@ | ||
{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=] | ||
Copyright (c) 2014, Jarl K. <Slacky> Holta || http://github.com/WarPie | ||
All rights reserved. | ||
[=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=} | ||
var | ||
Methods: array of record procAddr: Pointer; ProcDef:PChar; end; | ||
TypeDefs: array of record TypeName, TypeDef:PChar; end; | ||
TypesLoaded: Boolean = False; | ||
MethodsLoaded: Boolean = False; | ||
|
||
OldMemoryManager: TMemoryManager; | ||
MemIsset: Boolean = False; | ||
|
||
|
||
procedure AddMethod(ProcDef: PChar; ProcAddr: Pointer); | ||
var L: Integer; | ||
begin | ||
L := Length(Methods); | ||
SetLength(Methods, L + 1); | ||
Methods[l].ProcAddr := ProcAddr; | ||
Methods[l].ProcDef := ProcDef; | ||
end; | ||
|
||
procedure AddType(TypeName, TypeDef: PChar); | ||
var L: Integer; | ||
begin | ||
L := Length(TypeDefs); | ||
SetLength(TypeDefs, L + 1); | ||
TypeDefs[l].TypeName := TypeName; | ||
TypeDefs[l].TypeDef := TypeDef; | ||
end; | ||
|
||
procedure LoadExports; | ||
begin | ||
addType('TFontChar', | ||
'packed record' +#13#10+ | ||
' FChar:AnsiChar;' +#13#10+ | ||
' FWidth,FHeight:Int32;' +#13#10+ | ||
' loaded, hasShadow:LongBool;' +#13#10+ | ||
' pts,shadow,bad:TPointArray;' +#13#10+ | ||
'end;'); | ||
addType('TFontSet', | ||
'packed record' +#13#10+ | ||
' FData: Array of TFontChar;' +#13#10+ | ||
' SpaceWidth: Int32;' +#13#10+ | ||
'end;'); | ||
addType('TCompareRules', | ||
'packed record' +#13#10+ | ||
' Color, ColorMaxDiff: Int32;' +#13#10+ | ||
' UseShadow: LongBool;' +#13#10+ | ||
' ShadowMaxValue:Int32;' +#13#10+ | ||
' Threshold: Int32;' +#13#10+ | ||
' ThreshInv: LongBool;' +#13#10+ | ||
'end;'); | ||
addType('TSimpleOCR', | ||
'packed record' +#13#10+ | ||
' IsLoaded: LongBool;' +#13#10+ | ||
' FontData: TFontSet;' +#13#10+ | ||
' ClientID: TTarget_Exported;' +#13#10+ | ||
' Client: T2DIntArray;' +#13#10+ | ||
' __debugging: LongBool;' +#13#10+ | ||
'end;'); | ||
|
||
|
||
addMethod('procedure TFontSet.Load(Font:AnsiString; Space:Int32=4);', @TFontSet_Load); | ||
addMethod('procedure TFontSet.Free();', @TFontSet_Free); | ||
addMethod('procedure TSimpleOCR.Init(Font:TFontSet; Dbg:LongBool=False; AClient:TTarget_Exported=ExportImageTarget()); native;', @TSimpleOCR_Init); | ||
addMethod('procedure TSimpleOCR.Init(Font:AnsiString; SpaceWidth:Int32=4; Dbg:LongBool=False; AClient:TTarget_Exported=ExportImageTarget()); overload; native;', @TSimpleOCR_Init2); | ||
addMethod('procedure TSimpleOCR.SetFont(Font:TFontSet); native;', @TSimpleOCR_SetFont); | ||
addMethod('procedure TSimpleOCR.SetFont(Font:AnsiString; SpaceWidth:Int32=4); overload; native;', @TSimpleOCR_SetFont2); | ||
addMethod('procedure TSimpleOCR.Free(); native;', @TSimpleOCR_Free); | ||
addMethod('function TSimpleOCR.Recognize(B:TBox; Filter:TCompareRules; MaxWalk:Int32=70): AnsiString; native;', @TSimpleOCR_Recognize); | ||
addMethod('function TSimpleOCR.Recognize(AClient:T2DIntArray; Filter:TCompareRules; MaxWalk:Int32=70): AnsiString; overload; native;', @TSimpleOCR_Recognize2); | ||
|
||
MethodsLoaded := True; | ||
TypesLoaded := True; | ||
end; | ||
|
||
procedure FreeMethods; | ||
begin | ||
SetLength(Methods, 0); | ||
MethodsLoaded := False; | ||
end; | ||
|
||
|
||
procedure FreeTypes; | ||
begin | ||
SetLength(TypeDefs, 0); | ||
TypesLoaded := False; | ||
end; |
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,90 @@ | ||
<?xml version="1.0"?> | ||
<CONFIG> | ||
<ProjectOptions> | ||
<Version Value="9"/> | ||
<PathDelim Value="\"/> | ||
<General> | ||
<Flags> | ||
<MainUnitHasCreateFormStatements Value="False"/> | ||
<MainUnitHasTitleStatement Value="False"/> | ||
</Flags> | ||
<SessionStorage Value="InProjectDir"/> | ||
<MainUnit Value="0"/> | ||
<Title Value="SimpleOCR"/> | ||
<UseAppBundle Value="False"/> | ||
<ResourceType Value="res"/> | ||
</General> | ||
<i18n> | ||
<EnableI18N LFM="False"/> | ||
</i18n> | ||
<VersionInfo> | ||
<StringTable ProductVersion=""/> | ||
</VersionInfo> | ||
<BuildModes Count="1"> | ||
<Item1 Name="Default" Default="True"/> | ||
</BuildModes> | ||
<PublishOptions> | ||
<Version Value="2"/> | ||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> | ||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/> | ||
</PublishOptions> | ||
<RunParams> | ||
<local> | ||
<FormatVersion Value="1"/> | ||
</local> | ||
</RunParams> | ||
<RequiredPackages Count="2"> | ||
<Item1> | ||
<PackageName Value="LCL"/> | ||
</Item1> | ||
<Item2> | ||
<PackageName Value="LCLBase"/> | ||
</Item2> | ||
</RequiredPackages> | ||
<Units Count="1"> | ||
<Unit0> | ||
<Filename Value="SimpleOCR.lpr"/> | ||
<IsPartOfProject Value="True"/> | ||
<UnitName Value="SimpleOCR"/> | ||
</Unit0> | ||
</Units> | ||
</ProjectOptions> | ||
<CompilerOptions> | ||
<Version Value="11"/> | ||
<PathDelim Value="\"/> | ||
<Target> | ||
<Filename Value="SimpleOCR"/> | ||
</Target> | ||
<SearchPaths> | ||
<IncludeFiles Value="$(ProjOutDir)"/> | ||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> | ||
</SearchPaths> | ||
<CodeGeneration> | ||
<RelocatableUnit Value="True"/> | ||
</CodeGeneration> | ||
<Linking> | ||
<Options> | ||
<ExecutableType Value="Library"/> | ||
</Options> | ||
</Linking> | ||
<Other> | ||
<CompilerMessages> | ||
<MsgFileName Value=""/> | ||
</CompilerMessages> | ||
<CompilerPath Value="$(CompPath)"/> | ||
</Other> | ||
</CompilerOptions> | ||
<Debugging> | ||
<Exceptions Count="3"> | ||
<Item1> | ||
<Name Value="EAbort"/> | ||
</Item1> | ||
<Item2> | ||
<Name Value="ECodetoolError"/> | ||
</Item2> | ||
<Item3> | ||
<Name Value="EFOpenError"/> | ||
</Item3> | ||
</Exceptions> | ||
</Debugging> | ||
</CONFIG> |
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,95 @@ | ||
library SimpleOCR; | ||
|
||
{$mode objfpc}{$H+} | ||
{$macro on} | ||
{$inline on} | ||
|
||
{$DEFINE callconv:= | ||
{$IFDEF WINDOWS}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF} | ||
{$IFDEF LINUX}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF} | ||
} | ||
|
||
|
||
uses | ||
SysUtils, | ||
Math, | ||
Classes, | ||
OCRBitmap, | ||
OCRTypes, | ||
OCREngine; | ||
|
||
|
||
{$I SimbaPlugin.inc} | ||
|
||
{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=] | ||
Export our functions, name, information etc... | ||
All that is needed for scar to see this as a DLL. | ||
[=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=} | ||
function GetPluginABIVersion: Integer; cdecl; export; | ||
begin | ||
Result := 2; | ||
end; | ||
|
||
procedure SetPluginMemManager(MemMgr : TMemoryManager); cdecl; export; | ||
begin | ||
if memisset then | ||
exit; | ||
GetMemoryManager(OldMemoryManager); | ||
SetMemoryManager(MemMgr); | ||
memisset := True; | ||
end; | ||
|
||
|
||
procedure OnDetach; cdecl; export; | ||
begin | ||
SetMemoryManager(OldMemoryManager); | ||
end; | ||
|
||
|
||
function GetFunctionCount: Integer; cdecl; export; | ||
begin | ||
if not MethodsLoaded then LoadExports; | ||
Result := Length(Methods); | ||
end; | ||
|
||
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; cdecl; export; | ||
begin | ||
Result := x; | ||
if (x > -1) and InRange(x, 0, High(Methods)) then | ||
begin | ||
ProcAddr := Methods[x].procAddr; | ||
StrPCopy(ProcDef, Methods[x].ProcDef); | ||
if (x = High(Methods)) then FreeMethods; | ||
end; | ||
end; | ||
|
||
|
||
|
||
function GetTypeCount: Integer; cdecl; export; | ||
begin | ||
if not TypesLoaded then LoadExports; | ||
Result := Length(TypeDefs); | ||
end; | ||
|
||
function GetTypeInfo(x: Integer; var TypeName, TypeDef: PChar): integer; cdecl; export; | ||
begin | ||
Result := x; | ||
if (x > -1) and InRange(x, 0, High(TypeDefs)) then | ||
begin | ||
StrPCopy(TypeName, TypeDefs[x].TypeName); | ||
StrPCopy(TypeDef, TypeDefs[x].TypeDef); | ||
if (x = High(TypeDefs)) then FreeTypes; | ||
end; | ||
end; | ||
|
||
|
||
exports GetPluginABIVersion; | ||
exports SetPluginMemManager; | ||
exports GetTypeCount; | ||
exports GetTypeInfo; | ||
exports GetFunctionCount; | ||
exports GetFunctionInfo; | ||
exports OnDetach; | ||
|
||
begin | ||
end. |
Oops, something went wrong.