xref: /plan9/sys/src/cmd/gs/src/gxclpath.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1995, 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: gxclpath.h,v 1.13 2005/10/10 18:58:18 leonardo Exp $ */
18 /* Definitions and support procedures for higher-level band list commands */
19 /* Extends (requires) gxcldev.h */
20 
21 #ifndef gxclpath_INCLUDED
22 #  define gxclpath_INCLUDED
23 
24 /*
25  * Define the flags indicating whether a band knows the current values of
26  * various miscellaneous parameters (pcls->known).  The first N flags match
27  * the mask parameter for cmd_set_misc2 below.
28  */
29 #define cap_join_known		(1<<0)
30 #define cj_ac_sa_known		(1<<1)
31 #define flatness_known		(1<<2)
32 #define line_width_known	(1<<3)
33 #define miter_limit_known	(1<<4)
34 #define op_bm_tk_known		(1<<5)
35 /* segment_notes must fit in the first byte (i.e. be less than 1<<7). */
36 #define segment_notes_known	(1<<6) /* not used in pcls->known */
37 /* (flags beyond this point require an extra byte) */
38 #define opacity_alpha_known	(1<<7)
39 #define shape_alpha_known	(1<<8)
40 #define alpha_known		(1<<9)
41 #define misc2_all_known		((1<<10)-1)
42 /* End of misc2 flags. */
43 #define fill_adjust_known	(1<<10)
44 #define ctm_known		(1<<11)
45 #define dash_known		(1<<12)
46 #define clip_path_known		(1<<13)
47 #define stroke_all_known	((1<<14)-1)
48 #define color_space_known	(1<<14)
49 /*#define all_known             ((1<<15)-1) */
50 
51 /* Define the drawing color types for distinguishing different */
52 /* fill/stroke command variations. */
53 typedef enum {
54     cmd_dc_type_pure = 0,
55     cmd_dc_type_ht = 1,
56     cmd_dc_type_color = 2
57 } cmd_dc_type;
58 
59 /* Extend the command set.  See gxcldev.h for more information. */
60 typedef enum {
61     cmd_op_misc2 = 0xd0,	/* (see below) */
62     /* obsolete */
63     /* cmd_opv_set_color = 0xd0, */	/* Used if base values do not fit into 1 bit */
64     				/* #flags,#base[0],...#base[num_comp-1] if flags */
65 				/* colored halftone with base colors a,b,c,d */
66     /* obsolete */
67     /* cmd_opv_set_color_short = 0xd1, */ /* Used if base values fit into 1 bit */
68     					/* If num_comp <= 4 then use: */
69     					/* pqrsabcd, where a = base[0] */
70 					/* b = base[1], c= base[2], d = base[3] */
71 					/* p = level[0], q = level[1] */
72 					/* r = level[2], s = level[3] */
73     					/* If num_comp > 4 then use: */
74 					/* #flags, #bases */
75     cmd_opv_set_fill_adjust = 0xd2,	/* adjust_x/y(fixed) */
76     cmd_opv_set_ctm = 0xd3,	/* [per sput/sget_matrix] */
77     cmd_opv_set_color_space = 0xd4,	/* base(4)Indexed?(2)0(2) */
78 				/* [, hival#, table|map] */
79     /*
80      * cmd_opv_set_misc2_value is followed by a mask (a variable-length
81      * integer), and then by parameter values for the parameters selected
82      * by the mask.  See above for the "known" mask values.
83      */
84     /* cap_join: 0(2)cap(3)join(3) */
85     /* cj_ac_sa: 0(3)curve_join+1(3)acc.curves(1)stroke_adj(1) */
86     /* flatness: (float) */
87     /* line width: (float) */
88     /* miter limit: (float) */
89     /* op_bm_tk: blend mode(5)text knockout(1)o.p.mode(1)o.p.(1) */
90     /* segment notes: (byte) */
91     /* opacity/shape: alpha(float)mask(TBD) */
92     /* alpha: <<verbatim copy from imager state>> */
93     cmd_opv_set_misc2 = 0xd5,	/* mask#, selected parameters */
94     cmd_opv_set_dash = 0xd6,	/* adapt(1)abs.dot(1)n(6), dot */
95 				/* length(float), offset(float), */
96 				/* n x (float) */
97     cmd_opv_enable_clip = 0xd7,	/* (nothing) */
98     cmd_opv_disable_clip = 0xd8,	/* (nothing) */
99     cmd_opv_begin_clip = 0xd9,	/* (nothing) */
100     cmd_opv_end_clip = 0xda,	/* (nothing) */
101     cmd_opv_begin_image_rect = 0xdb, /* same as begin_image, followed by */
102 				/* x0#, w-x1#, y0#, h-y1# */
103     cmd_opv_begin_image = 0xdc,	/* image_type_table index, */
104 				/* [per image type] */
105     cmd_opv_image_data = 0xdd,	/* height# (premature EOD if 0), */
106 				/* raster#, <data> */
107     cmd_opv_image_plane_data = 0xde, /* height# (premature EOD if 0), */
108 				/* flags# (0 = same raster & data_x, */
109 				/* 1 = new raster & data_x, lsb first), */
110 				/* [raster#, [data_x#,]]* <data> */
111     cmd_opv_extend = 0xdf,	/* command, varies */
112     cmd_op_segment = 0xe0,	/* (see below) */
113     cmd_opv_rmoveto = 0xe0,	/* dx%, dy% */
114     cmd_opv_rlineto = 0xe1,	/* dx%, dy% */
115     cmd_opv_hlineto = 0xe2,	/* dx% */
116     cmd_opv_vlineto = 0xe3,	/* dy% */
117     cmd_opv_rmlineto = 0xe4,	/* dx1%,dy1%, dx2%,dy2% */
118     cmd_opv_rm2lineto = 0xe5,	/* dx1%,dy1%, dx2%,dy2%, dx3%,dy3% */
119     cmd_opv_rm3lineto = 0xe6,	/* dx1%,dy1%, dx2%,dy2%, dx3%,dy3%, */
120 				/* [-dx2,-dy2 implicit] */
121     cmd_opv_rrcurveto = 0xe7,	/* dx1%,dy1%, dx2%,dy2%, dx3%,dy3% */
122       cmd_opv_min_curveto = cmd_opv_rrcurveto,
123     cmd_opv_hvcurveto = 0xe8,	/* dx1%, dx2%,dy2%, dy3% */
124     cmd_opv_vhcurveto = 0xe9,	/* dy1%, dx2%,dy2%, dx3% */
125     cmd_opv_nrcurveto = 0xea,	/* dx2%,dy2%, dx3%,dy3% */
126     cmd_opv_rncurveto = 0xeb,	/* dx1%,dy1%, dx2%,dy2% */
127     cmd_opv_vqcurveto = 0xec,	/* dy1%, dx2%[,dy2=dx2 with sign */
128 				/* of dy1, dx3=dy1 with sign of dx2] */
129     cmd_opv_hqcurveto = 0xed,	/* dx1%, [dx2=dy2 with sign */
130 				/* of dx1,]%dy2, [dy3=dx1 with sign */
131 				/* of dy2] */
132     cmd_opv_scurveto = 0xee,	/* all implicit: previous op must have been */
133 				/* *curveto with one or more of dx/y1/3 = 0. */
134 				/* If h*: -dx3,dy3, -dx2,dy2, -dx1,dy1. */
135 				/* If v*: dx3,-dy3, dx2,-dy2, dx1,-dy1. */
136       cmd_opv_max_curveto = cmd_opv_scurveto,
137     cmd_opv_closepath = 0xef,	/* (nothing) */
138     cmd_op_path = 0xf0,		/* (see below) */
139     cmd_opv_fill = 0xf0,
140     /* cmd_opv_htfill = 0xf1, */ /* obsolete */
141     /* cmd_opv_colorfill = 0xf2, */ /* obsolete */
142     cmd_opv_eofill = 0xf3,
143     /* cmd_opv_hteofill = 0xf4, */ /* obsolete */
144     /* cmd_opv_coloreofill = 0xf5, */ /* obsolete */
145     cmd_opv_stroke = 0xf6,
146     /* cmd_opv_htstroke = 0xf7, */ /* obsolete */
147     /* cmd_opv_colorstroke = 0xf8, */ /* obsolete */
148     cmd_opv_polyfill = 0xf9
149     /* cmd_opv_htpolyfill = 0xfa, */ /* obsolete */
150     /* cmd_opv_colorpolyfill = 0xfb */ /* obsolete */
151 } gx_cmd_xop;
152 
153 /*
154  * Further extended command set. This code always occupies a byte, which
155  * is the second byte of a command whose first byte is cmd_opv_extend.
156  */
157 typedef enum {
158     cmd_opv_ext_put_params = 0x00,          /* serialized parameter list */
159     cmd_opv_ext_create_compositor = 0x01,   /* compositor id,
160                                              * serialized compositor */
161     cmd_opv_ext_put_halftone = 0x02,        /* length of entire halftone */
162     cmd_opv_ext_put_ht_seg = 0x03,          /* segment length,
163                                              * halftone segment data */
164     cmd_opv_ext_put_drawing_color = 0x04    /* length, color type id,
165                                              * serialized color */
166 } gx_cmd_ext_op;
167 
168 #define cmd_segment_op_num_operands_values\
169   2, 2, 1, 1, 4, 6, 6, 6, 4, 4, 4, 4, 2, 2, 0, 0
170 
171 #define cmd_misc2_op_name_strings\
172   "set_color", "set_color_short", "set_fill_adjust", "set_ctm",\
173   "set_color_space", "set_misc2", "set_dash", "enable_clip",\
174   "disable_clip", "begin_clip", "end_clip", "begin_image_rect",\
175   "begin_image", "image_data", "image_plane_data", "put_params"
176 
177 #define cmd_segment_op_name_strings\
178   "rmoveto", "rlineto", "hlineto", "vlineto",\
179   "rmlineto", "rm2lineto", "rm3lineto", "rrcurveto",\
180   "hvcurveto", "vhcurveto", "nrcurveto", "rncurveto",\
181   "vqcurveto", "hqcurveto", "scurveto", "closepath"
182 
183 #define cmd_path_op_name_strings\
184   "fill", "htfill", "colorfill", "eofill",\
185   "hteofill", "coloreofill", "stroke", "htstroke",\
186   "colorstroke", "polyfill", "htpolyfill", "colorpolyfill",\
187   "?fc?", "?fd?", "?fe?", "?ff?"
188 
189 /*
190  * We represent path coordinates as 'fixed' values in a variable-length,
191  * relative form (s/t = sign, x/y = integer, f/g = fraction):
192  *      00sxxxxx xfffffff ffffftyy yyyygggg gggggggg
193  *      01sxxxxx xxxxffff ffffffff
194  *      10sxxxxx xxxxxxxx xxxxffff ffffffff
195  *      110sxxxx xxxxxxff
196  *      111----- (a full-size `fixed' value)
197  */
198 #define is_bits(d, n) !(((d) + ((fixed)1 << ((n) - 1))) & (-(fixed)1 << (n)))
199 
200 /*
201  * Maximum size of a halftone segment. This leaves enough headroom to
202  * accommodate any reasonable requirements of the command buffer.
203  */
204 #define cbuf_ht_seg_max_size    (cbuf_size - 32)    /* leave some headroom */
205 
206 /* ---------------- Driver procedures ---------------- */
207 
208 /* In gxclpath.c */
209 dev_proc_fill_path(clist_fill_path);
210 dev_proc_stroke_path(clist_stroke_path);
211 dev_proc_fill_parallelogram(clist_fill_parallelogram);
212 dev_proc_fill_triangle(clist_fill_triangle);
213 
214 /* ---------------- Driver procedure support ---------------- */
215 
216 /* The procedures and macros defined here are used when writing */
217 /* (gxclimag.c, gxclpath.c). */
218 
219 /* Compare and update members of the imager state. */
220 #define state_neq(member)\
221   (cdev->imager_state.member != pis->member)
222 #define state_update(member)\
223   (cdev->imager_state.member = pis->member)
224 
225 /* ------ Exported by gxclpath.c ------ */
226 
227 /* Compute the colors used by a drawing color. */
228 gx_color_index cmd_drawing_colors_used(gx_device_clist_writer *cldev,
229 				       const gx_drawing_color *pdcolor);
230 
231 /*
232  * Compute whether a drawing operation will require the slow (full-pixel)
233  * RasterOp implementation.  If pdcolor is not NULL, it is the texture for
234  * the RasterOp.
235  */
236 bool cmd_slow_rop(gx_device *dev, gs_logical_operation_t lop,
237 		  const gx_drawing_color *pdcolor);
238 
239 /* Write out the color for filling, stroking, or masking. */
240 /* Return a cmd_dc_type. */
241 int cmd_put_drawing_color(gx_device_clist_writer * cldev,
242 			  gx_clist_state * pcls,
243 			  const gx_drawing_color * pdcolor);
244 
245 /* Clear (a) specific 'known' flag(s) for all bands. */
246 /* We must do this whenever the value of a 'known' parameter changes. */
247 void cmd_clear_known(gx_device_clist_writer * cldev, uint known);
248 
249 /* Compute the written CTM length. */
250 int cmd_write_ctm_return_length(gx_device_clist_writer * cldev, const gs_matrix *m);
251 /* Write out CTM. */
252 int cmd_write_ctm(const gs_matrix *m, byte *dp, int len);
253 
254 /* Write out values of any unknown parameters. */
255 #define cmd_do_write_unknown(cldev, pcls, must_know)\
256   ( ~(pcls)->known & (must_know) ?\
257     cmd_write_unknown(cldev, pcls, must_know) : 0 )
258 int cmd_write_unknown(gx_device_clist_writer * cldev, gx_clist_state * pcls,
259 		      uint must_know);
260 
261 /* Check whether we need to change the clipping path in the device. */
262 bool cmd_check_clip_path(gx_device_clist_writer * cldev,
263 			 const gx_clip_path * pcpath);
264 
265 #endif /* gxclpath_INCLUDED */
266