1 /* Copyright (C) 1995, 2000 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: gxistate.h,v 1.6.6.1.2.1 2003/01/17 00:49:04 giles Exp $ */
20 /* Imager state definition */
21 
22 #ifndef gxistate_INCLUDED
23 #  define gxistate_INCLUDED
24 
25 #include "gscsel.h"
26 #include "gsrefct.h"
27 #include "gsropt.h"
28 #include "gstparam.h"
29 #include "gxcvalue.h"
30 #include "gxcmap.h"
31 #include "gxfixed.h"
32 #include "gxline.h"
33 #include "gxmatrix.h"
34 #include "gxtmap.h"
35 
36 /*
37  * Define the subset of the PostScript graphics state that the imager
38  * library API needs.  The definition of this subset is subject to change
39  * as we come to understand better the boundary between the imager and
40  * the interpreter.  In particular, the imager state currently INCLUDES
41  * the following:
42  *      line parameters: cap, join, miter limit, dash pattern
43  *      transformation matrix (CTM)
44  *      logical operation: RasterOp, transparency
45  *      color modification: alpha, rendering algorithm
46  *	transparency information:
47  *	    blend mode
48  *	    (opacity + shape) (alpha + cached mask)
49  *	    text knockout flag
50  *	    rendering stack
51  *      overprint control: overprint flag and mode
52  *      rendering tweaks: flatness, fill adjustment, stroke adjust flag,
53  *        accurate curves flag, shading smoothness
54  *      color rendering information:
55  *          halftone, halftone phases
56  *          transfer functions
57  *          black generation, undercolor removal
58  *          CIE rendering tables
59  *          halftone and pattern caches
60  *	shared (constant) device color spaces
61  * The imager state currently EXCLUDES the following:
62  *      graphics state stack
63  *      default CTM
64  *      path
65  *      clipping path and stack
66  *      color specification: color, color space, substitute color spaces
67  *      font
68  *      device
69  *      caches for many of the above
70  */
71 
72 /*
73  * Define the color rendering state information.
74  * This should be a separate object (or at least a substructure),
75  * but making this change would require editing too much code.
76  */
77 
78 /* Opaque types referenced by the color rendering state. */
79 #ifndef gs_halftone_DEFINED
80 #  define gs_halftone_DEFINED
81 typedef struct gs_halftone_s gs_halftone;
82 #endif
83 #ifndef gx_device_color_DEFINED
84 #  define gx_device_color_DEFINED
85 typedef struct gx_device_color_s gx_device_color;
86 #endif
87 #ifndef gx_device_halftone_DEFINED
88 #  define gx_device_halftone_DEFINED
89 typedef struct gx_device_halftone_s gx_device_halftone;
90 #endif
91 
92 /*
93  * We need some special memory management for the components of a
94  * c.r. state, as indicated by the following notations on the elements:
95  *      (RC) means the element is reference-counted.
96  *      (Shared) means the element is shared among an arbitrary number of
97  *        c.r. states and is never freed.
98  *      (Owned) means exactly one c.r. state references the element,
99  *        and it is guaranteed that no references to it will outlive
100  *        the c.r. state itself.
101  */
102 
103 /* Define the interior structure of a transfer function. */
104 typedef struct gx_transfer_colored_s {
105     /* The components must be in this order: */
106     gx_transfer_map *red;	/* (RC) */
107     gx_transfer_map *green;	/* (RC) */
108     gx_transfer_map *blue;	/* (RC) */
109     gx_transfer_map *gray;	/* (RC) */
110 } gx_transfer_colored;
111 typedef union gx_transfer_s {
112     gx_transfer_map *indexed[4];	/* (RC) */
113     gx_transfer_colored colored;
114 } gx_transfer;
115 
116 #define gs_color_rendering_state_common\
117 \
118 		/* Halftone screen: */\
119 \
120 	gs_halftone *halftone;			/* (RC) */\
121 	gs_int_point screen_phase[gs_color_select_count];\
122 		/* dev_ht depends on halftone and device resolution. */\
123 	gx_device_halftone *dev_ht;		/* (RC) */\
124 		/* The contents of ht_cache depend on dev_ht. */\
125 	struct gx_ht_cache_s *ht_cache;		/* (Shared) by all gstates */\
126 \
127 		/* Color (device-dependent): */\
128 \
129 	struct gs_cie_render_s *cie_render;	/* (RC) may be 0 */\
130 	gx_transfer_map *black_generation;	/* (RC) may be 0 */\
131 	gx_transfer_map *undercolor_removal;	/* (RC) may be 0 */\
132 		/* set_transfer holds the transfer functions specified by */\
133 		/* set[color]transfer; effective_transfer includes the */\
134 		/* effects of overrides by TransferFunctions in halftone */\
135 		/* dictionaries.  (In Level 1 systems, set_transfer and */\
136 		/* effective_transfer are always the same.) */\
137 	gx_transfer set_transfer;		/* members are (RC) */\
138 	gx_transfer effective_transfer;		/* see below */\
139 \
140 		/* Color caches: */\
141 \
142 		/* cie_joint_caches depend on cie_render and */\
143 		/* the color space. */\
144 	struct gx_cie_joint_caches_s *cie_joint_caches;		/* (RC) */\
145 		/* cmap_procs depend on the device's color_info. */\
146 	const struct gx_color_map_procs_s *cmap_procs;		/* static */\
147 		/* The contents of pattern_cache depend on the */\
148 		/* the color space and the device's color_info and */\
149 		/* resolution. */\
150 	struct gx_pattern_cache_s *pattern_cache	/* (Shared) by all gstates */
151 
152 /*
153  * Enumerate the reference-counted pointers in a c.r. state.  Note that
154  * effective_transfer doesn't contribute to the reference count: it points
155  * either to the same objects as set_transfer, or to objects in a halftone
156  * structure that someone else worries about.
157  */
158 #define gs_cr_state_do_rc_ptrs(m)\
159   m(halftone) m(dev_ht) m(cie_render)\
160   m(black_generation) m(undercolor_removal)\
161   m(set_transfer.colored.red) m(set_transfer.colored.green)\
162   m(set_transfer.colored.blue) m(set_transfer.colored.gray)\
163   m(cie_joint_caches)
164 
165 /* Enumerate the pointers in a c.r. state. */
166 #define gs_cr_state_do_ptrs(m)\
167   m(0,halftone) m(1,dev_ht) m(2,ht_cache)\
168   m(3,cie_render) m(4,black_generation) m(5,undercolor_removal)\
169   m(6,set_transfer.colored.red) m(7,set_transfer.colored.green)\
170   m(8,set_transfer.colored.blue) m(9,set_transfer.colored.gray)\
171   m(10,effective_transfer.colored.red) m(11,effective_transfer.colored.green)\
172   m(12,effective_transfer.colored.blue) m(13,effective_transfer.colored.gray)\
173   m(14,cie_joint_caches) m(15,pattern_cache)
174 #define st_cr_state_num_ptrs 16
175 
176 /*
177  * Define constant values that can be allocated once and shared among
178  * all imager states in an address space.
179  */
180 #ifndef gs_color_space_DEFINED
181 #  define gs_color_space_DEFINED
182 typedef struct gs_color_space_s gs_color_space;
183 #endif
184 typedef union gx_device_color_spaces_s {
185     struct dcn_ {
186 	gs_color_space *Gray;
187 	gs_color_space *RGB;
188 	gs_color_space *CMYK;
189     } named;
190     gs_color_space *indexed[3];
191 } gx_device_color_spaces_t;
192 typedef struct gs_imager_state_shared_s {
193     rc_header rc;
194     gx_device_color_spaces_t device_color_spaces;
195 } gs_imager_state_shared_t;
196 
197 #define private_st_imager_state_shared()	/* in gsistate.c */\
198   gs_private_st_ptrs3(st_imager_state_shared, gs_imager_state_shared_t,\
199     "gs_imager_state_shared", imager_state_shared_enum_ptrs,\
200     imager_state_shared_reloc_ptrs, device_color_spaces.named.Gray,\
201     device_color_spaces.named.RGB, device_color_spaces.named.CMYK)
202 
203 /* Define the imager state structure itself. */
204 typedef struct gs_transparency_source_s {
205     float alpha;		/* constant alpha */
206     gs_transparency_mask_t *mask;
207 } gs_transparency_source_t;
208 #define gs_imager_state_common\
209 	gs_memory_t *memory;\
210 	void *client_data;\
211 	gs_imager_state_shared_t *shared;\
212 	gx_line_params line_params;\
213 	gs_matrix_fixed ctm;\
214 	gs_logical_operation_t log_op;\
215 	gx_color_value alpha;\
216 	gs_blend_mode_t blend_mode;\
217 	gs_transparency_source_t opacity, shape;\
218 	bool text_knockout;\
219 	gs_transparency_state_t *transparency_stack;\
220 	bool overprint;\
221 	int overprint_mode;\
222 	float flatness;\
223 	gs_fixed_point fill_adjust;	/* fattening for fill */\
224 	bool stroke_adjust;\
225 	bool accurate_curves;\
226 	float smoothness;\
227 	const gx_color_map_procs *\
228 	  (*get_cmap_procs)(P2(const gs_imager_state *, const gx_device *));\
229 	gs_color_rendering_state_common
230 #define st_imager_state_num_ptrs\
231   (st_line_params_num_ptrs + st_cr_state_num_ptrs + 5)
232 /* Access macros */
233 #define ctm_only(pis) (*(const gs_matrix *)&(pis)->ctm)
234 #define ctm_only_writable(pis) (*(gs_matrix *)&(pis)->ctm)
235 #define set_ctm_only(pis, mat) (*(gs_matrix *)&(pis)->ctm = (mat))
236 #define gs_init_rop(pis) ((pis)->log_op = lop_default)
237 #define gs_currentflat_inline(pis) ((pis)->flatness)
238 #define gs_currentlineparams_inline(pis) (&(pis)->line_params)
239 #define gs_current_logical_op_inline(pis) ((pis)->log_op)
240 #define gs_set_logical_op_inline(pis, lop) ((pis)->log_op = (lop))
241 
242 #ifndef gs_imager_state_DEFINED
243 #  define gs_imager_state_DEFINED
244 typedef struct gs_imager_state_s gs_imager_state;
245 #endif
246 
247 struct gs_imager_state_s {
248     gs_imager_state_common;
249 };
250 
251 /* Initialization for gs_imager_state */
252 #define gs_imager_state_initial(scale)\
253   0, 0, 0, { gx_line_params_initial },\
254    { scale, 0.0, 0.0, -(scale), 0.0, 0.0 },\
255   lop_default, gx_max_color_value, BLEND_MODE_Compatible,\
256    { 1.0, 0 }, { 1.0, 0 }, 0/*false*/, 0, 0/*false*/, 0, 1.0,\
257    { fixed_half, fixed_half }, 0/*false*/, 0/*false*/, 1.0,\
258   gx_default_get_cmap_procs
259 
260 /* The imager state structure is public only for subclassing. */
261 #define public_st_imager_state()	/* in gsistate.c */\
262   gs_public_st_composite(st_imager_state, gs_imager_state, "gs_imager_state",\
263     imager_state_enum_ptrs, imager_state_reloc_ptrs)
264 
265 /* Initialize an imager state, other than the parts covered by */
266 /* gs_imager_state_initial. */
267 int gs_imager_state_initialize(P2(gs_imager_state * pis, gs_memory_t * mem));
268 
269 /* Make a temporary copy of a gs_imager_state.  Note that this does not */
270 /* do all the necessary reference counting, etc. */
271 gs_imager_state *
272     gs_imager_state_copy(P2(const gs_imager_state * pis, gs_memory_t * mem));
273 
274 /* Increment reference counts to note that an imager state has been copied. */
275 void gs_imager_state_copied(P1(gs_imager_state * pis));
276 
277 /* Adjust reference counts before assigning one imager state to another. */
278 void gs_imager_state_pre_assign(P2(gs_imager_state *to,
279 				   const gs_imager_state *from));
280 
281 /* Free device color spaces.  Perhaps this should be declared elsewhere? */
282 void gx_device_color_spaces_free(P3(gx_device_color_spaces_t *pdcs,
283 				    gs_memory_t *mem, client_name_t cname));
284 
285 /* Release an imager state. */
286 void gs_imager_state_release(P1(gs_imager_state * pis));
287 
288 #endif /* gxistate_INCLUDED */
289