Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
img.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: img.h (Formerly image.h)
3  * Description: Class definition for the IMAGE class.
4  * Author: Ray Smith
5  * Created: Thu Jun 07 13:42:37 BST 1990
6  *
7  * (C) Copyright 1990, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef IMG_H
21 #define IMG_H
22 
23 #include "memry.h"
24 
25 struct Pix;
26 
28 #define MAXIMAGEWIDTH (900*14)
29 
31 #define MAXIMAGEHEIGHT (900*14)
32 
33 #define COMPUTE_IMAGE_XDIM(xsize,bpp) ((bpp)>8 ? ((xsize)*(bpp)+7)/8 :((xsize)+8/(bpp)-1)/(8/(bpp)))
34 
35 typedef inT8 (*IMAGE_OPENER) (int, inT32 *, inT32 *, inT8 *, inT8 *, inT32 *);
36 typedef inT8 (*IMAGE_READER) (int, uinT8 *, inT32, inT32, inT8, inT32);
37 typedef inT8 (*IMAGE_WRITER) (int, uinT8 *, inT32, inT32, inT8, inT8, inT32);
38 
40 typedef uinT8 *COLOUR_PIX;
42 {
46 };
47 
49 
52 {
53  public:
54  IMAGE(); //constructor
55 
56  ~IMAGE () { //destructor
57  destroy(); //free memory
58  }
59 
60  IMAGE & operator= ( //assignment
61  IMAGE & source);
62 
69  inT8 create(inT32 x,
70  inT32 y,
71  inT8 bits_per_pixel);
72 
80  inT8 capture(uinT8 *pixels,
81  inT32 x,
82  inT32 y,
83  inT8 bits_per_pixel);
84 
86  void destroy();
87 
93  return xsize;
94  }
100  return ysize;
101  }
107  return bpp;
108  }
114  return bps;
115  }
118  return photo_interp;
119  }
122  return (1 << bpp) - 1;
123  }
126  return res;
127  }
129  void set_res(inT32 resolution) {
130  res = resolution;
131  }
133  return image;
134  }
135 
141  uinT8 pixel(inT32 x,
142  inT32 y);
143 
151  void fast_get_line(inT32 x,
152  inT32 y,
153  inT32 width,
154  IMAGELINE *linebuf);
155 
164  void get_line(inT32 x,
165  inT32 y,
166  inT32 width,
167  IMAGELINE *linebuf,
168  inT32 margins);
177  void get_column(inT32 x,
178  inT32 y,
179  inT32 height,
180  IMAGELINE *linebuf,
181  inT32 margins);
182 
190  void fast_put_line(inT32 x,
191  inT32 y,
192  inT32 width,
193  IMAGELINE *linebuf);
194 
203  void put_line(inT32 x,
204  inT32 y,
205  inT32 width,
206  IMAGELINE *linebuf,
207  inT32 margins);
216  void put_column(inT32 x,
217  inT32 y,
218  inT32 height,
219  IMAGELINE *linebuf,
220  inT32 margins);
221 
228  void check_legal_access(inT32 x,
229  inT32 y,
230  inT32 xext);
231 
232 
234  Pix* ToPix();
235  void FromPix(const Pix* src_pix);
236 
243  void convolver (
244  inT32 win_width,
245  inT32 win_height,
246  void (*convolve) (
247  uinT8 ** pixels,
248  uinT8 bytespp,
249  inT32 win_wd,
250  inT32 win_ht,
251  uinT8 ret_white_value,
252  uinT8 * result
253  ));
254 
255  //copy rectangle
256  friend DLLSYM void copy_sub_image(IMAGE *source, //source image
257  inT32 xstart, //start coords
258  inT32 ystart,
259  inT32 xext, //extent to copy
260  inT32 yext,
261  IMAGE *dest, //destination image
262  inT32 xdest, //destination coords //shift to match bpp
263  inT32 ydest,
264  BOOL8 adjust_grey);
265 
266  //enlarge rectangle
267  friend DLLSYM void enlarge_sub_image(IMAGE *source, //source image
268  inT32 xstart, //scaled coords
269  inT32 ystart,
270  IMAGE *dest, //destination image
271  inT32 xdest, //destination coords
272  inT32 ydest,
273  inT32 xext, //extent to copy
274  inT32 yext,
275  inT32 scale, //scale factor
276  BOOL8 adjust_grey); //shift to match bpp
277 
278  //reduce rectangle
279  friend DLLSYM void fast_reduce_sub_image(IMAGE *source, //source image
280  inT32 xstart, //start coords
281  inT32 ystart,
282  inT32 xext, //extent to copy
283  inT32 yext,
284  IMAGE *dest, //destination image
285  inT32 xdest, //destination coords
286  inT32 ydest,
287  inT32 scale, //scale factor
288  BOOL8 adjust_grey); //shift to match bpp
289 
290  //reduce rectangle
291  friend DLLSYM void reduce_sub_image(IMAGE *source, //source image
292  inT32 xstart, //start coords
293  inT32 ystart,
294  inT32 xext, //extent to copy
295  inT32 yext,
296  IMAGE *dest, //destination image
297  inT32 xdest, //destination coords
298  inT32 ydest,
299  inT32 scale, //scale factor
300  BOOL8 adjust_grey); //shift to match bpp
301 
302  private:
303  inT8 bpp;
304  inT8 bps;
305  inT8 bytespp;
306  inT8 lineskip;
307  BOOL8 captured;
308  inT8 photo_interp;
309  inT32 xsize, ysize;
310  inT32 res;
311  uinT8 *image;
312  inT32 xdim;
313  inT32 bufheight;
314  int fd;
315  IMAGE_READER reader;
316  inT32 ymin;
317  inT32 ymax;
318 
322  inT8 bufread(inT32 y);
323 };
324 
325 class DLLSYM IMAGELINE //one line of image
326 {
327  public:
330 
331  COLOUR_PIX operator[] (
332  inT32 index) {
333  return &pixels[index * 3]; //coercion access op
334  }
335 
338  linewidth = 0;
339  line = NULL;
340  pixels = line;
341  bpp = 8;
342  }
343  void init( //setup size
344  inT32 width) { //size of line
345  if (width <= 0)
346  width = MAXIMAGEWIDTH;
347  if (width > linewidth) {
348  if (line != NULL)
349  free_mem(line);
350  linewidth = width;
351  line = (uinT8 *) alloc_mem (linewidth * sizeof (uinT8));
352  }
353  pixels = line;
354  bpp = 8;
355  }
356  ~IMAGELINE () { //destructor
357  if (line != NULL)
358  free_mem(line);
359  }
360 
362  void set_bpp(inT8 new_bpp) {
363  if (new_bpp <= 8)
364  bpp = 8;
365  else
366  bpp = 24;
367  }
368 
369  void init() {
370  if (line == NULL)
371  init (0);
372  else {
373  pixels = line;
374  bpp = 8;
375  }
376  }
377 
386  friend void IMAGE::get_line(inT32 x,
387  inT32 y,
388  inT32 width,
389  IMAGELINE *linebuf,
390  inT32 margins);
399  friend void IMAGE::get_column(inT32 x,
400  inT32 y,
401  inT32 height,
402  IMAGELINE *linebuf,
403  inT32 margins);
404 
413  friend void IMAGE::put_line(inT32 x,
414  inT32 y,
415  inT32 width,
416  IMAGELINE *linebuf,
417  inT32 margins);
418 
427  friend void IMAGE::put_column(inT32 x,
428  inT32 y,
429  inT32 height,
430  IMAGELINE *linebuf,
431  inT32 margins);
432 
440  friend void IMAGE::fast_get_line(inT32 x,
441  inT32 y,
442  inT32 width,
443  IMAGELINE *linebuf);
444 
452  friend void IMAGE::fast_put_line(inT32 x,
453  inT32 y,
454  inT32 width,
455  IMAGELINE *linebuf);
456 
457  private:
458  uinT8 * line;
459  inT32 linewidth;
460 };
461 #endif