00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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();
00055
00056 ~IMAGE () {
00057 destroy();
00058 }
00059
00060 IMAGE & operator= (
00061 IMAGE & source);
00062
00067 inT8 read_header(const char *name);
00068
00073 inT8 read(inT32 buflines);
00074
00079 inT8 write(const char *name);
00080
00087 inT8 create(inT32 x,
00088 inT32 y,
00089 inT8 bits_per_pixel);
00090
00098 inT8 capture(uinT8 *pixels,
00099 inT32 x,
00100 inT32 y,
00101 inT8 bits_per_pixel);
00102
00104 void destroy();
00105
00110 inT32 get_xsize() {
00111 return xsize;
00112 }
00117 inT32 get_ysize() {
00118 return ysize;
00119 }
00124 inT8 get_bpp() {
00125 return bpp;
00126 }
00131 inT8 get_bps() {
00132 return bps;
00133 }
00135 BOOL8 white_high() {
00136 return photo_interp;
00137 }
00139 uinT8 get_white_level() {
00140 return (1 << bpp) - 1;
00141 }
00143 inT32 get_res() {
00144 return res;
00145 }
00147 void set_res(inT32 resolution) {
00148 res = resolution;
00149 }
00150 uinT8 *get_buffer() {
00151 return image;
00152 }
00153
00159 uinT8 pixel(inT32 x,
00160 inT32 y);
00161
00169 void fast_get_line(inT32 x,
00170 inT32 y,
00171 inT32 width,
00172 IMAGELINE *linebuf);
00173
00182 void get_line(inT32 x,
00183 inT32 y,
00184 inT32 width,
00185 IMAGELINE *linebuf,
00186 inT32 margins);
00195 void get_column(inT32 x,
00196 inT32 y,
00197 inT32 height,
00198 IMAGELINE *linebuf,
00199 inT32 margins);
00200
00208 void fast_put_line(inT32 x,
00209 inT32 y,
00210 inT32 width,
00211 IMAGELINE *linebuf);
00212
00221 void put_line(inT32 x,
00222 inT32 y,
00223 inT32 width,
00224 IMAGELINE *linebuf,
00225 inT32 margins);
00234 void put_column(inT32 x,
00235 inT32 y,
00236 inT32 height,
00237 IMAGELINE *linebuf,
00238 inT32 margins);
00239
00245 void check_legal_access(inT32 x,
00246 inT32 y,
00247 inT32 xext);
00248
00249
00251 Pix* ToPix();
00252 void FromPix(const Pix* src_pix);
00253
00260 void convolver (
00261 inT32 win_width,
00262 inT32 win_height,
00263 void (*convolve) (
00264 uinT8 ** pixels,
00265 uinT8 bytespp,
00266 inT32 win_wd,
00267 inT32 win_ht,
00268 uinT8 ret_white_value,
00269 uinT8 * result
00270 ));
00271
00272
00273 friend DLLSYM void copy_sub_image(IMAGE *source,
00274 inT32 xstart,
00275 inT32 ystart,
00276 inT32 xext,
00277 inT32 yext,
00278 IMAGE *dest,
00279 inT32 xdest,
00280 inT32 ydest,
00281 BOOL8 adjust_grey);
00282
00283
00284 friend DLLSYM void enlarge_sub_image(IMAGE *source,
00285 inT32 xstart,
00286 inT32 ystart,
00287 IMAGE *dest,
00288 inT32 xdest,
00289 inT32 ydest,
00290 inT32 xext,
00291 inT32 yext,
00292 inT32 scale,
00293 BOOL8 adjust_grey);
00294
00295
00296 friend DLLSYM void fast_reduce_sub_image(IMAGE *source,
00297 inT32 xstart,
00298 inT32 ystart,
00299 inT32 xext,
00300 inT32 yext,
00301 IMAGE *dest,
00302 inT32 xdest,
00303 inT32 ydest,
00304 inT32 scale,
00305 BOOL8 adjust_grey);
00306
00307
00308 friend DLLSYM void reduce_sub_image(IMAGE *source,
00309 inT32 xstart,
00310 inT32 ystart,
00311 inT32 xext,
00312 inT32 yext,
00313 IMAGE *dest,
00314 inT32 xdest,
00315 inT32 ydest,
00316 inT32 scale,
00317 BOOL8 adjust_grey);
00318
00319 private:
00320 inT8 bpp;
00321 inT8 bps;
00322 inT8 bytespp;
00323 inT8 lineskip;
00324 BOOL8 captured;
00325 inT8 photo_interp;
00326 inT32 xsize, ysize;
00327 inT32 res;
00328 uinT8 *image;
00329 inT32 xdim;
00330 inT32 bufheight;
00331 int fd;
00332 IMAGE_READER reader;
00333 inT32 ymin;
00334 inT32 ymax;
00335
00339 inT8 bufread(inT32 y);
00340 };
00341
00342 class DLLSYM IMAGELINE
00343 {
00344 public:
00345 uinT8 * pixels;
00346 inT8 bpp;
00347
00348 COLOUR_PIX operator[] (
00349 inT32 index) {
00350 return &pixels[index * 3];
00351 }
00352
00354 IMAGELINE() {
00355 linewidth = 0;
00356 line = NULL;
00357 pixels = line;
00358 bpp = 8;
00359 }
00360 void init(
00361 inT32 width) {
00362 if (width <= 0)
00363 width = MAXIMAGEWIDTH;
00364 if (width > linewidth) {
00365 if (line != NULL)
00366 free_mem(line);
00367 linewidth = width;
00368 line = (uinT8 *) alloc_mem (linewidth * sizeof (uinT8));
00369 }
00370 pixels = line;
00371 bpp = 8;
00372 }
00373 ~IMAGELINE () {
00374 if (line != NULL)
00375 free_mem(line);
00376 }
00377
00379 void set_bpp(inT8 new_bpp) {
00380 if (new_bpp <= 8)
00381 bpp = 8;
00382 else
00383 bpp = 24;
00384 }
00385
00386 void init() {
00387 if (line == NULL)
00388 init (0);
00389 else {
00390 pixels = line;
00391 bpp = 8;
00392 }
00393 }
00394
00403 friend void IMAGE::get_line(inT32 x,
00404 inT32 y,
00405 inT32 width,
00406 IMAGELINE *linebuf,
00407 inT32 margins);
00416 friend void IMAGE::get_column(inT32 x,
00417 inT32 y,
00418 inT32 height,
00419 IMAGELINE *linebuf,
00420 inT32 margins);
00421
00430 friend void IMAGE::put_line(inT32 x,
00431 inT32 y,
00432 inT32 width,
00433 IMAGELINE *linebuf,
00434 inT32 margins);
00435
00444 friend void IMAGE::put_column(inT32 x,
00445 inT32 y,
00446 inT32 height,
00447 IMAGELINE *linebuf,
00448 inT32 margins);
00449
00457 friend void IMAGE::fast_get_line(inT32 x,
00458 inT32 y,
00459 inT32 width,
00460 IMAGELINE *linebuf);
00461
00469 friend void IMAGE::fast_put_line(inT32 x,
00470 inT32 y,
00471 inT32 width,
00472 IMAGELINE *linebuf);
00473
00474 private:
00475 uinT8 * line;
00476 inT32 linewidth;
00477 };
00478 #endif