1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: igstate.h 9043 2008-08-28 22:48:19Z giles $ */
15 /* Interpreter graphics state definition */
16 
17 #ifndef igstate_INCLUDED
18 #  define igstate_INCLUDED
19 
20 #include "gsstate.h"
21 #include "gxstate.h"		/* for 'client data' access */
22 #include "imemory.h"
23 #include "istruct.h"		/* for gstate obj definition */
24 #include "gxcindex.h"
25 
26 /*
27  * From the interpreter's point of view, the graphics state is largely opaque,
28  * i.e., the interpreter is just another client of the library.
29  * The interpreter does require additional items in the graphics state;
30  * these are "client data" from the library's point of view.
31  * Most of the complexity in this added state comes from
32  * the parameters associated with the various Level 2 color spaces.
33  * Note that the added information consists entirely of refs.
34  */
35 
36 /*
37  * The interpreter represents graphics state objects in a slightly
38  * unnatural way, namely, by a t_astruct ref that points to an object
39  * of type st_igstate_obj, which is essentially a t_struct ref that in turn
40  * points to a real graphics state (object of type st_gs_state).
41  * We do this so that save and restore can manipulate the intermediate
42  * object and not have to worry about copying entire gs_states.
43  *
44  * Because a number of different operators must test whether an object
45  * is a gstate, we make an exception to our convention of declaring
46  * structure descriptors only in the place where the structure itself
47  * is defined (see gsstruct.h for more information on this).
48  */
49 typedef struct igstate_obj_s {
50     ref gstate;			/* t_struct / st_gs_state */
51 } igstate_obj;
52 
53 extern_st(st_igstate_obj);
54 #define public_st_igstate_obj()	/* in zdps1.c */\
55   gs_public_st_ref_struct(st_igstate_obj, igstate_obj, "gstatetype")
56 #define igstate_ptr(rp) r_ptr(&r_ptr(rp, igstate_obj)->gstate, gs_state)
57 
58 /* DeviceN names and tint transform */
59 typedef struct ref_device_n_params_s {
60     ref layer_names, tint_transform;
61 } ref_device_n_params;
62 
63 /* CIE transformation procedures */
64 typedef struct ref_cie_procs_s {
65     union {
66 	ref DEFG;
67 	ref DEF;
68     } PreDecode;
69     union {
70 	ref ABC;
71 	ref A;
72     } Decode;
73     ref DecodeLMN;
74 } ref_cie_procs;
75 
76 /* CIE rendering transformation procedures */
77 typedef struct ref_cie_render_procs_s {
78     ref TransformPQR, EncodeLMN, EncodeABC, RenderTableT;
79 } ref_cie_render_procs;
80 
81 /* Separation name and tint transform */
82 typedef struct ref_separation_params_s {
83     ref layer_name, tint_transform;
84 } ref_separation_params;
85 
86 /* All color space parameters. */
87 /* All of these are optional. */
88 /* Note that they may actually be the parameters for an underlying or */
89 /* alternate space for a special space. */
90 typedef struct ref_color_procs_s {
91     ref_cie_procs cie;
92     union {
93 	ref_device_n_params device_n;
94 	ref_separation_params separation;
95 	ref index_proc;
96     } special;
97 } ref_color_procs;
98 typedef struct ref_colorspace_s {
99     ref array;			/* color space (array), only relevant if */
100 				/* the current color space has parameters */
101 				/* associated with it. */
102     ref_color_procs procs;	/* associated procedures/parameters, */
103 				/* only relevant for DeviceN, CIE, */
104 				/* Separation, Indexed/CIE, */
105 				/* Indexed with procedure, or a Pattern */
106 				/* with one of these. */
107 } ref_colorspace;
108 
109 #ifndef int_remap_color_info_DEFINED
110 #  define int_remap_color_info_DEFINED
111 typedef struct int_remap_color_info_s int_remap_color_info_t;
112 #endif
113 
114 typedef struct int_gstate_s {
115     ref dash_pattern_array;	/* (array) */
116     /* Screen_procs are only relevant if setscreen was */
117     /* executed more recently than sethalftone */
118     /* (for this graphics context). */
119     struct {
120 	ref red, green, blue, gray;
121     } screen_procs,		/* halftone screen procedures */
122           transfer_procs;	/* transfer procedures */
123     ref black_generation;	/* (procedure) */
124     ref undercolor_removal;	/* (procedure) */
125     ref_colorspace colorspace;
126     /*
127      * Pattern is relevant only if the current color space
128      * is a pattern space.
129      */
130     ref pattern;		/* pattern (dictionary) */
131     struct {
132 	ref dict;		/* CIE color rendering dictionary */
133 	ref_cie_render_procs procs;	/* (see above) */
134     } colorrendering;
135     /*
136      * Use_cie_color tracks the UseCIEColor parameter of the page
137      * device. This parameter may, during initialization, be read
138      * through the .getuseciecolor operator, and set (in Level 3)
139      * via the .setuseciecolor operator.
140      *
141      * Previously, the UseCIEColor color space substitution feature
142      * was implemented in the graphic library. It is now implemented
143      * strictly in the interpreter.
144      */
145     ref use_cie_color;
146     /*
147      * Halftone is relevant only if sethalftone was executed
148      * more recently than setscreen for this graphics context.
149      * setscreen sets it to null.
150      */
151     ref halftone;		/* halftone (dictionary) */
152     /*
153      * Pagedevice is only relevant if setpagedevice was executed more
154      * recently than nulldevice, setcachedevice, or setdevice with a
155      * non-page device (for this graphics context).  If the current device
156      * is not a page device, pagedevice is null.
157      */
158     ref pagedevice;		/* page device (dictionary|null) */
159     /*
160      * Remap_color_info is used temporarily to communicate the need for
161      * Pattern or DeviceNcolor remapping to the interpreter.  See
162      * e_RemapColor in ierrors.h.  The extra level of indirection through a
163      * structure is needed because the gstate passed to the PaintProc is
164      * different from the current gstate in the graphics state, and because
165      * the DeviceN color being remapped is not necessarily the current color
166      * in the graphics state (for shading or images): the structure is
167      * shared, so that the interpreter can get its hands on the remapping
168      * procedure.
169      */
170     ref remap_color_info;	/* t_struct (int_remap_color_info_t) */
171     /*
172      * The opacity and shape masks are a PDF 1.4 transparency feature,
173      * not standard PostScript.
174      */
175     ref opacity_mask, shape_mask; /* dictionary|null */
176 } int_gstate;
177 
178 #define clear_pagedevice(pigs) make_null(&(pigs)->pagedevice)
179 /*
180  * Even though the interpreter's part of the graphics state actually
181  * consists of refs, allocating it as refs tends to create sandbars;
182  * since it is always allocated and freed as a unit, we can treat it
183  * as an ordinary structure.
184  */
185 #define private_st_int_gstate()	/* in zgstate.c */\
186   gs_private_st_ref_struct(st_int_gstate, int_gstate, "int_gstate")
187 
188 /* Enumerate the refs in an int_gstate. */
189 /* Since all the elements of an int_gstate are refs, this is simple. */
190 #define int_gstate_map_refs(p,m)\
191  { register ref *rp_ = (ref *)(p);\
192    register int i = sizeof(int_gstate) / sizeof(ref);\
193    do { m(rp_); ++rp_; } while ( --i );\
194  }
195 
196 /* Create the gstate for a new context. */
197 /* We export this so that fork can use it. */
198 gs_state *int_gstate_alloc(const gs_dual_memory_t * dmem);
199 
200 /* Get the int_gstate from a gs_state. */
201 #define gs_int_gstate(pgs) ((int_gstate *)gs_state_client_data(pgs))
202 
203 /* The current instances for operators. */
204 #define igs (i_ctx_p->pgs)
205 #define istate gs_int_gstate(igs)
206 
207 #endif /* igstate_INCLUDED */
208