1 /* Copyright (C) 1997, 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: gsshade.h,v 1.9 2005/04/19 08:36:38 igor Exp $ */ 18 /* Definitions for shading */ 19 20 #ifndef gsshade_INCLUDED 21 # define gsshade_INCLUDED 22 23 #include "gsccolor.h" 24 #include "gscspace.h" 25 #include "gsdsrc.h" 26 #include "gsfunc.h" 27 #include "gsmatrix.h" 28 #include "gxfixed.h" 29 30 /* ---------------- Types and structures ---------------- */ 31 32 /* Define the shading types. */ 33 typedef enum { 34 shading_type_Function_based = 1, 35 shading_type_Axial = 2, 36 shading_type_Radial = 3, 37 shading_type_Free_form_Gouraud_triangle = 4, 38 shading_type_Lattice_form_Gouraud_triangle = 5, 39 shading_type_Coons_patch = 6, 40 shading_type_Tensor_product_patch = 7 41 } gs_shading_type_t; 42 43 /* 44 * Define information common to all shading types. We separate the private 45 * part from the parameters so that clients can create parameter structures 46 * without having to know the structure of the implementation. 47 */ 48 #define gs_shading_params_common\ 49 gs_color_space *ColorSpace;\ 50 gs_client_color *Background;\ 51 bool have_BBox;\ 52 gs_rect BBox;\ 53 bool AntiAlias 54 55 typedef struct gs_shading_params_s { 56 gs_shading_params_common; 57 } gs_shading_params_t; 58 59 /* Define the type-specific procedures for shadings. */ 60 #ifndef gs_shading_t_DEFINED 61 # define gs_shading_t_DEFINED 62 typedef struct gs_shading_s gs_shading_t; 63 #endif 64 #ifndef gx_device_DEFINED 65 # define gx_device_DEFINED 66 typedef struct gx_device_s gx_device; 67 #endif 68 69 /* 70 * Fill a user space rectangle. This will paint every pixel that is in the 71 * intersection of the rectangle and the shading's geometry, but it may 72 * leave some pixels in the rectangle unpainted, and it may also paint 73 * outside the rectangle: the caller is responsible for setting up a 74 * clipping device if necessary. 75 */ 76 #define SHADING_FILL_RECTANGLE_PROC(proc)\ 77 int proc(const gs_shading_t *psh, const gs_rect *prect,\ 78 const gs_fixed_rect *prect_clip, gx_device *dev,\ 79 gs_imager_state *pis) 80 typedef SHADING_FILL_RECTANGLE_PROC((*shading_fill_rectangle_proc_t)); 81 #define gs_shading_fill_rectangle(psh, prect, prect_clip, dev, pis)\ 82 ((psh)->head.procs.fill_rectangle(psh, prect, prect_clip, dev, pis)) 83 84 /* Define the generic shading structures. */ 85 typedef struct gs_shading_procs_s { 86 shading_fill_rectangle_proc_t fill_rectangle; 87 } gs_shading_procs_t; 88 typedef struct gs_shading_head_s { 89 gs_shading_type_t type; 90 gs_shading_procs_t procs; 91 } gs_shading_head_t; 92 93 /* Define a generic shading, for use as the target type of pointers. */ 94 struct gs_shading_s { 95 gs_shading_head_t head; 96 gs_shading_params_t params; 97 }; 98 #define ShadingType(psh) ((psh)->head.type) 99 #define private_st_shading() /* in gsshade.c */\ 100 gs_private_st_ptrs2(st_shading, gs_shading_t, "gs_shading_t",\ 101 shading_enum_ptrs, shading_reloc_ptrs,\ 102 params.ColorSpace, params.Background) 103 104 /* Define Function-based shading. */ 105 typedef struct gs_shading_Fb_params_s { 106 gs_shading_params_common; 107 float Domain[4]; 108 gs_matrix Matrix; 109 gs_function_t *Function; 110 } gs_shading_Fb_params_t; 111 112 #define private_st_shading_Fb() /* in gsshade.c */\ 113 gs_private_st_suffix_add1(st_shading_Fb, gs_shading_Fb_t,\ 114 "gs_shading_Fb_t", shading_Fb_enum_ptrs, shading_Fb_reloc_ptrs,\ 115 st_shading, params.Function) 116 117 /* Define Axial shading. */ 118 typedef struct gs_shading_A_params_s { 119 gs_shading_params_common; 120 float Coords[4]; 121 float Domain[2]; 122 gs_function_t *Function; 123 bool Extend[2]; 124 } gs_shading_A_params_t; 125 126 #define private_st_shading_A() /* in gsshade.c */\ 127 gs_private_st_suffix_add1(st_shading_A, gs_shading_A_t,\ 128 "gs_shading_A_t", shading_A_enum_ptrs, shading_A_reloc_ptrs,\ 129 st_shading, params.Function) 130 131 /* Define Radial shading. */ 132 typedef struct gs_shading_R_params_s { 133 gs_shading_params_common; 134 float Coords[6]; 135 float Domain[2]; 136 gs_function_t *Function; 137 bool Extend[2]; 138 } gs_shading_R_params_t; 139 140 #define private_st_shading_R() /* in gsshade.c */\ 141 gs_private_st_suffix_add1(st_shading_R, gs_shading_R_t,\ 142 "gs_shading_R_t", shading_R_enum_ptrs, shading_R_reloc_ptrs,\ 143 st_shading, params.Function) 144 145 /* Define common parameters for mesh shading. */ 146 #define gs_shading_mesh_params_common\ 147 gs_shading_params_common;\ 148 gs_data_source_t DataSource;\ 149 int BitsPerCoordinate;\ 150 int BitsPerComponent;\ 151 float *Decode;\ 152 gs_function_t *Function 153 /* The following are for internal use only. */ 154 typedef struct gs_shading_mesh_params_s { 155 gs_shading_mesh_params_common; 156 } gs_shading_mesh_params_t; 157 typedef struct gs_shading_mesh_s { 158 gs_shading_head_t head; 159 gs_shading_mesh_params_t params; 160 } gs_shading_mesh_t; 161 162 #define private_st_shading_mesh() /* in gsshade.c */\ 163 gs_private_st_composite(st_shading_mesh, gs_shading_mesh_t,\ 164 "gs_shading_mesh_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs) 165 166 /* Define Free-form Gouraud triangle mesh shading. */ 167 typedef struct gs_shading_FfGt_params_s { 168 gs_shading_mesh_params_common; 169 int BitsPerFlag; 170 } gs_shading_FfGt_params_t; 171 172 #define private_st_shading_FfGt() /* in gsshade.c */\ 173 gs_private_st_composite_only(st_shading_FfGt, gs_shading_FfGt_t,\ 174 "gs_shading_FfGt_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs) 175 176 /* Define Lattice-form Gouraud triangle mesh shading. */ 177 typedef struct gs_shading_LfGt_params_s { 178 gs_shading_mesh_params_common; 179 int VerticesPerRow; 180 } gs_shading_LfGt_params_t; 181 182 #define private_st_shading_LfGt() /* in gsshade.c */\ 183 gs_private_st_composite_only(st_shading_LfGt, gs_shading_LfGt_t,\ 184 "gs_shading_LfGt_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs) 185 186 /* Define Coons patch mesh shading. */ 187 typedef struct gs_shading_Cp_params_s { 188 gs_shading_mesh_params_common; 189 int BitsPerFlag; 190 } gs_shading_Cp_params_t; 191 192 #define private_st_shading_Cp() /* in gsshade.c */\ 193 gs_private_st_composite_only(st_shading_Cp, gs_shading_Cp_t,\ 194 "gs_shading_Cp_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs) 195 196 /* Define Tensor product patch mesh shading. */ 197 typedef struct gs_shading_Tpp_params_s { 198 gs_shading_mesh_params_common; 199 int BitsPerFlag; 200 } gs_shading_Tpp_params_t; 201 202 #define private_st_shading_Tpp() /* in gsshade.c */\ 203 gs_private_st_composite_only(st_shading_Tpp, gs_shading_Tpp_t,\ 204 "gs_shading_Tpp_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs) 205 206 /* ---------------- Procedures ---------------- */ 207 208 /* Initialize shading parameters of specific types. */ 209 void gs_shading_Fb_params_init(gs_shading_Fb_params_t * params); 210 void gs_shading_A_params_init(gs_shading_A_params_t * params); 211 void gs_shading_R_params_init(gs_shading_R_params_t * params); 212 void gs_shading_FfGt_params_init(gs_shading_FfGt_params_t * params); 213 void gs_shading_LfGt_params_init(gs_shading_LfGt_params_t * params); 214 void gs_shading_Cp_params_init(gs_shading_Cp_params_t * params); 215 void gs_shading_Tpp_params_init(gs_shading_Tpp_params_t * params); 216 217 /* Create (initialize) shadings of specific types. */ 218 int gs_shading_Fb_init(gs_shading_t ** ppsh, 219 const gs_shading_Fb_params_t * params, 220 gs_memory_t * mem); 221 int gs_shading_A_init(gs_shading_t ** ppsh, 222 const gs_shading_A_params_t * params, 223 gs_memory_t * mem); 224 int gs_shading_R_init(gs_shading_t ** ppsh, 225 const gs_shading_R_params_t * params, 226 gs_memory_t * mem); 227 int gs_shading_FfGt_init(gs_shading_t ** ppsh, 228 const gs_shading_FfGt_params_t * params, 229 gs_memory_t * mem); 230 int gs_shading_LfGt_init(gs_shading_t ** ppsh, 231 const gs_shading_LfGt_params_t * params, 232 gs_memory_t * mem); 233 int gs_shading_Cp_init(gs_shading_t ** ppsh, 234 const gs_shading_Cp_params_t * params, 235 gs_memory_t * mem); 236 int gs_shading_Tpp_init(gs_shading_t ** ppsh, 237 const gs_shading_Tpp_params_t * params, 238 gs_memory_t * mem); 239 240 /* 241 * Fill a path or a (device-space) rectangle with a shading. Both the path 242 * and the rectangle are optional, but at least one must be non-NULL; if 243 * both are specified, the filled region is their intersection. This is the 244 * only externally accessible procedure for rendering a shading. 245 * fill_background indicates whether to fill portions of the path outside 246 * the shading's geometry: it is true for filling with a pattern, false for 247 * shfill. 248 */ 249 #ifndef gx_path_DEFINED 250 # define gx_path_DEFINED 251 typedef struct gx_path_s gx_path; 252 #endif 253 int gs_shading_fill_path_adjusted(const gs_shading_t *psh, /*const*/ gx_path *ppath, 254 const gs_fixed_rect *prect, gx_device *dev, 255 gs_imager_state *pis, bool fill_background); 256 257 #endif /* gsshade_INCLUDED */ 258