Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: img.h (Formerly image.h) 00003 * Description: Class definition for the IMAGE class. 00004 * Author: Ray Smith 00005 * Created: Thu Jun 07 13:42:37 BST 1990 00006 * 00007 * (C) Copyright 1990, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef IMG_H 00021 #define IMG_H 00022 00023 #include "memry.h" 00024 00025 struct Pix; 00026 00028 #define MAXIMAGEWIDTH (900*14) 00029 00031 #define MAXIMAGEHEIGHT (900*14) 00032 00033 #define COMPUTE_IMAGE_XDIM(xsize,bpp) ((bpp)>8 ? ((xsize)*(bpp)+7)/8 :((xsize)+8/(bpp)-1)/(8/(bpp))) 00034 00035 typedef inT8 (*IMAGE_OPENER) (int, inT32 *, inT32 *, inT8 *, inT8 *, inT32 *); 00036 typedef inT8 (*IMAGE_READER) (int, uinT8 *, inT32, inT32, inT8, inT32); 00037 typedef inT8 (*IMAGE_WRITER) (int, uinT8 *, inT32, inT32, inT8, inT8, inT32); 00038 00040 typedef uinT8 *COLOUR_PIX; 00041 enum COLOUR_PIX_NAME 00042 { 00043 RED_PIX, 00044 GREEN_PIX, 00045 BLUE_PIX 00046 }; 00047 00048 class DLLSYM IMAGELINE; 00049 00051 class DLLSYM IMAGE 00052 { 00053 public: 00054 IMAGE(); //constructor 00055 00056 ~IMAGE () { //destructor 00057 destroy(); //free memory 00058 } 00059 00060 IMAGE & operator= ( //assignment 00061 IMAGE & source); 00062 00069 inT8 create(inT32 x, 00070 inT32 y, 00071 inT8 bits_per_pixel); 00072 00080 inT8 capture(uinT8 *pixels, 00081 inT32 x, 00082 inT32 y, 00083 inT8 bits_per_pixel); 00084 00086 void destroy(); 00087 00092 inT32 get_xsize() { 00093 return xsize; 00094 } 00099 inT32 get_ysize() { 00100 return ysize; 00101 } 00106 inT8 get_bpp() { 00107 return bpp; 00108 } 00113 inT8 get_bps() { 00114 return bps; 00115 } 00117 BOOL8 white_high() { 00118 return photo_interp; 00119 } 00121 uinT8 get_white_level() { 00122 return (1 << bpp) - 1; 00123 } 00125 inT32 get_res() { 00126 return res; 00127 } 00129 void set_res(inT32 resolution) { 00130 res = resolution; 00131 } 00132 uinT8 *get_buffer() { 00133 return image; 00134 } 00135 00141 uinT8 pixel(inT32 x, 00142 inT32 y); 00143 00151 void fast_get_line(inT32 x, 00152 inT32 y, 00153 inT32 width, 00154 IMAGELINE *linebuf); 00155 00164 void get_line(inT32 x, 00165 inT32 y, 00166 inT32 width, 00167 IMAGELINE *linebuf, 00168 inT32 margins); 00177 void get_column(inT32 x, 00178 inT32 y, 00179 inT32 height, 00180 IMAGELINE *linebuf, 00181 inT32 margins); 00182 00190 void fast_put_line(inT32 x, 00191 inT32 y, 00192 inT32 width, 00193 IMAGELINE *linebuf); 00194 00203 void put_line(inT32 x, 00204 inT32 y, 00205 inT32 width, 00206 IMAGELINE *linebuf, 00207 inT32 margins); 00216 void put_column(inT32 x, 00217 inT32 y, 00218 inT32 height, 00219 IMAGELINE *linebuf, 00220 inT32 margins); 00221 00228 void check_legal_access(inT32 x, 00229 inT32 y, 00230 inT32 xext); 00231 00232 00234 Pix* ToPix(); 00235 void FromPix(const Pix* src_pix); 00236 00243 void convolver ( 00244 inT32 win_width, 00245 inT32 win_height, 00246 void (*convolve) ( 00247 uinT8 ** pixels, 00248 uinT8 bytespp, 00249 inT32 win_wd, 00250 inT32 win_ht, 00251 uinT8 ret_white_value, 00252 uinT8 * result 00253 )); 00254 00255 //copy rectangle 00256 friend DLLSYM void copy_sub_image(IMAGE *source, //source image 00257 inT32 xstart, //start coords 00258 inT32 ystart, 00259 inT32 xext, //extent to copy 00260 inT32 yext, 00261 IMAGE *dest, //destination image 00262 inT32 xdest, //destination coords //shift to match bpp 00263 inT32 ydest, 00264 BOOL8 adjust_grey); 00265 00266 //enlarge rectangle 00267 friend DLLSYM void enlarge_sub_image(IMAGE *source, //source image 00268 inT32 xstart, //scaled coords 00269 inT32 ystart, 00270 IMAGE *dest, //destination image 00271 inT32 xdest, //destination coords 00272 inT32 ydest, 00273 inT32 xext, //extent to copy 00274 inT32 yext, 00275 inT32 scale, //scale factor 00276 BOOL8 adjust_grey); //shift to match bpp 00277 00278 //reduce rectangle 00279 friend DLLSYM void fast_reduce_sub_image(IMAGE *source, //source image 00280 inT32 xstart, //start coords 00281 inT32 ystart, 00282 inT32 xext, //extent to copy 00283 inT32 yext, 00284 IMAGE *dest, //destination image 00285 inT32 xdest, //destination coords 00286 inT32 ydest, 00287 inT32 scale, //scale factor 00288 BOOL8 adjust_grey); //shift to match bpp 00289 00290 //reduce rectangle 00291 friend DLLSYM void reduce_sub_image(IMAGE *source, //source image 00292 inT32 xstart, //start coords 00293 inT32 ystart, 00294 inT32 xext, //extent to copy 00295 inT32 yext, 00296 IMAGE *dest, //destination image 00297 inT32 xdest, //destination coords 00298 inT32 ydest, 00299 inT32 scale, //scale factor 00300 BOOL8 adjust_grey); //shift to match bpp 00301 00302 private: 00303 inT8 bpp; 00304 inT8 bps; 00305 inT8 bytespp; 00306 inT8 lineskip; 00307 BOOL8 captured; 00308 inT8 photo_interp; 00309 inT32 xsize, ysize; 00310 inT32 res; 00311 uinT8 *image; 00312 inT32 xdim; 00313 inT32 bufheight; 00314 int fd; 00315 IMAGE_READER reader; 00316 inT32 ymin; 00317 inT32 ymax; 00318 00322 inT8 bufread(inT32 y); 00323 }; 00324 00325 class DLLSYM IMAGELINE //one line of image 00326 { 00327 public: 00328 uinT8 * pixels; 00329 inT8 bpp; 00330 00331 COLOUR_PIX operator[] ( 00332 inT32 index) { 00333 return &pixels[index * 3]; //coercion access op 00334 } 00335 00337 IMAGELINE() { 00338 linewidth = 0; 00339 line = NULL; 00340 pixels = line; 00341 bpp = 8; 00342 } 00343 void init( //setup size 00344 inT32 width) { //size of line 00345 if (width <= 0) 00346 width = MAXIMAGEWIDTH; 00347 if (width > linewidth) { 00348 if (line != NULL) 00349 free_mem(line); 00350 linewidth = width; 00351 line = (uinT8 *) alloc_mem (linewidth * sizeof (uinT8)); 00352 } 00353 pixels = line; 00354 bpp = 8; 00355 } 00356 ~IMAGELINE () { //destructor 00357 if (line != NULL) 00358 free_mem(line); 00359 } 00360 00362 void set_bpp(inT8 new_bpp) { 00363 if (new_bpp <= 8) 00364 bpp = 8; 00365 else 00366 bpp = 24; 00367 } 00368 00369 void init() { 00370 if (line == NULL) 00371 init (0); 00372 else { 00373 pixels = line; 00374 bpp = 8; 00375 } 00376 } 00377 00386 friend void IMAGE::get_line(inT32 x, 00387 inT32 y, 00388 inT32 width, 00389 IMAGELINE *linebuf, 00390 inT32 margins); 00399 friend void IMAGE::get_column(inT32 x, 00400 inT32 y, 00401 inT32 height, 00402 IMAGELINE *linebuf, 00403 inT32 margins); 00404 00413 friend void IMAGE::put_line(inT32 x, 00414 inT32 y, 00415 inT32 width, 00416 IMAGELINE *linebuf, 00417 inT32 margins); 00418 00427 friend void IMAGE::put_column(inT32 x, 00428 inT32 y, 00429 inT32 height, 00430 IMAGELINE *linebuf, 00431 inT32 margins); 00432 00440 friend void IMAGE::fast_get_line(inT32 x, 00441 inT32 y, 00442 inT32 width, 00443 IMAGELINE *linebuf); 00444 00452 friend void IMAGE::fast_put_line(inT32 x, 00453 inT32 y, 00454 inT32 width, 00455 IMAGELINE *linebuf); 00456 00457 private: 00458 uinT8 * line; 00459 inT32 linewidth; 00460 }; 00461 #endif