int read_ctip_record( FILE *input_filePtr, int verbose_flag, long int expected_size, char *tmp_array) { /* expected_size: number of numbers expected - float or double */ int record_size, a, n=0, element_size; /* get the number of bytes in record 1 ( we expect a array of expected_size * with either float or double ) */ fread( &ctip_byte_value, 4, 1, input_filePtr); record_size = ctip_byte_value; if (ferror(input_filePtr) || feof(input_filePtr) ) { printf("ERROR with fread must have returned non zero status_code for file " "stream\n"); perror("input_filePtr"); return EXIT_FAILURE; } ctip_flip_endian=( (record_size != (sizeof(float)*expected_size) ) && (record_size != (sizeof(double)*expected_size) ) ); if (ctip_flip_endian) endian_flip((char *)&record_size, 4, 1); if (verbose_flag) { printf( "CTIP Record: found record_size: %d Expected: %ld\n", record_size, sizeof(float)*expected_size); } if ( (record_size != sizeof(float)*expected_size) && (record_size != sizeof(double)*expected_size )) { printf("Read_CTIP_record: record size not as expected!\n"); /* mmadddox - we don't need to die, pass error back to calling function */ /*exit(EXIT_FAILURE);*/ return ( EXIT_FAILURE ); } ctip_is_double=(record_size == sizeof(double)*expected_size ); /* sizeof float or double */ element_size=(1-ctip_is_double)*sizeof(float)+ctip_is_double*sizeof(double); if (verbose_flag) { printf( "CTIP_is_double: %d CTIP_flip_endian: %d Record_size: %d " "element_size: %d\n", ctip_is_double, ctip_flip_endian, record_size, element_size); } n = fread(tmp_array, 1, record_size, input_filePtr); if (n != record_size) { printf("CTIP_read_record: number of bytes read does not agree with record " "size \n"); return (EXIT_FAILURE); } if (ctip_flip_endian) endian_flip(tmp_array, element_size, expected_size); if (ferror(input_filePtr) || feof(input_filePtr) ) { printf("ERROR with fread must have returned non zero status_code for file " "stream\n"); perror("input_filePtr"); return EXIT_FAILURE; } fread( &ctip_byte_value_2, 4, 1, input_filePtr); if (ferror(input_filePtr) || feof(input_filePtr) ) { printf("ERROR with fread must have returned non zero status_code for file " "stream\n"); perror("input_filePtr"); return EXIT_FAILURE; } if (ctip_byte_value == ctip_byte_value_2) { if (verbose_flag) { printf("Read_CTIP_Record SUCCESSFUL\n"); } return EXIT_SUCCESS; } else { printf("ERROR reading input file\n"); return EXIT_FAILURE; } }
/* ** bmp8 must be grayscale ** (x1,y1) and (x2,y2) from top left of bitmap */ void ocrtess_single_word_from_bmp8(char *text,int maxlen,WILLUSBITMAP *bmp8, int x1,int y1,int x2,int y2, int ocr_type,int allow_spaces, int std_proc,FILE *out) { PIX *pix; int i,w,h,dw,dh,bw,status; unsigned char *src,*dst; if (x1>x2) { w = x1; x1 = x2; x2 = w; } w = x2-x1+1; bw = w/40; if (bw < 6) bw = 6; dw = w + bw * 2; dw = (dw + 3) & (~3); if (y1>y2) { h = y1; y1 = y2; y2 = h; } h = y2 - y1 + 1; dh = h + bw * 2; // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "BEFORE CREATE"); pix = pixCreate(dw, dh, 8); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER CREATE"); src = bmp_rowptr_from_top(bmp8, y1) + x1; // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "BEFORE FROM TOP"); dst = (unsigned char *)pixGetData(pix); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER GET DATA"); memset(dst, 255, dw*dh); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER MEMSET"); dst = (unsigned char *)pixGetData(pix); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER ANOTHER GET"); dst += bw + dw * bw; // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> CONDITION", "dw: %d, src_inc: %d", dw, bmp8->width); for (i=y1; i<=y2; i++, dst+=dw, src+=bmp8->width) memcpy(dst, src, w); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER MEMCOPY"); endian_flip((char *)pixGetData(pix), pixGetWpl(pix) * pixGetHeight(pix)); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "BEFORE OCR"); status = tess_capi_get_ocr(pix, text, maxlen, out); // __android_log_print(ANDROID_LOG_INFO, "K2PDFOPT - OCR>> ", "AFTER OCR"); pixDestroy(&pix); if (status<0) text[0]='\0'; // clean_line(text); if (std_proc) ocr_text_proc(text,allow_spaces); }