Main Page   Compound List   File List   Compound Members   File Members  

find.c

00001 /*
00002 GOCR Copyright (C) 2000  Joerg Schulenburg Joerg.Schulenburg@physik.uni-magdeburg.de 
00003 GOCR API Copyright (C) 2001 Bruno Barberi Gnecco <brunobg@sourceforge.net>
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019  
00020 #include "_gocr.h"
00021 #include "gocr_char.h"
00022 #include "unicode.h"
00023 
00024 static int began = 0;
00025 
00026 gocrBox *currentbox;
00027 
00028 /* idea: charBegin inits a structure;
00029    charset* sets bits in the image, and update the frame;
00030    charEnd creates a new image, sized frame, all white, and fills with the
00031        pixels set by charset*, and calls the charRecognizer module (how?
00032        by a signal? directly by runModule? 
00033 */
00042 int gocr_charBegin ( void ) {
00043   _gocr_debug(3, fprintf(_data.error, "gocr_charBegin()\n");)
00044   if ( began ) {
00045     _gocr_debug(1, fprintf(_data.error, "Character already begun\n");)
00046     return -1;
00047   }
00048 
00049   began++;
00050   currentbox = (gocrBox *)malloc(sizeof(gocrBox));
00051   if ( !currentbox ) {
00052     _gocr_debug(1, fprintf(_data.error, "charBegin: not enough memory\n");)
00053     return -1;
00054   }
00055     
00056   /* set the boundaries in such a way that they are not valid and will be updated */
00057   currentbox->x0 = currentblock->x1+1;
00058   currentbox->y0 = currentblock->y1+1;
00059   currentbox->x1 = currentblock->x0-1;
00060   currentbox->y1 = currentblock->y0-1;
00061 
00062   currentbox->attributes = NULL;
00063 
00064   list_init(&currentbox->possible);
00065   currentbox->ch = NULL;
00066 
00067   /* deprecated fields */
00068   currentbox->c = currentbox->ac = currentbox->modifier = UNICODE_NULL;
00069 
00070   return 0;
00071 }
00072 
00081 int gocr_charEnd ( void ) {
00082   _gocr_debug(3, fprintf(_data.error, "gocr_charEnd()\n");)
00083 
00084   if ( !began ) {
00085     _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00086     return -1;
00087   }
00088 
00089   began--;
00090   
00091   list_app(&currentblock->boxlist, currentbox);
00092 
00093   return 0;
00094 }
00095 
00107 int gocr_charSetAllNearPixels ( int action, int x, int y ) {
00108   _gocr_debug(3, fprintf(_data.error, "gocr_charSetAllNearPixels(%d, %d, %d)\n",
00109       action, x, y);)
00110 
00111   if ( !began ) {
00112     _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00113     return -1;
00114   }
00115   _gocr_debug(0, fprintf(_data.error, "gocr_charSetAllNearPixels not done yet\n");)
00116 }
00117 
00130 int gocr_charSetAttribute ( int action, char *name, ... ) {
00131   _gocr_debug(3, fprintf(_data.error, "gocr_charSetAttribute(%d, %s)\n", 
00132       action, name);)
00133 
00134   if ( !began ) {
00135     _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00136     return -1;
00137   }
00138 
00139   _gocr_debug(0, fprintf(_data.error, "gocr_charSetAttribute: use gocr_boxSetAttribute instead \n");)
00140    return -1;
00141 //  return gocr_boxAttributeSet(currentbox, action, name, ...);
00142 }
00143 
00155 int gocr_charSetPixel ( int action, int x, int y ) {
00156   _gocr_debug(3, fprintf(_data.error, "gocr_charSetPixel(%d, %d, %d)\n", 
00157       action, x, y);)
00158 
00159   if ( !began ) {
00160     _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00161     return -1;
00162   }
00163 
00164   /* check boundaries */
00165   if ( x < currentblock->x0 || x > currentblock->x1 ||
00166        y < currentblock->x0 || y > currentblock->x1 ) {
00167       _gocr_debug(1, fprintf(_data.error, "Pixel out of bounds.\n");)
00168       return -1;
00169   }
00170 
00171   /* update new boundaries */  
00172   if ( x < currentbox->x0 )
00173     currentbox->x0 = x;
00174   if ( x > currentbox->x1 )
00175     currentbox->x1 = x;
00176   if ( y < currentbox->y0 )
00177     currentbox->y0 = y;
00178   if ( y > currentbox->y1 )
00179     currentbox->y1 = y;
00180 
00181   currentblock->image.data[x][y].ischar = action;
00182   return 0;
00183 }
00184 
00196 int gocr_charSetRect ( int action, int x0, int y0, int x1, int y1 ) {
00197   int i, j;
00198   _gocr_debug(3, fprintf(_data.error, "gocr_charSetRect(%d, %d, %d, %d, %d)\n", 
00199       action, x0, y0, x1, y1);)
00200 
00201   if ( !began ) {
00202     _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00203     return -1;
00204   }
00205 
00206   /* should reverse x and y if needed */
00207   _gocr_fixParameters ( &x0, &y0, &x1, &y1 );
00208 
00209   /* check boundaries */
00210   if ( x0 < currentblock->x0 || x0 > currentblock->x1 ||
00211        x1 < currentblock->x0 || x1 > currentblock->x1 ||
00212        y0 < currentblock->x0 || y0 > currentblock->x1 ||
00213        y1 < currentblock->x0 || y1 > currentblock->x1 ) {
00214       _gocr_debug(1, fprintf(_data.error, "Rectangle out of bounds.\n");)
00215       return -1;
00216   }
00217 
00218   /* update new boundaries */  
00219   if ( x0 < currentbox->x0 )
00220     currentbox->x0 = x0;
00221   if ( x1 > currentbox->x1 )
00222     currentbox->x1 = x1;
00223   if ( y0 < currentbox->y0 )
00224     currentbox->y0 = y0;
00225   if ( y1 > currentbox->y1 )
00226     currentbox->y1 = y1;
00227 
00228   for ( ; i <= x1; x0++ )
00229     for ( ; j <= y1; x1++ )
00230       currentblock->image.data[i][j].ischar = action;
00231 
00232   return 0;
00233 }

Generated at Thu Mar 1 10:05:32 2001 for GOCR API by doxygen1.2.2 written by Dimitri van Heesch, © 1997-2000