home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXIMAGE.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  7KB  |  172 lines

  1. /* Copyright (C) 1989, 1990, 1991, 1992, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gximage.h */
  20. /* Internal definitions for image rendering */
  21. /* Requires gxcpath.h, gxdevmem.h, gxdcolor.h, gzpath.h */
  22. #include "gscspace.h"
  23. #include "gsimage.h"
  24.  
  25. /* Interface for routine used to unpack and shuffle incoming samples. */
  26. /* The Unix C compiler can't handle typedefs for procedure */
  27. /* (as opposed to pointer-to-procedure) types, */
  28. /* so we have to do it with macros instead. */
  29. #define iunpack_proc(proc)\
  30.   void proc(P6(const gs_image_enum *penum, const sample_map *pmap, byte *bptr, const byte *data, uint dsize, uint inpos))
  31. /* Interface for routine used to render a (source) scan line. */
  32. #define irender_proc(proc)\
  33.   int proc(P4(gs_image_enum *penum, byte *buffer, uint w, int h))
  34.  
  35. /*
  36.  * Incoming samples may go through two different transformations:
  37.  *
  38.  *    - For N-bit input samples with N <= 8, N-to-8-bit expansion
  39.  *    may involve a lookup map.  Currently this map is either an
  40.  *    identity function or a subtraction from 1 (inversion).
  41.  *
  42.  *    - The 8-bit or frac expanded sample may undergo decoding (a linear
  43.  *    transformation) before being handed off to the color mapping
  44.  *    machinery.
  45.  *
  46.  * If the decoding function's range is [0..1], we fold it into the
  47.  * expansion lookup; otherwise we must compute it separately.
  48.  * For speed, we distinguish 3 different cases of the decoding step:
  49.  */
  50. typedef enum {
  51.     sd_none,        /* decoded during expansion */
  52.     sd_lookup,        /* use lookup_decode table */
  53.     sd_compute        /* compute using base and factor */
  54. } sample_decoding;
  55. typedef struct sample_map_s {
  56.  
  57.     /* The following union implements the expansion of sample */
  58.     /* values from N bits to 8, and a possible inversion. */
  59.  
  60.     union {
  61.  
  62.         bits32 lookup4x1to32[16]; /* 1 bit/sample, not spreading */
  63.         bits16 lookup2x2to16[16]; /* 2 bits/sample, not spreading */
  64.         byte lookup8[256];    /* 1 bit/sample, spreading [2] */
  65.                     /* 2 bits/sample, spreading [4] */
  66.                     /* 4 bits/sample [16] */
  67.                     /* 8 bits/sample [256] */
  68.  
  69.     } table;
  70.  
  71.     /* If an 8-bit fraction doesn't represent the decoded value */
  72.     /* accurately enough, but the samples have 4 bits or fewer, */
  73.     /* we precompute the decoded values into a table. */
  74.     /* Different entries are used depending on bits/sample: */
  75.     /*    1,8,12 bits/sample: 0,15    */
  76.     /*    2 bits/sample: 0,5,10,15    */
  77.     /*    4 bits/sample: all    */
  78.  
  79.     float decode_lookup[16];
  80. #define decode_base decode_lookup[0]
  81. #define decode_max decode_lookup[15]
  82.  
  83.     /* In the worst case, we have to do the decoding on the fly. */
  84.     /* The value is base + sample * factor, where the sample is */
  85.     /* an 8-bit (unsigned) integer or a frac. */
  86.  
  87.     double decode_factor;
  88.  
  89.     sample_decoding decoding;
  90.  
  91. } sample_map;
  92.  
  93. /* Decode an 8-bit sample into a floating point color component. */
  94. /* penum points to the gs_image_enum structure. */
  95. #define decode_sample(sample_value, cc, i)\
  96.   switch ( penum->map[i].decoding )\
  97.   {\
  98.   case sd_none:\
  99.     cc.paint.values[i] = (sample_value) * (1.0 / 255.0);  /* faster than / */\
  100.     break;\
  101.   case sd_lookup:    /* <= 4 significant bits */\
  102.     cc.paint.values[i] =\
  103.       penum->map[i].decode_lookup[(sample_value) >> 4];\
  104.     break;\
  105.   case sd_compute:\
  106.     cc.paint.values[i] =\
  107.       penum->map[i].decode_base + (sample_value) * penum->map[i].decode_factor;\
  108.   }
  109.  
  110. /* Main state structure */
  111. struct gs_image_enum_s {
  112.     /* We really want the map structure to be long-aligned, */
  113.     /* so we choose shorter types for some flags. */
  114.     /* Following are set at structure initialization */
  115.     int width;
  116.     int height;
  117.     int bps;            /* bits per sample: 1, 2, 4, 8, 12 */
  118.     int log2_xbytes;        /* log2(bytes per expanded sample): */
  119.                     /* 0 if bps <= 8, log2(sizeof(frac)) */
  120.                     /* if bps > 8 */
  121.     int spp;            /* samples per pixel: 1, 3, or 4 */
  122.     int num_planes;            /* spp if colors are separated, */
  123.                     /* 1 otherwise */
  124.     int spread;            /* num_planes << log2_xbytes */
  125.     int masked;            /* 0 = [color]image, 1 = imagemask */
  126.     fixed fxx, fxy, fyx, fyy;    /* fixed version of matrix */
  127.     iunpack_proc((*unpack));
  128.     irender_proc((*render));
  129.     gs_state *pgs;
  130.     gs_fixed_rect clip_box;        /* pgs->clip_path.path->bbox, */
  131.                     /* possibly translated */
  132.     byte *buffer;            /* for expanding samples to a */
  133.                     /* byte or frac */
  134.     uint buffer_size;
  135.     byte *line;            /* buffer for an output scan line */
  136.     uint line_size;
  137.     uint line_width;        /* width of line in device pixels */
  138.     uint bytes_per_row;        /* # of input bytes per row */
  139.                     /* (per plane, if spp == 1 and */
  140.                     /* num_planes > 1) */
  141.     byte never_clip;        /* true if entire image fits */
  142.     byte skewed;            /* true if image is skewed */
  143.                     /* or rotated */
  144.     byte slow_loop;            /* true if !(skewed | */
  145.                     /* imagemask with a halftone) */
  146.     byte device_color;        /* true if device color space and */
  147.                     /* standard decoding */
  148.     fixed adjust;            /* adjustment when rendering */
  149.                     /* characters */
  150.     gx_device_clip *clip_dev;    /* clipping device (if needed) */
  151.     /* Following are updated dynamically */
  152.     gs_const_string planes[4];    /* separated color data, */
  153.                 /* all planes have the same size */
  154.     int plane_index;        /* current plane index, [0..spp) */
  155.     uint byte_in_row;        /* current input byte position in row */
  156.     fixed xcur, ycur;        /* device x, y of current row */
  157.     int yci, hci;            /* integer y & height of row */
  158.                     /* (if no skew) */
  159.     int y;
  160.     /* The maps are set at initialization.  We put them here */
  161.     /* so that the scalars will have smaller offsets. */
  162.     sample_map map[4];
  163.     /* Entries 0 and 255 of the following are set at initialization */
  164.     /* for monochrome images; other entries are updated dynamically. */
  165.     gx_device_color dev_colors[256];
  166. #define icolor0 dev_colors[0]
  167. #define icolor1 dev_colors[255]
  168. };
  169. #define private_st_gs_image_enum() /* in gsimage.c */\
  170.   gs_private_st_composite(st_gs_image_enum, gs_image_enum, "gs_image_enum",\
  171.     image_enum_enum_ptrs, image_enum_reloc_ptrs)
  172.