xref: /plan9/sys/src/cmd/gs/src/gxdevcli.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
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: gxdevcli.h,v 1.41 2005/10/12 17:59:55 leonardo Exp $ */
18 /* Definitions for device clients */
19 
20 #ifndef gxdevcli_INCLUDED
21 #  define gxdevcli_INCLUDED
22 
23 #include "std.h"		/* for FILE */
24 #include "stdint_.h"
25 #include "gscompt.h"
26 #include "gsdcolor.h"
27 #include "gsmatrix.h"
28 #include "gsiparam.h"		/* requires gsmatrix.h */
29 #include "gsrefct.h"
30 #include "gsropt.h"
31 #include "gsstruct.h"
32 #include "gstparam.h"
33 #include "gsxfont.h"
34 #include "gxbitmap.h"
35 #include "gxcindex.h"
36 #include "gxcvalue.h"
37 #include "gxfixed.h"
38 #include "gxtext.h"
39 #include "gxcmap.h"
40 
41 /* See Drivers.htm for documentation of the driver interface. */
42 
43 #ifndef gx_device_DEFINED
44 #  define gx_device_DEFINED
45 typedef struct gx_device_s gx_device;
46 #endif
47 
48 /* ---------------- Memory management ---------------- */
49 
50 /*
51  * NOTE: if you write code that creates device instances (either with
52  * gs_copydevice or by allocating them explicitly), allocates device
53  * instances as either local or static variables (actual instances, not
54  * pointers to instances), or sets the target of forwarding devices, please
55  * read the following documentation carefully.  The rules for doing these
56  * things changed substantially in release 5.68, in a
57  * non-backward-compatible way, and unfortunately we could not find a way to
58  * make the compiler give an error at places that need changing.
59  */
60 
61 /*
62  * Device instances are managed with reference counting: when the last
63  * reference to a device from a graphics state or the target field of a
64  * forwarding device is removed, the device is normally freed.  However,
65  * some device instances are referenced in other ways (for example, from
66  * objects in the PostScript interpreter, or from library client code) and
67  * will be freed by the garbage collector (if any) or explicitly: they
68  * should not be freed by reference counting.  These are called "retained"
69  * device instances.  Every device instance remembers whether or not it is
70  * retained, and an instance is freed iff its reference count is zero and it
71  * is not retained.
72  *
73  * Normally devices are initialized as not retained.  However, devices
74  * initialized by calling gx_device_init(pdev, proto, memory, false), or
75  * created by gs_copydevice are marked as retained.  You can also set the
76  * retention status of a device explicitly with gx_device_retain(pdev,
77  * true-or-false).  Note that if you change a retained device to
78  * non-retained, if there are no references to it from graphics states or
79  * targets, it will be freed immediately.
80  *
81  * The preferred technique for creating a new device is now gs_copydevice.
82  * There are a number of places in the code where memory is explicitly
83  * allocated, then initialized with gx_device_init. These should gradually
84  * be replaced.
85  *
86  * There are 3 ways that a device structure might be allocated:
87  *	1) Allocated dynamically, e.g.,
88  *		gx_device *pdev_new;
89  *		gs_copydevice(&pdev_new, pdev_old, memory);
90  *	2) Declared as a local or static variable, e.g.,
91  *		gx_device devv;
92  *	or
93  *		const gx_device devc = ...;
94  *	3) Embedded in an object allocated in one of the above ways.
95  * If you allocate a device using #2 or #3, you must either mark it as
96  * retained by calling gx_device_retain(pdev, true) or initialize it with a
97  * NULL memory.  If you do not do this, an attempt will be made to free the
98  * device, corrupting memory.  Note that when memory is NULL, the finalize
99  * method of the device will not be called when it is freed, so you cannot
100  * use it for cleanup.  */
101 
102 /*
103  * Do not set the target of a forwarding device with an assignment like
104  *	fdev->target = tdev;
105  * You must use the procedure
106  *	gx_device_set_target(fdev, tdev);
107  * Note that the first argument is a gx_device_forward *, not a gx_device *.
108  *
109  * We could have changed the member name "target" when this became
110  * necessary, so the compiler would flag places that needed editing, but
111  * there were literally hundreds of places that only read the target member
112  * that we would have had to change, so we decided to leave the name alone.
113  */
114 
115 /* ---------------- Auxiliary types and structures ---------------- */
116 
117 /* We need at least an abstract type for a graphics state, */
118 /* which is passed to the page device procedures. */
119 #ifndef gs_state_DEFINED
120 #  define gs_state_DEFINED
121 typedef struct gs_state_s gs_state;
122 #endif
123 
124 /* We need abstract types for paths and fill/stroke parameters, */
125 /* for the path-oriented device procedures. */
126 #ifndef gx_path_DEFINED
127 #  define gx_path_DEFINED
128 typedef struct gx_path_s gx_path;
129 #endif
130 #ifndef gx_clip_path_DEFINED
131 #  define gx_clip_path_DEFINED
132 typedef struct gx_clip_path_s gx_clip_path;
133 #endif
134 #ifndef gx_fill_params_DEFINED
135 #  define gx_fill_params_DEFINED
136 typedef struct gx_fill_params_s gx_fill_params;
137 #endif
138 #ifndef gx_stroke_params_DEFINED
139 #  define gx_stroke_params_DEFINED
140 typedef struct gx_stroke_params_s gx_stroke_params;
141 #endif
142 #ifndef gs_imager_state_DEFINED
143 #  define gs_imager_state_DEFINED
144 typedef struct gs_imager_state_s gs_imager_state;
145 #endif
146 
147 /* We need an abstract type for the image enumeration state, */
148 /* for begin[_typed]_image. */
149 #ifndef gx_image_enum_common_t_DEFINED
150 #  define gx_image_enum_common_t_DEFINED
151 typedef struct gx_image_enum_common_s gx_image_enum_common_t;
152 #endif
153 
154 /* We need an abstract type for the pattern instance, */
155 /* for pattern_manage. */
156 #ifndef gs_pattern1_instance_t_DEFINED
157 #  define gs_pattern1_instance_t_DEFINED
158 typedef struct gs_pattern1_instance_s gs_pattern1_instance_t;
159 #endif
160 
161 
162 /* Define the type for colors passed to the higher-level procedures. */
163 typedef gx_device_color gx_drawing_color;
164 
165 /* Define a type for telling get_alpha_bits what kind of object */
166 /* is being rendered. */
167 typedef enum {
168     go_text,
169     go_graphics
170 } graphics_object_type;
171 
172 /* Define an edge of a trapezoid.  Requirement: end.y >= start.y. */
173 typedef struct gs_fixed_edge_s {
174     gs_fixed_point start;
175     gs_fixed_point end;
176 } gs_fixed_edge;
177 
178 /* Define the parameters passed to get_bits_rectangle. */
179 #ifndef gs_get_bits_params_DEFINED
180 #  define gs_get_bits_params_DEFINED
181 typedef struct gs_get_bits_params_s gs_get_bits_params_t;
182 #endif
183 
184 /* Define the structure for device color capabilities. */
185 typedef struct gx_device_anti_alias_info_s {
186     int text_bits;		/* 1,2,4 */
187     int graphics_bits;		/* ditto */
188 } gx_device_anti_alias_info;
189 
190 typedef int32_t frac31; /* A fraction value in [-1,1].
191     Represents a color (in [0,1])
192     or a color difference (in [-1,1]) in shadings. */
193 
194 /* Define an edge of a linear color trapezoid.  Requirement: end.y >= start.y. */
195 typedef struct gs_linear_color_edge_s {
196     gs_fixed_point start;
197     gs_fixed_point end;
198     const frac31 *c0, *c1;
199     fixed clip_x;
200 } gs_linear_color_edge;
201 
202 
203 /*
204  * Possible values for the separable_and_linear flag in the
205  * gx_device_color_info structure. These form an order, with lower
206  * values having weaker properties.
207  *
208  *  GX_CINFO_SEP_LIN_UNKNOWN
209  *    The properties of the color encoding are not yet known. This is
210  *    always a safe default value.
211  *
212  *  GX_CINFO_SEP_LIN_NONE
213  *    The encoding is not separable and linear. If this value is set,
214  *    the device must provide an encode_color method, either directly
215  *    or via map_rgb_color/map_cmyk_color methods. This setting is
216  *    only legitimate for color models with 4 or fewer components.
217  *
218  *  GX_CINFO_SEP_LIN
219  *    A separable and linear encoding has the separability and
220  *    linearity properties.
221  *
222  *    Encodings with this property are completely characterized
223  *    by the comp_shift array. Hence, there is no need to provide
224  *    an encode_color procedure for such devices, though the device
225  *    creator may choose to do so for performance reasons (e.g.: when
226  *     each color component is assigned a byte).
227  */
228 
229 typedef enum {
230     GX_CINFO_UNKNOWN_SEP_LIN = -1,
231     GX_CINFO_SEP_LIN_NONE = 0,
232     GX_CINFO_SEP_LIN
233 } gx_color_enc_sep_lin_t;
234 
235 /*
236  * Color model component polarity. An "unknown" value has been added to
237  * this enumeration.
238  */
239 typedef enum {
240     GX_CINFO_POLARITY_UNKNOWN = -1,
241     GX_CINFO_POLARITY_SUBTRACTIVE = 0,
242     GX_CINFO_POLARITY_ADDITIVE
243 } gx_color_polarity_t;
244 
245 /*
246  * Enumerator to indicate if a color model will support overprint mode.
247  *
248  * Only "DeviceCMYK" color space support this option, but we interpret
249  * this designation some broadly: a DeviceCMYK color model is any sub-
250  * tractive color model that provides the components Cyan, Magenta,
251  * Yellow, and Black, and maps the DeviceCMYK space directly to these
252  * components. This includes DeviceCMYK color models with spot colors,
253  * and DeviceN color models that support the requisite components (the
254  * latter may vary from Adobe's implementations; this is not easily
255  * tested).
256  *
257  * In principle this parameter could be a boolean set at initialization
258  * time. Primarily for historical reasons, the determination of whether
259  * or not a color model supports overprint is delayed until this
260  * information is required, hence the use of an enumeration with an
261  * "unknown" setting.
262  */
263 typedef enum {
264     GX_CINFO_OPMODE_UNKNOWN = -1,
265     GX_CINFO_OPMODE_NOT = 0,
266     GX_CINFO_OPMODE
267 } gx_cm_opmode_t;
268 
269 /* component index value used to indicate no color component.  */
270 #define GX_CINFO_COMP_NO_INDEX 0xff
271 
272 /*
273  * Additional possible value for cinfo.gray_index, to indicate which
274  * component, if any, qualifies as the "gray" component.
275  */
276 #define GX_CINFO_COMP_INDEX_UNKNOWN 0xfe
277 
278 /*
279  * The enlarged color model information structure: Some of the
280  * information that was implicit in the component number in
281  * the earlier conventions (component names, polarity, mapping
282  * functions) are now explicitly provided.
283  *
284  * Also included is some information regarding the encoding of
285  * color information into gx_color_index. Some of this information
286  * was previously gathered indirectly from the mapping
287  * functions in the existing code, specifically to speed up the
288  * halftoned color rendering operator (see
289  * gx_dc_ht_colored_fill_rectangle in gxcht.c). The information
290  * is now provided explicitly because such optimizations are
291  * more critical when the number of color components is large.
292  *
293  * Note: no pointers have been added to this structure, so there
294  *       is no requirement for a structure descriptor.
295  */
296 typedef struct gx_device_color_info_s {
297 
298     /*
299      * max_components is the maximum number of components for all
300      * color models supported by this device. This does not include
301      * any alpha components.
302      */
303     int max_components;
304 
305     /*
306      * The number of color components. This does not include any
307      * alpha-channel information, which may be integrated into
308      * the gx_color_index but is otherwise passed as a separate
309      * component.
310      */
311     int num_components;
312 
313     /*
314      * Polarity of the components of the color space, either
315      * additive or subtractive. This is used to interpret transfer
316      * functions and halftone threshold arrays. Possible values
317      * are GX_CM_POLARITY_ADDITIVE or GX_CM_POLARITY_SUBTRACTIVE
318      */
319     gx_color_polarity_t polarity;
320 
321     /*
322      * The number of bits of gx_color_index actually used.
323      * This must be <= arch_sizeof_color_index, which is usually 64.
324      */
325     byte depth;
326 
327     /*
328      * Index of the gray color component, if any. The max_gray and
329      * dither_gray values apply to this component only; all other
330      * components use the max_color and dither_color values.
331      *
332      * Note:  This field refers to a 'gray' colorant because of the
333      * past use of the max_gray/color and dither_grays/colors fields.
334      * Prior to 8.00, the 'gray' values were used for monochrome
335      * devices and the 'color' values for RGB and CMYK devices.
336      * Ideally we would like to have the flexibiiity of allowing
337      * different numbers of intensity levels for each colorant.
338      * However this is not compatible with the pre 8.00 devices.
339      * With post 8.00 devices, we can have two different numbers of
340      * intensity levels.  For one colorant (which is specified by
341      * the gray_index) we will use the max_gray/dither_grays values.
342      * The remaining colorants will use the max_color/dither_colors
343      * values.  The colorant which is specified by the gray_index
344      * value does not have to be gray or black.  For example if we
345      * have an RGB device and we want 32 intensity levels for red and
346      * blue and 64 levels for green, then we can set gray_index to
347      * 1 (the green colorant), set max_gray to 63 and dither_grays to
348      * 64, and set max_color to 31 and dither_colors to 32.
349      *
350      * This will be GX_CINFO_COMP_NO_INDEX if there is no 'gray'
351      * component.
352      */
353     byte gray_index;
354 
355     /*
356      * max_gray and max_color are the number of distinct native
357      * intensity levels, less 1, for the 'gray' and all other color
358      * components, respectively. For nearly all current devices
359      * that support both 'gray' and non-'gray' components, the two
360      * parameters have the same value.  (See comment for gray_index.)
361      *
362      * dither_grays and dither_colors are the number of intensity
363      * levels between which halftoning can occur, for the 'gra'y and
364      * all other color components, respectively. This is
365      * essentially redundant information: in all reasonable cases,
366      * dither_grays = max_gray + 1 and dither_colors = max_color + 1.
367      * These parameters are, however, extensively used in the
368      * current code, and thus have been retained.
369      *
370      * Note that the non-'gray' values may now be relevant even if
371      * num_components == 1. This simplifies the handling of devices
372      * with configurable color models which may be set for a single
373      * non-'gray' color model.
374      */
375     uint max_gray;		/* # of distinct color levels -1 */
376     uint max_color;
377 
378     uint dither_grays;
379     uint dither_colors;
380 
381     /*
382      * Information to control super-sampling of objects to support
383      * anti-aliasing.
384      */
385     gx_device_anti_alias_info anti_alias;
386 
387     /*
388      * Flag to indicate if gx_color_index for this device may be divided
389      * into individual fields for each component. This is almost always
390      * the case for printers, and is the case for most modern displays
391      * as well. When this is the case, halftoning may be performed
392      * separately for each component, which greatly simplifies processing
393      * when the number of color components is large.
394      *
395      * If the gx_color_index is separable in this manner, the comp_shift
396      * array provides the location of the low-order bit for each
397      * component. This may be filled in by the client, but need not be.
398      * If it is not provided, it will be calculated based on the values
399      * in the max_gray and max_color fields as follows:
400      *
401      *     comp_shift[num_components - 1] = 0,
402      *     comp_shift[i] = comp_shift[i + 1]
403      *                      + ( i == gray_index ? ceil(log2(max_gray + 1))
404      *                                          : ceil(log2(max_color + 1)) )
405      *
406      * The comp_mask and comp_bits fields should be left empty by the client.
407      * They will be filled in during initialization using the following
408      * mechanism:
409      *
410      *     comp_bits[i] = ( i == gray_index ? ceil(log2(max_gray + 1))
411      *                                      : ceil(log2(max_color + 1)) )
412      *
413      *     comp_mask[i] = (((gx_color_index)1 << comp_bits[i]) - 1)
414      *                       << comp_shift[i]
415      *
416      * (For current devices, it is almost always the case that
417      * max_gray == max_color, if the color model contains both gray and
418      * non-gray components.)
419      *
420      * If separable_and_linear is not set, the data in the other fields
421      * is unpredictable and should be ignored.
422      */
423     gx_color_enc_sep_lin_t separable_and_linear;
424     byte                   comp_shift[GX_DEVICE_COLOR_MAX_COMPONENTS];
425     byte                   comp_bits[GX_DEVICE_COLOR_MAX_COMPONENTS];
426     gx_color_index         comp_mask[GX_DEVICE_COLOR_MAX_COMPONENTS];
427 
428     /*
429      * Pointer to name for the process color model.
430      */
431     const char * cm_name;
432 
433     /*
434      * Indicate if overprint mode is supported. This is only supported
435      * for color models that have "DeviceCMYK" like behaivor: they support
436      * the cyan, magenta, yellow, and black color components, and map the
437      * components of a DeviceCMYK color space directly to these compoents.
438      * Most such color spaces will have the name DeviceCMYK, but it is
439      * also possible for DeviceN color models this behavior.
440      *
441      * If opmode has the value GX_CINFO_OPMODE, the process_comps will
442      * be a bit mask, with the (1 << i) bit set if i'th component is the
443      * cyan, magenta, yellow, or black component.
444      */
445     gx_cm_opmode_t opmode;
446     gx_color_index process_comps;
447 } gx_device_color_info;
448 
449 /* NB encoding flag ignored */
450 #define dci_extended_alpha_values(mcmp, nc, p, d, gi, mg, \
451 		        mc, dg, dc, ta, ga, sl, cn)   \
452     {mcmp /* max components */, \
453      nc /* number components */, \
454      p /* polarity */, \
455      d /* depth */, \
456      gi /* gray index */, \
457      mg /* max gray */, \
458      mc /* max color */, \
459      dg /* dither grays */, \
460      dc /* dither colors */, \
461      { ta, ga } /* antialias info text, graphics */, \
462      sl /* separable_and_linear */, \
463      { 0 } /* component shift */, \
464      { 0 } /* component bits */, \
465      { 0 } /* component mask */, \
466      cn /* process color name */,\
467      GX_CINFO_OPMODE_UNKNOWN /* opmode */,\
468      0 /* process_cmps */ }
469 
470 /*
471  * The "has color" macro requires a slightly different definition
472  * with the more general color models.
473  */
474 #define gx_device_has_color(dev)                           \
475    ( (dev)->color_info.num_components > 1 ||                \
476      (dev)->color_info.gray_index == GX_CINFO_COMP_NO_INDEX )
477 
478 
479 /* parameter initialization macros for backwards compatibility */
480 
481 /*
482  * These macros are needed to define values for fields added when
483  * DeviceN compatibility was added.  Previously the graphics
484  * library and the much of the device code examined the number of
485  * components and assume that 1 --> DeviceGray, 3-->DeviceRGB,
486  * and 4--> DeviceCMYK.  Since the old device code does not
487  * specify a color model, these macros make the same assumption.
488  * This assumption is incorrect for a DeviceN device and thus
489  * the following macros should not be used.  The previously
490  * defined macros should be used for new devices.
491  */
492 
493 #define dci_std_cm_name(nc)                 \
494     ( (nc) == 1 ? "DeviceGray"              \
495                 : ((nc) == 3 ? "DeviceRGB"  \
496                              : "DeviceCMYK") )
497 
498 #define dci_std_polarity(nc)                    \
499     ( (nc) == 4 ? GX_CINFO_POLARITY_SUBTRACTIVE \
500                 : GX_CINFO_POLARITY_ADDITIVE )
501 
502       /*
503        * Get the default gray_index value, based on the number of color
504        * components. Note that this must be consistent with the index
505        * implicitly used by the get_color_comp_index method and the
506        * procedures in the structure returned by the
507        * get_color_mapping_procs method.
508        */
509 #define dci_std_gray_index(nc)    \
510     ((nc) == 3 ? GX_CINFO_COMP_NO_INDEX : (nc) - 1)
511 
512 #define dci_alpha_values(nc, depth, mg, mc, dg, dc, ta, ga) \
513     dci_extended_alpha_values(nc, nc,			    \
514                               dci_std_polarity(nc),         \
515                               depth,                        \
516                               dci_std_gray_index(nc),       \
517                               mg, mc, dg, dc, ta, ga,       \
518                               GX_CINFO_UNKNOWN_SEP_LIN,     \
519 			      dci_std_cm_name(nc) )
520 
521 
522 /*
523  * Determine the depth corresponding to a color_bits specification.
524  * Note that color_bits == 0 ==> depth == 0; surprisingly this
525  * case is used.
526 */
527 #define dci_std_color_depth(color_bits)   \
528     ((color_bits) == 1 ? 1 : ((color_bits) + 7) & ~7)
529 
530 /*
531  * Determine the number of components corresponding to a color_bits
532  * specification. A device is monochrome only if it is bi-level;
533  * the 4 and 8 bit cases are handled as mapped color displays (for
534  * compatibility with existing code). The peculiar color_bits = 0
535  * case is considered monochrome, for no apparent reason.
536  */
537 #define dci_std_color_num_components(color_bits)      \
538     ( (color_bits) <= 1 ? 1                           \
539                       : ((color_bits) % 3 == 0 ||     \
540                          (color_bits) == 4     ||     \
541                          (color_bits) == 8       ) ? 3 : 4 )
542 
543 /*
544  * The number of bits assigned to the gray/black color component,
545  * assuming there is such a component. The underlying assumption
546  * is that any extra bits are assigned to this component.
547  */
548 #define dci_std_gray_bits(nc, color_bits)    \
549     ((color_bits) - ((nc) - 1) * ((color_bits) / (nc)))
550 
551 /*
552  * The number of bits assigned to a color component. The underlying
553  * assumptions are that there is a gray component if nc != 3, and
554  * that the gray component uses any extra bits.
555  */
556 #define dci_std_color_bits(nc, color_bits)                        \
557     ( (nc) == 3                                                   \
558         ? (color_bits) / (nc)                                     \
559         : ( (nc) == 1                                             \
560               ? 0                                                 \
561               : ((color_bits) - dci_std_gray_bits(nc, color_bits))\
562                      / ((nc) == 1 ? (1) : (nc) - 1) ) )
563 
564 /*
565  * Determine the max_gray and max_color values based on the number
566  * of components and the color_bits value. See the comments above
567  * for information on the underlying assumptions.
568  */
569 #define dci_std_color_max_gray(nc, color_bits)            \
570     ( (nc) == 3                                           \
571         ? 0                                               \
572         : (1 << dci_std_gray_bits(nc, color_bits)) - 1 )
573 
574 #define dci_std_color_max_color(nc, color_bits)               \
575     ( (nc) == 1                                               \
576         ? 0                                                   \
577         : (1 << dci_std_color_bits(nc, color_bits)) - 1 )
578 
579 
580 /*
581  * Define a color model based strictly on the number of bits
582  * available for color representation. Please note, this is only
583  * intended to work for a limited set of devices.
584  */
585 #define dci_std_color_(nc, color_bits)                        \
586     dci_values( nc,                                           \
587                 dci_std_color_depth(color_bits),              \
588                 dci_std_color_max_gray(nc, color_bits),       \
589                 dci_std_color_max_color(nc, color_bits),      \
590                 dci_std_color_max_gray(nc, color_bits) + 1,   \
591                 dci_std_color_max_color(nc, color_bits) + 1 )
592 
593 #define dci_std_color(color_bits)                             \
594     dci_std_color_( dci_std_color_num_components(color_bits), \
595                     color_bits )
596 
597 #define dci_values(nc,depth,mg,mc,dg,dc)\
598   dci_alpha_values(nc, depth, mg, mc, dg, dc, 1, 1)
599 #define dci_black_and_white dci_std_color(1)
600 #define dci_black_and_white_() dci_black_and_white
601 #define dci_color(depth,maxv,dither)\
602   dci_values(3, depth, maxv, maxv, dither, dither)
603 
604 /*
605  * Macro to access the name of the process color model.
606  */
607 #define get_process_color_model_name(dev) \
608     ((dev)->color_info.cm_name)
609 
610 
611 /* Structure for device procedures. */
612 typedef struct gx_device_procs_s gx_device_procs;
613 
614 /* Structure for page device procedures. */
615 /* Note that these take the graphics state as a parameter. */
616 typedef struct gx_page_device_procs_s {
617 
618 #define dev_page_proc_install(proc)\
619   int proc(gx_device *dev, gs_state *pgs)
620     dev_page_proc_install((*install));
621 
622 #define dev_page_proc_begin_page(proc)\
623   int proc(gx_device *dev, gs_state *pgs)
624     dev_page_proc_begin_page((*begin_page));
625 
626 #define dev_page_proc_end_page(proc)\
627   int proc(gx_device *dev, int reason, gs_state *pgs)
628     dev_page_proc_end_page((*end_page));
629 
630 } gx_page_device_procs;
631 
632 /* Default procedures */
633 dev_page_proc_install(gx_default_install);
634 dev_page_proc_begin_page(gx_default_begin_page);
635 dev_page_proc_end_page(gx_default_end_page);
636 
637 /* ---------------- Device structure ---------------- */
638 
639 /*
640  * Define the generic device structure.  The device procedures can
641  * have two different configurations:
642  *
643  *      - Statically initialized devices predating release 2.8.1
644  *      set the static_procs pointer to point to a separate procedure record,
645  *      and do not initialize procs.
646  *
647  *      - Statically initialized devices starting with release 2.8.1,
648  *      and all dynamically created device instances,
649  *      set the static_procs pointer to 0, and initialize procs.
650  *
651  * The gx_device_set_procs procedure converts the first of these to
652  * the second, which is what all client code starting in 2.8.1 expects
653  * (using the procs record, not the static_procs pointer, to call the
654  * driver procedures).
655  *
656  * The choice of the name Margins (rather than, say, HWOffset), and the
657  * specification in terms of a default device resolution rather than
658  * 1/72" units, are due to Adobe.
659  *
660  * ****** NOTE: If you define any subclasses of gx_device, you *must* define
661  * ****** the finalization procedure as gx_device_finalize.  Finalization
662  * ****** procedures are not automatically inherited.
663  */
664 typedef struct gx_device_cached_colors_s {
665     gx_color_index black, white;
666 } gx_device_cached_colors_t;
667 #define gx_device_common\
668 	int params_size;		/* OBSOLETE if stype != 0: */\
669 					/* size of this structure */\
670 	const gx_device_procs *static_procs;	/* OBSOLETE */\
671 					/* pointer to procs */\
672 	const char *dname;		/* the device name */\
673 	gs_memory_t *memory;		/* (0 iff static prototype) */\
674 	gs_memory_type_ptr_t stype;	/* memory manager structure type, */\
675 					/* may be 0 if static prototype */\
676 	bool stype_is_dynamic;		/* if true, free the stype when */\
677 					/* freeing the device */\
678 	void (*finalize)(gx_device *);  /* finalization to execute */\
679 					/* before closing device, if any */\
680 	rc_header rc;			/* reference count from gstates */\
681 					/* and targets, +1 if retained */\
682 	bool retained;			/* true if retained */\
683 	bool is_open;			/* true if device has been opened */\
684 	int max_fill_band;		/* limit on band size for fill, */\
685 					/* must be 0 or a power of 2 */\
686 					/* (see gdevabuf.c for more info) */\
687 	gx_device_color_info color_info;	/* color information */\
688 	gx_device_cached_colors_t cached_colors;\
689 	int width;			/* width in pixels */\
690 	int height;			/* height in pixels */\
691         int TrayOrientation;            /* default 0 ( 90 180 270 ) if device supports */\
692 	float MediaSize[2];		/* media dimensions in points */\
693 	float ImagingBBox[4];		/* imageable region in points */\
694 	  bool ImagingBBox_set;\
695 	float HWResolution[2];		/* resolution, dots per inch */\
696 	float MarginsHWResolution[2];	/* resolution for Margins */\
697 	float Margins[2];		/* offset of physical page corner */\
698 					/* from device coordinate (0,0), */\
699 					/* in units given by MarginsHWResolution */\
700 	float HWMargins[4];		/* margins around imageable area, */\
701 					/* in default user units ("points") */\
702 	long PageCount;			/* number of pages written */\
703 	long ShowpageCount;		/* number of calls on showpage */\
704 	int NumCopies;\
705 	  bool NumCopies_set;\
706 	bool IgnoreNumCopies;		/* if true, force num_copies = 1 */\
707 	bool UseCIEColor;		/* for PS LL3 */\
708 	bool LockSafetyParams;		/* If true, prevent unsafe changes */\
709 	gx_page_device_procs page_procs;	/* must be last */\
710 		/* end of std_device_body */\
711 	gx_device_procs procs	/* object procedures */
712 /*
713  * Note: x/y_pixels_per_inch are here only for backward compatibility.
714  * They should not be used in new code.
715  */
716 #define x_pixels_per_inch HWResolution[0]
717 #define y_pixels_per_inch HWResolution[1]
718 #define offset_margin_values(x, y, left, bot, right, top)\
719   {x, y}, {left, bot, right, top}
720 #define margin_values(left, bot, right, top)\
721   offset_margin_values(0, 0, left, bot, right, top)
722 #define no_margins margin_values(0, 0, 0, 0)
723 #define no_margins_() no_margins
724 /* Define macros that give the page offset ("Margins") in inches. */
725 #define dev_x_offset(dev) ((dev)->Margins[0] / (dev)->MarginsHWResolution[0])
726 #define dev_y_offset(dev) ((dev)->Margins[1] / (dev)->MarginsHWResolution[1])
727 #define dev_y_offset_points(dev) (dev_y_offset(dev) * 72.0)
728 /* Note that left/right/top/bottom are defined relative to */
729 /* the physical paper, not the coordinate system. */
730 /* For backward compatibility, we define macros that give */
731 /* the margins in inches. */
732 #define dev_l_margin(dev) ((dev)->HWMargins[0] / 72.0)
733 #define dev_b_margin(dev) ((dev)->HWMargins[1] / 72.0)
734 #define dev_b_margin_points(dev) ((dev)->HWMargins[1])
735 #define dev_r_margin(dev) ((dev)->HWMargins[2] / 72.0)
736 #define dev_t_margin(dev) ((dev)->HWMargins[3] / 72.0)
737 #define dev_t_margin_points(dev) ((dev)->HWMargins[3])
738 /* The extra () are to prevent premature expansion. */
739 #define open_init_closed() 0 /*false*/, 0	/* max_fill_band */
740 #define open_init_open() 1 /*true*/, 0	/* max_fill_band */
741 /* Accessors for device procedures */
742 #define dev_proc(dev, p) ((dev)->procs.p)
743 #define set_dev_proc(dev, p, proc) ((dev)->procs.p = (proc))
744 #define fill_dev_proc(dev, p, dproc)\
745   if ( dev_proc(dev, p) == 0 ) set_dev_proc(dev, p, dproc)
746 #define assign_dev_procs(todev, fromdev)\
747   ((todev)->procs = (fromdev)->procs)
748 
749 
750 /* ---------------- Device procedures ---------------- */
751 
752 /* Define an opaque type for parameter lists. */
753 #ifndef gs_param_list_DEFINED
754 #  define gs_param_list_DEFINED
755 typedef struct gs_param_list_s gs_param_list;
756 #endif
757 
758 /*
759  * Definition of device procedures.
760  * Note that the gx_device * argument is not declared const,
761  * because many drivers maintain dynamic state in the device structure.
762  * Note also that the structure is defined as a template, so that
763  * we can instantiate it with device subclasses.
764  * Because C doesn't have real templates, we must do this with macros.
765  */
766 
767 /* Define macros for declaring device procedures. */
768 
769 #define dev_t_proc_open_device(proc, dev_t)\
770   int proc(dev_t *dev)
771 #define dev_proc_open_device(proc)\
772   dev_t_proc_open_device(proc, gx_device)
773 
774 #define dev_t_proc_get_initial_matrix(proc, dev_t)\
775   void proc(dev_t *dev, gs_matrix *pmat)
776 #define dev_proc_get_initial_matrix(proc)\
777   dev_t_proc_get_initial_matrix(proc, gx_device)
778 
779 #define dev_t_proc_sync_output(proc, dev_t)\
780   int proc(dev_t *dev)
781 #define dev_proc_sync_output(proc)\
782   dev_t_proc_sync_output(proc, gx_device)
783 
784 #define dev_t_proc_output_page(proc, dev_t)\
785   int proc(dev_t *dev, int num_copies, int flush)
786 #define dev_proc_output_page(proc)\
787   dev_t_proc_output_page(proc, gx_device)
788 
789 #define dev_t_proc_close_device(proc, dev_t)\
790   int proc(dev_t *dev)
791 #define dev_proc_close_device(proc)\
792   dev_t_proc_close_device(proc, gx_device)
793 
794 #define dev_t_proc_map_rgb_color(proc, dev_t)\
795   gx_color_index proc(dev_t *dev, const gx_color_value cv[])
796 #define dev_proc_map_rgb_color(proc)\
797   dev_t_proc_map_rgb_color(proc, gx_device)
798 
799 #define dev_t_proc_map_color_rgb(proc, dev_t)\
800   int proc(dev_t *dev,\
801     gx_color_index color, gx_color_value rgb[3])
802 #define dev_proc_map_color_rgb(proc)\
803   dev_t_proc_map_color_rgb(proc, gx_device)
804 
805 #define dev_t_proc_fill_rectangle(proc, dev_t)\
806   int proc(dev_t *dev,\
807     int x, int y, int width, int height, gx_color_index color)
808 #define dev_proc_fill_rectangle(proc)\
809   dev_t_proc_fill_rectangle(proc, gx_device)
810 
811 #define dev_t_proc_tile_rectangle(proc, dev_t)\
812   int proc(dev_t *dev,\
813     const gx_tile_bitmap *tile, int x, int y, int width, int height,\
814     gx_color_index color0, gx_color_index color1,\
815     int phase_x, int phase_y)
816 #define dev_proc_tile_rectangle(proc)\
817   dev_t_proc_tile_rectangle(proc, gx_device)
818 
819 #define dev_t_proc_copy_mono(proc, dev_t)\
820   int proc(dev_t *dev,\
821     const byte *data, int data_x, int raster, gx_bitmap_id id,\
822     int x, int y, int width, int height,\
823     gx_color_index color0, gx_color_index color1)
824 #define dev_proc_copy_mono(proc)\
825   dev_t_proc_copy_mono(proc, gx_device)
826 
827 #define dev_t_proc_copy_color(proc, dev_t)\
828   int proc(dev_t *dev,\
829     const byte *data, int data_x, int raster, gx_bitmap_id id,\
830     int x, int y, int width, int height)
831 #define dev_proc_copy_color(proc)\
832   dev_t_proc_copy_color(proc, gx_device)
833 
834 		/* OBSOLETED in release 3.66 */
835 
836 #define dev_t_proc_draw_line(proc, dev_t)\
837   int proc(dev_t *dev,\
838     int x0, int y0, int x1, int y1, gx_color_index color)
839 #define dev_proc_draw_line(proc)\
840   dev_t_proc_draw_line(proc, gx_device)
841 
842 		/* Added in release 2.4 */
843 
844 #define dev_t_proc_get_bits(proc, dev_t)\
845   int proc(dev_t *dev,\
846     int y, byte *data, byte **actual_data)
847 #define dev_proc_get_bits(proc)\
848   dev_t_proc_get_bits(proc, gx_device)
849 
850 		/* Added in release 2.4, changed in 2.8, */
851 		/* renamed in 2.9.6 */
852 
853 #define dev_t_proc_get_params(proc, dev_t)\
854   int proc(dev_t *dev, gs_param_list *plist)
855 #define dev_proc_get_params(proc)\
856   dev_t_proc_get_params(proc, gx_device)
857 
858 #define dev_t_proc_put_params(proc, dev_t)\
859   int proc(dev_t *dev, gs_param_list *plist)
860 #define dev_proc_put_params(proc)\
861   dev_t_proc_put_params(proc, gx_device)
862 
863 		/* Added in release 2.6 */
864 
865 #define dev_t_proc_map_cmyk_color(proc, dev_t)\
866   gx_color_index proc(dev_t *dev, const gx_color_value cv[])
867 #define dev_proc_map_cmyk_color(proc)\
868   dev_t_proc_map_cmyk_color(proc, gx_device)
869 
870 #define dev_t_proc_get_xfont_procs(proc, dev_t)\
871   const gx_xfont_procs *proc(dev_t *dev)
872 #define dev_proc_get_xfont_procs(proc)\
873   dev_t_proc_get_xfont_procs(proc, gx_device)
874 
875 		/* Added in release 2.6.1 */
876 
877 #define dev_t_proc_get_xfont_device(proc, dev_t)\
878   gx_device *proc(dev_t *dev)
879 #define dev_proc_get_xfont_device(proc)\
880   dev_t_proc_get_xfont_device(proc, gx_device)
881 
882 		/* Added in release 2.7.1 */
883 
884 #define dev_t_proc_map_rgb_alpha_color(proc, dev_t)\
885   gx_color_index proc(dev_t *dev,\
886     gx_color_value red, gx_color_value green, gx_color_value blue,\
887     gx_color_value alpha)
888 #define dev_proc_map_rgb_alpha_color(proc)\
889   dev_t_proc_map_rgb_alpha_color(proc, gx_device)
890 
891 		/* Added in release 2.8.1 */
892 
893 #define dev_t_proc_get_page_device(proc, dev_t)\
894   gx_device *proc(dev_t *dev)
895 #define dev_proc_get_page_device(proc)\
896   dev_t_proc_get_page_device(proc, gx_device)
897 
898 		/* Added in release 3.20, OBSOLETED in 5.65 */
899 
900 #define dev_t_proc_get_alpha_bits(proc, dev_t)\
901   int proc(dev_t *dev, graphics_object_type type)
902 #define dev_proc_get_alpha_bits(proc)\
903   dev_t_proc_get_alpha_bits(proc, gx_device)
904 
905 		/* Added in release 3.20 */
906 
907 #define dev_t_proc_copy_alpha(proc, dev_t)\
908   int proc(dev_t *dev, const byte *data, int data_x,\
909     int raster, gx_bitmap_id id, int x, int y, int width, int height,\
910     gx_color_index color, int depth)
911 #define dev_proc_copy_alpha(proc)\
912   dev_t_proc_copy_alpha(proc, gx_device)
913 
914 		/* Added in release 3.38 */
915 
916 #define dev_t_proc_get_band(proc, dev_t)\
917   int proc(dev_t *dev, int y, int *band_start)
918 #define dev_proc_get_band(proc)\
919   dev_t_proc_get_band(proc, gx_device)
920 
921 		/* Added in release 3.44 */
922 
923 #define dev_t_proc_copy_rop(proc, dev_t)\
924   int proc(dev_t *dev,\
925     const byte *sdata, int sourcex, uint sraster, gx_bitmap_id id,\
926     const gx_color_index *scolors,\
927     const gx_tile_bitmap *texture, const gx_color_index *tcolors,\
928     int x, int y, int width, int height,\
929     int phase_x, int phase_y, gs_logical_operation_t lop)
930 #define dev_proc_copy_rop(proc)\
931   dev_t_proc_copy_rop(proc, gx_device)
932 
933 		/* Added in release 3.60, changed in 3.68. */
934 
935 #define dev_t_proc_fill_path(proc, dev_t)\
936   int proc(dev_t *dev,\
937     const gs_imager_state *pis, gx_path *ppath,\
938     const gx_fill_params *params,\
939     const gx_drawing_color *pdcolor, const gx_clip_path *pcpath)
940 #define dev_proc_fill_path(proc)\
941   dev_t_proc_fill_path(proc, gx_device)
942 
943 #define dev_t_proc_stroke_path(proc, dev_t)\
944   int proc(dev_t *dev,\
945     const gs_imager_state *pis, gx_path *ppath,\
946     const gx_stroke_params *params,\
947     const gx_drawing_color *pdcolor, const gx_clip_path *pcpath)
948 #define dev_proc_stroke_path(proc)\
949   dev_t_proc_stroke_path(proc, gx_device)
950 
951 		/* Added in release 3.60 */
952 
953 #define dev_t_proc_fill_mask(proc, dev_t)\
954   int proc(dev_t *dev,\
955     const byte *data, int data_x, int raster, gx_bitmap_id id,\
956     int x, int y, int width, int height,\
957     const gx_drawing_color *pdcolor, int depth,\
958     gs_logical_operation_t lop, const gx_clip_path *pcpath)
959 #define dev_proc_fill_mask(proc)\
960   dev_t_proc_fill_mask(proc, gx_device)
961 
962 		/* Added in release 3.66, changed in 3.69 */
963 
964 #define dev_t_proc_fill_trapezoid(proc, dev_t)\
965   int proc(dev_t *dev,\
966     const gs_fixed_edge *left, const gs_fixed_edge *right,\
967     fixed ybot, fixed ytop, bool swap_axes,\
968     const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
969 #define dev_proc_fill_trapezoid(proc)\
970   dev_t_proc_fill_trapezoid(proc, gx_device)
971 
972 #define dev_t_proc_fill_parallelogram(proc, dev_t)\
973   int proc(dev_t *dev,\
974     fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,\
975     const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
976 #define dev_proc_fill_parallelogram(proc)\
977   dev_t_proc_fill_parallelogram(proc, gx_device)
978 
979 #define dev_t_proc_fill_triangle(proc, dev_t)\
980   int proc(dev_t *dev,\
981     fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,\
982     const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
983 #define dev_proc_fill_triangle(proc)\
984   dev_t_proc_fill_triangle(proc, gx_device)
985 
986 #define dev_t_proc_draw_thin_line(proc, dev_t)\
987   int proc(dev_t *dev,\
988     fixed fx0, fixed fy0, fixed fx1, fixed fy1,\
989     const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
990 #define dev_proc_draw_thin_line(proc)\
991   dev_t_proc_draw_thin_line(proc, gx_device)
992 
993 		/* Added in release 3.66 (as stubs); */
994 		/* changed in 3.68; */
995 		/* begin_image and image_data changed in 4.30, */
996 		/* begin_image changed in 5.23. */
997 
998 #define dev_t_proc_begin_image(proc, dev_t)\
999   int proc(dev_t *dev,\
1000     const gs_imager_state *pis, const gs_image_t *pim,\
1001     gs_image_format_t format, const gs_int_rect *prect,\
1002     const gx_drawing_color *pdcolor, const gx_clip_path *pcpath,\
1003     gs_memory_t *memory, gx_image_enum_common_t **pinfo)
1004 #define dev_proc_begin_image(proc)\
1005   dev_t_proc_begin_image(proc, gx_device)
1006 
1007 		/* OBSOLETED in release 5.23 */
1008 
1009 #define dev_t_proc_image_data(proc, dev_t)\
1010   int proc(dev_t *dev,\
1011     gx_image_enum_common_t *info, const byte **planes, int data_x,\
1012     uint raster, int height)
1013 #define dev_proc_image_data(proc)\
1014   dev_t_proc_image_data(proc, gx_device)
1015 
1016 		/* OBSOLETED in release 5.23 */
1017 
1018 #define dev_t_proc_end_image(proc, dev_t)\
1019   int proc(dev_t *dev,\
1020     gx_image_enum_common_t *info, bool draw_last)
1021 #define dev_proc_end_image(proc)\
1022   dev_t_proc_end_image(proc, gx_device)
1023 
1024 		/* Added in release 3.68 */
1025 
1026 #define dev_t_proc_strip_tile_rectangle(proc, dev_t)\
1027   int proc(dev_t *dev,\
1028     const gx_strip_bitmap *tiles, int x, int y, int width, int height,\
1029     gx_color_index color0, gx_color_index color1,\
1030     int phase_x, int phase_y)
1031 #define dev_proc_strip_tile_rectangle(proc)\
1032   dev_t_proc_strip_tile_rectangle(proc, gx_device)
1033 
1034 #define dev_t_proc_strip_copy_rop(proc, dev_t)\
1035   int proc(dev_t *dev,\
1036     const byte *sdata, int sourcex, uint sraster, gx_bitmap_id id,\
1037     const gx_color_index *scolors,\
1038     const gx_strip_bitmap *textures, const gx_color_index *tcolors,\
1039     int x, int y, int width, int height,\
1040     int phase_x, int phase_y, gs_logical_operation_t lop)
1041 #define dev_proc_strip_copy_rop(proc)\
1042   dev_t_proc_strip_copy_rop(proc, gx_device)
1043 
1044 		/* Added in release 4.20 */
1045 
1046 #define dev_t_proc_get_clipping_box(proc, dev_t)\
1047   void proc(dev_t *dev, gs_fixed_rect *pbox)
1048 #define dev_proc_get_clipping_box(proc)\
1049   dev_t_proc_get_clipping_box(proc, gx_device)
1050 
1051 		/* Added in release 5.20, changed in 5.23 */
1052 
1053 #define dev_t_proc_begin_typed_image(proc, dev_t)\
1054   int proc(dev_t *dev,\
1055     const gs_imager_state *pis, const gs_matrix *pmat,\
1056     const gs_image_common_t *pim, const gs_int_rect *prect,\
1057     const gx_drawing_color *pdcolor, const gx_clip_path *pcpath,\
1058     gs_memory_t *memory, gx_image_enum_common_t **pinfo)
1059 #define dev_proc_begin_typed_image(proc)\
1060   dev_t_proc_begin_typed_image(proc, gx_device)
1061 
1062 		/* Added in release 5.20 */
1063 
1064 #define dev_t_proc_get_bits_rectangle(proc, dev_t)\
1065   int proc(dev_t *dev, const gs_int_rect *prect,\
1066     gs_get_bits_params_t *params, gs_int_rect **unread)
1067 #define dev_proc_get_bits_rectangle(proc)\
1068   dev_t_proc_get_bits_rectangle(proc, gx_device)
1069 
1070 #define dev_t_proc_map_color_rgb_alpha(proc, dev_t)\
1071   int proc(dev_t *dev,\
1072     gx_color_index color, gx_color_value rgba[4])
1073 #define dev_proc_map_color_rgb_alpha(proc)\
1074   dev_t_proc_map_color_rgb_alpha(proc, gx_device)
1075 
1076 #define dev_t_proc_create_compositor(proc, dev_t)\
1077   int proc(dev_t *dev,\
1078     gx_device **pcdev, const gs_composite_t *pcte,\
1079     gs_imager_state *pis, gs_memory_t *memory)
1080 #define dev_proc_create_compositor(proc)\
1081   dev_t_proc_create_compositor(proc, gx_device)\
1082 
1083 		/* Added in release 5.23 */
1084 
1085 #define dev_t_proc_get_hardware_params(proc, dev_t)\
1086   int proc(dev_t *dev, gs_param_list *plist)
1087 #define dev_proc_get_hardware_params(proc)\
1088   dev_t_proc_get_hardware_params(proc, gx_device)
1089 
1090 		/* Added in release 5.24 */
1091 
1092      /* ... text_begin ... see gxtext.h for definition */
1093 
1094 		/* Added in release 6.23 */
1095 
1096 #define dev_t_proc_finish_copydevice(proc, dev_t)\
1097   int proc(dev_t *dev, const gx_device *from_dev)
1098 #define dev_proc_finish_copydevice(proc)\
1099   dev_t_proc_finish_copydevice(proc, gx_device)
1100 
1101 		/* Added in release 6.61 (raph) */
1102 
1103 
1104 /*
1105   This area of the transparency facilities is in flux.  Here is a proposal
1106   for extending the driver interface.
1107 */
1108 
1109 /*
1110   Push the current transparency state (*ppts) onto the associated stack,
1111   and set *ppts to a new transparency state of the given dimension.  The
1112   transparency state may copy some or all of the imager state, such as the
1113   current alpha and/or transparency mask values, and definitely copies the
1114   parameters.
1115 */
1116 #define dev_t_proc_begin_transparency_group(proc, dev_t)\
1117   int proc(gx_device *dev,\
1118     const gs_transparency_group_params_t *ptgp,\
1119     const gs_rect *pbbox,\
1120     gs_imager_state *pis,\
1121     gs_transparency_state_t **ppts,\
1122     gs_memory_t *mem)
1123 #define dev_proc_begin_transparency_group(proc)\
1124   dev_t_proc_begin_transparency_group(proc, gx_device)
1125 
1126 /*
1127   End a transparency group: blend the top element of the transparency
1128   stack, which must be a group, into the next-to-top element, popping the
1129   stack.  If the stack only had a single element, blend into the device
1130   output.  Set *ppts to 0 iff the stack is now empty.  If end_group fails,
1131   the stack is *not* popped.
1132 */
1133 #define dev_t_proc_end_transparency_group(proc, dev_t)\
1134   int proc(gx_device *dev,\
1135     gs_imager_state *pis,\
1136     gs_transparency_state_t **ppts)
1137 #define dev_proc_end_transparency_group(proc)\
1138   dev_t_proc_end_transparency_group(proc, gx_device)
1139 
1140 /*
1141   Push the transparency state and prepare to render a transparency mask.
1142   This is similar to begin_transparency_group except that it only
1143   accumulates coverage values, not full pixel values.
1144 */
1145 #define dev_t_proc_begin_transparency_mask(proc, dev_t)\
1146   int proc(gx_device *dev,\
1147     const gx_transparency_mask_params_t *ptmp,\
1148     const gs_rect *pbbox,\
1149     gs_imager_state *pis,\
1150     gs_transparency_state_t **ppts,\
1151     gs_memory_t *mem)
1152 #define dev_proc_begin_transparency_mask(proc)\
1153   dev_t_proc_begin_transparency_mask(proc, gx_device)
1154 
1155 /*
1156   Store a pointer to the rendered transparency mask into *pptm, popping the
1157   stack like end_group.  Normally, the client will follow this by using
1158   rc_assign to store the rendered mask into pis->{opacity,shape}.mask.  If
1159   end_mask fails, the stack is *not* popped.
1160 */
1161 #define dev_t_proc_end_transparency_mask(proc, dev_t)\
1162   int proc(gx_device *dev,\
1163     gs_transparency_mask_t **pptm)
1164 #define dev_proc_end_transparency_mask(proc)\
1165   dev_t_proc_end_transparency_mask(proc, gx_device)
1166 
1167 /*
1168   Pop the transparency stack, discarding the top element, which may be
1169   either a group or a mask.  Set *ppts to 0 iff the stack is now empty.
1170 */
1171 #define dev_t_proc_discard_transparency_layer(proc, dev_t)\
1172   int proc(gx_device *dev,\
1173     gs_transparency_state_t **ppts)
1174 #define dev_proc_discard_transparency_layer(proc)\
1175   dev_t_proc_discard_transparency_layer(proc, gx_device)
1176 
1177      /* (end of transparency driver interface extensions) */
1178 
1179      /* (start of DeviceN color support) */
1180 /*
1181  * The following macros are defined in gxcmap.h
1182  *
1183  * dev_t_proc_get_color_mapping_procs
1184  * dev_proc_get_color_mapping_procs
1185  * dev_t_proc_get_color_comp_index
1186  * dev_proc_get_color_comp_index
1187  * dev_t_proc_encode_color
1188  * dev_proc_encode_color
1189  * dev_t_proc_decode_color
1190  * dev_proc_decode_color
1191  */
1192      /* (end of DeviceN color support) */
1193 
1194 /*
1195   Pattern management for high level devices.
1196   Now we need it for PatternType 1 only.
1197   Return codes :
1198   1 - the device handles high level patterns.
1199   0 - the device needs low level pattern tiles.
1200   <0 - error.
1201 */
1202 
1203 		/* High level device support. */
1204 
1205 typedef enum {
1206     pattern_manage__can_accum,
1207     pattern_manage__start_accum,
1208     pattern_manage__finish_accum,
1209     pattern_manage__load,
1210     pattern_manage__shading_area
1211 } pattern_manage_t;
1212 
1213 #define dev_t_proc_pattern_manage(proc, dev_t)\
1214   int proc(gx_device *pdev, gx_bitmap_id id,\
1215 		gs_pattern1_instance_t *pinst, pattern_manage_t function)
1216 #define dev_proc_pattern_manage(proc)\
1217   dev_t_proc_pattern_manage(proc, gx_device)
1218 
1219 /*
1220   Fill rectangle with a high level color.
1221   Return rangecheck, if the device can't handle the high level color.
1222 
1223   The graphics library calls this function with degenerate (widths=0)
1224   rectangles, to know whether the device can handle a rectangle with
1225   the high level color. The device should skip such rectangles returning
1226   a proper code.
1227 
1228   Currently this function is used with gs_rectfill and gs_fillpage only.
1229   In future it should be called while decomposing other objects.
1230 */
1231 
1232 #define dev_t_proc_fill_rectangle_hl_color(proc, dev_t)\
1233   int proc(dev_t *dev, const gs_fixed_rect *rect, \
1234 	const gs_imager_state *pis, const gx_drawing_color *pdcolor, \
1235 	const gx_clip_path *pcpath)
1236 #define dev_proc_fill_rectangle_hl_color(proc)\
1237   dev_t_proc_fill_rectangle_hl_color(proc, gx_device)
1238 
1239 /*
1240   Include a color space into the output.
1241   This function is used to include DefaultGray, DefaultRGB,
1242   DefaultCMYK into PDF, PS, EPS output.
1243   Low level devices should ignore this call.
1244 */
1245 
1246 #define dev_t_proc_include_color_space(proc, dev_t)\
1247   int proc(dev_t *dev, gs_color_space *cspace, const byte *res_name, int name_length)
1248 #define dev_proc_include_color_space(proc)\
1249   dev_t_proc_include_color_space(proc, gx_device)
1250 
1251 		/* Shading support. */
1252 
1253 typedef struct gs_fill_attributes_s {
1254       const gs_fixed_rect *clip;
1255       bool swap_axes;
1256       const gx_device_halftone *ht; /* Reserved for possible use in future. */
1257       gs_logical_operation_t lop; /* Reserved for possible use in future. */
1258       fixed ystart, yend; /* Only for X-independent gradients. Base coordinates of the gradient. */
1259 } gs_fill_attributes;
1260 
1261 /* Fill a linear color scanline. */
1262 
1263 #define dev_t_proc_fill_linear_color_scanline(proc, dev_t)\
1264   int proc(dev_t *dev, const gs_fill_attributes *fa,\
1265 	int i, int j, int w, /* scanline coordinates and width */\
1266 	const frac31 *c0, /* initial color for the pixel (i,j), the integer part */\
1267 	const int32_t *c0_f, /* initial color for the pixel (i,j), the fraction part numerator */\
1268 	const int32_t *cg_num, /* color gradient numerator */\
1269 	int32_t cg_den /* color gradient denominator */)
1270 #define dev_proc_fill_linear_color_scanline(proc)\
1271   dev_t_proc_fill_linear_color_scanline(proc, gx_device)
1272 
1273 /* Fill a linear color trapezoid. */
1274 /* The server assumes a strongly linear color,
1275    i.e. it can ignore any of c0, c1, c2, c3. */
1276 /* [p0 : p1] - left edge, from bottom to top.
1277    [p2 : p3] - right edge, from bottom to top.
1278    The filled area is within Y-spans of both edges. */
1279 /* If either (c0 and c1) or (c2 and c3) may be NULL.
1280    In this case the color doesn't depend on X (on Y if fa->swap_axes).
1281    In this case the base coordinates for the color gradient
1282    may be unequal to p0, p1, p2, p3, and must be provided/taken
1283    in/from fa->ystart, fa->yend.
1284    The rerurn value 0 is not allowed in this case. */
1285 /* Return values :
1286   1 - success;
1287   0 - Too big. The area isn't filled. The client must decompose the area.
1288   <0 - error.
1289  */
1290 
1291 #define dev_t_proc_fill_linear_color_trapezoid(proc, dev_t)\
1292   int proc(dev_t *dev, const gs_fill_attributes *fa,\
1293 	const gs_fixed_point *p0, const gs_fixed_point *p1,\
1294 	const gs_fixed_point *p2, const gs_fixed_point *p3,\
1295 	const frac31 *c0, const frac31 *c1,\
1296 	const frac31 *c2, const frac31 *c3)
1297 #define dev_proc_fill_linear_color_trapezoid(proc)\
1298   dev_t_proc_fill_linear_color_trapezoid(proc, gx_device)
1299 
1300 /* Fill a linear color triangle. */
1301 /* Return values :
1302   1 - success;
1303   0 - Too big. The area isn't filled. The client must decompose the area.
1304   <0 - error.
1305  */
1306 
1307 #define dev_t_proc_fill_linear_color_triangle(proc, dev_t)\
1308   int proc(dev_t *dev, const gs_fill_attributes *fa,\
1309 	const gs_fixed_point *p0, const gs_fixed_point *p1,\
1310 	const gs_fixed_point *p2,\
1311 	const frac31 *c0, const frac31 *c1, const frac31 *c2)
1312 #define dev_proc_fill_linear_color_triangle(proc)\
1313   dev_t_proc_fill_linear_color_triangle(proc, gx_device)
1314 
1315 /*
1316  * Update the equivalent colors for spot colors in a color space.  The default
1317  * procedure does nothing.  However this routine provides a method for devices
1318  * to determine an equivalent color for a spot color.  See comments at the
1319  * start of src/gsequivc.c.
1320  */
1321 #define dev_t_proc_update_spot_equivalent_colors(proc, dev_t)\
1322   int proc(dev_t *dev, const gs_state * pgs)
1323 #define dev_proc_update_spot_equivalent_colors(proc)\
1324   dev_t_proc_update_spot_equivalent_colors(proc, gx_device)
1325 
1326 /* Define the device procedure vector template proper. */
1327 
1328 #define gx_device_proc_struct(dev_t)\
1329 {	dev_t_proc_open_device((*open_device), dev_t);\
1330 	dev_t_proc_get_initial_matrix((*get_initial_matrix), dev_t);\
1331 	dev_t_proc_sync_output((*sync_output), dev_t);\
1332 	dev_t_proc_output_page((*output_page), dev_t);\
1333 	dev_t_proc_close_device((*close_device), dev_t);\
1334 	dev_t_proc_map_rgb_color((*map_rgb_color), dev_t);\
1335 	dev_t_proc_map_color_rgb((*map_color_rgb), dev_t);\
1336 	dev_t_proc_fill_rectangle((*fill_rectangle), dev_t);\
1337 	dev_t_proc_tile_rectangle((*tile_rectangle), dev_t);\
1338 	dev_t_proc_copy_mono((*copy_mono), dev_t);\
1339 	dev_t_proc_copy_color((*copy_color), dev_t);\
1340 	dev_t_proc_draw_line((*obsolete_draw_line), dev_t);\
1341 	dev_t_proc_get_bits((*get_bits), dev_t);\
1342 	dev_t_proc_get_params((*get_params), dev_t);\
1343 	dev_t_proc_put_params((*put_params), dev_t);\
1344 	dev_t_proc_map_cmyk_color((*map_cmyk_color), dev_t);\
1345 	dev_t_proc_get_xfont_procs((*get_xfont_procs), dev_t);\
1346 	dev_t_proc_get_xfont_device((*get_xfont_device), dev_t);\
1347 	dev_t_proc_map_rgb_alpha_color((*map_rgb_alpha_color), dev_t);\
1348 	dev_t_proc_get_page_device((*get_page_device), dev_t);\
1349 	dev_t_proc_get_alpha_bits((*get_alpha_bits), dev_t);\
1350 	dev_t_proc_copy_alpha((*copy_alpha), dev_t);\
1351 	dev_t_proc_get_band((*get_band), dev_t);\
1352 	dev_t_proc_copy_rop((*copy_rop), dev_t);\
1353 	dev_t_proc_fill_path((*fill_path), dev_t);\
1354 	dev_t_proc_stroke_path((*stroke_path), dev_t);\
1355 	dev_t_proc_fill_mask((*fill_mask), dev_t);\
1356 	dev_t_proc_fill_trapezoid((*fill_trapezoid), dev_t);\
1357 	dev_t_proc_fill_parallelogram((*fill_parallelogram), dev_t);\
1358 	dev_t_proc_fill_triangle((*fill_triangle), dev_t);\
1359 	dev_t_proc_draw_thin_line((*draw_thin_line), dev_t);\
1360 	dev_t_proc_begin_image((*begin_image), dev_t);\
1361 	dev_t_proc_image_data((*image_data), dev_t);\
1362 	dev_t_proc_end_image((*end_image), dev_t);\
1363 	dev_t_proc_strip_tile_rectangle((*strip_tile_rectangle), dev_t);\
1364 	dev_t_proc_strip_copy_rop((*strip_copy_rop), dev_t);\
1365 	dev_t_proc_get_clipping_box((*get_clipping_box), dev_t);\
1366 	dev_t_proc_begin_typed_image((*begin_typed_image), dev_t);\
1367 	dev_t_proc_get_bits_rectangle((*get_bits_rectangle), dev_t);\
1368 	dev_t_proc_map_color_rgb_alpha((*map_color_rgb_alpha), dev_t);\
1369 	dev_t_proc_create_compositor((*create_compositor), dev_t);\
1370 	dev_t_proc_get_hardware_params((*get_hardware_params), dev_t);\
1371 	dev_t_proc_text_begin((*text_begin), dev_t);\
1372 	dev_t_proc_finish_copydevice((*finish_copydevice), dev_t);\
1373 	dev_t_proc_begin_transparency_group((*begin_transparency_group), dev_t);\
1374 	dev_t_proc_end_transparency_group((*end_transparency_group), dev_t);\
1375 	dev_t_proc_begin_transparency_mask((*begin_transparency_mask), dev_t);\
1376 	dev_t_proc_end_transparency_mask((*end_transparency_mask), dev_t);\
1377 	dev_t_proc_discard_transparency_layer((*discard_transparency_layer), dev_t);\
1378 	dev_t_proc_get_color_mapping_procs((*get_color_mapping_procs), dev_t); \
1379 	dev_t_proc_get_color_comp_index((*get_color_comp_index), dev_t); \
1380 	dev_t_proc_encode_color((*encode_color), dev_t); \
1381 	dev_t_proc_decode_color((*decode_color), dev_t); \
1382 	dev_t_proc_pattern_manage((*pattern_manage), dev_t); \
1383 	dev_t_proc_fill_rectangle_hl_color((*fill_rectangle_hl_color), dev_t); \
1384 	dev_t_proc_include_color_space((*include_color_space), dev_t); \
1385 	dev_t_proc_fill_linear_color_scanline((*fill_linear_color_scanline), dev_t); \
1386 	dev_t_proc_fill_linear_color_trapezoid((*fill_linear_color_trapezoid), dev_t); \
1387 	dev_t_proc_fill_linear_color_triangle((*fill_linear_color_triangle), dev_t); \
1388 	dev_t_proc_update_spot_equivalent_colors((*update_spot_equivalent_colors), dev_t); \
1389 }
1390 
1391 
1392 /*
1393  * Provide procedures for passing image data.  image_data and end_image
1394  * are the equivalents of the obsolete driver procedures.  image_plane_data
1395  * was originally planned as a driver procedure, but is now associated with
1396  * the image enumerator, like the other two.
1397  */
1398 
1399 typedef struct gx_image_plane_s {
1400     const byte *data;
1401     int data_x;
1402     uint raster;
1403 } gx_image_plane_t;
1404 
1405 #define gx_device_begin_image(dev, pis, pim, format, prect, pdcolor, pcpath, memory, pinfo)\
1406   ((*dev_proc(dev, begin_image))\
1407    (dev, pis, pim, format, prect, pdcolor, pcpath, memory, pinfo))
1408 #define gx_device_begin_typed_image(dev, pis, pmat, pim, prect, pdcolor, pcpath, memory, pinfo)\
1409   ((*dev_proc(dev, begin_typed_image))\
1410    (dev, pis, pmat, pim, prect, pdcolor, pcpath, memory, pinfo))
1411 
1412 /*
1413  * The driver-like procedures gx_device_{image_data, image_plane_data,
1414  * end_image} are now DEPRECATED and will eventually be removed.
1415  * Their replacements no longer take an ignored dev argument.
1416  */
1417 int gx_image_data(gx_image_enum_common_t *info, const byte **planes,
1418 		  int data_x, uint raster, int height);
1419 /*
1420  * Solely for backward compatibility, gx_image_plane_data doesn't return
1421  * rows_used.
1422  */
1423 int gx_image_plane_data(gx_image_enum_common_t *info,
1424 			const gx_image_plane_t *planes, int height);
1425 int gx_image_plane_data_rows(gx_image_enum_common_t *info,
1426 			     const gx_image_plane_t *planes, int height,
1427 			     int *rows_used);
1428 int gx_image_flush(gx_image_enum_common_t *info);
1429 bool gx_image_planes_wanted(const gx_image_enum_common_t *info, byte *wanted);
1430 int gx_image_end(gx_image_enum_common_t *info, bool draw_last);
1431 
1432 #define gx_device_image_data(dev, info, planes, data_x, raster, height)\
1433   gx_image_data(info, planes, data_x, raster, height)
1434 #define gx_device_image_plane_data(dev, info, planes, height)\
1435   gx_image_plane_data(info, planes, height)
1436 #define gx_device_end_image(dev, info, draw_last)\
1437   gx_image_end(info, draw_last)
1438 
1439 /*
1440  * Get the anti-aliasing parameters for a device.  This replaces the
1441  * obsolete get_alpha_bits device procedure.
1442  */
1443 #define gx_device_get_alpha_bits(dev, type)\
1444   gx_default_get_alpha_bits(dev, type)
1445 
1446 /* A generic device procedure record. */
1447 struct gx_device_procs_s gx_device_proc_struct(gx_device);
1448 
1449 /*
1450  * Define unaligned analogues of the copy_xxx procedures.
1451  * These are slower than the standard procedures, which require
1452  * aligned bitmaps, and also are not portable to non-byte-addressed machines.
1453  *
1454  * We allow both unaligned data and unaligned scan line widths;
1455  * however, we do require that both of these be aligned modulo the largest
1456  * power of 2 bytes that divides the data depth, i.e.:
1457  *      depth   alignment
1458  *      <= 8    1
1459  *      16      2
1460  *      24      1
1461  *      32      4
1462  */
1463 dev_proc_copy_mono(gx_copy_mono_unaligned);
1464 dev_proc_copy_color(gx_copy_color_unaligned);
1465 dev_proc_copy_alpha(gx_copy_alpha_unaligned);
1466 
1467 /* A generic device */
1468 struct gx_device_s {
1469     gx_device_common;
1470 };
1471 
1472 extern_st(st_device);
1473 struct_proc_finalize(gx_device_finalize);	/* public for subclasses */
1474 /* We use vacuous enum/reloc procedures, rather than 0, so that */
1475 /* gx_device can have subclasses. */
1476 #define public_st_device()	/* in gsdevice.c */\
1477   gs_public_st_complex_only(st_device, gx_device, "gx_device",\
1478     0, gs_no_struct_enum_ptrs, gs_no_struct_reloc_ptrs, gx_device_finalize)
1479 #define st_device_max_ptrs 0
1480 
1481 /* Enumerate or relocate a pointer to a device. */
1482 /* These take the containing space into account properly. */
1483 gx_device *gx_device_enum_ptr(gx_device *);
1484 gx_device *gx_device_reloc_ptr(gx_device *, gc_state_t *);
1485 
1486 /* Define typedefs for some of the device procedures, because */
1487 /* ansi2knr can't handle dev_proc_xxx((*xxx)) in a formal argument list. */
1488 typedef dev_proc_map_rgb_color((*dev_proc_map_rgb_color_t));
1489 typedef dev_proc_map_color_rgb((*dev_proc_map_color_rgb_t));
1490 
1491 /*
1492  * A forwarding device forwards all non-display operations, and possibly
1493  * some imaging operations (possibly transformed in some way), to another
1494  * device called the "target".  This is used for many different purposes
1495  * internally, including clipping, banding, image and pattern accumulation,
1496  * compositing, halftoning, and the null device.
1497  */
1498 #define gx_device_forward_common\
1499 	gx_device_common;\
1500 	gx_device *target
1501 /* A generic forwarding device. */
1502 typedef struct gx_device_forward_s {
1503     gx_device_forward_common;
1504 } gx_device_forward;
1505 
1506 extern_st(st_device_forward);
1507 #define public_st_device_forward()	/* in gsdevice.c */\
1508   gs_public_st_complex_only(st_device_forward, gx_device_forward,\
1509     "gx_device_forward", 0, device_forward_enum_ptrs,\
1510     device_forward_reloc_ptrs, gx_device_finalize)
1511 #define st_device_forward_max_ptrs (st_device_max_ptrs + 1)
1512 
1513 /* A null device.  This is used to temporarily disable output. */
1514 #ifndef gx_device_null_DEFINED
1515 #  define gx_device_null_DEFINED
1516 typedef struct gx_device_null_s gx_device_null;
1517 #endif
1518 struct gx_device_null_s {
1519     gx_device_forward_common;
1520 };
1521 extern const gx_device_null gs_null_device;
1522 
1523 #define gx_device_is_null(dev)\
1524   ((dev)->dname == gs_null_device.dname)
1525 extern_st(st_device_null);
1526 #define public_st_device_null()	/* in gsdevice.c */\
1527   gs_public_st_complex_only(st_device_null, gx_device_null,\
1528     "gx_device_null", 0, device_forward_enum_ptrs,\
1529     device_forward_reloc_ptrs, gx_device_finalize)
1530 #define st_device_null_max_ptrs st_device_forward_max_ptrs
1531 
1532 /*
1533  * Initialize a just-allocated device from a prototype.  If internal =
1534  * false, the device is marked retained; if internal = true, the device is
1535  * not marked retained.  See the beginning of this file for more information
1536  * about what this means.  Normally, devices created for temporary use have
1537  * internal = true (retained = false).
1538  */
1539 void gx_device_init(gx_device * dev, const gx_device * proto,
1540 		    gs_memory_t * mem, bool internal);
1541 
1542 /* Make a null device. */
1543 /* The gs_memory_t argument is 0 if the device is temporary and local, */
1544 /* or the allocator that was used to allocate it if it is a real object. */
1545 void gs_make_null_device(gx_device_null *dev_null, gx_device *target,
1546 			 gs_memory_t *mem);
1547 /* Is a null device ? */
1548 bool gs_is_null_device(gx_device *dev);
1549 
1550 /* Set the target of a (forwarding) device. */
1551 void gx_device_set_target(gx_device_forward *fdev, gx_device *target);
1552 
1553 /* Mark a device as retained or not retained. */
1554 void gx_device_retain(gx_device *dev, bool retained);
1555 
1556 /* Calculate the raster (number of bytes in a scan line), */
1557 /* with byte or word padding. */
1558 uint gx_device_raster(const gx_device * dev, bool pad_to_word);
1559 
1560 /* Adjust the resolution for devices that only have a fixed set of */
1561 /* geometries, so that the apparent size in inches remains constant. */
1562 /* If fit=1, the resolution is adjusted so that the entire image fits; */
1563 /* if fit=0, one dimension fits, but the other one is clipped. */
1564 int gx_device_adjust_resolution(gx_device * dev, int actual_width, int actual_height, int fit);
1565 
1566 /* Set the HWMargins to values defined in inches. */
1567 /* If move_origin is true, also reset the Margins. */
1568 void gx_device_set_margins(gx_device * dev, const float *margins /*[4] */ ,
1569 			   bool move_origin);
1570 
1571 /* Set the width and height (in pixels), updating MediaSize. */
1572 void gx_device_set_width_height(gx_device * dev, int width, int height);
1573 
1574 /* Set the resolution (in pixels per inch), updating width and height. */
1575 void gx_device_set_resolution(gx_device * dev, floatp x_dpi, floatp y_dpi);
1576 
1577 /* Set the MediaSize (in 1/72" units), updating width and height. */
1578 void gx_device_set_media_size(gx_device * dev, floatp media_width, floatp media_height);
1579 
1580 /****** BACKWARD COMPATIBILITY ******/
1581 #define gx_device_set_page_size(dev, w, h)\
1582   gx_device_set_media_size(dev, w, h)
1583 
1584 /*
1585  * Temporarily install a null device, or a special device such as
1586  * a clipping or cache device.
1587  */
1588 void gx_set_device_only(gs_state *, gx_device *);
1589 
1590 /* Close a device. */
1591 int gs_closedevice(gx_device *);
1592 
1593 /* "Free" a device locally allocated on the stack, by finalizing it. */
1594 void gx_device_free_local(gx_device *);
1595 
1596 /* ------ Device types (an unused concept right now) ------ */
1597 
1598 #define dev_type_proc_initialize(proc)\
1599   int proc(gx_device *)
1600 
1601 typedef struct gx_device_type_s {
1602     gs_memory_type_ptr_t stype;
1603     dev_type_proc_initialize((*initialize));
1604 } gx_device_type;
1605 
1606 #define device_type(dtname, stype, initproc)\
1607 private dev_type_proc_initialize(initproc);\
1608 const gx_device_type dtname = { &stype, initproc }
1609 
1610 /*dev_type_proc_initialize(gdev_initialize); */
1611 
1612 #endif /* gxdevcli_INCLUDED */
1613