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: gstrans.h 10200 2009-10-21 03:50:46Z mvrhel $ */ 15 /* Transparency definitions and interface */ 16 17 #ifndef gstrans_INCLUDED 18 # define gstrans_INCLUDED 19 20 #include "gstparam.h" 21 #include "gxcomp.h" 22 #include "gsmatrix.h" 23 #include "gxblend.h" 24 25 /* 26 * Define the operations for the PDF 1.4 transparency compositor. 27 */ 28 typedef enum { 29 PDF14_PUSH_DEVICE, 30 PDF14_POP_DEVICE, 31 PDF14_BEGIN_TRANS_GROUP, 32 PDF14_END_TRANS_GROUP, 33 PDF14_BEGIN_TRANS_MASK, 34 PDF14_END_TRANS_MASK, 35 PDF14_SET_BLEND_PARAMS, 36 PDF14_PUSH_TRANS_STATE, 37 PDF14_POP_TRANS_STATE 38 } pdf14_compositor_operations; 39 40 #define PDF14_OPCODE_NAMES \ 41 {\ 42 "PDF14_PUSH_DEVICE ",\ 43 "PDF14_POP_DEVICE ",\ 44 "PDF14_BEGIN_TRANS_GROUP",\ 45 "PDF14_END_TRANS_GROUP ",\ 46 "PDF14_BEGIN_TRANS_MASK ",\ 47 "PDF14_END_TRANS_MASK ",\ 48 "PDF14_SET_BLEND_PARAMS ",\ 49 "PDF14_PUSH_TRANS_STATE ",\ 50 "PDF14_POP_TRANS_STATE "\ 51 } 52 53 /* Bit definitions for serializing PDF 1.4 parameters */ 54 #define PDF14_SET_BLEND_MODE (1 << 0) 55 #define PDF14_SET_TEXT_KNOCKOUT (1 << 1) 56 #define PDF14_SET_SHAPE_ALPHA (1 << 2) 57 #define PDF14_SET_OPACITY_ALPHA (1 << 3) 58 #define PDF14_SET_OVERPRINT (1 << 4) 59 #define PDF14_SET_OVERPRINT_MODE (1 << 5) 60 61 #ifndef gs_function_DEFINED 62 typedef struct gs_function_s gs_function_t; 63 # define gs_function_DEFINED 64 #endif 65 66 typedef struct gs_transparency_source_s { 67 float alpha; /* constant alpha */ 68 } gs_transparency_source_t; 69 70 struct gs_pdf14trans_params_s { 71 /* The type of trasnparency operation */ 72 pdf14_compositor_operations pdf14_op; 73 int num_spot_colors; /* Only for devices which support spot colors. */ 74 /* Changed parameters flag */ 75 int changed; 76 /* Parameters from the gs_transparency_group_params_t structure */ 77 bool Isolated; 78 bool Knockout; 79 bool image_with_SMask; 80 gs_rect bbox; 81 /*The transparency channel selector */ 82 gs_transparency_channel_selector_t csel; 83 /* Parameters from the gx_transparency_mask_params_t structure */ 84 gs_transparency_mask_subtype_t subtype; 85 int Background_components; 86 bool function_is_identity; 87 float Background[GS_CLIENT_COLOR_MAX_COMPONENTS]; 88 float GrayBackground; /* This is used to determine if the 89 softmask's bbox needs to be adjusted 90 to the parent groups bbox. Since 91 the soft mask can affect areas 92 outside its own groups bounding 93 box in such a case */ 94 gs_function_t *transfer_function; 95 byte transfer_fn[MASK_TRANSFER_FUNCTION_SIZE]; 96 /* Individual transparency parameters */ 97 gs_blend_mode_t blend_mode; 98 bool text_knockout; 99 gs_transparency_source_t opacity; 100 gs_transparency_source_t shape; 101 bool mask_is_image; 102 gs_matrix ctm; 103 bool replacing; 104 bool overprint; 105 bool overprint_mode; 106 bool idle; /* For clist reader.*/ 107 uint mask_id; /* For clist reader.*/ 108 bool SMask_is_CIE; 109 int group_color_numcomps; 110 gs_transparency_color_t group_color; 111 }; 112 113 #ifndef gs_pdf14trans_params_DEFINED 114 #define gs_pdf14trans_params_DEFINED 115 typedef struct gs_pdf14trans_params_s gs_pdf14trans_params_t; 116 #endif 117 118 /* 119 * The PDF 1.4 transparency compositor structure. This is exactly analogous to 120 * other compositor structures, consisting of a the compositor common elements 121 * and the PDF 1.4 transparency specific parameters. 122 */ 123 typedef struct gs_pdf14trans_s { 124 gs_composite_common; 125 gs_pdf14trans_params_t params; 126 } gs_pdf14trans_t; 127 128 129 /* Access transparency-related graphics state elements. */ 130 int gs_setblendmode(gs_state *, gs_blend_mode_t); 131 gs_blend_mode_t gs_currentblendmode(const gs_state *); 132 int gs_setopacityalpha(gs_state *, floatp); 133 float gs_currentopacityalpha(const gs_state *); 134 int gs_setshapealpha(gs_state *, floatp); 135 float gs_currentshapealpha(const gs_state *); 136 int gs_settextknockout(gs_state *, bool); 137 bool gs_currenttextknockout(const gs_state *); 138 139 /* 140 * Manage transparency group and mask rendering. Eventually these will be 141 * driver procedures, taking dev + pis instead of pgs. 142 */ 143 144 gs_transparency_state_type_t 145 gs_current_transparency_type(const gs_state *pgs); 146 147 /* 148 * We have to abbreviate the procedure name because procedure names are 149 * only unique to 23 characters on VMS. 150 */ 151 int gs_push_pdf14trans_device(gs_state * pgs); 152 153 int gs_pop_pdf14trans_device(gs_state * pgs); 154 155 void gs_trans_group_params_init(gs_transparency_group_params_t *ptgp); 156 157 int gs_begin_transparency_group(gs_state * pgs, 158 const gs_transparency_group_params_t *ptgp, 159 const gs_rect *pbbox); 160 161 int gs_end_transparency_group(gs_state *pgs); 162 163 void gs_trans_mask_params_init(gs_transparency_mask_params_t *ptmp, 164 gs_transparency_mask_subtype_t subtype); 165 166 int gs_begin_transparency_mask(gs_state *pgs, 167 const gs_transparency_mask_params_t *ptmp, 168 const gs_rect *pbbox, bool mask_is_image); 169 170 int gs_end_transparency_mask(gs_state *pgs, 171 gs_transparency_channel_selector_t csel); 172 173 int gs_discard_transparency_layer(gs_state *pgs); 174 175 /* 176 * Imager level routines for the PDF 1.4 transparency operations. 177 */ 178 int gx_begin_transparency_group(gs_imager_state * pis, gx_device * pdev, 179 const gs_pdf14trans_params_t * pparams); 180 181 int gx_end_transparency_group(gs_imager_state * pis, gx_device * pdev); 182 183 int gx_begin_transparency_mask(gs_imager_state * pis, gx_device * pdev, 184 const gs_pdf14trans_params_t * pparams); 185 186 int gx_end_transparency_mask(gs_imager_state * pis, gx_device * pdev, 187 const gs_pdf14trans_params_t * pparams); 188 189 int gx_discard_transparency_layer(gs_imager_state *pis); 190 191 /* These are used for watching for q Smask Q events. We need to 192 send special compositor commands to keep the bands in sync 193 with the current softmask during clist rendering. Like the 194 other transparency operations the gs functions occur on the 195 clist writer side and the gx functions occur on the 196 clist reader side */ 197 198 int gs_push_transparency_state(gs_state *pgs); 199 200 int gs_pop_transparency_state(gs_state *pgs); 201 202 int gx_push_transparency_state(gs_imager_state * pis, gx_device * pdev); 203 204 int gx_pop_transparency_state(gs_imager_state * pis, gx_device * pdev); 205 206 207 /* 208 * Verify that a compositor data structure is for the PDF 1.4 compositor. 209 */ 210 int gs_is_pdf14trans_compositor(const gs_composite_t * pct); 211 212 /* 213 * Estimate the amount of space that will be required by the PDF 1.4 214 * transparency buffers for doing the blending operations. These buffers 215 * use 8 bits per component plus one or two 8 bit alpha component values. 216 * In theory there can be a large number of these buffers required. However 217 * we do not know the required number of buffers, the required numbe of 218 * alpha chanels, or the number of components for the blending operations. 219 * (This information is determined later as the data streams are parsed.) 220 * For now we are simply assuming that we will have three buffers with five 221 * eight bit values. This is a hack but not too unreasonable. However 222 * since it is a hack, we may exceed our desired buffer space while 223 * processing the file. 224 */ 225 #define NUM_PDF14_BUFFERS 3 226 #define NUM_ALPHA_CHANNELS 1 227 #define NUM_COLOR_CHANNELS 4 228 #define BITS_PER_CHANNEL 8 229 /* The estimated size of an individual PDF 1.4 buffer row (in bits) */ 230 #define ESTIMATED_PDF14_ROW_SIZE(width) ((width) * BITS_PER_CHANNEL\ 231 * (NUM_ALPHA_CHANNELS + NUM_COLOR_CHANNELS)) 232 /* The estimated size of one row in all PDF 1.4 buffers (in bits) */ 233 #define ESTIMATED_PDF14_ROW_SPACE(width) \ 234 (NUM_PDF14_BUFFERS * ESTIMATED_PDF14_ROW_SIZE(width)) 235 236 #endif /* gstrans_INCLUDED */ 237