1 /* Copyright (C) 1996, 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: gsiparam.h,v 1.4.6.1.2.1 2003/01/17 00:49:02 giles Exp $ */ 20 /* Image parameter definition */ 21 22 #ifndef gsiparam_INCLUDED 23 # define gsiparam_INCLUDED 24 25 #include "gsccolor.h" /* for GS_CLIENT_COLOR_MAX_COMPONENTS */ 26 #include "gsmatrix.h" 27 #include "gsstype.h" /* for extern_st */ 28 29 /* ---------------- Image parameters ---------------- */ 30 31 /* 32 * Unfortunately, we defined the gs_image_t type as designating an ImageType 33 * 1 image or mask before we realized that there were going to be other 34 * ImageTypes. We could redefine this type to include a type field without 35 * perturbing clients, but it would break implementations of driver 36 * begin_image procedures, since they are currently only prepared to handle 37 * ImageType 1 images and would have to be modified to check the ImageType. 38 * Therefore, we use gs_image_common_t for an abstract image type, and 39 * gs_image<n>_t for the various ImageTypes. 40 */ 41 42 /* 43 * Define the data common to all image types. The type structure is 44 * opaque here, defined in gxiparam.h. 45 */ 46 #ifndef gx_image_type_DEFINED 47 # define gx_image_type_DEFINED 48 typedef struct gx_image_type_s gx_image_type_t; 49 50 #endif 51 #define gs_image_common\ 52 const gx_image_type_t *type;\ 53 /*\ 54 * Define the transformation from user space to image space.\ 55 */\ 56 gs_matrix ImageMatrix 57 typedef struct gs_image_common_s { 58 gs_image_common; 59 } gs_image_common_t; 60 61 #define public_st_gs_image_common() /* in gximage.c */\ 62 gs_public_st_simple(st_gs_image_common, gs_image_common_t,\ 63 "gs_image_common_t") 64 65 /* 66 * Define the maximum number of components in image data. 67 * The +1 is for either color + alpha or mask + color. 68 */ 69 #define GS_IMAGE_MAX_COLOR_COMPONENTS GS_CLIENT_COLOR_MAX_COMPONENTS 70 #define GS_IMAGE_MAX_COMPONENTS (GS_IMAGE_MAX_COLOR_COMPONENTS + 1) 71 /* Backward compatibility */ 72 #define gs_image_max_components GS_IMAGE_MAX_COMPONENTS 73 74 /* 75 * Define the maximum number of planes in image data. Since we support 76 * allocating a plane for each bit, the maximum value is the maximum number 77 * of components (see above) times the maximum depth per component 78 * (currently 8 for multi-component bit-planar images, but could be 16 79 * someday; 32 or maybe 64 for DevicePixel images). 80 */ 81 #define GS_IMAGE_MAX_PLANES (GS_IMAGE_MAX_COMPONENTS * 8) 82 /* Backward compatibility */ 83 #define gs_image_max_planes GS_IMAGE_MAX_PLANES 84 85 /* 86 * Define the structure for defining data common to ImageType 1 images, 87 * ImageType 3 DataDicts and MaskDicts, and ImageType 4 images -- i.e., 88 * all the image types that use explicitly supplied data. It follows 89 * closely the discussion on pp. 219-223 of the PostScript Language 90 * Reference Manual, Second Edition, with the following exceptions: 91 * 92 * DataSource and MultipleDataSources are not members of this 93 * structure, since the structure doesn't take a position on 94 * how the data are actually supplied. 95 */ 96 #define gs_data_image_common\ 97 gs_image_common;\ 98 /*\ 99 * Define the width of source image in pixels.\ 100 */\ 101 int Width;\ 102 /*\ 103 * Define the height of source image in pixels.\ 104 */\ 105 int Height;\ 106 /*\ 107 * Define B, the number of bits per pixel component.\ 108 * Currently this must be 1 for masks.\ 109 */\ 110 int BitsPerComponent;\ 111 /*\ 112 * Define the linear remapping of the input values.\ 113 * For the I'th pixel component, we start by treating\ 114 * the B bits of component data as a fraction F between\ 115 * 0 and 1; the actual component value is then\ 116 * Decode[I*2] + F * (Decode[I*2+1] - Decode[I*2]).\ 117 * For masks, only the first two entries are used;\ 118 * they must be 1,0 for write-0s masks, 0,1 for write-1s.\ 119 */\ 120 float Decode[GS_IMAGE_MAX_COMPONENTS * 2];\ 121 /*\ 122 * Define whether to smooth the image.\ 123 */\ 124 bool Interpolate 125 typedef struct gs_data_image_s { 126 gs_data_image_common; 127 } gs_data_image_t; 128 129 #define public_st_gs_data_image() /* in gximage.c */\ 130 gs_public_st_simple(st_gs_data_image, gs_data_image_t,\ 131 "gs_data_image_t") 132 133 /* 134 * Define the data common to ImageType 1 images, ImageType 3 DataDicts, 135 * and ImageType 4 images -- i.e., all the image types that provide pixel 136 * (as opposed to mask) data. The following are added to the PostScript 137 * image parameters: 138 * 139 * format is not PostScript or PDF standard: it is normally derived 140 * from MultipleDataSources. 141 * 142 * ColorSpace is added from PDF. 143 * 144 * CombineWithColor is not PostScript or PDF standard: see the 145 * RasterOp section of Language.htm for a discussion of 146 * CombineWithColor. 147 */ 148 typedef enum { 149 /* Single plane, chunky pixels. */ 150 gs_image_format_chunky = 0, 151 /* num_components planes, chunky components. */ 152 gs_image_format_component_planar = 1, 153 /* BitsPerComponent * num_components planes, 1 bit per plane */ 154 gs_image_format_bit_planar = 2 155 } gs_image_format_t; 156 157 /* Define an opaque type for a color space. */ 158 #ifndef gs_color_space_DEFINED 159 # define gs_color_space_DEFINED 160 typedef struct gs_color_space_s gs_color_space; 161 162 #endif 163 164 #define gs_pixel_image_common\ 165 gs_data_image_common;\ 166 /*\ 167 * Define how the pixels are divided up into planes.\ 168 */\ 169 gs_image_format_t format;\ 170 /*\ 171 * Define the source color space (must be NULL for masks).\ 172 */\ 173 const gs_color_space *ColorSpace;\ 174 /*\ 175 * Define whether to use the drawing color as the\ 176 * "texture" for RasterOp. For more information,\ 177 * see the discussion of RasterOp in Language.htm.\ 178 */\ 179 bool CombineWithColor 180 typedef struct gs_pixel_image_s { 181 gs_pixel_image_common; 182 } gs_pixel_image_t; 183 184 extern_st(st_gs_pixel_image); 185 #define public_st_gs_pixel_image() /* in gximage.c */\ 186 gs_public_st_ptrs1(st_gs_pixel_image, gs_pixel_image_t,\ 187 "gs_data_image_t", pixel_image_enum_ptrs, pixel_image_reloc_ptrs,\ 188 ColorSpace) 189 190 /* 191 * Define an ImageType 1 image. ImageMask is an added member from PDF. 192 * adjust and Alpha are not PostScript or PDF standard. 193 */ 194 typedef enum { 195 /* No alpha. This must be 0 for true-false tests. */ 196 gs_image_alpha_none = 0, 197 /* Alpha precedes color components. */ 198 gs_image_alpha_first, 199 /* Alpha follows color components. */ 200 gs_image_alpha_last 201 } gs_image_alpha_t; 202 203 typedef struct gs_image1_s { 204 gs_pixel_image_common; 205 /* 206 * Define whether this is a mask or a solid image. 207 * For masks, Alpha must be 'none'. 208 */ 209 bool ImageMask; 210 /* 211 * Define whether to expand each destination pixel, to make 212 * masked characters look better. Only used for masks. 213 */ 214 bool adjust; 215 /* 216 * Define whether there is an additional component providing 217 * alpha information for each pixel, in addition to the 218 * components implied by the color space. 219 */ 220 gs_image_alpha_t Alpha; 221 } gs_image1_t; 222 223 /* The descriptor is public for soft masks. */ 224 extern_st(st_gs_image1); 225 #define public_st_gs_image1() /* in gximage1.c */\ 226 gs_public_st_suffix_add0(st_gs_image1, gs_image1_t, "gs_image1_t",\ 227 image1_enum_ptrs, image1_reloc_ptrs, st_gs_pixel_image) 228 229 /* 230 * In standard PostScript Level 1 and 2, this is the only defined ImageType. 231 */ 232 typedef gs_image1_t gs_image_t; 233 234 /* 235 * Define procedures for initializing the standard forms of image structures 236 * to default values. Note that because these structures may add more 237 * members in the future, all clients constructing gs_*image*_t values 238 * *must* start by initializing the value by calling one of the following 239 * procedures. Note also that these procedures do not set the image type. 240 */ 241 void 242 /* 243 * Sets ImageMatrix to the identity matrix. 244 */ 245 gs_image_common_t_init(P1(gs_image_common_t * pic)), /* 246 * Also sets Width = Height = 0, BitsPerComponent = 1, 247 * format = chunky, Interpolate = false. 248 * If num_components = N > 0, sets the first N elements of Decode to (0, 1); 249 * if num_components = N < 0, sets the first -N elements of Decode to (1, 0); 250 * if num_components = 0, doesn't set Decode. 251 */ 252 gs_data_image_t_init(P2(gs_data_image_t * pim, int num_components)), 253 /* 254 * Also sets CombineWithColor = false, ColorSpace = color_space, Alpha = 255 * none. num_components is obtained from ColorSpace; if ColorSpace = 256 * NULL or ColorSpace is a Pattern space, num_components is taken as 0 257 * (Decode is not initialized). 258 */ 259 gs_pixel_image_t_init(P2(gs_pixel_image_t * pim, 260 const gs_color_space * color_space)); 261 262 /* 263 * Initialize an ImageType 1 image (or imagemask). Also sets ImageMask, 264 * adjust, and Alpha, and the image type. For masks, write_1s = false 265 * paints 0s, write_1s = true paints 1s. This is consistent with the 266 * "polarity" operand of the PostScript imagemask operator. 267 * 268 * init and init_mask initialize adjust to true. This is a bad decision 269 * which unfortunately we can't undo without breaking backward 270 * compatibility. That is why we added init_adjust and init_mask_adjust. 271 * Note that for init and init_adjust, adjust is only relevant if 272 * pim->ImageMask is true. 273 */ 274 void gs_image_t_init_adjust(P3(gs_image_t * pim, const gs_color_space * pcs, 275 bool adjust)); 276 #define gs_image_t_init(pim, pcs)\ 277 gs_image_t_init_adjust(pim, pcs, true) 278 void gs_image_t_init_mask_adjust(P3(gs_image_t * pim, bool write_1s, 279 bool adjust)); 280 #define gs_image_t_init_mask(pim, write_1s)\ 281 gs_image_t_init_mask_adjust(pim, write_1s, true) 282 283 /* init_gray and init_color require a (const) imager state. */ 284 #define gs_image_t_init_gray(pim, pis)\ 285 gs_image_t_init(pim, gs_cspace_DeviceGray(pis)) 286 #define gs_image_t_init_rgb(pim, pis)\ 287 gs_image_t_init(pim, gs_cspace_DeviceRGB(pis)) 288 #define gs_image_t_init_cmyk(pim, pis)\ 289 gs_image_t_init(pim, gs_cspace_DeviceCMYK(pis)) 290 291 /****** REMAINDER OF FILE UNDER CONSTRUCTION. PROCEED AT YOUR OWN RISK. ******/ 292 293 #if 0 294 295 /* ---------------- Services ---------------- */ 296 297 /* 298 In order to make the driver's life easier, we provide the following callback 299 procedure: 300 */ 301 302 int gx_map_image_color(P5(gx_device * dev, 303 const gs_image_t * pim, 304 const gx_color_rendering_info * pcri, 305 const uint components[GS_IMAGE_MAX_COMPONENTS], 306 gx_drawing_color * pdcolor)); 307 308 /* 309 Map a source color to a drawing color. The components are simply the 310 pixel component values from the input data, i.e., 1 to 311 GS_IMAGE_MAX_COMPONENTS B-bit numbers from the source data. Return 0 if 312 the operation succeeded, or a negative error code. 313 */ 314 315 #endif /*************************************************************** */ 316 317 #endif /* gsiparam_INCLUDED */ 318