image/img.h

Go to the documentation of this file.
00001 
00019 #ifndef           IMG_H
00020 #define           IMG_H
00021 
00022 #include          "memry.h"
00023 
00025 #define MAXIMAGEWIDTH   (900*14)
00026 
00027 #define MAXIMAGEHEIGHT    (900*14)
00028 
00029 #define COMPUTE_IMAGE_XDIM(xsize,bpp) ((bpp)>8 ? ((xsize)*(bpp)+7)/8 :((xsize)+8/(bpp)-1)/(8/(bpp)))
00030 
00031 typedef INT8 (*IMAGE_OPENER) (int, INT32 *, INT32 *, INT8 *, INT8 *, INT32 *);
00032 typedef INT8 (*IMAGE_READER) (int, UINT8 *, INT32, INT32, INT8, INT32);
00033 typedef INT8 (*IMAGE_WRITER) (int, UINT8 *, INT32, INT32, INT8, INT8, INT32);
00034 
00039 typedef UINT8 *COLOUR_PIX;
00040 
00045 enum COLOUR_PIX_NAME
00046 {
00047   RED_PIX,
00048   GREEN_PIX,
00049   BLUE_PIX
00050 };
00051 
00052 class DLLSYM IMAGELINE;
00053 
00058 class DLLSYM IMAGE
00059 {
00060   public:
00061     IMAGE();  //constructor
00062 
00063     ~IMAGE () {                  //destructor
00064       destroy();  //free memory
00065     }
00066 
00067     IMAGE & operator= (          //assignment
00068       IMAGE & source);
00069 
00070     INT8 read_header(                    //get file header
00071                      const char *name);  //name of image
00072 
00073     INT8 read(                  //get rest of image
00074               INT32 buflines);  //size of buffer
00075 
00076     INT8 write(                    //write image
00077                const char *name);  //name to write
00078 
00079     INT8 create(                       //create blank image
00080                 INT32 x,               //x size required
00081                 INT32 y,               //ysize required
00082                 INT8 bits_per_pixel);  //bpp required
00083 
00084     INT8 capture(                       //capture raw image
00085                  UINT8 *pixels,         //pixels to capture
00086                  INT32 x,               //x size required
00087                  INT32 y,               //ysize required
00088                  INT8 bits_per_pixel);  //bpp required
00089 
00090     void destroy();  //destroy image
00091 
00092     INT32 get_xsize() { 
00093       return xsize;
00094     }
00095     //access function
00096     INT32 get_ysize() { 
00097       return ysize;
00098     }
00099     //access function
00100     INT8 get_bpp() { 
00101       return bpp;
00102     }                            //access function
00103     INT8 get_bps() { 
00104       return bps;
00105     }                            //bits per sample
00106     BOOL8 white_high() {  //photo interp
00107       return photo_interp;
00108     }
00109     UINT8 get_white_level() {  //access function
00110       return (1 << bpp) - 1;
00111     }
00112     INT32 get_res() { 
00113       return res;
00114     }                            //access function
00115     void set_res(  //set resolution
00116                  INT32 resolution) {
00117       res = resolution;
00118     }
00119     UINT8 *get_buffer() { 
00120       return image;
00121     }
00122     //access function
00123 
00124     UINT8 pixel(           //access pixel
00125                 INT32 x,   //x coord
00126                 INT32 y);  //y coord
00127 
00128     void fast_get_line(                      //get image line
00129                        INT32 x,              //coord to start at
00130                        INT32 y,              //line to get
00131                        INT32 width,          //no of pixels to get
00132                        IMAGELINE *linebuf);  //line to copy to
00133 
00134     void get_line(                     //get image line
00135                   INT32 x,             //coord to start at
00136                   INT32 y,             //line to get
00137                   INT32 width,         //no of pixels to get
00138                   IMAGELINE *linebuf,  //line to copy to
00139                   INT32 margins);      //size of margins
00140     void get_column(                     //get image column
00141                     INT32 x,             //coord to start at
00142                     INT32 y,             //line to get
00143                     INT32 height,        //no of pixels to get
00144                     IMAGELINE *linebuf,  //line to copy to
00145                     INT32 margins);      //size of margins
00146 
00147     void fast_put_line(                      //put image line
00148                        INT32 x,              //coord to start at
00149                        INT32 y,              //line to put
00150                        INT32 width,          //no of pixels to put
00151                        IMAGELINE *linebuf);  //line to copy from
00152 
00153     void put_line(                     //put image line
00154                   INT32 x,             //coord to start at
00155                   INT32 y,             //line to put
00156                   INT32 width,         //no of pixels to put
00157                   IMAGELINE *linebuf,  //line to copy from
00158                   INT32 margins);      //size of margins
00159     void put_column(                     //put image column
00160                     INT32 x,             //coord to start at
00161                     INT32 y,             //line to put
00162                     INT32 height,        //no of pixels to put
00163                     IMAGELINE *linebuf,  //line to copy to
00164                     INT32 margins);      //size of margins
00165 
00166     void check_legal_access(              //check coords
00167                             INT32 x,      //xcoord to check
00168                             INT32 y,
00169                             INT32 xext);  //ycoord to check
00170 
00171     void convolver (             //Map fn over window
00172       INT32 win_width,           //Window width
00173       INT32 win_height,          //Window height
00174       void (*convolve) (         //Conv Function
00175       UINT8 ** pixels,           //Of window
00176       UINT8 bytespp,             //1 or 3 for colour
00177       INT32 win_wd,              //Window width
00178       INT32 win_ht,              //Window height
00179       UINT8 ret_white_value,     //White value to RETURN
00180       UINT8 * result));          //Result pixel(s)
00181 
00182                                  //copy rectangle
00183     friend DLLSYM void copy_sub_image(IMAGE *source,  //source image
00184                                       INT32 xstart,   //start coords
00185                                       INT32 ystart,
00186                                       INT32 xext,     //extent to copy
00187                                       INT32 yext,
00188                                       IMAGE *dest,    //destination image
00189                                       INT32 xdest,    //destination coords //shift to match bpp
00190                                       INT32 ydest,
00191                                       BOOL8 adjust_grey);
00192 
00193                                  //enlarge rectangle
00194     friend DLLSYM void enlarge_sub_image(IMAGE *source,       //source image
00195                                          INT32 xstart,        //scaled coords
00196                                          INT32 ystart,
00197                                          IMAGE *dest,         //destination image
00198                                          INT32 xdest,         //destination coords
00199                                          INT32 ydest,
00200                                          INT32 xext,          //extent to copy
00201                                          INT32 yext,
00202                                          INT32 scale,         //scale factor
00203                                          BOOL8 adjust_grey);  //shift to match bpp
00204 
00205                                  //reduce rectangle
00206     friend DLLSYM void fast_reduce_sub_image(IMAGE *source,       //source image
00207                                              INT32 xstart,        //start coords
00208                                              INT32 ystart,
00209                                              INT32 xext,          //extent to copy
00210                                              INT32 yext,
00211                                              IMAGE *dest,         //destination image
00212                                              INT32 xdest,         //destination coords
00213                                              INT32 ydest,
00214                                              INT32 scale,         //scale factor
00215                                              BOOL8 adjust_grey);  //shift to match bpp
00216 
00217                                  //reduce rectangle
00218     friend DLLSYM void reduce_sub_image(IMAGE *source,       //source image
00219                                         INT32 xstart,        //start coords
00220                                         INT32 ystart,
00221                                         INT32 xext,          //extent to copy
00222                                         INT32 yext,
00223                                         IMAGE *dest,         //destination image
00224                                         INT32 xdest,         //destination coords
00225                                         INT32 ydest,
00226                                         INT32 scale,         //scale factor
00227                                         BOOL8 adjust_grey);  //shift to match bpp
00228 
00229   private:
00230     INT8 bpp;                    //bits per pixel
00231     INT8 bps;                    //bits per sample
00232     INT8 bytespp;                //per pixel
00233     INT8 lineskip;               //waste bytes on line
00234     BOOL8 captured;              //true if buffer captured
00235     INT8 photo_interp;           //interpretation
00236     INT32 xsize, ysize;          //size of image
00237     INT32 res;                   //resolution
00238     UINT8 *image;                //the actual image
00239     INT32 xdim;                  //bytes per line
00240     INT32 bufheight;             //height of buffer
00241     int fd;                      //open file descriptor
00242     IMAGE_READER reader;         //reading function
00243     INT32 ymin;                  //bottom line in mem
00244     INT32 ymax;                  //top line in mem+1
00245     INT8 bufread(           //read some more
00246                  INT32 y);  //ycoord required
00247 };
00248 
00253 class DLLSYM IMAGELINE
00254 {
00255   public:
00256     UINT8 * pixels;              //image pixels
00257     INT8 bpp;                    //bits per pixel
00258     COLOUR_PIX operator[] (      //colour pixels
00259     INT32 index) {
00260       return &pixels[index * 3]; //coercion access op
00261     }
00262 
00263     IMAGELINE() {  //default constructor
00264       linewidth = 0;
00265       line = NULL;
00266       pixels = line;
00267       bpp = 8;
00268     }
00269     void init(                //setup size
00270               INT32 width) {  //size of line
00271       if (width <= 0)
00272         width = MAXIMAGEWIDTH;
00273       if (width > linewidth) {
00274         if (line != NULL)
00275           free_mem(line); 
00276         linewidth = width;
00277         line = (UINT8 *) alloc_mem (linewidth * sizeof (UINT8));
00278       }
00279       pixels = line;
00280       bpp = 8;
00281     }
00282     ~IMAGELINE () {              //destructor
00283       if (line != NULL)
00284         free_mem(line); 
00285     }
00286 
00287     void set_bpp(  //For colour
00288                  INT8 new_bpp) {
00289       if (new_bpp <= 8)
00290         bpp = 8;
00291       else
00292         bpp = 24;
00293     }
00294 
00295     void init() { 
00296       if (line == NULL)
00297         init (0);
00298       else {
00299         pixels = line;
00300         bpp = 8;
00301       }
00302     }
00303 
00304     friend void IMAGE::get_line(                     //copies a line
00305                                 INT32 x,             //coord to start at
00306                                 INT32 y,             //line to get
00307                                 INT32 width,         //no of pixels to get
00308                                 IMAGELINE *linebuf,  //line to copy to
00309                                 INT32 margins);      //size of margins
00310                                  //copies a column
00311     friend void IMAGE::get_column(INT32 x,             //coord to start at
00312                                   INT32 y,             //line to get
00313                                   INT32 height,        //no of pixels to get
00314                                   IMAGELINE *linebuf,  //line to copy to
00315                                   INT32 margins);      //size of margins
00316 
00317     friend void IMAGE::put_line(                     //writes a line
00318                                 INT32 x,             //coord to start at
00319                                 INT32 y,             //line to put
00320                                 INT32 width,         //no of pixels to put
00321                                 IMAGELINE *linebuf,  //line to copy from
00322                                 INT32 margins);      //size of margins
00323                                  //writes a column
00324     friend void IMAGE::put_column(INT32 x,             //coord to start at
00325                                   INT32 y,             //line to put
00326                                   INT32 height,        //no of pixels to put
00327                                   IMAGELINE *linebuf,  //line to copy from
00328                                   INT32 margins);      //size of margins
00329 
00330                                  //may just change pointer
00331     friend void IMAGE::fast_get_line(INT32 x,              //coord to start at
00332                                      INT32 y,              //line to get
00333                                      INT32 width,          //no of pixels to get
00334                                      IMAGELINE *linebuf);  //line to copy to
00335 
00336                                  //may just change pointer
00337     friend void IMAGE::fast_put_line(INT32 x,              //coord to start at
00338                                      INT32 y,              //line to get
00339                                      INT32 width,          //no of pixels to get
00340                                      IMAGELINE *linebuf);  //line to copy to
00341 
00342   private:
00343     UINT8 * line;                //local buffer
00344     INT32 linewidth;             //width of buffer
00345 };
00346 #endif

Generated on Wed Feb 28 19:49:11 2007 for Tesseract by  doxygen 1.5.1