/////////////////////////////////////////////////////////////////////// // File: tessdll.cpp // Description: Windows dll interface for Tesseract. // Author: Glen Wernersbach // Created: Tue May 15 10:30:01 PDT 2007 // // (C) Copyright 2007, Jetsoftdev. // 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. // /////////////////////////////////////////////////////////////////////// // tessdll.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "mfcpch.h" #include "applybox.h" #include "control.h" #include "tessvars.h" #include "tessedit.h" #include "pageres.h" #include "imgs.h" #include "varabled.h" #include "tprintf.h" #include "tesseractmain.h" #include "stderr.h" #include "notdll.h" #include "tessdll.h" #ifdef __MSW32__ extern ESHM_INFO shm; /*info on shm */ #define TICKS 1000 #endif extern BOOL_VARIABLE tessedit_write_ratings; extern BOOL_VARIABLE tessedit_write_output; extern BOOL_VARIABLE tessedit_write_raw_output; extern BOOL_VARIABLE tessedit_write_txt_map; extern BOOL_VARIABLE tessedit_resegment_from_boxes; //unsigned char membuf[sizeof (ETEXT_DESC)+32000L*sizeof (EANYCODE_CHAR)]; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } TessDllAPI::TessDllAPI(const char* lang) { const char *fake_argv[] = { "api_config" }; uinT16 oldlang; //language ocr_open_shm ("0", "0", "0", "0", "0", "0", &oldlang); init_tesseract ("TESSEDIT", "tessapi", lang, 0L, 1, fake_argv); if (interactive_mode) { debug_window_on.set_value (TRUE); } tessedit_write_ratings.set_value (TRUE); tessedit_write_output.set_value(FALSE); tessedit_write_raw_output.set_value(FALSE); tessedit_write_txt_map.set_value(FALSE); page_res=0L; block_list = 0L; membuf = (unsigned char *) new BYTE[(sizeof (ETEXT_DESC)+32000L*sizeof (EANYCODE_CHAR))]; } TessDllAPI::~TessDllAPI() { EndPage(); End(); if (membuf) delete []membuf; } int TessDllAPI::BeginPage(uinT32 xsize,uinT32 ysize,unsigned char *buf) { return BeginPage(xsize,ysize,buf,1); } int TessDllAPI::BeginPage(uinT32 xsize,uinT32 ysize,unsigned char *buf,uinT8 bpp) { inT16 c; EndPage(); if (page_image.create (xsize+800, ysize+800, 1)==-1) return 0L; //make the image bigger to enclose in whitespace //copy the passed buffer into the center of the image IMAGE tmp; tmp.create(xsize, ysize, bpp); for (c=0;ccount;i++) { global_monitor->text[i].left-=400; global_monitor->text[i].right-=400; global_monitor->text[i].bottom-=400; global_monitor->text[i].top-=400; } global_monitor = 0L; return ((ETEXT_DESC *) membuf); } TessDllAPI *recognize=0L; char* current_lang = 0L; extern "C" { TESSDLL_API void __cdecl TessDllRelease() { if (recognize) delete recognize; recognize=0L; } TESSDLL_API void * __cdecl TessDllInit(const char* lang) { if (recognize) TessDllRelease(); recognize = new TessDllAPI(lang); if (current_lang != 0L) free(current_lang); current_lang = lang ? strdup(lang) : 0L; return (void*) recognize; } TESSDLL_API int __cdecl TessDllBeginPageBPP(uinT32 xsize,uinT32 ysize, unsigned char *buf, uinT8 bpp) { return TessDllBeginPageLangBPP(xsize, ysize, buf, NULL,bpp); } TESSDLL_API int __cdecl TessDllBeginPageLangBPP(uinT32 xsize, uinT32 ysize, unsigned char *buf, const char* lang, uinT8 bpp) { if (recognize==0L || (lang != 0L) != (current_lang != 0L) || lang != 0L && strcmp(lang, current_lang)) TessDllInit(lang); return recognize->BeginPage(xsize, ysize, buf,bpp); } TESSDLL_API int __cdecl TessDllBeginPageUprightBPP(uinT32 xsize, uinT32 ysize, unsigned char *buf, const char* lang, uinT8 bpp) { if (recognize==0L || (lang != 0L) != (current_lang != 0L) || lang != 0L && strcmp(lang, current_lang)) TessDllInit(lang); return recognize->BeginPageUpright(xsize, ysize, buf,bpp); } TESSDLL_API int __cdecl TessDllBeginPage(uinT32 xsize,uinT32 ysize, unsigned char *buf) { return TessDllBeginPageLangBPP(xsize, ysize, buf, NULL,1); } TESSDLL_API int __cdecl TessDllBeginPageLang(uinT32 xsize, uinT32 ysize, unsigned char *buf, const char* lang) { if (recognize==0L || (lang != 0L) != (current_lang != 0L) || lang != 0L && strcmp(lang, current_lang)) TessDllInit(lang); return recognize->BeginPage(xsize, ysize, buf,1); } TESSDLL_API int __cdecl TessDllBeginPageUpright(uinT32 xsize, uinT32 ysize, unsigned char *buf, const char* lang) { if (recognize==0L || (lang != 0L) != (current_lang != 0L) || lang != 0L && strcmp(lang, current_lang)) TessDllInit(lang); return recognize->BeginPageUpright(xsize, ysize, buf); } TESSDLL_API void __cdecl TessDllEndPage(void) { recognize->EndPage(); } TESSDLL_API ETEXT_DESC * __cdecl TessDllRecognize_a_Block(uinT32 left, uinT32 right, uinT32 top, uinT32 bottom) { return recognize->Recognize_a_Block(left,right,top,bottom); } TESSDLL_API ETEXT_DESC * __cdecl TessDllRecognize_all_Words(void) { return recognize->Recognize_all_Words(); } //deprecated funtions TESSDLL_API void __cdecl ReleaseRecognize() { if (recognize) delete recognize;recognize=0L; } TESSDLL_API void * __cdecl InitRecognize() { if (recognize) ReleaseRecognize(); recognize = new TessDllAPI(); return (void*) recognize; } TESSDLL_API int __cdecl CreateRecognize(uinT32 xsize,uinT32 ysize,unsigned char *buf) { InitRecognize(); return recognize->BeginPage(xsize,ysize,buf); } TESSDLL_API ETEXT_DESC * __cdecl reconize_a_word(uinT32 left,uinT32 right,uinT32 top,uinT32 bottom) { return recognize->Recognize_a_Block(left,right,top,bottom); } }