Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 1989, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gxcmap.h,v 1.12 2004/10/01 23:35:02 ghostgum Exp $ */
18
/* Color mapping procedures */
19
/* Requires gxdcolor.h. */
20
 
21
#ifndef gxcmap_INCLUDED
22
#  define gxcmap_INCLUDED
23
 
24
#include "gscsel.h"
25
#include "gxfmap.h"
26
 
27
#ifndef gx_device_DEFINED
28
#  define gx_device_DEFINED
29
typedef struct gx_device_s gx_device;
30
#endif
31
#ifndef gx_device_color_DEFINED
32
#  define gx_device_color_DEFINED
33
typedef struct gx_device_color_s gx_device_color;
34
#endif
35
 
36
/* Procedures for rendering colors specified by fractions. */
37
 
38
#define cmap_proc_gray(proc)\
39
  void proc(frac, gx_device_color *, const gs_imager_state *,\
40
	    gx_device *, gs_color_select_t)
41
#define cmap_proc_rgb(proc)\
42
  void proc(frac, frac, frac, gx_device_color *, const gs_imager_state *,\
43
	    gx_device *, gs_color_select_t)
44
#define cmap_proc_cmyk(proc)\
45
  void proc(frac, frac, frac, frac, gx_device_color *,\
46
	    const gs_imager_state *, gx_device *, gs_color_select_t)
47
#define cmap_proc_rgb_alpha(proc)\
48
  void proc(frac, frac, frac, frac, gx_device_color *,\
49
	       const gs_imager_state *, gx_device *, gs_color_select_t)
50
#define cmap_proc_separation(proc)\
51
  void proc(frac, gx_device_color *, const gs_imager_state *,\
52
	       gx_device *, gs_color_select_t)
53
#define cmap_proc_devicen(proc)\
54
  void proc(const frac *, gx_device_color *, const gs_imager_state *, \
55
	       gx_device *, gs_color_select_t)
56
#define cmap_proc_is_halftoned(proc)\
57
  bool proc(const gs_imager_state *, gx_device *)
58
 
59
/*
60
 * List of mapping functions from the standard color spaces to the
61
 * device color model. Any unused component will be mapped to 0.
62
 */
63
#define cm_map_proc_gray(proc) \
64
    void proc (gx_device * dev, frac gray, \
65
              frac * out)
66
 
67
#define cm_map_proc_rgb(proc) \
68
    void proc (gx_device * dev, \
69
	      const gs_imager_state *pis, \
70
              frac r, frac g, frac b, \
71
              frac * out)
72
 
73
#define cm_map_proc_cmyk(proc) \
74
    void proc (gx_device * dev, \
75
              frac c, frac m, frac y, frac k, \
76
              frac * out)
77
 
78
/*
79
 * The following procedures come from the device.  It they are
80
 * specified then  they are used to convert from the given
81
 * color space to the device's color model.  Otherwise the
82
 * standard conversions are used.  The procedures must be defined
83
 * for a DeviceN color model
84
 *
85
 * Because of a bug in the Watcom C compiler, we have to split the
86
 * struct from the typedef.
87
 */
88
struct gx_cm_color_map_procs_s {
89
    cm_map_proc_gray((*map_gray));
90
    cm_map_proc_rgb((*map_rgb));
91
    cm_map_proc_cmyk((*map_cmyk));
92
};
93
 
94
typedef struct gx_cm_color_map_procs_s  gx_cm_color_map_procs;
95
 
96
/*
97
 * Make some routine global for use in the forwarding device.
98
 */
99
cm_map_proc_gray(gray_cs_to_gray_cm);
100
cm_map_proc_rgb(rgb_cs_to_rgb_cm);
101
cm_map_proc_cmyk(cmyk_cs_to_cmyk_cm);
102
 
103
/*
104
 * Color mapping may now be device specific, so the color space
105
 * to color model mapping is separated from other maps, such as
106
 * applying the current transfer function or halftone.
107
 *
108
 * The routine pointed to by get_cmap_procs (a field in the image
109
 * state; see gxistate.h) should initialize the cm_color_map_procs
110
 * pointer, using the get_color_mapping_procs method of the device.
111
 *
112
 * Because of a bug in the Watcom C compiler, we have to split the
113
 * struct from the typedef.
114
 */
115
struct gx_color_map_procs_s {
116
    cmap_proc_gray((*map_gray));
117
    cmap_proc_rgb((*map_rgb));
118
    cmap_proc_cmyk((*map_cmyk));
119
    cmap_proc_rgb_alpha((*map_rgb_alpha));
120
    cmap_proc_separation((*map_separation));
121
    cmap_proc_devicen((*map_devicen));
122
    cmap_proc_is_halftoned((*is_halftoned));
123
};
124
typedef struct gx_color_map_procs_s gx_color_map_procs;
125
 
126
/*
127
 * Determine the color mapping procedures for a device.  Even though this
128
 * does not currently use information from the imager state, it must be
129
 * a virtual procedure of the state for internal reasons.
130
 */
131
const gx_color_map_procs *
132
    gx_get_cmap_procs(const gs_imager_state *, const gx_device *);
133
const gx_color_map_procs *
134
    gx_default_get_cmap_procs(const gs_imager_state *, const gx_device *);
135
 
136
/*
137
 * Set the color mapping procedures in the graphics state.  This is
138
 * currently only needed when switching devices, but might be used more
139
 * often in the future.
140
 */
141
void gx_set_cmap_procs(gs_imager_state *, const gx_device *);
142
 
143
/* Remap a concrete (frac) gray, RGB or CMYK color. */
144
/* These cannot fail, and do not return a value. */
145
#define gx_remap_concrete_gray(cgray, pdc, pis, dev, select)\
146
  ((pis)->cmap_procs->map_gray)(cgray, pdc, pis, dev, select)
147
#define gx_remap_concrete_rgb(cr, cg, cb, pdc, pis, dev, select)\
148
  ((pis)->cmap_procs->map_rgb)(cr, cg, cb, pdc, pis, dev, select)
149
#define gx_remap_concrete_cmyk(cc, cm, cy, ck, pdc, pis, dev, select)\
150
  ((pis)->cmap_procs->map_cmyk)(cc, cm, cy, ck, pdc, pis, dev, select)
151
#define gx_remap_concrete_rgb_alpha(cr, cg, cb, ca, pdc, pis, dev, select)\
152
  ((pis)->cmap_procs->map_rgb_alpha)(cr, cg, cb, ca, pdc, pis, dev, select)
153
#define gx_remap_concrete_separation(pcc, pdc, pis, dev, select)\
154
  ((pis)->cmap_procs->map_separation)(pcc, pdc, pis, dev, select)
155
#define gx_remap_concrete_devicen(pcc, pdc, pis, dev, select)\
156
  ((pis)->cmap_procs->map_devicen)(pcc, pdc, pis, dev, select)
157
 
158
/* Map a color */
159
#include "gxcindex.h"
160
#include "gxcvalue.h"
161
 
162
/*
163
 * These are the default routines for converting a color space into
164
 * a list of device colorants.
165
 */
166
extern cm_map_proc_gray(gx_default_gray_cs_to_gray_cm);
167
extern cm_map_proc_rgb(gx_default_rgb_cs_to_gray_cm);
168
extern cm_map_proc_cmyk(gx_default_cmyk_cs_to_gray_cm);
169
 
170
extern cm_map_proc_gray(gx_default_gray_cs_to_rgb_cm);
171
extern cm_map_proc_rgb(gx_default_rgb_cs_to_rgb_cm);
172
extern cm_map_proc_cmyk(gx_default_cmyk_cs_to_rgb_cm);
173
 
174
extern cm_map_proc_gray(gx_default_gray_cs_to_cmyk_cm);
175
extern cm_map_proc_rgb(gx_default_rgb_cs_to_cmyk_cm);
176
extern cm_map_proc_cmyk(gx_default_cmyk_cs_to_cmyk_cm);
177
 
178
extern cm_map_proc_gray(gx_default_gray_cs_to_cmyk_cm);
179
extern cm_map_proc_rgb(gx_default_rgb_cs_to_cmyk_cm);
180
extern cm_map_proc_cmyk(gx_default_cmyk_cs_to_cmyk_cm);
181
 
182
extern cm_map_proc_gray(gx_error_gray_cs_to_cmyk_cm);
183
extern cm_map_proc_rgb(gx_error_rgb_cs_to_cmyk_cm);
184
extern cm_map_proc_cmyk(gx_error_cmyk_cs_to_cmyk_cm);
185
 
186
 
187
/*
188
  Get the mapping procedures appropriate for the currently set
189
  color model.
190
 */
191
#define dev_t_proc_get_color_mapping_procs(proc, dev_t) \
192
    const gx_cm_color_map_procs * (proc)(const dev_t * dev)
193
 
194
#define dev_proc_get_color_mapping_procs(proc) \
195
    dev_t_proc_get_color_mapping_procs(proc, gx_device)
196
 
197
/*
198
  Define the options for the component_type parameter to get_color_comp_index
199
  routines.  Note:  This information is currently being used by the routines
200
  for identifying when they are being given a separation name.  Some devices
201
  automaticaly add separations to the device's components if the separation
202
  is not previously known and there is room in the device.
203
*/
204
#define NO_COMP_NAME_TYPE	0
205
#define SEPARATION_NAME		1
206
 
207
/*
208
  Convert a color component name into a colorant index.
209
*/
210
#define dev_t_proc_get_color_comp_index(proc, dev_t) \
211
    int (proc)(dev_t * dev, const char * pname, int name_size, int component_type)
212
 
213
#define dev_proc_get_color_comp_index(proc) \
214
    dev_t_proc_get_color_comp_index(proc, gx_device)
215
 
216
/*
217
  Map a color into the device's color model.
218
*/
219
#define dev_t_proc_encode_color(proc, dev_t) \
220
    gx_color_index (proc)(dev_t * dev, const gx_color_value colors[])
221
 
222
#define dev_proc_encode_color(proc) \
223
    dev_t_proc_encode_color(proc, gx_device)
224
 
225
/*
226
  Map a color index from the device's current color model into a list of
227
  colorant values.
228
*/
229
#define dev_t_proc_decode_color(proc, dev_t) \
230
    int (proc)(dev_t * dev, gx_color_index cindex, gx_color_value colors[])
231
 
232
#define dev_proc_decode_color(proc) \
233
    dev_t_proc_decode_color(proc, gx_device)
234
 
235
 
236
 
237
/*
238
 * These are the default routines for translating a color component
239
 * name into the device colorant index.
240
 */
241
dev_proc_get_color_comp_index(gx_error_get_color_comp_index);
242
dev_proc_get_color_comp_index(gx_default_DevGray_get_color_comp_index);
243
dev_proc_get_color_comp_index(gx_default_DevRGB_get_color_comp_index);
244
dev_proc_get_color_comp_index(gx_default_DevCMYK_get_color_comp_index);
245
dev_proc_get_color_comp_index(gx_default_DevRGBK_get_color_comp_index);
246
 
247
/*
248
 * These are the default routines for getting the color space conversion
249
 * routines.
250
 */
251
dev_proc_get_color_mapping_procs(gx_error_get_color_mapping_procs);
252
dev_proc_get_color_mapping_procs(gx_default_DevGray_get_color_mapping_procs);
253
dev_proc_get_color_mapping_procs(gx_default_DevRGB_get_color_mapping_procs);
254
dev_proc_get_color_mapping_procs(gx_default_DevCMYK_get_color_mapping_procs);
255
dev_proc_get_color_mapping_procs(gx_default_DevRGBK_get_color_mapping_procs);
256
 
257
/*
258
 * These are the default routines for converting a colorant value list
259
 * into a gx_color_index.
260
 */
261
dev_proc_encode_color(gx_error_encode_color);
262
dev_proc_encode_color(gx_default_encode_color);
263
 
264
/*
265
 * These are the default routines for converting a colorant value list
266
 * into a gx_color_index.
267
 */
268
dev_proc_encode_color(gx_default_gray_fast_encode);
269
dev_proc_encode_color(gx_default_gray_encode);
270
 
271
/*
272
 * This is the default encode_color routine for grayscale devices
273
 * that provide a map_rgb_color procedure, but don't themselves
274
 * provide encode_color.
275
 */
276
dev_proc_encode_color(gx_backwards_compatible_gray_encode);
277
 
278
/*
279
 * These are the default routines for converting a gx_color_index into
280
 * a list of device colorant values
281
 */
282
dev_proc_decode_color(gx_error_decode_color);
283
dev_proc_decode_color(gx_default_decode_color);
284
 
285
 
286
#define unit_frac(v, ftemp)\
287
  (ftemp = (v),\
288
   (is_fneg(ftemp) ? frac_0 : is_fge1(ftemp) ? frac_1 : float2frac(ftemp)))
289
 
290
#endif /* gxcmap_INCLUDED */