1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Definitions for device implementors */
18 
19 #ifndef gxdevice_INCLUDED
20 #  define gxdevice_INCLUDED
21 
22 #include "stdio_.h"             /* for FILE */
23 #include "gxdevcli.h"
24 #include "gsfname.h"
25 #include "gsparam.h"
26 /*
27  * Many drivers still use gs_malloc and gs_free, so include the interface
28  * for these.  (Eventually they should go away.)
29  */
30 #include "gsmalloc.h"
31 /*
32  * Similarly, quite a few drivers reference stdout and/or stderr.
33  * (Eventually these references must go away.)
34  */
35 #include "gxstdio.h"
36 
37 /*
38  * NOTE: if you write code that creates device instances (either with
39  * gs_copydevice or by allocating them explicitly), allocates device
40  * instances as either local or static variables (actual instances, not
41  * pointers to instances), or sets the target of forwarding devices, please
42  * read the documentation in gxdevcli.h about memory management for devices.
43  * The rules for doing these things changed substantially in release 5.68,
44  * in a non-backward-compatible way, and unfortunately we could not find a
45  * way to make the compiler give an error at places that need changing.
46  */
47 
48 /* ---------------- Auxiliary types and structures ---------------- */
49 
50 /* Define default pages sizes. */
51 /* U.S. letter paper (8.5" x 11"). */
52 #define DEFAULT_WIDTH_10THS_US_LETTER 85
53 #define DEFAULT_HEIGHT_10THS_US_LETTER 110
54 /* A4 paper (210mm x 297mm), we use 595pt x 842pt. */
55 #define DEFAULT_WIDTH_10THS_A4 82.6389
56 #define DEFAULT_HEIGHT_10THS_A4 116.9444
57 /* Choose a default.  A4 may be set in the makefile. */
58 #ifdef A4
59 #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_A4
60 #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_A4
61 #else
62 #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_US_LETTER
63 #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_US_LETTER
64 #endif
65 
66 /* ---------------- Device structure ---------------- */
67 
68 /*
69  * To insulate statically defined device templates from the
70  * consequences of changes in the device structure, the following macros
71  * must be used for generating initialized device structures.
72  *
73  * The computations of page width and height in pixels should really be
74  *      ((int)(page_width_inches*x_dpi))
75  * but some compilers (the Ultrix 3.X pcc compiler and the HPUX compiler)
76  * can't cast a computed float to an int.  That's why we specify
77  * the page width and height in inches/10 instead of inches.
78  * This has been now been changed to use floats.
79  *
80  * Note that the macro is broken up so as to be usable for devices that
81  * add further initialized state to the generic device.
82  * Note also that the macro does not initialize procs, which is
83  * the next element of the structure.
84  */
85 #define std_device_part1_(devtype, ptr_procs, dev_name, stype, open_init)\
86         sizeof(devtype), ptr_procs, dev_name,\
87         0 /*memory*/, stype, 0 /*stype_is_dynamic*/, 0 /*finalize*/,\
88         { 0 } /*rc*/, 0 /*retained*/, open_init() /*is_open, max_fill_band*/
89         /* color_info goes here */
90 /*
91  * The MetroWerks compiler has some bizarre bug that produces a spurious
92  * error message if the width and/or height are defined as 0 below,
93  * unless we use the +/- workaround in the next macro.
94  */
95 #define std_device_part2_(width, height, x_dpi, y_dpi)\
96         { gx_no_color_index, gx_no_color_index },\
97           width, height, 0/*TrayOrientation*/,\
98         { (float)((((width) * 72.0 + 0.5) - 0.5) / (x_dpi))/*MediaSize[0]*/,\
99           (float)((((height) * 72.0 + 0.5) - 0.5) / (y_dpi))/*MediaSize[1]*/},\
100         { 0, 0, 0, 0 }/*ImagingBBox*/, 0/*ImagingBBox_set*/,\
101         { x_dpi, y_dpi }/*HWResolution*/, { x_dpi, y_dpi }/*MarginsHWResolution*/
102 
103 /* offsets and margins go here */
104 #define std_device_part3_()\
105         0/*PageCount*/, 0/*ShowpageCount*/, 1/*NumCopies*/, 0/*NumCopies_set*/,\
106         0/*IgnoreNumCopies*/, 0/*UseCIEColor*/, 0/*LockSafetyParams*/,\
107         0/*band_offset_x*/, 0/*band_offset_y*/, {false}/* sgr */, 0/* MaxPatternBitmap */,\
108         0/*Profile Array*/,\
109         0/* graphics_type_tag default GS_UNKNOWN_TAG */,\
110         { gx_default_install, gx_default_begin_page, gx_default_end_page }
111 /*
112  * We need a number of different variants of the std_device_ macro simply
113  * because we can't pass the color_info or offsets/margins
114  * as macro arguments, which in turn is because of the early macro
115  * expansion issue noted in stdpre.h.  The basic variants are:
116  *      ...body_with_macros_, which uses 0-argument macros to supply
117  *        open_init, color_info, and offsets/margins;
118  *      ...full_body, which takes 12 values (6 for dci_values,
119  *        6 for offsets/margins);
120  *      ...color_full_body, which takes 9 values (3 for dci_color,
121  *        6 for margins/offset).
122  *      ...std_color_full_body, which takes 7 values (1 for dci_std_color,
123  *        6 for margins/offset).
124  *
125  */
126 #define std_device_body_with_macros_(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, open_init, dci_macro, margins_macro)\
127         std_device_part1_(dtype, pprocs, dname, stype, open_init),\
128         dci_macro(),\
129         std_device_part2_(w, h, xdpi, ydpi),\
130         margins_macro(),\
131         std_device_part3_()
132 
133 #define std_device_std_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\
134         std_device_body_with_macros_(dtype, pprocs, dname, stype,\
135           w, h, xdpi, ydpi,\
136           open_init_closed, dci_black_and_white_, no_margins_)
137 
138 #define std_device_std_body(dtype, pprocs, dname, w, h, xdpi, ydpi)\
139         std_device_std_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi)
140 
141 #define std_device_std_body_type_open(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\
142         std_device_body_with_macros_(dtype, pprocs, dname, stype,\
143           w, h, xdpi, ydpi,\
144           open_init_open, dci_black_and_white_, no_margins_)
145 
146 #define std_device_std_body_open(dtype, pprocs, dname, w, h, xdpi, ydpi)\
147         std_device_std_body_type_open(dtype, pprocs, dname, 0, w, h, xdpi, ydpi)
148 
149 #define std_device_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\
150         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
151         dci_values(ncomp, depth, mg, mc, dg, dc),\
152         std_device_part2_(w, h, xdpi, ydpi),\
153         offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
154         std_device_part3_()
155 
156 #define std_device_full_body_type_extended(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, mcomp, ncomp, pol, depth, gi, mg, mc, dg, dc, ef, cn, xoff, yoff, lm, bm, rm, tm)\
157         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
158         dci_extended_alpha_values(mcomp, ncomp, pol, depth, gi, mg, mc, dg, dc, 1, 1, ef, cn), \
159         std_device_part2_(w, h, xdpi, ydpi),\
160         offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
161         std_device_part3_()
162 
163 #define std_device_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\
164         std_device_full_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi,\
165             ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)
166 
167 #define std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, ta, ga)\
168         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
169         dci_alpha_values(ncomp, depth, mg, mc, dg, dc, ta, ga),\
170         std_device_part2_(w, h, xdpi, ydpi),\
171         offset_margin_values(0, 0, 0, 0, 0, 0),\
172         std_device_part3_()
173 
174 #define std_device_dci_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\
175         std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h,\
176           xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, 1, 1)
177 
178 #define std_device_dci_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\
179         std_device_dci_type_body(dtype, pprocs, dname, 0,\
180           w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)
181 
182 #define std_device_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither, xoff, yoff, lm, bm, rm, tm)\
183         std_device_part1_(dtype, pprocs, dname, 0, open_init_closed),\
184         dci_color(depth, max_value, dither),\
185         std_device_part2_(w, h, xdpi, ydpi),\
186         offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
187         std_device_part3_()
188 
189 #define std_device_color_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither)\
190         std_device_color_full_body(dtype, pprocs, dname,\
191           w, h, xdpi, ydpi,\
192           depth, max_value, dither,\
193           0, 0, 0, 0, 0, 0)
194 
195 #define std_device_color_stype_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, max_value, dither)\
196         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
197         dci_color(depth, max_value, dither),\
198         std_device_part2_(w, h, xdpi, ydpi),\
199         offset_margin_values(0, 0, 0, 0, 0, 0),\
200         std_device_part3_()
201 
202 #define std_device_std_color_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\
203         std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
204         dci_std_color(depth),\
205         std_device_part2_(w, h, xdpi, ydpi),\
206         offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
207         std_device_part3_()
208 
209 #define std_device_std_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\
210         std_device_std_color_full_body_type(dtype, pprocs, dname, 0,\
211             w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)
212 
213 /* ---------------- Default implementations ---------------- */
214 
215 /* Default implementations of optional procedures. */
216 /* Note that the default map_xxx_color routines assume white_on_black. */
217 dev_proc_open_device(gx_default_open_device);
218 dev_proc_get_initial_matrix(gx_default_get_initial_matrix);
219 dev_proc_get_initial_matrix(gx_upright_get_initial_matrix);
220 dev_proc_sync_output(gx_default_sync_output);
221 dev_proc_output_page(gx_default_output_page);
222 dev_proc_close_device(gx_default_close_device);
223 dev_proc_map_rgb_color(gx_default_w_b_map_rgb_color);
224 dev_proc_map_color_rgb(gx_default_w_b_map_color_rgb);
225 #define gx_default_map_rgb_color gx_default_w_b_map_rgb_color
226 #define gx_default_map_color_rgb gx_default_w_b_map_color_rgb
227 dev_proc_tile_rectangle(gx_default_tile_rectangle);
228 dev_proc_copy_mono(gx_default_copy_mono);
229 dev_proc_copy_color(gx_default_copy_color);
230 dev_proc_draw_line(gx_default_draw_line);
231 dev_proc_get_bits(gx_no_get_bits);      /* gives error */
232 dev_proc_get_bits(gx_default_get_bits);
233 dev_proc_get_params(gx_default_get_params);
234 dev_proc_put_params(gx_default_put_params);
235 dev_proc_map_cmyk_color(gx_default_map_cmyk_color);
236 dev_proc_get_xfont_procs(gx_default_get_xfont_procs);
237 dev_proc_get_xfont_device(gx_default_get_xfont_device);
238 dev_proc_map_rgb_alpha_color(gx_default_map_rgb_alpha_color);
239 dev_proc_get_page_device(gx_default_get_page_device);   /* returns NULL */
240 dev_proc_get_page_device(gx_page_device_get_page_device);       /* returns dev */
241 dev_proc_get_alpha_bits(gx_default_get_alpha_bits);
242 dev_proc_copy_alpha(gx_no_copy_alpha);  /* gives error */
243 dev_proc_copy_alpha(gx_default_copy_alpha);
244 dev_proc_get_band(gx_default_get_band);
245 dev_proc_copy_rop(gx_no_copy_rop);      /* gives error */
246 dev_proc_copy_rop(gx_default_copy_rop);
247 dev_proc_fill_path(gx_default_fill_path);
248 dev_proc_stroke_path(gx_default_stroke_path);
249 dev_proc_fill_mask(gx_default_fill_mask);
250 dev_proc_fill_trapezoid(gx_default_fill_trapezoid);
251 dev_proc_fill_parallelogram(gx_default_fill_parallelogram);
252 dev_proc_fill_triangle(gx_default_fill_triangle);
253 dev_proc_draw_thin_line(gx_default_draw_thin_line);
254 dev_proc_begin_image(gx_default_begin_image);
255 dev_proc_image_data(gx_default_image_data);
256 dev_proc_end_image(gx_default_end_image);
257 dev_proc_strip_tile_rectangle(gx_default_strip_tile_rectangle);
258 dev_proc_strip_copy_rop(gx_no_strip_copy_rop);  /* gives error */
259 dev_proc_strip_copy_rop(gx_default_strip_copy_rop);
260 dev_proc_get_clipping_box(gx_default_get_clipping_box);
261 dev_proc_get_clipping_box(gx_get_largest_clipping_box);
262 dev_proc_begin_typed_image(gx_default_begin_typed_image);
263 dev_proc_get_bits_rectangle(gx_no_get_bits_rectangle);  /* gives error */
264 dev_proc_get_bits_rectangle(gx_default_get_bits_rectangle);
265 dev_proc_map_color_rgb_alpha(gx_default_map_color_rgb_alpha);
266 dev_proc_create_compositor(gx_no_create_compositor);
267 /* default is for ordinary "leaf" devices, null is for */
268 /* devices that only care about coverage and not contents. */
269 dev_proc_create_compositor(gx_default_create_compositor);
270 dev_proc_create_compositor(gx_null_create_compositor);
271 dev_proc_get_hardware_params(gx_default_get_hardware_params);
272 dev_proc_text_begin(gx_default_text_begin);
273 dev_proc_finish_copydevice(gx_default_finish_copydevice);
274 dev_proc_dev_spec_op(gx_default_dev_spec_op);
275 dev_proc_fill_rectangle_hl_color(gx_default_fill_rectangle_hl_color);
276 dev_proc_include_color_space(gx_default_include_color_space);
277 dev_proc_fill_linear_color_scanline(gx_default_fill_linear_color_scanline);
278 dev_proc_fill_linear_color_scanline(gx_hl_fill_linear_color_scanline);
279 dev_proc_fill_linear_color_trapezoid(gx_default_fill_linear_color_trapezoid);
280 dev_proc_fill_linear_color_triangle(gx_default_fill_linear_color_triangle);
281 dev_proc_update_spot_equivalent_colors(gx_default_update_spot_equivalent_colors);
282 dev_proc_ret_devn_params(gx_default_ret_devn_params);
283 dev_proc_fillpage(gx_default_fillpage);
284 dev_proc_get_profile(gx_default_get_profile);
285 dev_proc_set_graphics_type_tag(gx_default_set_graphics_type_tag);
286 dev_proc_strip_copy_rop2(gx_default_strip_copy_rop2);
287 dev_proc_strip_tile_rect_devn(gx_default_strip_tile_rect_devn);
288 dev_proc_copy_alpha_hl_color(gx_default_copy_alpha_hl_color);
289 /* BACKWARD COMPATIBILITY */
290 #define gx_non_imaging_create_compositor gx_null_create_compositor
291 
292 /* Color mapping routines for black-on-white, gray scale, true RGB, */
293 /* true CMYK, and 1-bit CMYK color. */
294 dev_proc_map_rgb_color(gx_default_b_w_map_rgb_color);
295 dev_proc_map_color_rgb(gx_default_b_w_map_color_rgb);
296 dev_proc_map_rgb_color(gx_default_gray_map_rgb_color);
297 dev_proc_map_color_rgb(gx_default_gray_map_color_rgb);
298 dev_proc_map_color_rgb(gx_default_rgb_map_color_rgb);
299 #define gx_default_cmyk_map_cmyk_color cmyk_8bit_map_cmyk_color /*see below*/
300 /*
301  * The following are defined as "standard" color mapping procedures
302  * that can be propagated through device pipelines and that color
303  * processing code can test for.
304  */
305 dev_proc_map_rgb_color(gx_default_rgb_map_rgb_color);
306 dev_proc_map_cmyk_color(cmyk_1bit_map_cmyk_color);
307 dev_proc_map_color_rgb(cmyk_1bit_map_color_rgb);
308 dev_proc_decode_color(cmyk_1bit_map_color_cmyk);
309 dev_proc_map_cmyk_color(cmyk_8bit_map_cmyk_color);
310 dev_proc_map_color_rgb(cmyk_8bit_map_color_rgb);
311 dev_proc_decode_color(cmyk_8bit_map_color_cmyk);
312 dev_proc_map_cmyk_color(cmyk_16bit_map_cmyk_color);
313 dev_proc_decode_color(cmyk_16bit_map_color_cmyk);
314 dev_proc_encode_color(gx_default_8bit_map_gray_color);
315 dev_proc_decode_color(gx_default_8bit_map_color_gray);
316 
317 /* Default implementations for forwarding devices */
318 dev_proc_close_device(gx_forward_close_device);
319 dev_proc_get_initial_matrix(gx_forward_get_initial_matrix);
320 dev_proc_sync_output(gx_forward_sync_output);
321 dev_proc_output_page(gx_forward_output_page);
322 dev_proc_map_rgb_color(gx_forward_map_rgb_color);
323 dev_proc_map_color_rgb(gx_forward_map_color_rgb);
324 dev_proc_fill_rectangle(gx_forward_fill_rectangle);
325 dev_proc_tile_rectangle(gx_forward_tile_rectangle);
326 dev_proc_copy_mono(gx_forward_copy_mono);
327 dev_proc_copy_color(gx_forward_copy_color);
328 dev_proc_get_bits(gx_forward_get_bits);
329 dev_proc_get_params(gx_forward_get_params);
330 dev_proc_put_params(gx_forward_put_params);
331 dev_proc_map_cmyk_color(gx_forward_map_cmyk_color);
332 dev_proc_get_xfont_procs(gx_forward_get_xfont_procs);
333 dev_proc_get_xfont_device(gx_forward_get_xfont_device);
334 dev_proc_map_rgb_alpha_color(gx_forward_map_rgb_alpha_color);
335 dev_proc_get_page_device(gx_forward_get_page_device);
336 #define gx_forward_get_alpha_bits gx_default_get_alpha_bits
337 dev_proc_copy_alpha(gx_forward_copy_alpha);
338 dev_proc_get_band(gx_forward_get_band);
339 dev_proc_copy_rop(gx_forward_copy_rop);
340 dev_proc_fill_path(gx_forward_fill_path);
341 dev_proc_stroke_path(gx_forward_stroke_path);
342 dev_proc_fill_mask(gx_forward_fill_mask);
343 dev_proc_fill_trapezoid(gx_forward_fill_trapezoid);
344 dev_proc_fill_parallelogram(gx_forward_fill_parallelogram);
345 dev_proc_fill_triangle(gx_forward_fill_triangle);
346 dev_proc_draw_thin_line(gx_forward_draw_thin_line);
347 dev_proc_begin_image(gx_forward_begin_image);
348 #define gx_forward_image_data gx_default_image_data
349 #define gx_forward_end_image gx_default_end_image
350 dev_proc_strip_tile_rectangle(gx_forward_strip_tile_rectangle);
351 dev_proc_strip_copy_rop(gx_forward_strip_copy_rop);
352 dev_proc_get_clipping_box(gx_forward_get_clipping_box);
353 dev_proc_begin_typed_image(gx_forward_begin_typed_image);
354 dev_proc_get_bits_rectangle(gx_forward_get_bits_rectangle);
355 dev_proc_map_color_rgb_alpha(gx_forward_map_color_rgb_alpha);
356 /* There is no forward_create_compositor (see Drivers.htm). */
357 dev_proc_get_hardware_params(gx_forward_get_hardware_params);
358 dev_proc_text_begin(gx_forward_text_begin);
359 dev_proc_get_color_mapping_procs(gx_forward_get_color_mapping_procs);
360 dev_proc_get_color_comp_index(gx_forward_get_color_comp_index);
361 dev_proc_encode_color(gx_forward_encode_color);
362 dev_proc_decode_color(gx_forward_decode_color);
363 dev_proc_dev_spec_op(gx_forward_dev_spec_op);
364 dev_proc_fill_rectangle_hl_color(gx_forward_fill_rectangle_hl_color);
365 dev_proc_include_color_space(gx_forward_include_color_space);
366 dev_proc_fill_linear_color_scanline(gx_forward_fill_linear_color_scanline);
367 dev_proc_fill_linear_color_trapezoid(gx_forward_fill_linear_color_trapezoid);
368 dev_proc_fill_linear_color_triangle(gx_forward_fill_linear_color_triangle);
369 dev_proc_update_spot_equivalent_colors(gx_forward_update_spot_equivalent_colors);
370 dev_proc_ret_devn_params(gx_forward_ret_devn_params);
371 dev_proc_fillpage(gx_forward_fillpage);
372 dev_proc_copy_planes(gx_forward_copy_planes);
373 dev_proc_create_compositor(gx_forward_create_compositor);
374 dev_proc_get_profile(gx_forward_get_profile);
375 dev_proc_set_graphics_type_tag(gx_forward_set_graphics_type_tag);
376 dev_proc_strip_copy_rop2(gx_forward_strip_copy_rop2);
377 dev_proc_strip_tile_rect_devn(gx_forward_strip_tile_rect_devn);
378 dev_proc_copy_alpha_hl_color(gx_forward_copy_alpha_hl_color);
379 
380 /* ---------------- Implementation utilities ---------------- */
381 
382 /* Convert the device procedures to the proper form (see above). */
383 void gx_device_set_procs(gx_device *);
384 
385 /* Fill in defaulted procedures in a device procedure record. */
386 void gx_device_fill_in_procs(gx_device *);
387 void gx_device_forward_fill_in_procs(gx_device_forward *);
388 
389 /* Forward the color mapping procedures from a device to its target. */
390 void gx_device_forward_color_procs(gx_device_forward *);
391 
392 /*
393  * Check if the device's encode_color routine uses 'separable' bit encodings
394  * for each colorant.  For more info see the routine's header.
395  */
396 void check_device_separable(gx_device * dev);
397 /*
398  * If a device has a linear and separable encode color function then
399  * set up the comp_bits, comp_mask, and comp_shift fields.
400  */
401 void set_linear_color_bits_mask_shift(gx_device * dev);
402 /*
403  * Copy the color mapping procedures from the target if they are
404  * standard ones (saving a level of procedure call at mapping time).
405  */
406 void gx_device_copy_color_procs(gx_device *dev, const gx_device *target);
407 
408 /* Get the black and white pixel values of a device. */
409 gx_color_index gx_device_black(gx_device *dev);
410 #define gx_device_black_inline(dev)\
411   ((dev)->cached_colors.black == gx_no_color_index ?\
412    gx_device_black(dev) : (dev)->cached_colors.black)
413 gx_color_index gx_device_white(gx_device *dev);
414 #define gx_device_white_inline(dev)\
415   ((dev)->cached_colors.white == gx_no_color_index ?\
416    gx_device_white(dev) : (dev)->cached_colors.white)
417 
418 /* Clear the black/white pixel cache. */
419 void gx_device_decache_colors(gx_device *dev);
420 
421 /*
422  * Copy the color-related device parameters back from the target:
423  * color_info and color mapping procedures.
424  */
425 void gx_device_copy_color_params(gx_device *dev, const gx_device *target);
426 
427 /*
428  * Copy device parameters back from a target.  This copies all standard
429  * parameters related to page size and resolution, plus color_info
430  * and (if appropriate) color mapping procedures.
431  */
432 void gx_device_copy_params(gx_device *dev, const gx_device *target);
433 
434 /*
435  * Parse the output file name for a device, recognizing "-" and "|command",
436  * and also detecting and validating any %nnd format for inserting the
437  * page count.  If a format is present, store a pointer to its last
438  * character in *pfmt, otherwise store 0 there.  Note that an empty name
439  * is currently allowed.
440  */
441 int gx_parse_output_file_name(gs_parsed_file_name_t *pfn,
442                               const char **pfmt, const char *fname,
443                               uint len, gs_memory_t *memory);
444 
445 /*
446  * Returns true if the outputfile requests separate pages (contains %d)
447  */
448 bool gx_outputfile_is_separate_pages(const char *fname, gs_memory_t *memory);
449 
450 /*
451  * Open the output file for a device.  Note that if the file name is empty,
452  * it may be replaced with the name of a scratch file.
453  */
454 int gx_device_open_output_file(const gx_device * dev, char *fname,
455                                bool binary, bool positionable,
456                                FILE ** pfile);
457 
458 /* Close the output file for a device. */
459 int gx_device_close_output_file(const gx_device * dev, const char *fname,
460                                 FILE *file);
461 
462 /*
463  * Define the number of levels for a colorant above which we do not halftone.
464  */
465 #define MIN_CONTONE_LEVELS 31
466 
467 /*
468  * Determine whether a given device needs to halftone.  Eventually this
469  * should take an imager state as an additional argument.
470  */
471 #define gx_device_must_halftone(dev)\
472   ((gx_device_has_color(dev) ? (dev)->color_info.max_color :\
473     (dev)->color_info.max_gray) < MIN_CONTONE_LEVELS)
474 
475 /*
476  * Do generic work for output_page.  All output_page procedures must call
477  * this as the last thing they do, unless an error has occurred earlier.
478  */
479 dev_proc_output_page(gx_finish_output_page);
480 
481 /*
482  * Device procedures that draw into rectangles need to clip the coordinates
483  * to the rectangle ((0,0),(dev->width,dev->height)).  The following macros
484  * do the clipping.  They assume that the arguments of the procedure are
485  * named dev, x, y, w, and h, and may modify the arguments (other than dev).
486  *
487  * For procedures that fill a region, dev, x, y, w, and h are the only
488  * relevant arguments.  For procedures that copy bitmaps, see below.
489  *
490  * The following group of macros for region-filling procedures clips
491  * specific edges of the supplied rectangle, as indicated by the macro name.
492  */
493 #define fit_fill_xy(dev, x, y, w, h)\
494   BEGIN\
495         if ( (x | y) < 0 ) {\
496           if ( x < 0 )\
497             w += x, x = 0;\
498           if ( y < 0 )\
499             h += y, y = 0;\
500         }\
501   END
502 #define fit_fill_y(dev, y, h)\
503   BEGIN\
504         if ( y < 0 )\
505           h += y, y = 0;\
506   END
507 #define fit_fill_w(dev, x, w)\
508   BEGIN\
509         if ( w > (dev)->width - x )\
510           w = (dev)->width - x;\
511   END
512 #define fit_fill_h(dev, y, h)\
513   BEGIN\
514         if ( h > (dev)->height - y )\
515           h = (dev)->height - y;\
516   END
517 #define fit_fill_xywh(dev, x, y, w, h)\
518   BEGIN\
519         fit_fill_xy(dev, x, y, w, h);\
520         fit_fill_w(dev, x, w);\
521         fit_fill_h(dev, y, h);\
522   END
523 /*
524  * Clip all edges, and return from the procedure if the result is empty.
525  */
526 #define fit_fill(dev, x, y, w, h)\
527   BEGIN\
528         fit_fill_xywh(dev, x, y, w, h);\
529         if ( w <= 0 || h <= 0 )\
530           return 0;\
531   END
532 
533 /*
534  * For driver procedures that copy bitmaps (e.g., copy_mono, copy_color),
535  * clipping the destination region also may require adjusting the pointer to
536  * the source data.  In addition to dev, x, y, w, and h, the clipping macros
537  * for these procedures reference data, data_x, raster, and id; they may
538  * modify the values of data, data_x, and id.
539  *
540  * Clip the edges indicated by the macro name.
541  */
542 #define fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h)\
543   BEGIN\
544         if ( (x | y) < 0 ) {\
545           if ( x < 0 )\
546             w += x, data_x -= x, x = 0;\
547           if ( y < 0 )\
548             h += y, data -= (int)(y * raster), id = gx_no_bitmap_id, y = 0; \
549         }\
550         if ( w > (dev)->width - x )\
551           w = (dev)->width - x;\
552   END
553 /*
554  * Clip all edges, and return from the procedure if the result is empty.
555  */
556 #define fit_copy(dev, data, data_x, raster, id, x, y, w, h)\
557   BEGIN\
558         fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h);\
559         if ( h > (dev)->height - y )\
560           h = (dev)->height - y;\
561         if ( w <= 0 || h <= 0 )\
562           return 0;\
563   END
564 
565 /* ---------------- Media parameters ---------------- */
566 
567 /* Define the InputAttributes and OutputAttributes of a device. */
568 /* The device get_params procedure would call these. */
569 
570 typedef struct gdev_input_media_s {
571     float PageSize[4];          /* nota bene */
572     const char *MediaColor;
573     float MediaWeight;
574     const char *MediaType;
575 } gdev_input_media_t;
576 
577 #define gdev_input_media_default_values { 0, 0, 0, 0 }, 0, 0, 0
578 extern const gdev_input_media_t gdev_input_media_default;
579 
580 void gdev_input_media_init(gdev_input_media_t * pim);
581 
582 int gdev_begin_input_media(gs_param_list * mlist, gs_param_dict * pdict,
583                            int count);
584 
585 int gdev_write_input_page_size(int index, gs_param_dict * pdict,
586                                floatp width_points, floatp height_points);
587 
588 int gdev_write_input_media(int index, gs_param_dict * pdict,
589                            const gdev_input_media_t * pim);
590 
591 int gdev_end_input_media(gs_param_list * mlist, gs_param_dict * pdict);
592 
593 typedef struct gdev_output_media_s {
594     const char *OutputType;
595 } gdev_output_media_t;
596 
597 #define gdev_output_media_default_values 0
598 extern const gdev_output_media_t gdev_output_media_default;
599 
600 int gdev_begin_output_media(gs_param_list * mlist, gs_param_dict * pdict,
601                             int count);
602 
603 int gdev_write_output_media(int index, gs_param_dict * pdict,
604                             const gdev_output_media_t * pom);
605 
606 /* Can be called from set user params */
607 void gx_default_put_icc_dir(gs_param_string *icc_pro, gx_device * dev);
608 
609 int gdev_end_output_media(gs_param_list * mlist, gs_param_dict * pdict);
610 
611 void gx_device_request_leadingedge(gx_device *dev, int le_req);
612 
613 #endif /* gxdevice_INCLUDED */
614