xref: /plan9/sys/src/cmd/gs/src/gxiparam.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1997, 1998, 1999 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: gxiparam.h,v 1.5 2002/06/16 08:45:43 lpd Exp $ */
18 /* Definitions for implementors of image types */
19 
20 #ifndef gxiparam_INCLUDED
21 #  define gxiparam_INCLUDED
22 
23 #include "gsstype.h"		/* for extern_st */
24 #include "gxdevcli.h"
25 
26 /* ---------------- Image types ---------------- */
27 
28 /* Define the structure for image types. */
29 
30 #ifndef stream_DEFINED
31 #  define stream_DEFINED
32 typedef struct stream_s stream;
33 #endif
34 
35 #ifndef gx_image_type_DEFINED
36 #  define gx_image_type_DEFINED
37 typedef struct gx_image_type_s gx_image_type_t;
38 #endif
39 
40 struct gx_image_type_s {
41 
42     /*
43      * Define the storage type for this type of image.
44      */
45     gs_memory_type_ptr_t stype;
46 
47     /*
48      * Provide the default implementation of begin_typed_image for this
49      * type.
50      */
51     dev_proc_begin_typed_image((*begin_typed_image));
52 
53     /*
54      * Compute the width and height of the source data.  For images with
55      * explicit data, this information is in the gs_data_image_t
56      * structure, but ImageType 2 images must compute it.
57      */
58 #define image_proc_source_size(proc)\
59   int proc(const gs_imager_state *pis, const gs_image_common_t *pic,\
60     gs_int_point *psize)
61 
62     image_proc_source_size((*source_size));
63 
64     /*
65      * Put image parameters on a stream.  Currently this is used
66      * only for banding.  If the parameters include a color space,
67      * store it in *ppcs.
68      */
69 #define image_proc_sput(proc)\
70   int proc(const gs_image_common_t *pic, stream *s,\
71     const gs_color_space **ppcs)
72 
73     image_proc_sput((*sput));
74 
75     /*
76      * Get image parameters from a stream.  Currently this is used
77      * only for banding.  If the parameters include a color space,
78      * use pcs.
79      */
80 #define image_proc_sget(proc)\
81   int proc(gs_image_common_t *pic, stream *s, const gs_color_space *pcs)
82 
83     image_proc_sget((*sget));
84 
85     /*
86      * Release any parameters allocated by sget.
87      * Currently this only frees the parameter structure itself.
88      */
89 #define image_proc_release(proc)\
90   void proc(gs_image_common_t *pic, gs_memory_t *mem)
91 
92     image_proc_release((*release));
93 
94     /*
95      * We put index last so that if we add more procedures and some
96      * implementor fails to initialize them, we'll get a type error.
97      */
98     int index;		/* PostScript ImageType */
99 };
100 
101 /*
102  * Define the procedure for getting the source size of an image with
103  * explicit data.
104  */
105 image_proc_source_size(gx_data_image_source_size);
106 /*
107  * Define dummy sput/sget/release procedures for image types that don't
108  * implement these functions.
109  */
110 image_proc_sput(gx_image_no_sput); /* rangecheck error */
111 image_proc_sget(gx_image_no_sget); /* rangecheck error */
112 image_proc_release(gx_image_default_release); /* just free the params */
113 /*
114  * Define sput/sget/release procedures for generic pixel images.
115  * Note that these procedures take different parameters.
116  */
117 int gx_pixel_image_sput(const gs_pixel_image_t *pic, stream *s,
118 			const gs_color_space **ppcs, int extra);
119 int gx_pixel_image_sget(gs_pixel_image_t *pic, stream *s,
120 			const gs_color_space *pcs);
121 void gx_pixel_image_release(gs_pixel_image_t *pic, gs_memory_t *mem);
122 
123 /* Internal procedures for use in sput/sget implementations. */
124 bool gx_image_matrix_is_default(const gs_data_image_t *pid);
125 void gx_image_matrix_set_default(gs_data_image_t *pid);
126 void sput_variable_uint(stream *s, uint w);
127 int sget_variable_uint(stream *s, uint *pw);
128 #define DECODE_DEFAULT(i, dd1)\
129   ((i) == 1 ? dd1 : (i) & 1)
130 
131 /* ---------------- Image enumerators ---------------- */
132 
133 #ifndef gx_image_enum_common_t_DEFINED
134 #  define gx_image_enum_common_t_DEFINED
135 typedef struct gx_image_enum_common_s gx_image_enum_common_t;
136 #endif
137 
138 /*
139  * Define the procedures associated with an image enumerator.
140  */
141 typedef struct gx_image_enum_procs_s {
142 
143     /*
144      * Pass the next batch of data for processing.  *rows_used is set
145      * even in the case of an error.
146      */
147 
148 #define image_enum_proc_plane_data(proc)\
149   int proc(gx_image_enum_common_t *info, const gx_image_plane_t *planes,\
150 	   int height, int *rows_used)
151 
152     image_enum_proc_plane_data((*plane_data));
153 
154     /*
155      * End processing an image, freeing the enumerator.  We keep this
156      * procedure as the last required one, so that we can detect obsolete
157      * static initializers.
158      */
159 
160 #define image_enum_proc_end_image(proc)\
161   int proc(gx_image_enum_common_t *info, bool draw_last)
162 
163     image_enum_proc_end_image((*end_image));
164 
165     /*
166      * Flush any intermediate buffers to the target device.
167      * We need this for situations where two images interact
168      * (currently, only the mask and the data of ImageType 3).
169      *
170      * This procedure is optional (may be 0).
171      */
172 
173 #define image_enum_proc_flush(proc)\
174   int proc(gx_image_enum_common_t *info)
175 
176     image_enum_proc_flush((*flush));
177 
178     /*
179      * Determine which data planes should be passed on the next call to the
180      * plane_data procedure, by filling wanted[0 .. num_planes - 1] with 0
181      * for unwanted planes and non-0 for wanted planes.  This procedure may
182      * also change the plane_depths[] and/or plane_widths[] values.  The
183      * procedure returns true if the returned vector will always be the same
184      * *and* the plane depths and widths remain constant, false if the
185      * wanted planes *or* plane depths or widths may vary over the course of
186      * the image.  Note also that the only time a plane's status can change
187      * from wanted to not wanted, and the only time a wanted plane's depth
188      * or width can change, is after a call of plane_data that actually
189      * provides data for that plane.
190      *
191      * By default, all data planes are always wanted; however, ImageType 3
192      * images with separate mask and image data sources may want mask data
193      * before image data or vice versa.
194      *
195      * This procedure is optional (may be 0).
196      */
197 
198 #define image_enum_proc_planes_wanted(proc)\
199   bool proc(const gx_image_enum_common_t *info, byte *wanted)
200 
201     image_enum_proc_planes_wanted((*planes_wanted));
202 
203 } gx_image_enum_procs_t;
204 
205 /*
206  * Define the common prefix of the image enumerator structure.  All
207  * implementations of begin[_typed]_image must initialize all of the members
208  * of this structure, by calling gx_image_enum_common_init and then filling
209  * in whatever else they need to.
210  *
211  * Note that the structure includes a unique ID, so that the banding
212  * machinery could in principle keep track of multiple enumerations that may
213  * be in progress simultaneously.
214  */
215 #define gx_image_enum_common\
216 	const gx_image_type_t *image_type;\
217 	const gx_image_enum_procs_t *procs;\
218 	gx_device *dev;\
219 	gs_id id;\
220 	int num_planes;\
221 	int plane_depths[gs_image_max_planes];	/* [num_planes] */\
222 	int plane_widths[gs_image_max_planes]	/* [num_planes] */
223 struct gx_image_enum_common_s {
224     gx_image_enum_common;
225 };
226 
227 extern_st(st_gx_image_enum_common);
228 #define public_st_gx_image_enum_common()	/* in gdevddrw.c */\
229   gs_public_st_composite(st_gx_image_enum_common, gx_image_enum_common_t,\
230     "gx_image_enum_common_t",\
231      image_enum_common_enum_ptrs, image_enum_common_reloc_ptrs)
232 
233 /*
234  * Initialize the common part of an image enumerator.
235  */
236 int gx_image_enum_common_init(gx_image_enum_common_t * piec,
237 			      const gs_data_image_t * pic,
238 			      const gx_image_enum_procs_t * piep,
239 			      gx_device * dev, int num_components,
240 			      gs_image_format_t format);
241 
242 /*
243  * Define image_plane_data and end_image procedures for image types that
244  * don't have any source data (ImageType 2 and composite images).
245  */
246 image_enum_proc_plane_data(gx_no_plane_data);
247 image_enum_proc_end_image(gx_ignore_end_image);
248 /*
249  * Define the procedures and type data for ImageType 1 images,
250  * which are always included and which are shared with ImageType 4.
251  */
252 dev_proc_begin_typed_image(gx_begin_image1);
253 image_enum_proc_plane_data(gx_image1_plane_data);
254 image_enum_proc_end_image(gx_image1_end_image);
255 image_enum_proc_flush(gx_image1_flush);
256 
257 #endif /* gxiparam_INCLUDED */
258