00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019
00020
00021 #include "_gocr.h"
00022 #include "gocr_module.h"
00023
00024 static int returnflag = 0;
00025
00026
00049 int gocr_printArea ( gocrImage *image, int x0, int y0, int x1, int y1 ) {
00050 int i, j;
00051
00052 _gocr_debug(3, fprintf(_data.error, "gocr_printArea(%p, %d, %d, %d, %d)\n",
00053 image, x0, y0, x1, y1);)
00054
00055 if ( image == NULL || image->data == NULL ) {
00056 _gocr_debug(1, fprintf(_data.error, "NULL image or image data\n");)
00057 return -1;
00058 }
00059
00060 _gocr_fixParameters ( &x0, &y0, &x1, &y1 );
00061
00062 for ( i = x0; i <= x1; i++ ) {
00063 if ( _data.print == 6 ) { /* just dump it */
00064 fwrite(image->data[i], sizeof(gocrPixel), y0-y1+1, _data.error);
00065 }
00066 else for ( j = y0; j <= y1; j++ )
00067 switch ( _data.print ) {
00068 case 0: /* only data bit */
00069 fputc((image->data[i][j].value == GOCR_BLACK ? '*' : '.'), _data.error);
00070 break;
00071 case 1: /* marked bits */
00072 fputc('0' + image->data[i][j].mark1 + 2*image->data[i][j].mark2
00073 + 4*image->data[i][j].mark3, _data.error);
00074 break;
00075 case 2: /* data+marked */
00076 fputc((image->data[i][j].value == GOCR_BLACK? 'A' : 'a') +
00077 image->data[i][j].mark1 + 2*image->data[i][j].mark2 +
00078 4*image->data[i][j].mark3, _data.error);
00079 break;
00080 case 3: /* block bit */
00081 fputc((image->data[i][j].isblock == GOCR_BLACK ? '*' : '.'), _data.error);
00082 break;
00083 case 4: /* recognized bit */
00084 fputc((image->data[i][j].ischar == GOCR_BLACK ? '*' : '.'), _data.error);
00085 break;
00086 case 5: /* all, hexa */
00087 fprintf(_data.error, "%x", (int)*((unsigned char *)&image->data[i][j]));
00088 break;
00089 }
00090 if ( !returnflag ) /* this is used by gocr_printBox2 */
00091 fputc('\n', _data.error);
00092 }
00093 return 0;
00094 }
00095
00107 int gocr_printBlock ( gocrBlock *b ) {
00108 _gocr_debug(3, fprintf(_data.error, "gocr_printBlock(%p)\n", b);)
00109
00110 if ( b == NULL ) {
00111 _gocr_debug(1, fprintf(_data.error, "NULL gocrBlock at gocr_printBlock\n");)
00112 return -1;
00113 }
00114
00115 /* future: let the user provide his own print block function too */
00116 fprintf(_data.error, "Block: x0:%d, y0:%d, x1:%d, y1:%; type %s\n",
00117 b->x0, b->y0, b->x1, b->y1, gocr_getNamebyType(b->t));
00118
00119 if ( _data.print_image )
00120 return gocr_printArea(&b->image, 0, 0, b->image.x-1, b->image.y-1);
00121
00122 return 0;
00123 }
00124
00136 int gocr_printBox ( gocrBox *b ) {
00137 _gocr_debug(3, fprintf(_data.error, "gocr_printBox(%p)\n", b);)
00138
00139 if ( b == NULL ) {
00140 _gocr_debug(1, fprintf(_data.error, "NULL gocrBox at gocr_printBox\n");)
00141 return -1;
00142 }
00143
00144 fprintf(_data.error, "Box: x0:%d, y0:%d, x1:%d, y1:%; c:%x ac:%x mod:%x\n",
00145 b->x0, b->y0, b->x1, b->y1, b->c, b->ac, b->modifier);
00146
00147 if ( _data.print_image )
00148 return gocr_printArea(¤tblock->image, b->x0, b->y0, b->x1, b->y1);
00149
00150 return 0;
00151 }
00152
00164 int gocr_printBox2 ( gocrBox *b1, gocrBox *b2 ) {
00165 int xmax, xend, i, j;
00166
00167 _gocr_debug(3, fprintf(_data.error, "gocr_printBox2(%p, %p)\n", b1, b2);)
00168
00169 if ( b1 == NULL || b2 == NULL ) {
00170 _gocr_debug(1, fprintf(_data.error, "NULL gocrBox at gocr_printBox2\n");)
00171 return -1;
00172 }
00173 #if 0
00174 if ( b1->image == NULL || b2->image == NULL ) {
00175 _gocr_debug(1, fprintf(_data.error, "NULL gocrBox image at gocr_printBox2\n");)
00176 return -1;
00177 }
00178 #endif
00179
00180 /* these are used below, to know which box ends first */
00181 if ( b1->x1 - b1->x0 < b2->x1 - b2->x0 ) {
00182 xmax = b1->x1 - b1->x0 + 1;
00183 xend = b2->x1 - b2->x0 + 1;
00184 }
00185 else {
00186 xmax = b2->x1 - b2->x0 + 1;
00187 xend = b1->x1 - b1->x0 + 1;
00188 }
00189
00190 fprintf(_data.error, "Box1: x0:%d, y0:%d, x1:%d, y1:%; c:%x ac:%x mod:%x\n",
00191 b1->x0, b1->y0, b1->x1, b1->y1, b1->c, b1->ac, b1->modifier);
00192 fprintf(_data.error, "Box2: x0:%d, y0:%d, x1:%d, y1:%; c:%x ac:%x mod:%x\n",
00193 b2->x0, b2->y0, b2->x1, b2->y1, b2->c, b2->ac, b2->modifier);
00194
00195 returnflag++; /* so printArea doesn't print \n */
00196 /* print */
00197 if ( _data.print_image ) {
00198 for ( i = 0; i < xmax; i++ ) {
00199 gocr_printArea(¤tblock->image, b1->x0+i, b1->y0, b1->x0+i, b1->y1);
00200 fputs(" ", _data.error);
00201 gocr_printArea(¤tblock->image, b2->x0+i, b2->y0, b2->x0+i, b2->y1);
00202 fputs("\n", _data.error);
00203 }
00204 }
00205 /* one of the characters ended first; print the rest of the other */
00206 for ( ; i < xend; i++ ) {
00207 if ( b1->x1 - b1->x0 < b2->x1 - b2->x0 ) { /* pad with spaces */
00208 for ( j = b1->y0; j <= b1->y1; j++ )
00209 fputc(' ', _data.error);
00210 fputs(" ", _data.error);
00211 gocr_printArea(¤tblock->image, b2->x0+i, b2->y0, b2->x0+i, b2->y1);
00212 }
00213 else {
00214 gocr_printArea(¤tblock->image, b1->x0+i, b1->y0, b1->x0+i, b1->y1);
00215 }
00216 fputs("\n", _data.error);
00217 }
00218 returnflag = 0;
00219
00220 return 0;
00221 }