1 /* Copyright (C) 2001-2006 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, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: gxmclip.h 8137 2007-07-24 21:18:53Z ray $ */
15 /* Mask clipping device and interface */
16 /* Requires gxdevice.h, gxdevmem.h */
17 
18 #ifndef gxmclip_INCLUDED
19 #  define gxmclip_INCLUDED
20 
21 #include "gxclip.h"
22 
23 /*
24  * ImageType 3 images and Patterns that don't completely fill their
25  * bounding box require the ability to clip against a mask.
26  * The interface declared here doesn't take a position on whether
27  * the mask will be used only in one position (ImageType 3) or in
28  * multiple positions for tiling (Patterns).
29  *
30  * All the information in this file is logically private, but we must expose
31  * the structure definition so that clients can allocate instances in the
32  * stack frame.
33  */
34 
35 #define tile_clip_buffer_request 16384	/* enough for 2400 dpi up to 54" wide */
36 #define tile_clip_buffer_size\
37   ((tile_clip_buffer_request / arch_sizeof_long) * arch_sizeof_long)
38 typedef struct gx_device_mask_clip_s {
39     gx_device_forward_common;	/* target is set by client */
40     gx_strip_bitmap tiles;
41     gx_device_memory mdev;	/* for tile buffer for copy_mono */
42     gs_int_point phase;		/* device space origin relative */
43 				/* to tile (backwards from gstate phase) */
44     /* Ensure that the buffer is long-aligned. */
45     union _b {
46 	byte bytes[tile_clip_buffer_size];
47 	ulong longs[tile_clip_buffer_size / arch_sizeof_long];
48     } buffer;
49 } gx_device_mask_clip;
50 
51 extern_st(st_device_mask_clip);
52 #define public_st_device_mask_clip()	/* in gxmclip.c */\
53   gs_public_st_composite_use_final(st_device_mask_clip, gx_device_mask_clip,\
54     "gx_device_mask_clip", device_mask_clip_enum_ptrs,\
55     device_mask_clip_reloc_ptrs, gx_device_finalize)
56 
57 /*
58  * Internal routine to initialize a mask clipping device.
59  * We supply an explicit device space origin or phase.
60  * Note that this procedure does not set cdev->tiles.
61  */
62 int gx_mask_clip_initialize(gx_device_mask_clip * cdev,
63 			    const gx_device_mask_clip * proto,
64 			    const gx_bitmap * bits, gx_device * tdev,
65 			    int tx, int ty, gs_memory_t *mem);
66 
67 /*
68  * Prepare colors for a copy_mono operation.
69  * The arguments of copy_mono are free variables:
70  *   dev, data, sourcex, raster, id, x, y, w, y, color0, color1.
71  */
72 #define setup_mask_copy_mono(cdev, color, mcolor0, mcolor1)\
73 	BEGIN\
74 	  if ( cdev->mdev.base == 0 ) {\
75 	    /*\
76 	     * The tile was too large for us to buffer even one scan line.\
77 	     * Punt to the very, very slow default implementation of\
78 	     * copy_mono.\
79 	     */\
80 	    return gx_default_copy_mono(dev, data, sourcex, raster, id,\
81 					x, y, w, h, color0, color1);\
82 	  }\
83 	  if ( color1 != gx_no_color_index ) {\
84 	    if ( color0 != gx_no_color_index ) {\
85 	      /* Pre-fill with color0. */\
86 	      code =\
87 		(*dev_proc(dev, fill_rectangle))(dev, x, y, w, h, color0);\
88 	      if ( code < 0 )\
89 		return code;\
90 	    }\
91 	    color = color1;\
92 	    mcolor0 = 0, mcolor1 = gx_no_color_index;\
93 	  } else if ( color0 != gx_no_color_index ) {\
94 	    color = color0;\
95 	    mcolor0 = gx_no_color_index, mcolor1 = 0;\
96 	  } else\
97 	    return 0;\
98 	END
99 
100 #endif /* gxmclip_INCLUDED */
101