#include "mfcpch.h"
#include "ocrshell.h"
#include "tprintf.h"
#include <stdlib.h>
Go to the source code of this file.
#define EXTERN |
* (C) Copyright 1996, Hewlett-Packard Co. ** 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.
Definition at line 28 of file ocrshell.cpp.
#define TICKS 1 |
enum OCR_STATE |
State of the OCR engine.
OCS_UNINIT | |
OCS_SETUP_SHM | |
OCS_SETUP_INFO | |
OCS_READING_STRIPS | |
OCS_READ_STRIPS | |
OCS_RECOGNIZING | |
OCS_SENDING_TEXT | |
OCS_DEAD |
Definition at line 63 of file ocrshell.cpp.
00063 { 00064 OCS_UNINIT, /*uninitialized */ 00065 OCS_SETUP_SHM, /*shm setup done */ 00066 OCS_SETUP_INFO, /*startinfo sent */ 00067 OCS_READING_STRIPS, /*read first but more to come */ 00068 OCS_READ_STRIPS, /*read all but no monitor yet */ 00069 OCS_RECOGNIZING, /*OCR incomplete */ 00070 OCS_SENDING_TEXT, /*sent buffer but more to come */ 00071 OCS_DEAD /*disconnected */ 00072 } OCR_STATE;
INT16 ocr_append_char | ( | UINT16 | char_code, | |
INT16 | left, | |||
INT16 | right, | |||
INT16 | top, | |||
INT16 | bottom, | |||
INT16 | font_index, | |||
UINT8 | confidence, | |||
UINT8 | point_size, | |||
INT8 | blanks, | |||
UINT8 | enhancement, | |||
OCR_CHAR_DIRECTION | text_dir, | |||
OCR_LINE_DIRECTION | line_dir, | |||
OCR_NEWLINE_TYPE | nl_type | |||
) |
Add a character to the output (shm).
char_code | character itself | |
left | of char (-1) | |
right | of char (-1) | |
top | of char (-1) | |
bottom | of char (-1) | |
font_index | what font (-1) | |
confidence | 0=perfect, 100=reject (0/100) | |
point_size | of char, 72=i inch, (10) | |
blanks | no of spaces before this char (1) | |
enhancement | char enhancement (0) | |
text_dir | rendering direction (OCR_CDIR_RIGHT_LEFT) | |
line_dir | line rendering direction (OCR_LDIR_DOWN_RIGHT) | |
nl_type | type of newline (if any) (OCR_NL_NONE) |
Definition at line 510 of file ocrshell.cpp.
References EANYCODE_CHAR::blanks, EANYCODE_CHAR::bottom, EANYCODE_CHAR::char_code, EANYCODE_CHAR::confidence, ETEXT_DESC::count, EUC_FORMAT_MASK, EANYCODE_CHAR::font_index, EANYCODE_CHAR::formatting, EANYCODE_CHAR::left, OCR_API_BAD_CHAR, OCR_API_BAD_STATE, OCR_API_NO_MEM, OCR_CDIR_BOTTOM_TOP, OCR_CDIR_TOP_BOTTOM, OCR_ERR_BAD_STATE, ocr_error(), OCR_NL_NONE, ocr_state, OCS_RECOGNIZING, OCS_SENDING_TEXT, OKAY, EANYCODE_CHAR::point_size, EANYCODE_CHAR::right, shm, ESHM_INFO::shm_mem, ESHM_INFO::shm_size, ETEXT_DESC::text, and EANYCODE_CHAR::top.
Referenced by ocr_send_text(), and write_shm_text().
00524 { 00525 ETEXT_DESC *buf; /*text buffer */ 00526 int index; /*char index */ 00527 INT16 result; /*of callback */ 00528 00529 if (ocr_state != OCS_RECOGNIZING && ocr_state != OCS_SENDING_TEXT) { 00530 ocr_error(OCR_ERR_BAD_STATE); 00531 return OCR_API_BAD_STATE; /*incorrect state */ 00532 } 00533 00534 if (char_code == ' ' || char_code == '\n' || char_code == '\r' 00535 || char_code == '\t') 00536 return OCR_API_BAD_CHAR; /*illegal char */ 00537 00538 /*progress info */ 00539 buf = (ETEXT_DESC *) shm.shm_mem; 00540 00541 result = 00542 (shm.shm_size - sizeof (ETEXT_DESC)) / sizeof (EANYCODE_CHAR) - 00543 buf->count; 00544 if (result < 1) 00545 return OCR_API_NO_MEM; /*insufficient room */ 00546 00547 index = buf->count++; /*count of chars */ 00548 /*setup structure */ 00549 buf->text[index].char_code = char_code; 00550 buf->text[index].left = left; /*setup structure */ 00551 buf->text[index].right = right;/*setup structure */ 00552 buf->text[index].top = top; /*setup structure */ 00553 /*setup structure */ 00554 buf->text[index].bottom = bottom; 00555 /*setup structure */ 00556 buf->text[index].font_index = font_index; 00557 /*setup structure */ 00558 buf->text[index].confidence = confidence; 00559 /*setup structure */ 00560 buf->text[index].point_size = point_size; 00561 /*setup structure */ 00562 buf->text[index].blanks = blanks; 00563 if (nl_type == OCR_NL_NONE) { 00564 if (text_dir == OCR_CDIR_TOP_BOTTOM || text_dir == OCR_CDIR_BOTTOM_TOP) 00565 buf->text[index].formatting = (text_dir << 5) | 128; 00566 /*setup structure */ 00567 else 00568 /*setup structure */ 00569 buf->text[index].formatting = text_dir << 5; 00570 } 00571 else { 00572 buf->text[index].formatting = (nl_type << 6) | (line_dir << 5); 00573 /*setup structure */ 00574 } 00575 buf->text[index].formatting |= enhancement & (~EUC_FORMAT_MASK); 00576 return OKAY; 00577 }
INT16 ocr_append_fontinfo | ( | UINT16 | language, | |
UINT8 | font_family, | |||
UINT8 | char_set, | |||
UINT8 | pitch, | |||
const char * | name | |||
) |
Put font info into shm.
Initialize one of the font descriptors.
Definition at line 230 of file ocrshell.cpp.
References EFONT_DESC::char_set, font_count, EFONT_DESC::font_family, EOCR_DESC::fonts, EFONT_DESC::language, MAX_FONT_NAME, EFONT_DESC::name, NULL, OCR_API_BAD_STATE, OCR_API_NO_MEM, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_SETUP_SHM, OKAY, EFONT_DESC::pitch, shm, ESHM_INFO::shm_mem, and ESHM_INFO::shm_size.
00236 { 00237 EOCR_DESC *desc; /*ocr engine info */ 00238 int index; /*char index */ 00239 INT32 font_index; /*which font */ 00240 00241 if (ocr_state != OCS_SETUP_SHM) { 00242 ocr_error(OCR_ERR_BAD_STATE); 00243 return OCR_API_BAD_STATE; /*incorrect state */ 00244 } 00245 00246 /*turn to right type */ 00247 desc = (EOCR_DESC *) shm.shm_mem; 00248 if (font_count > 00249 (INT32) ((shm.shm_size - sizeof (EOCR_DESC)) / sizeof (EFONT_DESC))) 00250 return OCR_API_NO_MEM; /*insufficient space */ 00251 font_index = font_count++; /*add a font */ 00252 /*setup structure */ 00253 desc->fonts[font_index].language = language; 00254 /*setup structure */ 00255 desc->fonts[font_index].font_family = font_family; 00256 /*setup structure */ 00257 desc->fonts[font_index].char_set = char_set; 00258 /*setup structure */ 00259 desc->fonts[font_index].pitch = pitch; 00260 if (name != NULL) { 00261 for (index = 0; index < MAX_FONT_NAME && name[index] != 0; index++) 00262 desc->fonts[font_index].name[index] = name[index]; 00263 } 00264 else 00265 index = 0; 00266 desc->fonts[font_index].name[index] = 0; 00267 return OKAY; 00268 }
INT32 ocr_char_space | ( | ) |
Put char into shm.
Return the number of chars that can be fitted into the buffer.
Definition at line 471 of file ocrshell.cpp.
References ETEXT_DESC::count, shm, ESHM_INFO::shm_mem, and ESHM_INFO::shm_size.
Referenced by write_shm_text().
00471 { /*put char into shm */ 00472 ETEXT_DESC *buf; /*text buffer */ 00473 int result; 00474 00475 /*progress info */ 00476 buf = (ETEXT_DESC *) shm.shm_mem; 00477 result = 00478 (shm.shm_size - sizeof (ETEXT_DESC)) / sizeof (EANYCODE_CHAR) - 00479 buf->count + 1; 00480 00481 // while (buf->hp_alive==-1) 00482 // Sleep(50); /*wait for HP*/ 00483 00484 return result; 00485 }
void ocr_error | ( | OCR_ERR_CODE | code | ) |
Send an error code.
Inform the HP side of an error. The OCR engine should do any cleanup of its own and exit aferwards. Uses the current state to determine how to send it and cleanup.
Definition at line 179 of file ocrshell.cpp.
References FALSE, font_count, LANGE_NONE, NULL, ocr_get_first_image_strip(), ocr_internal_shutdown(), ocr_setup_startinfo_ansi(), ocr_state, OCS_DEAD, OCS_READ_STRIPS, OCS_READING_STRIPS, OCS_RECOGNIZING, OCS_SENDING_TEXT, OCS_SETUP_INFO, OCS_SETUP_SHM, OCS_UNINIT, release_mutex(), release_ocr(), shm, ESHM_INFO::shm_mem, TRUE, and ESTRIP_DESC::x_size.
Referenced by ocr_append_char(), ocr_append_fontinfo(), ocr_get_first_image_strip(), ocr_get_next_image_strip(), ocr_open_shm(), ocr_send_text(), ocr_setup_startinfo(), ocr_setup_startinfo_ansi(), and ocr_shutdown().
00181 { 00182 ESTRIP_DESC *strip = (ESTRIP_DESC *) shm.shm_mem; 00183 /*strip info */ 00184 ETEXT_DESC *monitor = (ETEXT_DESC *) shm.shm_mem; 00185 /*progress monitor */ 00186 00187 switch (ocr_state) { 00188 case OCS_UNINIT: /*uninitialized */ 00189 case OCS_DEAD: /*uninitialized */ 00190 return; /*can't do anything else */ 00191 case OCS_SETUP_SHM: /*shm setup done */ 00192 if (font_count < 1) 00193 font_count = 1; 00194 ocr_setup_startinfo_ansi (-code, LANGE_NONE, "", ""); 00195 /*report error */ 00196 break; 00197 case OCS_SETUP_INFO: /*startinfo sent */ 00198 if (ocr_get_first_image_strip () == NULL) 00199 break; /*disconnected */ 00200 case OCS_READING_STRIPS: /*read first but more to come */ 00201 strip->x_size = -code; /*report error */ 00202 release_ocr(); /*send ack */ 00203 release_mutex(); 00204 break; 00205 case OCS_READ_STRIPS: /*read all but no monitor yet */ 00206 monitor->count = 0; /*chars in this buffer(-1) */ 00207 monitor->progress = 0; /*percent complete increasing (0-100) */ 00208 /*text not complete */ 00209 monitor->more_to_come = FALSE; 00210 monitor->ocr_alive = TRUE; /*ocr sets to 1, hp 0 */ 00211 monitor->err_code = -code; /*report error */ 00212 monitor->cancel = FALSE; /*0=continue, 1=cancel */ 00213 release_ocr(); /*send ack */ 00214 break; 00215 case OCS_RECOGNIZING: /*OCR incomplete */ 00216 case OCS_SENDING_TEXT: /*sent buffer but more to come */ 00217 monitor->err_code = -code; /*report error */ 00218 release_ocr(); /*send ack */ 00219 } 00220 ocr_internal_shutdown(); /*get ready for exit */ 00221 }
ESTRIP_DESC* ocr_get_first_image_strip | ( | ) |
Get first image strip.
Wait for the master to send the first image strip and return a pointer to it. The result is NULL if it is time to exit.
Definition at line 361 of file ocrshell.cpp.
References lines_read, NULL, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_READ_STRIPS, OCS_READING_STRIPS, OCS_SETUP_INFO, OKAY, READIM_TIMEOUT, release_mutex(), shm, ESHM_INFO::shm_mem, ESTRIP_DESC::strip_size, tprintf(), wait_for_hp(), wait_for_mutex(), ESTRIP_DESC::x_size, and ESTRIP_DESC::y_size.
Referenced by ocr_error().
00361 { /*get image strip */ 00362 ESTRIP_DESC *strip; /*strip info */ 00363 INT16 result; /*of wait/release */ 00364 00365 if (ocr_state != OCS_SETUP_INFO) { 00366 tprintf ("Bad state reading strip"); 00367 ocr_error(OCR_ERR_BAD_STATE); 00368 return NULL; /*incorrect state */ 00369 } 00370 00371 /*strip info */ 00372 strip = (ESTRIP_DESC *) shm.shm_mem; 00373 lines_read = 0; 00374 00375 result = wait_for_mutex (); 00376 if (result != OKAY) { 00377 tprintf ("Mutax wait failed reading strip"); 00378 return NULL; /*HP dead */ 00379 } 00380 result = release_mutex (); 00381 if (result != OKAY) { 00382 tprintf ("Mutax release failed reading strip"); 00383 return NULL; /*HP dead */ 00384 } 00385 result = wait_for_hp (READIM_TIMEOUT); 00386 if (result != OKAY) { 00387 tprintf ("Wait for HP failed reading strip"); 00388 return NULL; /*HP dead */ 00389 } 00390 lines_read = strip->strip_size;/*lines read so far */ 00391 if (lines_read < strip->y_size) 00392 /*record state */ 00393 ocr_state = OCS_READING_STRIPS; 00394 else 00395 ocr_state = OCS_READ_STRIPS; 00396 if (strip->x_size == 0 || strip->y_size == 0) 00397 return NULL; /*end of job */ 00398 00399 return strip; 00400 }
ESTRIP_DESC* ocr_get_next_image_strip | ( | ) |
Get next image strip.
Wait for the master to send the next image strip and return a pointer to it. The result is NULL if it is time to exit.
Definition at line 410 of file ocrshell.cpp.
References lines_read, NULL, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_READ_STRIPS, OCS_READING_STRIPS, OKAY, READIM_TIMEOUT, release_ocr(), shm, ESHM_INFO::shm_mem, ESTRIP_DESC::strip_size, and wait_for_hp().
00410 { /*get image strip */ 00411 ESTRIP_DESC *strip; /*strip info */ 00412 INT16 result; /*of wait/release */ 00413 00414 if (ocr_state != OCS_READING_STRIPS) { 00415 ocr_error(OCR_ERR_BAD_STATE); 00416 return NULL; /*incorrect state */ 00417 } 00418 00419 /*strip info */ 00420 strip = (ESTRIP_DESC *) shm.shm_mem; 00421 result = release_ocr (); 00422 if (result != OKAY) 00423 return NULL; /*HP dead */ 00424 result = wait_for_hp (READIM_TIMEOUT); 00425 if (result != OKAY) 00426 return NULL; /*HP dead */ 00427 /*lines read so far */ 00428 lines_read += strip->strip_size; 00429 if (lines_read < strip->y_size) 00430 /*record state */ 00431 ocr_state = OCS_READING_STRIPS; 00432 else 00433 ocr_state = OCS_READ_STRIPS; 00434 00435 return strip; 00436 }
INT16 ocr_internal_shutdown | ( | ) |
Close-down OCR.
Free up handles or whatever to clean up without attempting to communicate.
Definition at line 665 of file ocrshell.cpp.
References NULL, ocr_state, OCS_DEAD, OKAY, shm, and ESHM_INFO::shm_mem.
Referenced by ocr_error(), release_mutex(), release_ocr(), wait_for_hp(), and wait_for_mutex().
00665 { /*closedown */ 00666 ocr_state = OCS_DEAD; /*record state */ 00667 #ifdef __MSW32__ 00668 if (shm.shm_mem != NULL) { 00669 UnmapViewOfFile (shm.shm_mem); 00670 CloseHandle (shm.shm_hand); /*no longer used */ 00671 CloseHandle (shm.mutex); /*release handles */ 00672 CloseHandle (shm.ocr_sem); 00673 CloseHandle (shm.hp_sem); 00674 shm.shm_mem = NULL; 00675 } 00676 #elif defined (__MAC__) 00677 shm.OCRProcess.lowLongOfPSN = kNoProcess; 00678 shm.OCRProcess.highLongOfPSN = 0; 00679 #endif 00680 return OKAY; 00681 }
INT16 ocr_open_shm | ( | const char * | shm_h, | |
const char * | shm_size, | |||
const char * | mutex_h, | |||
const char * | ocr_h, | |||
const char * | hp_h, | |||
const char * | lang_str, | |||
UINT16 * | lang | |||
) |
Attempt to connect to the shared memory segment and semaphores used talking to the OCR engine.
shm_h | handle of shm | |
shm_size | size of shm segment | |
mutex_h | hp mutex | |
ocr_h | ocr semaphore | |
hp_h | hp semaphore | |
lang_str | language | |
lang | language (Mac only) |
Definition at line 120 of file ocrshell.cpp.
References FALSE, font_count, HPERR, NULL, OCR_API_BAD_STATE, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_SETUP_SHM, OCS_UNINIT, OKAY, shm, ESHM_INFO::shm_mem, and ESHM_INFO::shm_size.
00130 { 00131 font_count = 0; /*no fonts yet */ 00132 #ifdef __MAC__ 00133 if (shm.OCRProcess.lowLongOfPSN && shm.OCRProcess.highLongOfPSN) 00134 return HPERR; 00135 *lang = shm.language; 00136 GetCurrentProcess (&shm.OCRProcess); 00137 if (WakeUpProcess (&shm.IPEProcess)) 00138 ExitToShell(); 00139 AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, 00140 (AEEventHandlerUPP) TerminateOCR, 0, FALSE); 00141 #else 00142 if (lang != NULL) 00143 /*get language */ 00144 *lang = (UINT16) strtol (lang_str, NULL, 10); 00145 #endif // __MAC__ 00146 if (ocr_state != OCS_UNINIT) { 00147 ocr_error(OCR_ERR_BAD_STATE); 00148 return OCR_API_BAD_STATE; /*incorrect state */ 00149 } 00150 #ifdef __MSW32__ 00151 shm.shm_size = strtol (shm_size, NULL, 10); 00152 /*convert to handle */ 00153 shm.shm_hand = (HANDLE) strtol (shm_h, NULL, 10); 00154 shm.shm_mem = MapViewOfFile (shm.shm_hand, FILE_MAP_WRITE, 0, 0, 0); 00155 if (shm.shm_mem == NULL) 00156 return HPERR; /*failed */ 00157 /*convert to handle */ 00158 shm.mutex = (HANDLE) strtol (mutex_h, NULL, 10); 00159 /*convert to handle */ 00160 shm.ocr_sem = (HANDLE) strtol (ocr_h, NULL, 10); 00161 /*convert to handle */ 00162 shm.hp_sem = (HANDLE) strtol (hp_h, NULL, 10); 00163 #endif //__MSW32__ 00164 00165 ocr_state = OCS_SETUP_SHM; /*record state */ 00166 return OKAY; 00167 00168 }
Send shm.
Send the text to the host and wait for the ACK. Use this function after a sequence of ocr_append_char calls to actually sent the text to the master process. Set more to come TRUE if there is more text in this page, FALSE if the OCR engine is now ready to receive another image.
Definition at line 590 of file ocrshell.cpp.
References ETEXT_DESC::count, EANYCODE_CHAR::formatting, HPERR, ETEXT_DESC::more_to_come, OCR_API_BAD_STATE, ocr_append_char(), OCR_CDIR_RIGHT_LEFT, OCR_ERR_BAD_STATE, ocr_error(), OCR_LDIR_DOWN_RIGHT, OCR_NL_NEWLINE, OCR_NL_NEWPARA, ocr_state, OCS_RECOGNIZING, OCS_SENDING_TEXT, OCS_SETUP_INFO, OKAY, READTEXT_TIMEOUT, release_ocr(), shm, ESHM_INFO::shm_mem, ETEXT_DESC::text, and wait_for_hp().
Referenced by output_pass(), and write_shm_text().
00592 { 00593 ETEXT_DESC *buf; /*text buffer */ 00594 00595 if (ocr_state != OCS_RECOGNIZING && ocr_state != OCS_SENDING_TEXT) { 00596 ocr_error(OCR_ERR_BAD_STATE); 00597 return OCR_API_BAD_STATE; /*incorrect state */ 00598 } 00599 00600 /*progress info */ 00601 buf = (ETEXT_DESC *) shm.shm_mem; 00602 00603 /*setup structure */ 00604 buf->more_to_come = more_to_come; 00605 if (more_to_come) { 00606 if ((buf->text[buf->count - 1].formatting >> 6) != OCR_NL_NEWLINE 00607 && (buf->text[buf->count - 1].formatting >> 6) != OCR_NL_NEWPARA) { 00608 /*force line end */ 00609 buf->text[buf->count - 1].formatting &= 63; 00610 buf->text[buf->count - 1].formatting |= OCR_NL_NEWLINE << 6; 00611 } 00612 } 00613 else { 00614 if (buf->count < 1) 00615 ocr_append_char ('~', -1, -1, -1, -1, 0, 100, 10, 0, 00616 0, OCR_CDIR_RIGHT_LEFT, OCR_LDIR_DOWN_RIGHT, 00617 OCR_NL_NEWPARA); 00618 /*dummy character */ 00619 else if ((buf->text[buf->count - 1].formatting >> 6) != OCR_NL_NEWPARA) { 00620 /*force para end */ 00621 buf->text[buf->count - 1].formatting &= 63; 00622 buf->text[buf->count - 1].formatting |= OCR_NL_NEWPARA << 6; 00623 } 00624 } 00625 00626 if (release_ocr () != OKAY) 00627 return HPERR; /*release failed */ 00628 if (wait_for_hp (READTEXT_TIMEOUT) != OKAY) 00629 return HPERR; 00630 if (more_to_come) { 00631 buf->count = 0; /*setup structure */ 00632 ocr_state = OCS_SENDING_TEXT;/*record state */ 00633 } 00634 else 00635 ocr_state = OCS_SETUP_INFO; /*record state */ 00636 return OKAY; 00637 }
ETEXT_DESC* ocr_setup_monitor | ( | ) |
Setup the progress monitor.
Call before starting the recognize task.
Definition at line 445 of file ocrshell.cpp.
References ETEXT_DESC::cancel, ETEXT_DESC::count, ETEXT_DESC::err_code, FALSE, ETEXT_DESC::more_to_come, NULL, ETEXT_DESC::ocr_alive, ocr_state, OCS_RECOGNIZING, OKAY, ETEXT_DESC::progress, release_ocr(), shm, ESHM_INFO::shm_mem, and TRUE.
00445 { /*setup monitor */ 00446 ETEXT_DESC *monitor; /*progress monitor */ 00447 00448 /*text info */ 00449 monitor = (ETEXT_DESC *) shm.shm_mem; 00450 monitor->count = 0; /*chars in this buffer(-1) */ 00451 monitor->progress = 0; /*percent complete increasing (0-100) */ 00452 monitor->more_to_come = TRUE; /*text not complete */ 00453 monitor->ocr_alive = TRUE; /*ocr sets to 1, hp 0 */ 00454 monitor->err_code = 0; /*used by ocr_error */ 00455 monitor->cancel = FALSE; /*0=continue, 1=cancel */ 00456 00457 if (release_ocr () != OKAY) 00458 return NULL; /*release failed */ 00459 00460 ocr_state = OCS_RECOGNIZING; /*record state */ 00461 return monitor; 00462 }
INT16 ocr_setup_startinfo | ( | INT32 | protocol, | |
UINT16 | language, | |||
const UINT16 * | name, | |||
const UINT16 * | version | |||
) |
put start info into shm
Setup the info on the OCR engine. Uses 16 bit chars to name the engine.
Definition at line 278 of file ocrshell.cpp.
References EOCR_DESC::font_count, font_count, EOCR_DESC::language, MAX_OCR_NAME, MAX_OCR_VERSION, EOCR_DESC::name, OCR_API_BAD_STATE, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_SETUP_INFO, OCS_SETUP_SHM, OKAY, EOCR_DESC::protocol, release_ocr(), shm, ESHM_INFO::shm_mem, and EOCR_DESC::version.
00283 { 00284 EOCR_DESC *desc; /*ocr engine info */ 00285 int index; /*char index */ 00286 INT16 result; /*from open */ 00287 00288 if (ocr_state != OCS_SETUP_SHM || font_count < 1) { 00289 ocr_error(OCR_ERR_BAD_STATE); 00290 return OCR_API_BAD_STATE; /*incorrect state */ 00291 } 00292 00293 /*turn to right type */ 00294 desc = (EOCR_DESC *) shm.shm_mem; 00295 desc->protocol = protocol; /*setup structure */ 00296 desc->font_count = font_count; 00297 desc->language = language; 00298 for (index = 0; index < MAX_OCR_NAME && name[index] != 0; index++) 00299 desc->name[index] = name[index]; 00300 desc->name[index] = 0; 00301 for (index = 0; index < MAX_OCR_VERSION && version[index] != 0; index++) 00302 desc->version[index] = version[index]; 00303 desc->version[index] = 0; 00304 00305 result = release_ocr (); 00306 if (result != OKAY) 00307 return result; 00308 ocr_state = OCS_SETUP_INFO; /*record state */ 00309 return OKAY; 00310 }
INT16 ocr_setup_startinfo_ansi | ( | UINT32 | protocol, | |
UINT16 | language, | |||
const char * | name, | |||
const char * | version | |||
) |
Setup the info on the OCR engine.
Uses 8 bit chars to name the engine.
Definition at line 319 of file ocrshell.cpp.
References font_count, EOCR_DESC::font_count, EOCR_DESC::language, MAX_OCR_NAME, MAX_OCR_VERSION, EOCR_DESC::name, OCR_API_BAD_STATE, OCR_ERR_BAD_STATE, ocr_error(), ocr_state, OCS_SETUP_INFO, OCS_SETUP_SHM, OKAY, EOCR_DESC::protocol, release_ocr(), shm, ESHM_INFO::shm_mem, and EOCR_DESC::version.
Referenced by ocr_error().
00324 { 00325 EOCR_DESC *desc; /*ocr engine info */ 00326 int index; /*char index */ 00327 INT16 result; /*from open */ 00328 00329 if (ocr_state != OCS_SETUP_SHM || font_count < 1) { 00330 ocr_error(OCR_ERR_BAD_STATE); 00331 return OCR_API_BAD_STATE; /*incorrect state */ 00332 } 00333 00334 /*turn to right type */ 00335 desc = (EOCR_DESC *) shm.shm_mem; 00336 desc->protocol = protocol; /*setup structure */ 00337 desc->font_count = font_count; 00338 desc->language = language; 00339 for (index = 0; index < MAX_OCR_NAME && name[index] != 0; index++) 00340 desc->name[index] = name[index]; 00341 desc->name[index] = 0; 00342 for (index = 0; index < MAX_OCR_VERSION && version[index] != 0; index++) 00343 desc->version[index] = version[index]; 00344 desc->version[index] = 0; 00345 00346 result = release_ocr (); 00347 if (result != OKAY) 00348 return result; 00349 ocr_state = OCS_SETUP_INFO; /*record state */ 00350 return OKAY; 00351 }
INT16 ocr_shutdown | ( | ) |
Close-down OCR.
Closedown communications with the HP side and free up handles.
Definition at line 647 of file ocrshell.cpp.
References OCR_ERR_CLEAN_EXIT, ocr_error(), OKAY, and shm.
00647 { /*closedown */ 00648 #ifdef __MAC__ 00649 shm.OCRProcess.lowLongOfPSN = kNoProcess; 00650 shm.OCRProcess.highLongOfPSN = 0; 00651 #endif 00652 ocr_error(OCR_ERR_CLEAN_EXIT); /*signal exit */ 00653 00654 return OKAY; 00655 }
INT16 release_mutex | ( | ) |
Release the HP mutex.
The return value is OKAY if the call succeeds.
Definition at line 734 of file ocrshell.cpp.
References HPERR, ocr_internal_shutdown(), OKAY, and shm.
Referenced by ocr_error(), and ocr_get_first_image_strip().
00734 { /*release mutex */ 00735 INT16 result = HPERR; /*return code */ 00736 #ifdef __MSW32__ 00737 /*release it */ 00738 result = ReleaseMutex (shm.mutex) ? OKAY : HPERR; 00739 #elif defined (__MAC__) 00740 /*release it */ 00741 result = ReleaseSemaphore (shm.mutex) ? OKAY : HPERR; 00742 #endif 00743 if (result != OKAY) 00744 ocr_internal_shutdown(); 00745 return result; 00746 }
INT16 release_ocr | ( | ) |
Release the OCR semaphore.
The return value is OKAY if the call succeeds.
Definition at line 755 of file ocrshell.cpp.
References FALSE, HPERR, NULL, ocr_internal_shutdown(), OKAY, RELEASE_TIMEOUT, shm, and TICKS.
Referenced by ocr_error(), ocr_get_next_image_strip(), ocr_send_text(), ocr_setup_monitor(), ocr_setup_startinfo(), and ocr_setup_startinfo_ansi().
00755 { 00756 INT32 timeout; //time allowed 00757 00758 timeout = RELEASE_TIMEOUT * TICKS; 00759 #ifdef __MSW32__ 00760 BOOL result = 0; //of release 00761 do { 00762 //release it 00763 result = ReleaseSemaphore (shm.ocr_sem, 1, NULL); 00764 if (result == FALSE) { 00765 timeout -= 50; 00766 Sleep (50); 00767 } 00768 } 00769 while (result == FALSE && timeout > 0); 00770 if (!result) 00771 ocr_internal_shutdown(); 00772 return OKAY; 00773 #elif defined (__MAC__) 00774 INT16 result = HPERR; /*return code */ 00775 /*release it */ 00776 result = ReleaseSemaphore (shm.ocr_sem) ? OKAY : HPERR; 00777 00778 if (result != OKAY) 00779 ocr_internal_shutdown(); 00780 return result; 00781 #elif defined (__UNIX__) 00782 return 0; 00783 #endif 00784 }
Wait for semaphore.
Wait for the HP side to release its semaphore. The return value is HPERR if the timeout (in seconds) elapsed.
Definition at line 712 of file ocrshell.cpp.
References HPERR, ocr_internal_shutdown(), OKAY, shm, and TICKS.
Referenced by ocr_get_first_image_strip(), ocr_get_next_image_strip(), and ocr_send_text().
00714 { 00715 INT16 result = HPERR; /*return code */ 00716 #if defined (__MSW32__) || defined (__MAC__) 00717 /*wait for thread to move */ 00718 result = WaitForSingleObject (shm.hp_sem, timeout * TICKS) 00719 /*bad if timeout */ 00720 == WAIT_OBJECT_0 ? OKAY : HPERR; 00721 #endif 00722 if (result != OKAY) 00723 ocr_internal_shutdown(); 00724 return result; 00725 }
INT16 wait_for_mutex | ( | ) |
Wait for HP to be ready.
Wait for the HP side to release its mutex. The return value is HPERR if the HP side has terminated.
Definition at line 691 of file ocrshell.cpp.
References HPERR, ocr_internal_shutdown(), OKAY, and shm.
Referenced by ocr_get_first_image_strip().
00691 { /*wait for HP to be ready */ 00692 INT16 result = HPERR; /*return code */ 00693 #if defined (__MSW32__) || defined (__MAC__) 00694 result = WaitForSingleObject (shm.mutex, (unsigned long) -1) 00695 /*wait for thread to move */ 00696 /*bad if timeout */ 00697 == WAIT_OBJECT_0 ? OKAY : HPERR; 00698 #endif 00699 if (result != OKAY) 00700 ocr_internal_shutdown(); 00701 return result; 00702 }
INT32 font_count = 0 [static] |
Definition at line 83 of file ocrshell.cpp.
Referenced by ocr_append_fontinfo(), ocr_error(), ocr_open_shm(), ocr_setup_startinfo(), and ocr_setup_startinfo_ansi().
INT16 lines_read = 0 [static] |
Definition at line 84 of file ocrshell.cpp.
Referenced by ocr_get_first_image_strip(), and ocr_get_next_image_strip().
Definition at line 86 of file ocrshell.cpp.
Referenced by ocr_append_char(), ocr_append_fontinfo(), ocr_error(), ocr_get_first_image_strip(), ocr_get_next_image_strip(), ocr_internal_shutdown(), ocr_open_shm(), ocr_send_text(), ocr_setup_monitor(), ocr_setup_startinfo(), and ocr_setup_startinfo_ansi().
Definition at line 31 of file ocrshell.cpp.
Referenced by ocr_append_char(), ocr_append_fontinfo(), ocr_char_space(), ocr_error(), ocr_get_first_image_strip(), ocr_get_next_image_strip(), ocr_internal_shutdown(), ocr_open_shm(), ocr_send_text(), ocr_setup_monitor(), ocr_setup_startinfo(), ocr_setup_startinfo_ansi(), ocr_shutdown(), release_mutex(), release_ocr(), wait_for_hp(), and wait_for_mutex().