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

  1. /* Copyright (C) 1989, 1992, 1993, 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. /* gxcmap.h */
  20. /* Private definition of color mapping for Ghostscript */
  21. /* Requires gxdcolor.h, gxdevice.h. */
  22. #include "gxfmap.h"
  23.  
  24. /* Procedures for rendering colors specified by fractions. */
  25.  
  26. #define cmap_proc_gray(proc)\
  27.   void proc(P3(frac, gx_device_color *, const gs_state *))
  28. #define cmap_proc_rgb(proc)\
  29.   void proc(P5(frac, frac, frac, gx_device_color *, const gs_state *))
  30. #define cmap_proc_cmyk(proc)\
  31.   void proc(P6(frac, frac, frac, frac, gx_device_color *, const gs_state *))
  32.  
  33. typedef struct gx_color_map_procs_s {
  34.     cmap_proc_gray((*map_gray));
  35.     cmap_proc_rgb((*map_rgb));
  36.     cmap_proc_cmyk((*map_cmyk));
  37. } gx_color_map_procs;
  38.  
  39. /* Set the color mapping procedures in the graphics state. */
  40. /* This is only needed when switching devices. */
  41. void gx_set_cmap_procs(P1(gs_state *));
  42.  
  43. /* Map a color, with optional tracing if we are debugging. */
  44. #ifdef DEBUG
  45. /* Use procedures in gxcmap.c */
  46. gx_color_index gx_proc_map_rgb_color(P4(gx_device *,
  47.   gx_color_value, gx_color_value, gx_color_value));
  48. gx_color_index gx_proc_map_rgb_alpha_color(P5(gx_device *,
  49.   gx_color_value, gx_color_value, gx_color_value, gx_color_value));
  50. gx_color_index gx_proc_map_cmyk_color(P5(gx_device *,
  51.   gx_color_value, gx_color_value, gx_color_value, gx_color_value));
  52. #  define gx_map_rgb_color(dev, vr, vg, vb)\
  53.      gx_proc_map_rgb_color(dev, vr, vg, vb)
  54. #  define gx_map_rgb_alpha_color(dev, vr, vg, vb, va)\
  55.      gx_proc_map_rgb_alpha_color(dev, vr, vg, vb, va)
  56. #  define gx_map_cmyk_color(dev, vc, vm, vy, vk)\
  57.      gx_proc_map_cmyk_color(dev, vc, vm, vy, vk)
  58. #else
  59. #  define gx_map_rgb_color(dev, vr, vg, vb)\
  60.      (*dev_proc(dev, map_rgb_color))(dev, vr, vg, vb)
  61. #  define gx_map_rgb_alpha_color(dev, vr, vg, vb, va)\
  62.      (*dev_proc(dev, map_rgb_alpha_color))(dev, vr, vg, vb, va)
  63. #  define gx_map_cmyk_color(dev, vc, vm, vy, vk)\
  64.      (*dev_proc(dev, map_cmyk_color))(dev, vc, vm, vy, vk)
  65. #endif
  66.  
  67. /* A color transfer function and cache. */
  68. /* This is also used for black generation and undercolor removal. */
  69. /* log2... must not be greater than frac_bits. */
  70. #define log2_transfer_map_size 8
  71. #define transfer_map_size (1 << log2_transfer_map_size)
  72. #ifndef gx_transfer_map_DEFINED
  73. #  define gx_transfer_map_DEFINED
  74. typedef struct gx_transfer_map_s gx_transfer_map;
  75. #endif
  76. struct gx_transfer_map_s {
  77.     frac_map(log2_transfer_map_size);
  78. };
  79. /* We export st_transfer_map for gscolor.c. */
  80. extern_st(st_transfer_map);
  81. #define public_st_transfer_map() /* in gsstate.c */\
  82.   gs_public_st_simple(st_transfer_map, gx_transfer_map, "gx_transfer_map")
  83.  
  84. /* Map a color fraction through a transfer map. */
  85. frac gx_color_frac_map(P2(frac, const frac *));
  86. #define gx_map_color_frac(pgs,cf,m)\
  87.   gx_color_frac_map(cf, &pgs->m->values[0])
  88. /****************
  89. #if log2_transfer_map_size <= 8
  90. #  define byte_to_tmx(b) ((b) >> (8 - log2_transfer_map_size))
  91. #else
  92. #  define byte_to_tmx(b)\
  93.     (((b) << (log2_transfer_map_size - 8)) +\
  94.      ((b) >> (16 - log2_transfer_map_size)))
  95. #endif
  96. #define gx_map_color_frac_byte(pgs,b,m)\
  97.  (pgs->m->values[byte_to_tmx(b)])
  98.  ****************/
  99.  
  100. /* Map a floating point value through a transfer map. */
  101. #define gx_map_color_float(pgs,v,m)\
  102.   (pgs->m->values[(int)((v) * transfer_map_size + 0.5)] / frac_1_float)
  103.