xref: /plan9/sys/src/cmd/gs/src/gdevdevn.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2003 Artifex Software Inc.  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: gdevdevn.h,v 1.12 2005/10/01 04:40:18 dan Exp $ */
18 /* Include file for common DeviceN process color model devices. */
19 
20 #ifndef gdevdevn_INCLUDED
21 # define gdevdevn_INCLUDED
22 
23 /*
24  * Define the maximum number of spot colors supported by this device.
25  * This value is arbitrary.  It is set simply to define a limit on
26  * on the separation_name_array and separation_order map.
27  */
28 #define GX_DEVICE_MAX_SEPARATIONS 16
29 /*
30  * Define the maximum number of process model colorants.  Currently we only
31  * have code for DeviceGray, DeviceRGB, and DeviceCMYK.  Thus this value
32  * only needs to be 4.  However we are allowing for a future hexachrome
33  * device.  (This value does not include spot colors.  See previous value.)
34  */
35 #define MAX_DEVICE_PROCESS_COLORS 6
36 
37 /*
38  * Type definitions associated with the fixed color model names.
39  */
40 typedef const char * fixed_colorant_name;
41 typedef fixed_colorant_name * fixed_colorant_names_list;
42 
43 /*
44  * Structure for holding SeparationNames elements.
45  */
46 typedef struct devn_separation_name_s {
47     int size;
48     byte * data;
49 } devn_separation_name;
50 
51 /*
52  * Structure for holding SeparationNames elements.
53  */
54 typedef struct gs_separations_s {
55     int num_separations;
56     devn_separation_name names[GX_DEVICE_MAX_SEPARATIONS];
57 } gs_separations;
58 
59 /*
60  * Type for holding a separation order map
61  */
62 typedef int gs_separation_map[GX_DEVICE_MAX_SEPARATIONS];
63 
64 typedef struct gs_devn_params_s {
65     /*
66      * Bits per component (device colorant).  Currently only 1 and 8 are
67      * supported.
68      */
69     int bitspercomponent;
70 
71     /*
72      * Pointer to the colorant names for the color model.  This will be
73      * null if we have DeviceN type device.  The actual possible colorant
74      * names are those in this list plus those in the separation[i].name
75      * list (below).
76      */
77     fixed_colorant_names_list std_colorant_names;
78     int num_std_colorant_names;	/* Number of names in list */
79     int max_separations;	/* From MaxSeparation parameter */
80 
81     /*
82     * Separation info (if any).
83     */
84     gs_separations separations;
85 
86     /*
87      * Separation Order (if specified).
88      */
89     int num_separation_order_names;
90     /*
91      * The SeparationOrder parameter may change the logical order of
92      * components.
93      */
94     gs_separation_map separation_order_map;
95 } gs_devn_params_t;
96 
97 typedef gs_devn_params_t gs_devn_params;
98 
99 extern fixed_colorant_name DeviceCMYKComponents[];
100 
101 #include "gsequivc.h"
102 
103 /*
104  * Utility routines for common DeviceN related parameters:
105  *   SeparationColorNames, SeparationOrder, and MaxSeparations
106  */
107 
108 /*
109  * Convert standard color spaces into DeviceN colorants.
110  * Note;  This routine require SeparationOrder map.
111  */
112 void gray_cs_to_devn_cm(gx_device * dev, int * map, frac gray, frac out[]);
113 
114 void rgb_cs_to_devn_cm(gx_device * dev, int * map,
115 		const gs_imager_state *pis, frac r, frac g, frac b, frac out[]);
116 
117 void cmyk_cs_to_devn_cm(gx_device * dev, int * map,
118 		frac c, frac m, frac y, frac k, frac out[]);
119 
120 /*
121  * Possible values for the 'auto_spot_colors' parameter.
122  */
123 /*
124  * Do not automatically include spot colors
125  */
126 #define NO_AUTO_SPOT_COLORS 0
127 /*
128  * Automatically add spot colors up to the number that the device can image.
129  * Spot colors over that limit will be handled by the alternate color space
130  * for the Separation or DeviceN color space.
131  */
132 #define ENABLE_AUTO_SPOT_COLORS	1
133 /*
134  * Automatically add spot colors up to the GX_DEVICE_MAX_SEPARATIONS value.
135  * Note;  Spot colors beyond the number that the device can image will be
136  * ignored (i.e. treated like a colorant that is not specified by the
137  * SeparationOrder device parameter.
138  */
139 #define ALLOW_EXTRA_SPOT_COLORS 2
140 
141 /*
142  * This routine will check to see if the color component name  match those
143  * that are available amoung the current device's color components.
144  *
145  * Parameters:
146  *   dev - pointer to device data structure.
147  *   pname - pointer to name (zero termination not required)
148  *   nlength - length of the name
149  *   component_type - separation name or not
150  *   pdevn_params - pointer to device's DeviceN paramters
151  *   pequiv_colors - pointer to equivalent color structure (may be NULL)
152  *   auto_spot_colors - See comments above.
153  *
154  * This routine returns a positive value (0 to n) which is the device colorant
155  * number if the name is found.  It returns GX_DEVICE_COLOR_MAX_COMPONENTS if
156  * the color component is found but is not being used due to the
157  * SeparationOrder parameter.  It returns a negative value if not found.
158  *
159  * This routine will also add separations to the device if space is
160  * available.
161  */
162 int devn_get_color_comp_index(const gx_device * dev,
163     gs_devn_params * pdevn_params, equivalent_cmyk_color_params * pequiv_colors,
164     const char * pname, int name_size, int component_type,
165     int auto_spot_colors);
166 
167 /* Utility routine for getting DeviceN parameters */
168 int devn_get_params(gx_device * pdev, gs_param_list * plist,
169 		    gs_devn_params * pdevn_params,
170 		    equivalent_cmyk_color_params * pequiv_colors);
171 
172 /*
173  * Utility routine for handling DeviceN related parameters.  This routine
174  * assumes that the device is based upon a standard printer type device.
175  * (See the next routine if not.)
176  *
177  * Note that this routine requires a pointer to the DeviceN parameters within
178  * the device structure.  The pointer to the equivalent_cmyk_color_params is
179  * optional (it should be NULL if this feature is not used by the device).
180  */
181 int devn_printer_put_params(gx_device * pdev, gs_param_list * plist,
182 			gs_devn_params * pdevn_params,
183 			equivalent_cmyk_color_params * pequiv_colors);
184 
185 /*
186  * Utility routine for handling DeviceN related parameters.  This routine
187  * may modify the color_info, devn_params, and the * equiv_colors fields.
188  * The pointer to the equivalent_cmyk_color_params is optional (it should be
189  * NULL if this feature is not used by the device).
190  *
191  * Note:  This routine does not restore values in case of a problem.  This
192  * is left to the caller.
193  */
194 int devn_put_params(gx_device * pdev, gs_param_list * plist,
195 			gs_devn_params * pdevn_params,
196 			equivalent_cmyk_color_params * pequiv_colors);
197 
198 /*
199  * This routine will check to see if the color component name  match those
200  * of either the process color model colorants or the names on the
201  * SeparationColorNames list.
202  *
203  * Parameters:
204  *   dev - pointer to device data structure.
205  *   pname - pointer to name (zero termination not required)
206  *   nlength - length of the name
207  *
208  * This routine returns a positive value (0 to n) which is the device colorant
209  * number if the name is found.  It returns a negative value if not found.
210  */
211 int check_pcm_and_separation_names(const gx_device * dev,
212 		const gs_devn_params * pparams, const char * pname,
213 		int name_size, int component_type);
214 
215 /*
216  * This routine will extract a specified set of bits from a buffer and pack
217  * them into a given buffer.
218  *
219  * Parameters:
220  *   source - The source of the data
221  *   dest - The destination for the data
222  *   depth - The size of the bits per pixel - must be a multiple of 8
223  *   first_bit - The location of the first data bit (LSB).
224  *   bit_width - The number of bits to be extracted.
225  *   npixel - The number of pixels.
226  *
227  * Returns:
228  *   Length of the output line (in bytes)
229  *   Data in dest.
230  */
231 int repack_data(byte * source, byte * dest, int depth, int first_bit,
232 		int bit_width, int npixel);
233 
234 /*
235  * This utility routine calculates the number of bits required to store
236  * color information.  In general the values are rounded up to an even
237  * byte boundary except those cases in which mulitple pixels can evenly
238  * into a single byte.
239  *
240  * The parameter are:
241  *   ncomp - The number of components (colorants) for the device.  Valid
242  * 	values are 1 to GX_DEVICE_COLOR_MAX_COMPONENTS
243  *   bpc - The number of bits per component.  Valid values are 1, 2, 4, 5,
244  *	and 8.
245  * Input values are not tested for validity.
246  */
247 int bpc_to_depth(int ncomp, int bpc);
248 
249 #endif		/* ifndef gdevdevn_INCLUDED */
250