xref: /plan9/sys/src/cmd/gs/src/gxcspace.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1996, 2000 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: gxcspace.h,v 1.13 2004/08/04 19:36:12 stefan Exp $ */
18 /* Implementation of color spaces */
19 /* Requires gsstruct.h */
20 
21 #ifndef gxcspace_INCLUDED
22 #  define gxcspace_INCLUDED
23 
24 #include "gscspace.h"		/* client interface */
25 #include "gsccolor.h"
26 #include "gscsel.h"
27 #include "gxfrac.h"		/* for concrete colors */
28 
29 /* Define opaque types. */
30 
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 #ifndef gx_device_DEFINED
37 #  define gx_device_DEFINED
38 typedef struct gx_device_s gx_device;
39 #endif
40 
41 #ifndef stream_DEFINED
42 #  define stream_DEFINED
43 typedef struct stream_s stream;
44 #endif
45 
46 /* Color space types (classes): */
47 /*typedef struct gs_color_space_type_s gs_color_space_type; */
48 struct gs_color_space_type_s {
49 
50     gs_color_space_index index;
51 
52     /*
53      * Define whether the space can be the base space for an Indexed
54      * color space or the alternate space for a Separation or DeviceN
55      * color space.
56      */
57 
58     bool can_be_base_space;
59     bool can_be_alt_space;
60 
61     /*
62      * Define the true structure type for this variant of the color
63      * space union.
64      */
65 
66     gs_memory_type_ptr_t stype;
67 
68     /* ------ Procedures ------ */
69 
70     /*
71      * Define the number of components in a color of this space.  For
72      * Pattern spaces, where the number of components depends on the
73      * underlying space, this value is -1 for colored Patterns,
74      * -N-1 for uncolored Patterns, where N is the number of components
75      * in the base space.
76      */
77 
78 #define cs_proc_num_components(proc)\
79   int proc(const gs_color_space *)
80 #define cs_num_components(pcs)\
81   (*(pcs)->type->num_components)(pcs)
82 	cs_proc_num_components((*num_components));
83 
84     /*
85      * Return the base or alternate color space underlying this one.
86      * Only defined for Indexed, Separation, DeviceN, and
87      * uncolored Pattern spaces; returns NULL for all others.
88      */
89 
90 #define cs_proc_base_space(proc)\
91   const gs_color_space *proc(const gs_color_space *)
92 #define cs_base_space(pcs)\
93   (*(pcs)->type->base_space)(pcs)
94 	cs_proc_base_space((*base_space));
95 
96     /* Construct the initial color value for this space. */
97 
98 #define cs_proc_init_color(proc)\
99   void proc(gs_client_color *, const gs_color_space *)
100 #define cs_init_color(pcc, pcs)\
101   (*(pcs)->type->init_color)(pcc, pcs)
102 #define cs_full_init_color(pcc, pcs)\
103   ((pcc)->pattern = 0, cs_init_color(pcc, pcs))
104 	cs_proc_init_color((*init_color));
105 
106     /* Force a client color into its legal range. */
107 
108 #define cs_proc_restrict_color(proc)\
109   void proc(gs_client_color *, const gs_color_space *)
110 #define cs_restrict_color(pcc, pcs)\
111   ((pcs)->type->restrict_color(pcc, pcs))
112 	cs_proc_restrict_color((*restrict_color));
113 
114     /* Return the concrete color space underlying this one. */
115     /* (Not defined for Pattern spaces.) */
116 
117 #define cs_proc_concrete_space(proc)\
118   const gs_color_space *proc(const gs_color_space *,\
119 				const gs_imager_state *)
120 #define cs_concrete_space(pcs, pis)\
121   (*(pcs)->type->concrete_space)(pcs, pis)
122 	cs_proc_concrete_space((*concrete_space));
123 
124     /*
125      * Reduce a color to a concrete color.  A concrete color is one
126      * that the device can handle directly (possibly with halftoning):
127      * a DeviceGray/RGB/CMYK/Pixel color, or a Separation or DeviceN
128      * color that does not use the alternate space.
129      * (Not defined for Pattern spaces.)
130      */
131 
132 #define cs_proc_concretize_color(proc)\
133   int proc(const gs_client_color *, const gs_color_space *,\
134     frac *, const gs_imager_state *)
135 #define cs_concretize_color(pcc, pcs, values, pis)\
136   (*(pcs)->type->concretize_color)(pcc, pcs, values, pis)
137 	cs_proc_concretize_color((*concretize_color));
138 
139     /* Map a concrete color to a device color. */
140     /* (Only defined for concrete color spaces.) */
141 
142 #define cs_proc_remap_concrete_color(proc)\
143   int proc(const frac *, const gs_color_space * pcs, gx_device_color *,\
144 	const gs_imager_state *, gx_device *, gs_color_select_t)
145 	cs_proc_remap_concrete_color((*remap_concrete_color));
146 
147     /* Map a color directly to a device color. */
148 
149 #define cs_proc_remap_color(proc)\
150   int proc(const gs_client_color *, const gs_color_space *,\
151     gx_device_color *, const gs_imager_state *, gx_device *,\
152     gs_color_select_t)
153 	cs_proc_remap_color((*remap_color));
154 
155     /* Install the color space in a graphics state. */
156 
157 #define cs_proc_install_cspace(proc)\
158   int proc(const gs_color_space *, gs_state *)
159 	cs_proc_install_cspace((*install_cspace));
160 
161     /*
162      * Push the appropriate overprint compositor onto the current device.
163      * This is distinct from install_cspace as it may need to be called
164      * when the overprint parameter is changed.
165      *
166      * This routine need only be called if:
167      *   1. The color space or color model has changed, and overprint
168      *      is true.
169      *   2. The overprint mode setting has changed, and overprint is true.
170      *   3. The overprint mode setting has changed.
171      */
172 
173 #define cs_proc_set_overprint(proc)\
174   int proc(const gs_color_space *, gs_state *)
175 	cs_proc_set_overprint((*set_overprint));
176 
177     /* Adjust reference counts of indirect color space components. */
178 
179 #define cs_proc_adjust_cspace_count(proc)\
180   void proc(const gs_color_space *, int)
181 #define cs_adjust_cspace_count(pgs, delta)\
182   (*(pgs)->color_space->type->adjust_cspace_count)((pgs)->color_space, delta)
183 	cs_proc_adjust_cspace_count((*adjust_cspace_count));
184 
185     /* Adjust reference counts of indirect color components. */
186     /*
187      * Note: the color space argument may be NULL, which indicates that the
188      * caller warrants that any subsidiary colors don't have allocation
189      * issues.  This is a hack for an application that needs to be able to
190      * release Pattern colors.
191      */
192 
193 #define cs_proc_adjust_color_count(proc)\
194   void proc(const gs_client_color *, const gs_color_space *, int)
195 #define cs_adjust_color_count(pgs, delta)\
196   (*(pgs)->color_space->type->adjust_color_count)\
197     ((pgs)->ccolor, (pgs)->color_space, delta)
198 	cs_proc_adjust_color_count((*adjust_color_count));
199 
200 /* Adjust both reference counts. */
201 #define cs_adjust_counts(pgs, delta)\
202   (cs_adjust_color_count(pgs, delta), cs_adjust_cspace_count(pgs, delta))
203 
204     /* Serialization. */
205     /*
206      * Note : We don't include *(pcs)->type into serialization,
207      * because we assume it is a static constant to be processed separately.
208      */
209 
210 #define cs_proc_serialize(proc)\
211   int proc(const gs_color_space *, stream *)
212 #define cs_serialize(pcs, s)\
213   (*(pcs)->type->serialize)(pcs, s)
214 	cs_proc_serialize((*serialize));
215 
216     /* A color mapping linearity check. */
217 
218 #define cs_proc_is_linear(proc)\
219   int proc(gs_direct_color_space *cs, const gs_imager_state * pis,\
220 		gx_device *dev,\
221 		const gs_client_color *c0, const gs_client_color *c1,\
222 		const gs_client_color *c2, const gs_client_color *c3,\
223 		float smoothness)
224 #define cs_is_linear(pcs, pis, dev, c0, c1, c2, c3, smoothness)\
225   (*(pcs)->type->is_linear)(pcs, pis, dev, c0, c1, c2, c3, smoothness)
226 	cs_proc_is_linear((*is_linear));
227 };
228 
229 /* Standard color space structure types */
230 extern_st(st_base_color_space);
231 #define public_st_base_color_space()	/* in gscspace.c */\
232   gs_public_st_simple(st_base_color_space, gs_base_color_space,\
233     "gs_base_color_space")
234 /*extern_st(st_paint_color_space); *//* (not needed) */
235 
236 /* Standard color space procedures */
237 cs_proc_num_components(gx_num_components_1);
238 cs_proc_num_components(gx_num_components_3);
239 cs_proc_num_components(gx_num_components_4);
240 cs_proc_base_space(gx_no_base_space);
241 cs_proc_init_color(gx_init_paint_1);
242 cs_proc_init_color(gx_init_paint_3);
243 cs_proc_init_color(gx_init_paint_4);
244 cs_proc_restrict_color(gx_restrict01_paint_1);
245 cs_proc_restrict_color(gx_restrict01_paint_3);
246 cs_proc_restrict_color(gx_restrict01_paint_4);
247 cs_proc_concrete_space(gx_no_concrete_space);
248 cs_proc_concrete_space(gx_same_concrete_space);
249 cs_proc_concretize_color(gx_no_concretize_color);
250 cs_proc_remap_color(gx_default_remap_color);
251 cs_proc_install_cspace(gx_no_install_cspace);
252 cs_proc_set_overprint(gx_spot_colors_set_overprint);
253 cs_proc_adjust_cspace_count(gx_no_adjust_cspace_count);
254 cs_proc_adjust_color_count(gx_no_adjust_color_count);
255 cs_proc_serialize(gx_serialize_cspace_type);
256 cs_proc_is_linear(gx_cspace_no_linear);
257 cs_proc_is_linear(gx_cspace_is_linear_default);
258 
259 /*
260  * Define the implementation procedures for the standard device color
261  * spaces.  These are implemented in gxcmap.c.
262  */
263 cs_proc_remap_color(gx_remap_DeviceGray);
264 cs_proc_concretize_color(gx_concretize_DeviceGray);
265 cs_proc_remap_concrete_color(gx_remap_concrete_DGray);
266 cs_proc_remap_color(gx_remap_DeviceRGB);
267 cs_proc_concretize_color(gx_concretize_DeviceRGB);
268 cs_proc_remap_concrete_color(gx_remap_concrete_DRGB);
269 cs_proc_remap_color(gx_remap_DeviceCMYK);
270 cs_proc_concretize_color(gx_concretize_DeviceCMYK);
271 cs_proc_remap_concrete_color(gx_remap_concrete_DCMYK);
272 
273 /* Define the allocator type for color spaces. */
274 extern_st(st_color_space);
275 
276 /*
277  * Initialize the type and memory fields of a color space, possibly
278  * allocating it first.  This is only used by color space implementations.
279  */
280 void gs_cspace_init(gs_color_space *pcs,
281 		    const gs_color_space_type *pcstype,
282 		    gs_memory_t *mem, bool isheap);
283 int gs_cspace_alloc(gs_color_space **ppcspace,
284 		    const gs_color_space_type *pcstype,
285 		    gs_memory_t *mem);
286 
287 #endif /* gxcspace_INCLUDED */
288