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