xref: /plan9/sys/src/cmd/gs/src/gxpcolor.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1993, 1995, 1996, 1997, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gxpcolor.h,v 1.9 2003/08/20 19:53:11 igor Exp $ */
18 /* Pattern color and tile structures and procedures */
19 /* Requires gsmatrix.h, gxcolor2.h, gxdcolor.h */
20 
21 #ifndef gxpcolor_INCLUDED
22 #  define gxpcolor_INCLUDED
23 
24 #include "gspcolor.h"
25 #include "gxcspace.h"
26 #include "gxdevice.h"
27 #include "gxdevmem.h"
28 #include "gxpcache.h"
29 
30 /*
31  * Define the type of a Pattern, also used with Pattern instances.
32  */
33 #ifndef gs_pattern_type_DEFINED
34 #  define gs_pattern_type_DEFINED
35 typedef struct gs_pattern_type_s gs_pattern_type_t;
36 #endif
37 struct gs_pattern_type_s {
38     int PatternType;
39     struct pp_ {
40 
41 	/*
42 	 * Define whether a Pattern uses the base color space in its color
43 	 * space, requiring setcolor to provide values for the base color
44 	 * space.  Currently this is true for uncolored PatternType 1
45 	 * patterns, false for all others.
46 	 */
47 
48 #define pattern_proc_uses_base_space(proc)\
49   bool proc(const gs_pattern_template_t *)
50 
51 	pattern_proc_uses_base_space((*uses_base_space));
52 
53 	/*
54 	 * Make an instance of a Pattern.
55 	 */
56 
57 #define pattern_proc_make_pattern(proc)\
58   int proc(gs_client_color *, const gs_pattern_template_t *,\
59 	   const gs_matrix *, gs_state *, gs_memory_t *)
60 
61 	pattern_proc_make_pattern((*make_pattern));
62 
63 	/*
64 	 * Get the template from a Pattern instance.
65 	 */
66 
67 #define pattern_proc_get_pattern(proc)\
68   const gs_pattern_template_t *proc(const gs_pattern_instance_t *)
69 
70 	pattern_proc_get_pattern((*get_pattern));
71 
72 	/*
73 	 * Remap a Pattern color to a device color.
74 	 * cs_proc_remap_color is defined in gxcspace.h.
75 	 */
76 
77 #define pattern_proc_remap_color(proc)\
78   cs_proc_remap_color(proc)
79 
80 	pattern_proc_remap_color((*remap_color));
81 
82 	/*
83 	 * Perform any special actions required when a pattern instance
84 	 * is made the current color "color" (i.e.: at setcolor time).
85 	 * This is primarily useful for PatternType2 patterns, where the
86 	 * pattern instance specifies a color space.
87 	 */
88 #define pattern_proc_set_color(proc)\
89   int proc(const gs_client_color *, gs_state *)
90 
91 	pattern_proc_set_color((*set_color));
92 
93     } procs;
94 };
95 
96 /*
97  * Initialize the common part of a pattern template.  This procedure is for
98  * the use of gs_pattern*_init implementations, not clients.
99  */
100 void gs_pattern_common_init(gs_pattern_template_t *,
101 			    const gs_pattern_type_t *);
102 
103 /*
104  * Do the generic work for makepattern: allocate the instance and the
105  * saved graphics state, and fill in the common members.
106  */
107 int gs_make_pattern_common(gs_client_color *, const gs_pattern_template_t *,
108 			   const gs_matrix *, gs_state *, gs_memory_t *,
109 			   gs_memory_type_ptr_t);
110 
111 /* Declare the freeing procedure for Pattern instances. */
112 extern rc_free_proc(rc_free_pattern_instance);
113 
114 /* Declare the Pattern color space type. */
115 extern const gs_color_space_type gs_color_space_type_Pattern;
116 
117 /*
118  * Define the (PatternType 1) Pattern device color types.  There is one type
119  * for colored patterns, and one uncolored pattern type for each non-Pattern
120  * device color type.
121  */
122 extern const gx_device_color_type_t
123     gx_dc_pattern,
124     gx_dc_pure_masked, gx_dc_binary_masked, gx_dc_colored_masked;
125 
126 #define gx_dc_type_pattern (&gx_dc_pattern)
127 
128 /*
129  * These device color methods are shared amongst pattern types.
130  */
131 extern dev_color_proc_save_dc(gx_dc_pattern_save_dc);
132 extern dev_color_proc_write(gx_dc_pattern_write);
133 extern dev_color_proc_read(gx_dc_pattern_read);
134 
135 /*
136  * For shading and colored tiling patterns, it is not possible to say
137  * which color components have non-zero values.
138  */
139 extern dev_color_proc_get_nonzero_comps(gx_dc_pattern_get_nonzero_comps);
140 
141 /*
142  * Define a color tile, an entry in the rendered Pattern cache (and
143  * eventually in the colored halftone cache).  Note that the depth is
144  * not sufficient to ensure that the rendering matches a given device;
145  * however, we don't currently have an object that represents the
146  * abstraction of a 'color representation'.
147  */
148 struct gx_color_tile_s {
149     /* ------ The following are the 'key' in the cache. ------ */
150     /* Note that the id is a generated instance ID, */
151     /* and has no relation to the template's gs_uid. */
152     gx_bitmap_id id;
153     int depth;
154     /* We do, however, copy the template's gs_uid, */
155     /* for use in selective cache purging. */
156     gs_uid uid;
157     /* ------ The following are the cache 'value'. ------ */
158     /* Note that if tbits and tmask both have data != 0, */
159     /* both must have the same rep_shift. */
160 /****** NON-ZERO shift VALUES ARE NOT SUPPORTED YET. ******/
161     int tiling_type;		/* TilingType */
162     gs_matrix step_matrix;	/* tiling space -> device space, */
163     /* see gxcolor2.h for details */
164     gs_rect bbox;		/* bbox of tile in tiling space */
165     gx_strip_bitmap tbits;	/* data = 0 if uncolored */
166     gx_strip_bitmap tmask;	/* data = 0 if no mask */
167     /* (i.e., the mask is all 1's) */
168     bool is_simple;		/* true if xstep/ystep = tile size */
169     bool is_dummy;		/* if true, the device manages the pattern,
170                                    and the content of the tile is empty. */
171     /* The following is neither key nor value. */
172     uint index;			/* the index of the tile within */
173     /* the cache (for GC) */
174 };
175 
176 #define private_st_color_tile()	/* in gxpcmap.c */\
177   gs_private_st_ptrs2(st_color_tile, gx_color_tile, "gx_color_tile",\
178     color_tile_enum_ptrs, color_tile_reloc_ptrs, tbits.data, tmask.data)
179 #define private_st_color_tile_element()	/* in gxpcmap.c */\
180   gs_private_st_element(st_color_tile_element, gx_color_tile,\
181     "gx_color_tile[]", color_tile_elt_enum_ptrs, color_tile_elt_reloc_ptrs,\
182     st_color_tile)
183 
184 /* Define the Pattern cache. */
185 /*#include "gxpcache.h" *//* (above) */
186 
187 /* Allocate a Pattern cache. */
188 /* We shorten the procedure names because some VMS compilers */
189 /* truncate names to 23 characters. */
190 uint gx_pat_cache_default_tiles(void);
191 ulong gx_pat_cache_default_bits(void);
192 gx_pattern_cache *gx_pattern_alloc_cache(gs_memory_t *, uint, ulong);
193 
194 /* Get or set the Pattern cache in a gstate. */
195 gx_pattern_cache *gstate_pattern_cache(gs_state *);
196 void gstate_set_pattern_cache(gs_state *, gx_pattern_cache *);
197 
198 /*
199  * Define a device for accumulating the rendering of a Pattern.
200  * This is actually a wrapper for two other devices: one that accumulates
201  * the actual pattern image (if this is a colored pattern), and one that
202  * accumulates a mask defining which pixels in the image are set.
203  */
204 typedef struct gx_device_pattern_accum_s {
205     gx_device_forward_common;
206     /* Client sets these before opening */
207     gs_memory_t *bitmap_memory;
208     const gs_pattern1_instance_t *instance;
209     /* open sets these */
210     gx_device_memory *bits;	/* target also points to bits */
211     gx_device_memory *mask;
212 } gx_device_pattern_accum;
213 
214 #define private_st_device_pattern_accum() /* in gxpcmap.c */\
215   gs_private_st_suffix_add3_final(st_device_pattern_accum,\
216     gx_device_pattern_accum, "pattern accumulator", pattern_accum_enum,\
217     pattern_accum_reloc, gx_device_finalize, st_device_forward,\
218     instance, bits, mask)
219 
220 /* Allocate a pattern accumulator. */
221 gx_device_pattern_accum *gx_pattern_accum_alloc(gs_memory_t * memory, client_name_t);
222 
223 /* Add an accumulated pattern to the cache. */
224 /* Note that this does not free any of the data in the accumulator */
225 /* device, but it may zero out the bitmap_memory pointers to prevent */
226 /* the accumulated bitmaps from being freed when the device is closed. */
227 int gx_pattern_cache_add_entry(gs_imager_state *, gx_device_pattern_accum *,
228 			       gx_color_tile **);
229 /* Add a dummy Pattern cache entry.  Stubs a pattern tile for interpreter when
230    device handles high level patterns. */
231 int gx_pattern_cache_add_dummy_entry(gs_imager_state *pis, gs_pattern1_instance_t *pinst,
232 				int depth);
233 
234 /* Look up a pattern color in the cache. */
235 bool gx_pattern_cache_lookup(gx_device_color *, const gs_imager_state *,
236 			     gx_device *, gs_color_select_t);
237 
238 /* Purge selected entries from the pattern cache. */
239 void gx_pattern_cache_winnow(gx_pattern_cache *,
240 			     bool (*)(gx_color_tile *, void *),
241 			     void *);
242 
243 #endif /* gxpcolor_INCLUDED */
244