home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GZCOLOR.H < prev    next >
C/C++ Source or Header  |  1992-07-17  |  5KB  |  133 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gzcolor.h */
  21. /* Private definition of color representation for Ghostscript */
  22. #include "gscolor.h"            /* client interface */
  23. #include "gxlum.h"
  24.  
  25. /* Colors as seen by clients. */
  26. /* The color parameters are stored internally as color_params. */
  27. typedef unsigned short color_param;
  28. /*
  29.  * The following line should read:
  30.  *    #define max_color_param max_ushort
  31.  * but this seems to trigger brain-damage in a number of compilers.
  32.  * The problems all seem to come up when the compiler has to cast this value
  33.  * to some other type, so we define all the relevant casted values explicitly:
  34.  */
  35. #define max_color_param ((ushort)0xffff)
  36. #define max_color_param_long 0xffffL
  37. #define max_color_param_float ((float)0xffffL)
  38. /* Color_param_bits must be between 8 and 16. */
  39. #define color_param_bits 16
  40. /* Convert a byte to or from a color_param efficiently. */
  41. #define color_param_from_byte(b)\
  42.   (((ushort)(b) << (color_param_bits - 8)) + ((b) >> (16 - color_param_bits)))
  43. #define color_param_to_byte(p)\
  44.   ((p) >> (color_param_bits - 8))
  45.  
  46. /*
  47.  * The following members are used in the structure, depending on the space:
  48.  *    DeviceGray    red, green, blue (all equal)
  49.  *    DeviceRGB    red, green, blue
  50.  *    DeviceCMYK    red, green, blue, not_black (not used yet)
  51.  * luminance is also used for all of the above.
  52.  * Note that red, green, and blue are used even for DeviceCMYK;
  53.  * this is somewhat bogus and will be fixed when we really implement CMYK.
  54.  */
  55. /*typedef struct gs_color_s gs_color;*/    /* in gscolor.h */
  56. struct gs_color_s {
  57.     color_param red, green, blue;    /* RGB/~CMY */
  58.     color_param not_black;        /* ~K (not used yet) */
  59.     color_param luminance;        /* computed luminance */
  60.     byte /*gs_color_space_type*/ space;    /* see above */
  61.     unsigned is_gray : 1;        /* quick test for gray */
  62.                     /* (red==green==blue) */
  63.     unsigned unused : 6;
  64.     unsigned luminance_set : 1;    /* true if luminance is set */
  65. };
  66. extern color_param gx_color_luminance(P1(struct gs_color_s *));
  67. #define color_luminance(pcolor)\
  68.     ((pcolor)->luminance_set ? (pcolor)->luminance :\
  69.      gx_color_luminance(pcolor))
  70.  
  71. /*
  72.  * The following parameters are computed from the above,
  73.  * and kept current through changes in transfer function or device.
  74.  * If the halftone is a colored tile, color1 == color2 == gx_no_color_index,
  75.  * and halftone_level == -1.  (Colored tiles are not currently used.)
  76.  */
  77. typedef struct gx_device_color_s gx_device_color;
  78. struct gx_device_color_s {
  79.     gx_color_index color1;        /* device color, or */
  80.                     /* darker color for halftoning */
  81.     gx_color_index color2;        /* lighter color for halftoning */
  82.     int halftone_level;        /* number of spots to whiten */
  83.                     /* when halftoning, 0 if */
  84.                     /* halftoning not needed, */
  85.                     /* <0 if color halftone */
  86.     struct gx_bitmap_s *tile;    /* pointer to cached halftone */
  87. };
  88. #define color_is_pure(pdevc)\
  89.   ((pdevc)->halftone_level == 0)
  90. #define color_is_color_halftone(pdevc)\
  91.   ((pdevc)->halftone_level < 0)
  92.  
  93. /* A fast version of gz_fill_rectangle. */
  94. /* Note that it takes additional arguments. */
  95. #define gz_fill_rectangle_open(dev, xi, yi, w, h, fill_proc, tile_proc, pdevc, pgs)\
  96.   (color_is_pure(pdevc) ?\
  97.     (*fill_proc)(dev, xi, yi, w, h, pdevc->color1) :\
  98.     (*tile_proc)(dev, pdevc->tile, xi, yi, w, h,\
  99.     pdevc->color1, pdevc->color2,\
  100.     pgs->phase_mod.x, pgs->phase_mod.y) )
  101.  
  102. /* Procedures in gxcolor.c used elsewhere. */
  103. void    gx_set_gray_only(P2(gs_color *, color_param)),
  104.     gx_set_rgb_only(P4(gs_color *, color_param, color_param, color_param));
  105. color_param    gx_color_unit_param(P1(floatp));
  106.  
  107. /* A color transfer function and cache. */
  108. /* log2... must not be greater than color_param_bits. */
  109. #define log2_transfer_map_size 8
  110. #define transfer_map_size (1 << log2_transfer_map_size)
  111. typedef struct gx_transfer_map_s {
  112.     gs_transfer_proc proc;
  113.     color_param values[transfer_map_size];
  114. } gx_transfer_map;
  115. typedef struct gx_transfer_s {
  116.     int ref_count;            /* # of references from gstates */
  117.     gx_transfer_map red, green, blue, gray;
  118. } gx_transfer;
  119.  
  120. /* Map a color_param or byte through a transfer map. */
  121. extern color_param gx_color_param_map(P2(color_param, const color_param *));
  122. #define gx_map_color_param(pgs,cp,m)\
  123.   gx_color_param_map(cp, &pgs->transfer->m.values[0])
  124. #if log2_transfer_map_size <= 8
  125. #  define byte_to_tmx(b) ((b) >> (8 - log2_transfer_map_size))
  126. #else
  127. #  define byte_to_tmx(b)\
  128.     (((b) << (log2_transfer_map_size - 8)) +\
  129.      ((b) >> (16 - log2_transfer_map_size)))
  130. #endif
  131. #define gx_map_color_param_byte(pgs,b,m)\
  132.  (pgs->transfer->m.values[byte_to_tmx(b)])
  133.