xref: /plan9/sys/src/cmd/gs/src/gxblend.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /*
2   Copyright (C) 2001 artofcode LLC.
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   For more information about licensing, please refer to
12   http://www.ghostscript.com/licensing/. For information on
13   commercial licensing, go to http://www.artifex.com/licensing/ or
14   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
15   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
16 
17   Author: Raph Levien <raph@artofcode.com>
18 */
19 /* $Id: gxblend.h,v 1.3 2002/02/21 22:24:53 giles Exp $ */
20 /* PDF 1.4 blending functions */
21 
22 #ifndef gxblend_INCLUDED
23 #  define gxblend_INCLUDED
24 
25 typedef bits16 ArtPixMaxDepth;
26 
27 #define ART_MAX_CHAN 16
28 
29 /**
30  * art_blend_pixel: Compute PDF 1.4 blending function.
31  * @dst: Where to store resulting pixel.
32  * @backdrop: Backdrop pixel color.
33  * @src: Source pixel color.
34  * @n_chan: Number of channels.
35  * @blend_mode: Blend mode.
36  *
37  * Computes the blend of two pixels according the PDF 1.4 transparency
38  * spec (section 3.2, Blend Mode). A few things to keep in mind about
39  * this implementation:
40  *
41  * 1. This is a reference implementation, not a high-performance one.
42  * Blending using this function will incur a function call and switch
43  * statement per pixel, and will also incur the extra cost of 16 bit
44  * math.
45  *
46  * 2. Zero is black, one is white. In a subtractive color space such
47  * as CMYK, all pixels should be represented as "complemented", as
48  * described in section 3.1 (Blending Color Space) of the PDF 1.4
49  * transparency spec.
50  *
51  * 3. I haven't really figured out how to handle the Compatible blend
52  * mode. I wouldn't be surprised if it required an API change.
53  **/
54 void
55 art_blend_pixel(ArtPixMaxDepth * dst, const ArtPixMaxDepth * backdrop,
56 		const ArtPixMaxDepth * src, int n_chan,
57 		gs_blend_mode_t blend_mode);
58 
59 /**
60  * art_blend_pixel_8: Compute PDF 1.4 blending function on 8-bit pixels.
61  * @dst: Where to store resulting pixel.
62  * @backdrop: Backdrop pixel color.
63  * @src: Source pixel color.
64  * @n_chan: Number of channels.
65  * @blend_mode: Blend mode.
66  *
67  * Computes the blend of two pixels according the PDF 1.4 transparency
68  * spec (section 3.2, Blend Mode). A few things to keep in mind about
69  * this implementation:
70  *
71  * 1. This is a reference implementation, not a high-performance one.
72  * Blending using this function will incur a function call and switch
73  * statement per pixel, and will also incur the extra cost of 16 bit
74  * math.
75  *
76  * 2. Zero is black, one is white. In a subtractive color space such
77  * as CMYK, all pixels should be represented as "complemented", as
78  * described in section 3.1 (Blending Color Space) of the PDF 1.4
79  * transparency spec.
80  *
81  * 3. I haven't really figured out how to handle the Compatible blend
82  * mode. I wouldn't be surprised if it required an API change.
83  **/
84 void
85 art_blend_pixel_8(byte *dst, const byte *backdrop,
86 		  const byte *src, int n_chan, gs_blend_mode_t blend_mode);
87 
88 /**
89  * art_pdf_union_8: Union together two alpha values.
90  * @alpha1: One alpha value.
91  * @alpha2: Another alpha value.
92  *
93  * Return value: Union (@alpha1, @alpha2).
94  **/
95 byte art_pdf_union_8(byte alpha1, byte alpha2);
96 
97 /**
98  * art_pdf_union_mul_8: Union together two alpha values, with mask.
99  * @alpha1: One alpha value.
100  * @alpha2: Another alpha value.
101  * @alpha_mask: A mask alpha value;
102  *
103  * Return value: Union (@alpha1, @alpha2 * @alpha_mask).
104  **/
105 byte art_pdf_union_mul_8(byte alpha1, byte alpha2, byte alpha_mask);
106 
107 /**
108  * art_pdf_composite_pixel_alpha_8: Composite two alpha pixels.
109  * @dst: Where to store resulting pixel, also initially backdrop color.
110  * @src: Source pixel color.
111  * @n_chan: Number of channels.
112  * @blend_mode: Blend mode.
113  *
114  * Composites two pixels using the basic compositing operation. A few
115  * things to keep in mind:
116  *
117  * 1. This is a reference implementation, not a high-performance one.
118  *
119  * 2. All pixels are assumed to have a single alpha channel.
120  *
121  * 3. Zero is black, one is white.
122  *
123  * Also note that src and dst are expected to be allocated aligned to
124  * 32 bit boundaries, ie bytes from [0] to [(n_chan + 3) & -4] may
125  * be accessed.
126  **/
127 void
128 art_pdf_composite_pixel_alpha_8(byte *dst, const byte *src, int n_chan,
129 
130 				gs_blend_mode_t blend_mode);
131 
132 /**
133  * art_pdf_uncomposite_group_8: Uncomposite group pixel.
134  * @dst: Where to store uncomposited pixel.
135  * @backdrop: Backdrop.
136  * @src: Composited source pixel.
137  * @src_alpha_g: alpha_g value associated with @src.
138  * @n_chan: Number of channels.
139  *
140  * Performs uncompositing operation as described in 5.3 of the Adobe spec.
141  **/
142 void
143 art_pdf_uncomposite_group_8(byte *dst,
144 			    const byte *backdrop,
145 
146 			    const byte *src, byte src_alpha_g, int n_chan);
147 
148 /**
149  * art_pdf_recomposite_group_8: Recomposite group pixel.
150  * @dst: Where to store pixel, also initial backdrop of group.
151  * @dst_alpha_g: Optional pointer to alpha g value associated with @dst.
152  * @alpha: Alpha mask value.
153  * @src_alpha_g: alpha_g value associated with @src.
154  * @blend_mode: Blend mode for compositing.
155  *
156  * Note: this is only for non-isolated groups. This covers only the
157  * single-alpha case. A separate function is needed for dual-alpha,
158  * and that probably needs to treat knockout separately.
159  *
160  * @src_alpha_g corresponds to $\alpha g_n$ in the Adobe notation.
161  *
162  * @alpha corresponds to $fk_i \cdot fm_i \cdot qk_i \cdot qm_i$.
163  **/
164 void
165 art_pdf_recomposite_group_8(byte *dst, byte *dst_alpha_g,
166 			    const byte *src, byte src_alpha_g,
167 			    int n_chan,
168 
169 			    byte alpha, gs_blend_mode_t blend_mode);
170 
171 /**
172  * art_pdf_composite_group_8: Composite group pixel.
173  * @dst: Where to store pixel, also initial backdrop of group.
174  * @dst_alpha_g: Optional pointer to alpha g value.
175  * @alpha: Alpha mask value.
176  *
177  * Note: this is only for isolated groups. This covers only the
178  * single-alpha case. A separate function is needed for dual-alpha,
179  * and that probably needs to treat knockout separately.
180  *
181  * @alpha corresponds to $fk_i \cdot fm_i \cdot qk_i \cdot qm_i$.
182  **/
183 void
184 art_pdf_composite_group_8(byte *dst, byte *alpha_g,
185 			  const byte *src,
186 
187 			  int n_chan, byte alpha, gs_blend_mode_t blend_mode);
188 
189 /**
190  * art_pdf_composite_knockout_simple_8: Simple knockout compositing.
191  * @dst: Destination pixel.
192  * @dst_shape: Shape associated with @dst.
193  * @src: Source pixel.
194  * @n_chan: Number of channels.
195  * @opacity: Opacity.
196  *
197  * This function handles the simplest knockout case: an isolated
198  * knockout group, and an elementary shape. The alpha channel of @src
199  * is interpreted as shape.
200  **/
201 void
202 art_pdf_composite_knockout_simple_8(byte *dst,
203 				    byte *dst_shape,
204 
205 				    const byte *src,
206 				    int n_chan, byte opacity);
207 
208 /**
209  * art_pdf_composite_knockout_isolated_8: Simple knockout compositing.
210  * @dst: Destination pixel.
211  * @dst_shape: Shape associated with @dst.
212  * @src: Source pixel.
213  * @n_chan: Number of channels.
214  * @shape: Shape.
215  * @alpha_mask: Alpha mask.
216  * @shape_mask: Shape mask.
217  *
218  * This function handles compositin in an isolated knockout case. The
219  * alpha channel of @src is interpreted as alpha.
220  **/
221 void
222 art_pdf_composite_knockout_isolated_8(byte *dst,
223 				      byte *dst_shape,
224 				      const byte *src,
225 				      int n_chan,
226 				      byte shape,
227 				      byte alpha_mask, byte shape_mask);
228 
229 /**
230  * art_pdf_composite_knockout_8: General knockout compositing.
231  * @dst: Destination pixel.
232  * @dst_alpha_g: Pointer to alpha g value associated with @dst.
233  * @backdrop: Backdrop pixel (initial backdrop of knockout group).
234  * @src: Source pixel.
235  * @n_chan: Number of channels.
236  * @shape: Shape.
237  * @alpha_mask: Alpha mask.
238  * @shape_mask: Shape mask.
239  * @blend_mode: Blend mode for compositing.
240  *
241  * This function handles compositing in the case where the knockout
242  * group is non-isolated. If the @src pixels themselves come from a
243  * non-isolated group, they should be uncomposited before calling this
244  * routine.
245  **/
246 void
247 art_pdf_composite_knockout_8(byte *dst,
248 			     byte *dst_alpha_g,
249 			     const byte *backdrop,
250 			     const byte *src,
251 			     int n_chan,
252 			     byte shape,
253 
254 			     byte alpha_mask,
255 			     byte shape_mask, gs_blend_mode_t blend_mode);
256 
257 #endif /* gxblend_INCLUDED */
258