1 /* Copyright (C) 1995, 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: gxistate.h,v 1.23 2005/08/30 13:01:03 igor Exp $ */ 18 /* Imager state definition */ 19 20 #ifndef gxistate_INCLUDED 21 # define gxistate_INCLUDED 22 23 #include "gscsel.h" 24 #include "gsrefct.h" 25 #include "gsropt.h" 26 #include "gstparam.h" 27 #include "gxcvalue.h" 28 #include "gxcmap.h" 29 #include "gxfixed.h" 30 #include "gxline.h" 31 #include "gxmatrix.h" 32 #include "gxtmap.h" 33 #include "gscspace.h" 34 #include "gstrans.h" 35 36 /* 37 Define the subset of the PostScript graphics state that the imager library 38 API needs. The intended division between the two state structures is that 39 the imager state contain only information that (1) is not part of the 40 parameters for individual drawing commands at the gx_ interface (i.e., 41 will likely be different for each drawing call), and (2) is not an 42 artifact of the PostScript language (i.e., doesn't need to burden the 43 structure when it is being used for other imaging, specifically for 44 imaging a command list). While this criterion is somewhat fuzzy, it leads 45 us to INCLUDE the following state elements: 46 line parameters: cap, join, miter limit, dash pattern 47 transformation matrix (CTM) 48 logical operation: RasterOp, transparency 49 color modification: alpha, rendering algorithm 50 transparency information: 51 blend mode 52 (opacity + shape) (alpha + cached mask) 53 text knockout flag 54 rendering stack 55 overprint control: overprint flag, mode, and effective mode 56 rendering tweaks: flatness, fill adjustment, stroke adjust flag, 57 accurate curves flag, shading smoothness 58 color rendering information: 59 halftone, halftone phases 60 transfer functions 61 black generation, undercolor removal 62 CIE rendering tables 63 halftone and pattern caches 64 shared (constant) device color spaces 65 We EXCLUDE the following for reason #1 (drawing command parameters): 66 path 67 clipping path and stack 68 color specification: color, color space, substitute color spaces 69 font 70 device 71 We EXCLUDE the following for reason #2 (specific to PostScript): 72 graphics state stack 73 default CTM 74 clipping path stack 75 In retrospect, perhaps the device should have been included in the 76 imager state, but we don't think this change is worth the trouble now. 77 */ 78 79 /* 80 * Define the color rendering state information. 81 * This should be a separate object (or at least a substructure), 82 * but making this change would require editing too much code. 83 */ 84 85 /* Opaque types referenced by the color rendering state. */ 86 #ifndef gs_halftone_DEFINED 87 # define gs_halftone_DEFINED 88 typedef struct gs_halftone_s gs_halftone; 89 #endif 90 #ifndef gx_device_color_DEFINED 91 # define gx_device_color_DEFINED 92 typedef struct gx_device_color_s gx_device_color; 93 #endif 94 #ifndef gx_device_halftone_DEFINED 95 # define gx_device_halftone_DEFINED 96 typedef struct gx_device_halftone_s gx_device_halftone; 97 #endif 98 99 /* 100 * We need some special memory management for the components of a 101 * c.r. state, as indicated by the following notations on the elements: 102 * (RC) means the element is reference-counted. 103 * (Shared) means the element is shared among an arbitrary number of 104 * c.r. states and is never freed. 105 * (Owned) means exactly one c.r. state references the element, 106 * and it is guaranteed that no references to it will outlive 107 * the c.r. state itself. 108 */ 109 110 /* Define the interior structure of a transfer function. */ 111 typedef struct gx_transfer_s { 112 int red_component_num; 113 gx_transfer_map *red; /* (RC) */ 114 int green_component_num; 115 gx_transfer_map *green; /* (RC) */ 116 int blue_component_num; 117 gx_transfer_map *blue; /* (RC) */ 118 int gray_component_num; 119 gx_transfer_map *gray; /* (RC) */ 120 } gx_transfer; 121 122 #define gs_color_rendering_state_common\ 123 \ 124 /* Halftone screen: */\ 125 \ 126 gs_halftone *halftone; /* (RC) */\ 127 gs_int_point screen_phase[gs_color_select_count];\ 128 /* dev_ht depends on halftone and device resolution. */\ 129 gx_device_halftone *dev_ht; /* (RC) */\ 130 \ 131 /* Color (device-dependent): */\ 132 \ 133 struct gs_cie_render_s *cie_render; /* (RC) may be 0 */\ 134 gx_transfer_map *black_generation; /* (RC) may be 0 */\ 135 gx_transfer_map *undercolor_removal; /* (RC) may be 0 */\ 136 /* set_transfer holds the transfer functions specified by */\ 137 /* set[color]transfer; effective_transfer includes the */\ 138 /* effects of overrides by TransferFunctions in halftone */\ 139 /* dictionaries. (In Level 1 systems, set_transfer and */\ 140 /* effective_transfer are always the same.) */\ 141 gx_transfer set_transfer; /* members are (RC) */\ 142 gx_transfer_map *effective_transfer[GX_DEVICE_COLOR_MAX_COMPONENTS]; /* see below */\ 143 \ 144 /* Color caches: */\ 145 \ 146 /* cie_joint_caches depend on cie_render and */\ 147 /* the color space. */\ 148 struct gx_cie_joint_caches_s *cie_joint_caches; /* (RC) */\ 149 /* cmap_procs depend on the device's color_info. */\ 150 const struct gx_color_map_procs_s *cmap_procs; /* static */\ 151 /* DeviceN component map for current color space */\ 152 gs_devicen_color_map color_component_map;\ 153 /* The contents of pattern_cache depend on the */\ 154 /* the color space and the device's color_info and */\ 155 /* resolution. */\ 156 struct gx_pattern_cache_s *pattern_cache /* (Shared) by all gstates */ 157 158 /* 159 * Enumerate the reference-counted pointers in a c.r. state. Note that 160 * effective_transfer doesn't contribute to the reference count: it points 161 * either to the same objects as set_transfer, or to objects in a halftone 162 * structure that someone else worries about. 163 */ 164 #define gs_cr_state_do_rc_ptrs(m)\ 165 m(halftone) m(dev_ht) m(cie_render)\ 166 m(black_generation) m(undercolor_removal)\ 167 m(set_transfer.red) m(set_transfer.green)\ 168 m(set_transfer.blue) m(set_transfer.gray)\ 169 m(cie_joint_caches) 170 171 /* Enumerate the pointers in a c.r. state. */ 172 #define gs_cr_state_do_ptrs(m)\ 173 m(0,halftone) m(1,dev_ht)\ 174 m(2,cie_render) m(3,black_generation) m(4,undercolor_removal)\ 175 m(5,set_transfer.red) m(6,set_transfer.green)\ 176 m(7,set_transfer.blue) m(8,set_transfer.gray)\ 177 m(9,cie_joint_caches) m(10,pattern_cache) 178 /* 179 * We handle effective_transfer specially in gsistate.c since its pointers 180 * are not enumerated for garbage collection but they are are relocated. 181 */ 182 /* 183 * This count does not include the effective_transfer pointers since they 184 * are not enumerated for GC. 185 */ 186 #define st_cr_state_num_ptrs 11 187 188 189 typedef struct gs_devicen_color_map_s { 190 bool use_alt_cspace; 191 separation_type sep_type; 192 uint num_components; /* Input - Duplicate of value in gs_device_n_params */ 193 uint num_colorants; /* Number of colorants - output */ 194 gs_id cspace_id; /* Used to verify color space and map match */ 195 int color_map[GS_CLIENT_COLOR_MAX_COMPONENTS]; 196 } gs_devicen_color_map; 197 198 199 /* Define the imager state structure itself. */ 200 /* 201 * Note that the ctm member is a gs_matrix_fixed. As such, it cannot be 202 * used directly as the argument for procedures like gs_point_transform. 203 * Instead, one must use the ctm_only macro, e.g., &ctm_only(pis) rather 204 * than &pis->ctm. 205 */ 206 #define gs_imager_state_common\ 207 gs_memory_t *memory;\ 208 void *client_data;\ 209 gx_line_params line_params;\ 210 gs_matrix_fixed ctm;\ 211 bool current_point_valid;\ 212 gs_point current_point;\ 213 gs_point subpath_start;\ 214 bool clamp_coordinates;\ 215 gs_logical_operation_t log_op;\ 216 gx_color_value alpha;\ 217 gs_blend_mode_t blend_mode;\ 218 gs_transparency_source_t opacity, shape;\ 219 gs_id soft_mask_id;\ 220 bool text_knockout;\ 221 uint text_rendering_mode;\ 222 gs_transparency_state_t *transparency_stack;\ 223 bool overprint;\ 224 int overprint_mode;\ 225 int effective_overprint_mode;\ 226 float flatness;\ 227 gs_fixed_point fill_adjust; /* A path expansion for fill; -1 = dropout prevention*/\ 228 bool stroke_adjust;\ 229 bool accurate_curves;\ 230 bool have_pattern_streams;\ 231 float smoothness;\ 232 const gx_color_map_procs *\ 233 (*get_cmap_procs)(const gs_imager_state *, const gx_device *);\ 234 gs_color_rendering_state_common 235 #define st_imager_state_num_ptrs\ 236 (st_line_params_num_ptrs + st_cr_state_num_ptrs + 4) 237 /* Access macros */ 238 #define ctm_only(pis) (*(const gs_matrix *)&(pis)->ctm) 239 #define ctm_only_writable(pis) (*(gs_matrix *)&(pis)->ctm) 240 #define set_ctm_only(pis, mat) (*(gs_matrix *)&(pis)->ctm = (mat)) 241 #define gs_init_rop(pis) ((pis)->log_op = lop_default) 242 #define gs_currentflat_inline(pis) ((pis)->flatness) 243 #define gs_currentlineparams_inline(pis) (&(pis)->line_params) 244 #define gs_current_logical_op_inline(pis) ((pis)->log_op) 245 #define gs_set_logical_op_inline(pis, lop) ((pis)->log_op = (lop)) 246 247 #ifndef gs_imager_state_DEFINED 248 # define gs_imager_state_DEFINED 249 typedef struct gs_imager_state_s gs_imager_state; 250 #endif 251 252 struct gs_imager_state_s { 253 gs_imager_state_common; 254 }; 255 256 /* Initialization for gs_imager_state */ 257 #define gs_imager_state_initial(scale)\ 258 0, 0, { gx_line_params_initial },\ 259 { (float)(scale), 0.0, 0.0, (float)(-(scale)), 0.0, 0.0 },\ 260 false, {0, 0}, {0, 0}, false, \ 261 lop_default, gx_max_color_value, BLEND_MODE_Compatible,\ 262 { 1.0, 0 }, { 1.0, 0 }, 0, 0/*false*/, 0, 0, 0/*false*/, 0, 0, 1.0,\ 263 { fixed_half, fixed_half }, 0/*false*/, 0/*false*/, 0/*false*/, 1.0,\ 264 gx_default_get_cmap_procs 265 266 /* The imager state structure is public only for subclassing. */ 267 #define public_st_imager_state() /* in gsistate.c */\ 268 gs_public_st_composite(st_imager_state, gs_imager_state, "gs_imager_state",\ 269 imager_state_enum_ptrs, imager_state_reloc_ptrs) 270 271 /* Initialize an imager state, other than the parts covered by */ 272 /* gs_imager_state_initial. */ 273 int gs_imager_state_initialize(gs_imager_state * pis, gs_memory_t * mem); 274 275 /* Make a temporary copy of a gs_imager_state. Note that this does not */ 276 /* do all the necessary reference counting, etc. */ 277 gs_imager_state * 278 gs_imager_state_copy(const gs_imager_state * pis, gs_memory_t * mem); 279 280 /* Increment reference counts to note that an imager state has been copied. */ 281 void gs_imager_state_copied(gs_imager_state * pis); 282 283 /* Adjust reference counts before assigning one imager state to another. */ 284 void gs_imager_state_pre_assign(gs_imager_state *to, 285 const gs_imager_state *from); 286 287 288 /* Release an imager state. */ 289 void gs_imager_state_release(gs_imager_state * pis); 290 int gs_currentscreenphase_pis(const gs_imager_state *, gs_int_point *, gs_color_select_t); 291 292 #endif /* gxistate_INCLUDED */ 293