Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imgs.cpp File Reference
#include "mfcpch.h"
#include <unistd.h>
#include <string.h>
#include "allheaders.h"
#include "stderr.h"
#include "tprintf.h"
#include "imgerrs.h"
#include "memry.h"
#include "imgs.h"
#include "imgunpk.h"

Go to the source code of this file.

Macros

#define FIXED_COLOURS   32 /*number of fixed colours */
 
#define MIN_4BIT   48 /*4bpp range */
 
#define MAX_4BIT   64
 
#define MIN_6BIT   64 /*6bpp range */
 
#define MAX_6BIT   128
 
#define BLACK_PIX   0
 
#define EXTERN
 

Functions

inT32 check_legal_image_size (inT32 x, inT32 y, inT8 bits_per_pixel)
 
DLLSYM void copy_sub_image (IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, IMAGE *dest, inT32 xdest, inT32 ydest, BOOL8 adjust_grey)
 
DLLSYM void enlarge_sub_image (IMAGE *source, inT32 xstart, inT32 ystart, IMAGE *dest, inT32 xdest, inT32 ydest, inT32 xext, inT32 yext, inT32 scale, BOOL8 adjust_grey)
 
DLLSYM void fast_reduce_sub_image (IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, IMAGE *dest, inT32 xdest, inT32 ydest, inT32 scale, BOOL8 adjust_grey)
 
DLLSYM void reduce_sub_image (IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, IMAGE *dest, inT32 xdest, inT32 ydest, inT32 scale, BOOL8 adjust_grey)
 
DLLSYM void invert_image (IMAGE *image)
 
DLLSYM void bias_sub_image (IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, uinT8 bias)
 
DLLSYM void starbase_to_normal (IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, IMAGE *dest, inT32 xdest, inT32 ydest, BOOL8 preserve_grey)
 

Variables

const uinT8 grey_scales [FIXED_COLOURS]
 
EXTERN int image_default_resolution = 300
 

Macro Definition Documentation

#define BLACK_PIX   0

Definition at line 50 of file imgs.cpp.

#define EXTERN

Definition at line 60 of file imgs.cpp.

#define FIXED_COLOURS   32 /*number of fixed colours */

Definition at line 45 of file imgs.cpp.

#define MAX_4BIT   64

Definition at line 47 of file imgs.cpp.

#define MAX_6BIT   128

Definition at line 49 of file imgs.cpp.

#define MIN_4BIT   48 /*4bpp range */

Definition at line 46 of file imgs.cpp.

#define MIN_6BIT   64 /*6bpp range */

Definition at line 48 of file imgs.cpp.

Function Documentation

DLLSYM void bias_sub_image ( IMAGE source,
inT32  xstart,
inT32  ystart,
inT32  xext,
inT32  yext,
uinT8  bias 
)

Definition at line 832 of file imgs.cpp.

839  {
840  IMAGELINE copyline; //copy of line
841  uinT8 *copy; //source pointer
842  inT32 pixel; //pixel index
843  inT32 y; //line index
844  uinT8 bytespp; //bytes per pixel
845 
846  if (xstart < 0 || ystart < 0)
847  return;
848  if (xext <= 0)
849  xext = source->get_xsize (); //default to all
850  if (xext > source->get_xsize () - xstart)
851  //clip to smallest
852  xext = source->get_xsize () - xstart;
853  if (yext <= 0)
854  yext = source->get_ysize (); //default to all
855  if (yext > source->get_ysize () - ystart)
856  //clip to smallest
857  yext = source->get_ysize () - ystart;
858  if (xext <= 0 || yext <= 0)
859  return; //nothing to do
860 
861  bytespp = source->get_bpp () == 24 ? 3 : 1;
862  for (y = 0; y < yext; y++) {
863  source->check_legal_access (xstart, ystart + y, xext);
864  source->fast_get_line (xstart, ystart + y, xext, &copyline);
865  for (pixel = xext * bytespp, copy = copyline.pixels; pixel > 0;
866  pixel--, copy++)
867  *copy += bias; //add bias
868 
869  source->fast_put_line (xstart, ystart + y, xext, &copyline);
870  }
871 }
Definition: img.h:325
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
int inT32
Definition: host.h:102
inT32 get_ysize()
Definition: img.h:99
uinT8 * pixels
image pixels
Definition: img.h:328
inT8 get_bpp()
Definition: img.h:106
unsigned char uinT8
Definition: host.h:99
inT32 get_xsize()
Definition: img.h:92
void fast_put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:1203
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
inT32 check_legal_image_size ( inT32  x,
inT32  y,
inT8  bits_per_pixel 
)

Definition at line 240 of file imgs.cpp.

244  {
245  if (x <= 0 || y <= 0) {
246  BADIMAGESIZE.error ("check_legal_image_size", TESSLOG, "(%d,%d)", x, y);
247  return -1; //failed
248  }
249  if (bits_per_pixel != 1 && bits_per_pixel != 2 &&
250  bits_per_pixel != 4 && bits_per_pixel != 5 &&
251  bits_per_pixel != 6 && bits_per_pixel != 8 &&
252  bits_per_pixel != 16 && bits_per_pixel != 24 &&
253  bits_per_pixel != 32) {
254  BADBPP.error ("check_legal_image_size", TESSLOG, "%d", bits_per_pixel);
255  return -1;
256  }
257  //bytes per line
258  return COMPUTE_IMAGE_XDIM (x, bits_per_pixel);
259 }
const ERRCODE BADIMAGESIZE
Definition: imgerrs.h:31
const ERRCODE BADBPP
Definition: imgerrs.h:33
#define COMPUTE_IMAGE_XDIM(xsize, bpp)
Definition: img.h:33
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
DLLSYM void copy_sub_image ( IMAGE source,
inT32  xstart,
inT32  ystart,
inT32  xext,
inT32  yext,
IMAGE dest,
inT32  xdest,
inT32  ydest,
BOOL8  adjust_grey 
)

Definition at line 270 of file imgs.cpp.

280  {
281  IMAGELINE copyline; //copy of line
282  uinT8 *copy; //source pointer
283  inT8 shift; //shift factor
284  inT32 pixel; //pixel index
285  inT32 y; //line index
286  inT32 yoffset; //current adjusted offset
287  inT32 bytesize; //no of bytes to copy
288  inT32 srcppb; //pixels per byte
289  BOOL8 aligned;
290 
291  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
292  return;
293  if (xext <= 0)
294  xext = source->xsize; //default to all
295  if (xext > source->xsize - xstart)
296  //clip to smallest
297  xext = source->xsize - xstart;
298  if (xext > dest->xsize - xdest)
299  xext = dest->xsize - xdest;
300  if (yext <= 0)
301  yext = source->ysize; //default to all
302  if (yext > source->ysize - ystart)
303  //clip to smallest
304  yext = source->ysize - ystart;
305  if (yext > dest->ysize - ydest)
306  yext = dest->ysize - ydest;
307  if (xext <= 0 || yext <= 0)
308  return; //nothing to do
309 
310  srcppb = 8 / source->bpp; //pixels per byte
311  if (source->bpp == dest->bpp || !adjust_grey)
312  shift = 0; //no adjustment
313  else {
314  shift = source->bps - dest->bps;
315  if (shift < 0)
316  shift = -shift; //keep positive
317  }
318  aligned = source->bpp == dest->bpp;
319  if (aligned && srcppb != 0) {
320  aligned = xstart % srcppb == 0
321  && xdest % srcppb == 0
322  && (xext % srcppb == 0 || xdest + xext == dest->xsize);
323  }
324  for (y = 0; y < yext; y++) {
325  if (ystart >= ydest)
326  yoffset = y; //top down
327  else
328  yoffset = yext - y - 1; //bottom up
329  source->check_legal_access (xstart, ystart + yoffset, xext);
330  dest->check_legal_access (xdest, ydest + yoffset, xext);
331  if (aligned) {
332  bytesize = COMPUTE_IMAGE_XDIM (xext, source->bpp);
333  //get bytes per line
334  if (srcppb == 0)
335  //do cheap move
336  memmove (dest->image + (dest->ymax - 1 - ydest - yoffset) * dest->xdim + xdest * 3, source->image + (source->ymax - 1 - ystart - yoffset) * source->xdim + xstart * 3, (unsigned) bytesize);
337  else
338  //do cheap move
339  memmove (dest->image + (dest->ymax - 1 - ydest - yoffset) * dest->xdim + xdest / srcppb, source->image + (source->ymax - 1 - ystart - yoffset) * source->xdim + xstart / srcppb, (unsigned) bytesize);
340  }
341  else {
342  if (shift == 0) {
343  source->fast_get_line (xstart, ystart + yoffset, xext,
344  &copyline);
345  }
346  else if (source->bpp < dest->bpp) {
347  source->get_line (xstart, ystart + yoffset, xext, &copyline, 0);
348  if (source->bpp <= shift
349  && (source->bpp == 1 || source->bpp == 4)) {
350  if (source->bpp == 1) {
351  for (pixel = 0, copy = copyline.pixels; pixel < xext;
352  pixel++, copy++)
353  if (*copy)
354  *copy = 0xff;
355  }
356  else {
357  for (pixel = 0, copy = copyline.pixels; pixel < xext;
358  pixel++, copy++)
359  //scale up
360  *copy = (*copy << shift) | *copy;
361  }
362  }
363  else {
364  for (pixel = 0, copy = copyline.pixels; pixel < xext;
365  pixel++)
366  *copy++ <<= shift; //scale up
367  }
368  }
369  else {
370  source->get_line (xstart, ystart + yoffset, xext, &copyline, 0);
371  if (source->bpp == 24) {
372  for (pixel = 0, copy = copyline.pixels + 1; pixel < xext;
373  pixel++) {
374  *copy >>= shift;
375  copy += 3;
376  }
377  }
378  else {
379  for (pixel = 0, copy = copyline.pixels; pixel < xext;
380  pixel++)
381  *copy++ >>= shift; //scale down
382  }
383  }
384  dest->put_line (xdest, ydest + yoffset, xext, &copyline, 0);
385  }
386  }
387 }
Definition: img.h:325
unsigned char BOOL8
Definition: host.h:113
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
int inT32
Definition: host.h:102
void put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1222
#define COMPUTE_IMAGE_XDIM(xsize, bpp)
Definition: img.h:33
uinT8 * pixels
image pixels
Definition: img.h:328
SIGNED char inT8
Definition: host.h:98
void get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1003
unsigned char uinT8
Definition: host.h:99
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
DLLSYM void enlarge_sub_image ( IMAGE source,
inT32  xstart,
inT32  ystart,
IMAGE dest,
inT32  xdest,
inT32  ydest,
inT32  xext,
inT32  yext,
inT32  scale,
BOOL8  adjust_grey 
)

Definition at line 398 of file imgs.cpp.

409  {
410  inT8 shift; //shift factor
411  uinT8 pixel; //current pixel
412  inT32 srcext; //source extent
413  inT32 xoffset; //column index
414  inT32 yoffset; //line index
415  inT32 xindex, yindex; //index in super pixel
416  inT32 startxindex; //initial x index
417  inT32 xscale; //x scale factor
418  uinT8 *src; //source pixels
419  uinT8 *destpix; //dest pixels
420  IMAGELINE copyline; //copy of line
421  IMAGELINE bigline; //expanded line
422 
423  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
424  return;
425 
426  if (xext <= 0)
427  xext = dest->xsize; //default to all
428  if (xext > source->xsize * scale - xstart)
429  //clip to smallest
430  xext = source->xsize * scale - xstart;
431  if (xext > dest->xsize - xdest)
432  xext = dest->xsize - xdest;
433  if (yext <= 0)
434  yext = dest->ysize; //default to all
435  if (yext > source->ysize * scale - ystart)
436  yext = source->ysize * scale - ystart;
437  if (yext > dest->ysize - ydest)
438  yext = dest->ysize - ydest;
439  if (xext <= 0 || yext <= 0)
440  return; //nothing to do
441 
442  xindex = xstart % scale; //offset in super pixel
443  startxindex = xindex;
444  yindex = ystart % scale;
445  //no of source pixels
446  srcext = (xext + xindex + scale - 1) / scale;
447  xstart /= scale; //actual start
448  ystart /= scale;
449  if (adjust_grey) {
450  shift = dest->bps - source->bps;
451  }
452  else
453  shift = 0; //no adjustment
454  bigline.init (xext * 3);
455  bigline.bpp = dest->bpp == 24 ? source->bpp : dest->bpp;
456 
457  for (yoffset = 0; yoffset < yext; ystart++) {
458  source->check_legal_access (xstart, ystart, srcext);
459  dest->check_legal_access (xdest, ydest + yoffset, xext);
460  source->fast_get_line (xstart, ystart, srcext, &copyline);
461  src = copyline.pixels;
462  destpix = bigline.pixels;
463  xscale = scale; //enlargement factor
464  if (source->bpp == 24 && dest->bpp == 24) {
465  for (xoffset = 0, xindex = startxindex; xoffset < xext;
466  src += source->bytespp) {
467  xoffset += xscale - xindex;
468  if (xoffset > xext)
469  xscale -= xoffset - xext;
470  for (; xindex < xscale; xindex++) {
471  *destpix++ = *src;
472  *destpix++ = *(src + 1);
473  *destpix++ = *(src + 2);
474  }
475  xindex = 0;
476  }
477  }
478  else {
479  if (source->bpp == 24)
480  src++;
481  for (xoffset = 0, xindex = startxindex; xoffset < xext;
482  src += source->bytespp) {
483  xoffset += xscale - xindex;
484  if (xoffset > xext)
485  //clip to dest limit
486  xscale -= xoffset - xext;
487  if (shift == 0)
488  pixel = *src;
489  else if (shift > 0)
490  pixel = *src << shift;
491  else
492  pixel = *src >> (-shift);
493  for (; xindex < xscale; xindex++)
494  *destpix++ = pixel; //duplicate pixel
495  xindex = 0;
496  }
497  }
498  for (; yoffset < yext && yindex < scale; yindex++, yoffset++) {
499  dest->put_line (xdest, ydest + yoffset, xext, &bigline, 0);
500  }
501  yindex = 0;
502  }
503 }
Definition: img.h:325
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
void init(inT32 width)
Definition: img.h:343
int inT32
Definition: host.h:102
void put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1222
uinT8 * pixels
image pixels
Definition: img.h:328
inT8 bpp
bits per pixel
Definition: img.h:329
SIGNED char inT8
Definition: host.h:98
unsigned char uinT8
Definition: host.h:99
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
DLLSYM void fast_reduce_sub_image ( IMAGE source,
inT32  xstart,
inT32  ystart,
inT32  xext,
inT32  yext,
IMAGE dest,
inT32  xdest,
inT32  ydest,
inT32  scale,
BOOL8  adjust_grey 
)

Definition at line 516 of file imgs.cpp.

527  {
528  inT8 shift; //shift factor
529  inT32 xfactor; //run on x coord
530  inT32 divisor; //total cell area
531  inT32 xindex, yindex; //into averaging square
532  inT32 xcoord; //current x coord
533  inT32 destext; //destination size
534  inT32 yoffset; //current adjusted offset
535  uinT8 *pixel; //ptr to source pixels
536  inT32 *sums; //ptr to sums array
537  IMAGELINE copyline; //copy of line
538  inT32 *linesums; //averaging sums
539 
540  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
541  return;
542  if (xext <= 0)
543  xext = source->xsize; //default to all
544  if (xext > source->xsize - xstart)
545  //clip to smallest
546  xext = source->xsize - xstart;
547  if (xext > (dest->xsize - xdest) * scale)
548  xext = (dest->xsize - xdest) * scale;
549  if (yext <= 0)
550  yext = source->ysize; //default to all
551  if (yext > source->ysize - ystart)
552  //clip to smallest
553  yext = source->ysize - ystart;
554  if (yext > (dest->ysize - ydest) * scale)
555  yext = (dest->ysize - ydest) * scale;
556  if (xext <= 0 || yext <= 0)
557  return; //nothing to do
558 
559  xfactor = xext % scale; //left overs
560  if (xfactor == 0)
561  xfactor = scale;
562  //destination pixels
563  destext = (xext + scale - 1) / scale;
564  if (adjust_grey)
565  //shift factor
566  shift = dest->bps - source->bps;
567  else
568  shift = 0; //no adjustment
569  linesums = new inT32[destext * source->bytespp];
570 
571  for (yoffset = 0; yoffset < yext; ydest++) {
572  source->check_legal_access (xstart, ystart + yoffset, xext);
573  dest->check_legal_access (xdest, ydest, destext);
574  for (xindex = destext * source->bytespp - 1; xindex >= 0; xindex--)
575  linesums[xindex] = 0; //zero sums
576  for (yindex = 0; yindex < scale
577  && ystart + yoffset < source->ysize; yindex += 3) {
578  source->fast_get_line (xstart, ystart + yoffset, xext, &copyline);
579  pixel = copyline.pixels; //start of line
580  if (source->bpp == 24) {
581  for (xcoord = 1, sums = linesums; xcoord < destext;
582  xcoord++, sums += 3) {
583  for (xindex = 0; xindex < scale; xindex += 2) {
584  *sums += *pixel++;
585  *(sums + 1) += *pixel++;
586  *(sums + 2) += *pixel++;
587  pixel += 3;
588  }
589  if (scale & 1)
590  pixel -= 3; //correct position
591  }
592  for (xindex = 0; xindex < xfactor; xindex += 2) {
593  *sums += *pixel++;
594  *(sums + 1) += *pixel++;
595  *(sums + 2) += *pixel++;
596  pixel += 3;
597  }
598  }
599  else {
600  for (xcoord = 1, sums = linesums; xcoord < destext;
601  xcoord++, sums++) {
602  for (xindex = 0; xindex < scale; xindex += 2) {
603  *sums += *pixel;
604  pixel += 2;
605  }
606  if (scale & 1)
607  pixel--; //correct position
608  }
609  for (xindex = 0; xindex < xfactor; xindex += 2) {
610  *sums += *pixel;
611  pixel += 2;
612  }
613  }
614  yoffset += 3; //every 3 lines
615  }
616  if (yindex > scale)
617  yoffset -= yindex - scale; //back on right scale
618  copyline.init (); //set pixels back to array
619  copyline.bpp = source->bpp;
620  pixel = copyline.pixels;
621  //pixels in block
622  divisor = ((yindex + 2) / 3) * ((scale + 1) / 2);
623  if (shift <= 0) {
624  divisor <<= (-shift); //do greyscale correction
625  for (sums = linesums, xindex = (destext - 1) * source->bytespp;
626  xindex > 0; xindex--)
627  //turn to destination value
628  *pixel++ = (uinT8) (*sums++ / divisor);
629  for (xindex = source->bytespp; xindex > 0; xindex--)
630  *pixel++ = *sums++
631  / (((yindex + 2) / 3) * ((xfactor + 1) / 2) << (-shift));
632  //lastone different
633  }
634  else {
635  for (sums = linesums, xindex = (destext - 1) * source->bytespp;
636  xindex > 0; xindex--)
637  *pixel++ = (uinT8) ((*sums++ << shift) / divisor);
638  //destination value
639  for (xindex = source->bytespp; xindex > 0; xindex--)
640  //last one different
641  *pixel++ = (*(sums++) << shift) / (((yindex + 2) / 3) * ((xfactor + 1) / 2));
642  }
643  //put in destination
644  dest->put_line (xdest, ydest, destext, &copyline, 0);
645  }
646  delete [] linesums;
647 }
Definition: img.h:325
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
void init(inT32 width)
Definition: img.h:343
int inT32
Definition: host.h:102
void put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1222
uinT8 * pixels
image pixels
Definition: img.h:328
inT8 bpp
bits per pixel
Definition: img.h:329
SIGNED char inT8
Definition: host.h:98
unsigned char uinT8
Definition: host.h:99
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
DLLSYM void invert_image ( IMAGE image)

Definition at line 797 of file imgs.cpp.

799  {
800  uinT8 mask; //bit mask
801  uinT8 bytespp; //bytes per pixel
802  inT32 xsize, ysize; /*size of image */
803  inT32 xindex, yindex; /*index into image */
804  uinT8 *pixel; /*current pixel */
805  IMAGELINE line; /*line of image */
806 
807  bytespp = image->get_bpp () == 24 ? 3 : 1;
808  xsize = image->get_xsize (); /*find sizes */
809  ysize = image->get_ysize ();
810  //pixel mask
811  mask = (1 << image->get_bpp ()) - 1;
812  /*do each line */
813  for (yindex = ysize - 1; yindex >= 0; yindex--) {
814  image->fast_get_line (0, yindex, xsize, &line);
815  for (pixel = line.pixels, xindex = xsize * bytespp; xindex > 0;
816  xindex--) {
817  *pixel = (*pixel) ^ mask; //invert image only
818  ++pixel;
819  }
820  /*put it back */
821  image->fast_put_line (0, yindex, xsize, &line);
822  }
823 }
Definition: img.h:325
int inT32
Definition: host.h:102
inT32 get_ysize()
Definition: img.h:99
uinT8 * pixels
image pixels
Definition: img.h:328
inT8 get_bpp()
Definition: img.h:106
unsigned char uinT8
Definition: host.h:99
inT32 get_xsize()
Definition: img.h:92
void fast_put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:1203
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
DLLSYM void reduce_sub_image ( IMAGE source,
inT32  xstart,
inT32  ystart,
inT32  xext,
inT32  yext,
IMAGE dest,
inT32  xdest,
inT32  ydest,
inT32  scale,
BOOL8  adjust_grey 
)

Definition at line 658 of file imgs.cpp.

669  {
670  inT8 shift; //shift factor
671  inT32 xfactor; //run on x coord
672  inT32 divisor; //total cell area
673  inT32 div2; //total cell area divided by 2
674  inT32 xindex, yindex; //into averaging square
675  inT32 xcoord; //current x coord
676  inT32 destext; //destination size
677  inT32 yoffset; //current adjusted offset
678  uinT8 *pixel; //ptr to source pixels
679  inT32 *sums; //ptr to sums array
680  IMAGELINE copyline; //copy of line
681  inT32 *linesums; //averaging sums
682 
683  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
684  return;
685  if (xext <= 0)
686  xext = source->xsize; //default to all
687  if (xext > source->xsize - xstart)
688  //clip to smallest
689  xext = source->xsize - xstart;
690  if (xext > (dest->xsize - xdest) * scale)
691  xext = (dest->xsize - xdest) * scale;
692  if (yext <= 0)
693  yext = source->ysize; //default to all
694  if (yext > source->ysize - ystart)
695  //clip to smallest
696  yext = source->ysize - ystart;
697  if (yext > (dest->ysize - ydest) * scale)
698  yext = (dest->ysize - ydest) * scale;
699  if (xext <= 0 || yext <= 0)
700  return; //nothing to do
701 
702  xfactor = xext % scale; //left overs
703  if (xfactor == 0)
704  xfactor = scale;
705  //destination pixels
706  destext = (xext + scale - 1) / scale;
707  if (adjust_grey)
708  //shift factor
709  shift = dest->bps - source->bps;
710  else
711  shift = 0; //no adjustment
712  linesums = new inT32[destext * source->bytespp];
713 
714  for (yoffset = 0; yoffset < yext; ydest++) {
715  source->check_legal_access (xstart, ystart + yoffset, xext);
716  dest->check_legal_access (xdest, ydest, destext);
717  for (xindex = 0; xindex < (destext) * source->bytespp; xindex++)
718  linesums[xindex] = 0; //zero sums
719  for (yindex = 0; yindex < scale && ystart + yoffset < source->ysize;
720  yindex++) {
721  source->fast_get_line (xstart, ystart + yoffset, xext, &copyline);
722  pixel = copyline.pixels; //start of line
723  if (source->bpp == 24) {
724  for (xcoord = 1, sums = linesums; xcoord < destext;
725  xcoord++, sums += 3) {
726  for (xindex = 0; xindex < scale; xindex++) {
727  *sums += *pixel++;
728  *(sums + 1) += *pixel++;
729  *(sums + 2) += *pixel++;
730  }
731  }
732  for (xindex = 0; xindex < xfactor; xindex++) {
733  *sums += *pixel++;
734  *(sums + 1) += *pixel++;
735  *(sums + 2) += *pixel++;
736  }
737  }
738  else {
739  for (xcoord = 1, sums = linesums; xcoord < destext;
740  xcoord++, sums++) {
741  for (xindex = 0; xindex < scale; xindex++)
742  *sums += *pixel++;
743  }
744  for (xindex = 0; xindex < xfactor; xindex++)
745  *sums += *pixel++;
746  }
747  yoffset++; //next line
748  }
749  copyline.init (); //set pixels back to array
750  copyline.set_bpp (source->bpp);
751  pixel = copyline.pixels;
752  divisor = yindex * scale;
753  if (divisor == 0) {
754  tprintf
755  ("Impossible:divisor=0!, yindex=%d, scale=%d, yoffset=%d,yext=%d\n",
756  yindex, scale, yoffset, yext);
757  break;
758  }
759  if (shift <= 0) {
760  divisor <<= (-shift); //do greyscale correction
761  div2 = divisor / 2;
762  for (sums = linesums, xindex = (destext - 1) * source->bytespp;
763  xindex > 0; xindex--)
764  *pixel++ = (uinT8) ((div2 + *sums++) / divisor);
765  //turn to destination value
766  div2 = (yindex * xfactor << (-shift)) / 2;
767  for (xindex = source->bytespp; xindex > 0; xindex--)
768  *pixel++ =
769  (uinT8) ((div2 + *sums++) / (yindex * xfactor << (-shift)));
770  //lastone different
771  }
772  else {
773  div2 = divisor / 2;
774  for (sums = linesums, xindex = (destext - 1) * source->bytespp;
775  xindex > 0; xindex--)
776  *pixel++ = (uinT8) ((div2 + (*sums++ << shift)) / divisor);
777  //destination value
778  div2 = (yindex * xfactor) / 2;
779  for (xindex = source->bytespp; xindex > 0; xindex--)
780  *pixel++ =
781  (uinT8) ((div2 + (*sums++ << shift)) / (yindex * xfactor));
782  //last one different
783  }
784  //put in destination
785  dest->put_line (xdest, ydest, destext, &copyline, 0);
786  }
787  delete [] linesums;
788 }
Definition: img.h:325
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
void init(inT32 width)
Definition: img.h:343
int inT32
Definition: host.h:102
void set_bpp(inT8 new_bpp)
Definition: img.h:362
void put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1222
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
uinT8 * pixels
image pixels
Definition: img.h:328
SIGNED char inT8
Definition: host.h:98
unsigned char uinT8
Definition: host.h:99
void fast_get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf)
Definition: imgs.cpp:978
DLLSYM void starbase_to_normal ( IMAGE source,
inT32  xstart,
inT32  ystart,
inT32  xext,
inT32  yext,
IMAGE dest,
inT32  xdest,
inT32  ydest,
BOOL8  preserve_grey 
)

Definition at line 882 of file imgs.cpp.

892  {
893  IMAGELINE copyline; //copy of line
894  uinT8 *copy; //source pointer
895  inT8 shift4; //shift factor
896  inT8 shift6; //shift factor
897  inT8 colour_shift; //shift of colours
898  uinT8 white_level; //dest white value
899  inT32 pixel; //pixel index
900  inT32 y; //line index
901  inT32 yoffset; //current adjusted offset
902  inT8 srcppb; //pixels per byte
903 
904  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
905  return;
906  if (xext <= 0)
907  xext = source->get_xsize (); //default to all
908  if (xext > source->get_xsize () - xstart)
909  //clip to smallest
910  xext = source->get_xsize () - xstart;
911  if (xext > dest->get_xsize () - xdest)
912  xext = dest->get_xsize () - xdest;
913  if (yext <= 0)
914  yext = source->get_ysize (); //default to all
915  if (yext > source->get_ysize () - ystart)
916  //clip to smallest
917  yext = source->get_ysize () - ystart;
918  if (yext > dest->get_ysize () - ydest)
919  yext = dest->get_ysize () - ydest;
920  if (xext <= 0 || yext <= 0)
921  return; //nothing to do
922 
923  //pixels per byte
924  srcppb = 8 / source->get_bpp ();
925  shift4 = 4 - dest->get_bpp (); //for different bpps
926  shift6 = 6 - dest->get_bpp ();
927  //for grey preserve
928  colour_shift = 8 - dest->get_bpp ();
929  white_level = dest->get_white_level ();
930  for (y = 0; y < yext; y++) {
931  if (ystart >= ydest)
932  yoffset = y; //top down
933  else
934  yoffset = yext - y - 1; //bottom up
935  source->check_legal_access (xstart, ystart + yoffset, xext);
936  dest->check_legal_access (xdest, ydest + yoffset, xext);
937  source->get_line (xstart, ystart + yoffset, xext, &copyline, 0);
938  for (pixel = 0, copy = copyline.pixels; pixel < xext; pixel++) {
939  if (*copy < FIXED_COLOURS && preserve_grey)
940  *copy = grey_scales[*copy] >> colour_shift;
941  else if (*copy < FIXED_COLOURS) {
942  if (*copy == BLACK_PIX)
943  *copy = white_level; //black->white
944  else
945  *copy = 0; //others->black
946  }
947  else if (*copy >= MIN_4BIT && *copy < MAX_4BIT) {
948  if (shift4 < 0)
949  *copy = (*copy - MIN_4BIT) << (-shift4);
950  else
951  *copy = (*copy - MIN_4BIT) >> shift4;
952  }
953  else if (*copy >= MIN_6BIT && *copy < MAX_6BIT) {
954  if (shift6 < 0)
955  *copy = (*copy - MIN_6BIT) << (-shift6);
956  else
957  *copy = (*copy - MIN_6BIT) >> shift6;
958  }
959  else {
960  *copy = white_level; //white the rest
961  }
962  copy++;
963  }
964  dest->put_line (xdest, ydest + yoffset, xext, &copyline, 0);
965  }
966 }
#define MIN_4BIT
Definition: imgs.cpp:46
Definition: img.h:325
void check_legal_access(inT32 x, inT32 y, inT32 xext)
Definition: imgs.cpp:1484
int inT32
Definition: host.h:102
#define MAX_4BIT
Definition: imgs.cpp:47
#define MAX_6BIT
Definition: imgs.cpp:49
void put_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1222
inT32 get_ysize()
Definition: img.h:99
const uinT8 grey_scales[FIXED_COLOURS]
Definition: imgs.cpp:52
uinT8 get_white_level()
Definition: img.h:121
uinT8 * pixels
image pixels
Definition: img.h:328
SIGNED char inT8
Definition: host.h:98
void get_line(inT32 x, inT32 y, inT32 width, IMAGELINE *linebuf, inT32 margins)
Definition: imgs.cpp:1003
inT8 get_bpp()
Definition: img.h:106
unsigned char uinT8
Definition: host.h:99
inT32 get_xsize()
Definition: img.h:92
#define BLACK_PIX
Definition: imgs.cpp:50
#define FIXED_COLOURS
Definition: imgs.cpp:45
#define MIN_6BIT
Definition: imgs.cpp:48

Variable Documentation

const uinT8 grey_scales[FIXED_COLOURS]
Initial value:
= {
0, 255, 76, 227, 151, 179, 28, 104,
149, 72, 215, 67, 53, 44, 156, 137,
110, 153, 79, 181, 166, 218, 55, 81,
129, 105, 179, 149, 168, 69, 84, 126
}

Definition at line 52 of file imgs.cpp.

EXTERN int image_default_resolution = 300

"Image resolution dpi"

Definition at line 64 of file imgs.cpp.