1 /*  Ocradlib - Optical Character Recognition library
2     Copyright (C) 2009-2019 Antonio Diaz Diaz.
3 
4     This library is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 2 of the License, or
7     (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 const char * const OCRAD_version_string = "0.27";
23 
24 
25 /* OCRAD_Pixmap.data is a pointer to image data formed by "height" rows
26    of "width" pixels each.
27    The format for each pixel depends on mode like this:
28    OCRAD_bitmap   --> 1 byte  per pixel;  0 = white, 1 = black
29    OCRAD_greymap  --> 1 byte  per pixel;  256 level greymap (0 = black)
30    OCRAD_colormap --> 3 bytes per pixel;  16777216 colors RGB (0,0,0 = black) */
31 
32 enum OCRAD_Pixmap_Mode { OCRAD_bitmap, OCRAD_greymap, OCRAD_colormap };
33 
34 struct OCRAD_Pixmap
35   {
36   const unsigned char * data;
37   int height;
38   int width;
39   enum OCRAD_Pixmap_Mode mode;
40   };
41 
42 
43 enum OCRAD_Errno { OCRAD_ok = 0, OCRAD_bad_argument, OCRAD_mem_error,
44                    OCRAD_sequence_error, OCRAD_library_error };
45 
46 struct OCRAD_Descriptor;
47 
48 
49 const char * OCRAD_version( void );
50 
51 
52 /*--------------------- Functions ---------------------*/
53 
54 struct OCRAD_Descriptor * OCRAD_open( void );
55 
56 int OCRAD_close( struct OCRAD_Descriptor * const ocrdes );
57 
58 enum OCRAD_Errno OCRAD_get_errno( struct OCRAD_Descriptor * const ocrdes );
59 
60 int OCRAD_set_image( struct OCRAD_Descriptor * const ocrdes,
61                      const struct OCRAD_Pixmap * const image,
62                      const bool invert );
63 
64 int OCRAD_set_image_from_file( struct OCRAD_Descriptor * const ocrdes,
65                                const char * const filename,
66                                const bool invert );
67 
68 int OCRAD_set_utf8_format( struct OCRAD_Descriptor * const ocrdes,
69                            const bool utf8 );		// 0 = byte, 1 = utf8
70 
71 int OCRAD_set_threshold( struct OCRAD_Descriptor * const ocrdes,
72                          const int threshold );		// 0..255, -1 = auto
73 
74 int OCRAD_scale( struct OCRAD_Descriptor * const ocrdes, const int value );
75 
76 int OCRAD_recognize( struct OCRAD_Descriptor * const ocrdes,
77                      const bool layout );
78 
79 int OCRAD_result_blocks( struct OCRAD_Descriptor * const ocrdes );
80 
81 int OCRAD_result_lines( struct OCRAD_Descriptor * const ocrdes,
82                         const int blocknum );		// 0..blocks-1
83 
84 int OCRAD_result_chars_total( struct OCRAD_Descriptor * const ocrdes );
85 
86 int OCRAD_result_chars_block( struct OCRAD_Descriptor * const ocrdes,
87                               const int blocknum );	// 0..blocks-1
88 
89 int OCRAD_result_chars_line( struct OCRAD_Descriptor * const ocrdes,
90                              const int blocknum,	// 0..blocks-1
91                              const int linenum );	// 0..lines(block)-1
92 
93 const char * OCRAD_result_line( struct OCRAD_Descriptor * const ocrdes,
94                                 const int blocknum,	// 0..blocks-1
95                                 const int linenum );	// 0..lines(block)-1
96 
97 int OCRAD_result_first_character( struct OCRAD_Descriptor * const ocrdes );
98 
99 #ifdef __cplusplus
100 }
101 #endif
102