xref: /plan9/sys/src/cmd/gs/src/gxhldevc.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2003 Artifex Software Inc, artofcode llc.  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 /* $Id: gxhldevc.h,v 1.4 2003/09/08 11:45:08 igor Exp $ */
17 /* High level device color save/compare procedures */
18 
19 #ifndef gxhldevc_INCLUDED
20 #  define gxhldevc_INCLUDED
21 
22 #include "gsdcolor.h"
23 
24 /*
25  * Most high level devices want more information about the color spaces
26  * which were used to create color values.
27  *
28  * There are some added complications:
29  *
30  * 1. Ghostscript has many dozens, if not hundreds, of device drivers which
31  * have been written for it.  Many of these devices are outside of our
32  * control.  (However we do receive questions and complaints when they no
33  * longer work.)  Thus we also want to avoid making changes in the device
34  * interface which would require changes to the code in these devices.
35  *
36  * 2. We also desire to not save pointers to color space structures, etc.
37  * within the high level device.  Many of these structures are temporary,
38  * stack based, or are deleted outside of the control of the device.  Thus
39  * it becomes almost impossible to prevent pointers to deleted objects.
40  *
41  * 3. Both color spaces and device colors are passed to devices via pointers
42  * to objects.  These objects, in turn, often contain pointers to other
43  * objects.
44  *
45  * These constraints imply the need within the device to save color spaces
46  * and colors in some form which will allows us to detect color space or
47  * color changes when a new color space and a color is compared to the old
48  * saved color space and color.  These 'saved' forms should not include
49  * pointers to objects outside of the control of the device.
50  *
51  * The functions below are desiged to assist the high level device in the
52  * saving, comparing, and getting high level color information.
53  */
54 
55 
56 #ifndef gs_imager_state_DEFINED
57 #  define gs_imager_state_DEFINED
58 typedef struct gs_imager_state_s gs_imager_state;
59 #endif
60 
61 #ifndef gx_device_color_DEFINED
62 #  define gx_device_color_DEFINED
63 typedef struct gx_device_color_s gx_device_color;
64 #endif
65 
66 /*
67  * A structure for saving high level color information for high level devices.
68  */
69 typedef struct gx_hl_saved_color_s {
70     gs_id color_space_id;
71     gs_id pattern_id;
72     bool ccolor_valid;
73     gs_client_color ccolor;
74     gx_device_color_saved saved_dev_color;
75 } gx_hl_saved_color;
76 
77 /*
78  * Initiailze a high level saved color to null
79  */
80 void gx_hld_saved_color_init(gx_hl_saved_color * psc);
81 
82 /*
83  * Get graphics state pointer (from imager state pointer)
84  * Return NULL if the imager state is not also a graphics state.
85  */
86 const gs_state * gx_hld_get_gstate_ptr(const gs_imager_state * pis);
87 
88 /*
89  * Save the device color information including the color space id and
90  * client color data (if available).  The pattern id is also saved for
91  * detection of changes in the pattern.
92  *
93  * This routine returns 'true' if sufficient information was provided
94  * to completely describe a full high level (non process color model)
95  * color.  Otherwise 'false' is returned.  Thus the return does both
96  * a save and test on the given color.
97  *
98  * If the device can't handle high level colors, it must pass NULL to
99  * the 'pis' argument.
100  */
101 bool gx_hld_save_color(const gs_imager_state * pis,
102 	const gx_device_color * pdevc, gx_hl_saved_color * psc);
103 
104 /*
105  * Compare two saved colors to check if match.  Note this routine assumes
106  * unused parts of the saved color have been zeroed.  See gx_hld_save_color()
107  * for what is actually being compared.
108  */
109 bool gx_hld_saved_color_equal(const gx_hl_saved_color * psc1,
110 			   const gx_hl_saved_color * psc2);
111 
112 /*
113  * Check whether two saved colors have same color space.
114  */
115 bool gx_hld_saved_color_same_cspace(const gx_hl_saved_color * psc1,
116 			   const gx_hl_saved_color * psc2);
117 
118 /*
119  * Check if a high level color is availavble.
120  */
121 bool
122 gx_hld_is_hl_color_available(const gs_imager_state * pis,
123 		const gx_device_color * pdevc);
124 
125 /*
126  * Return status from get_color_space_and_ccolor.  See that routine for
127  * more information.
128  *
129  * Hopefully I will be given more information to allow the choice of
130  * better names.
131  */
132 typedef enum {
133         non_pattern_color_space,
134         pattern_color_sapce,
135 	use_process_color
136 } gx_hld_get_color_space_and_ccolor_status;
137 
138 /*
139  * Get pointers to the current color space and client color.
140  *
141  * There are four possible cases:
142  * 1.  Either the device color or imager state pointer is NULL.  If so then
143  *     we do not have enough information.  Thus we need to fall back to the
144  *     process color model color.  Return NULL for both pointers.
145  * 2.  The device color was not created from a color space and a client color.
146  *     (See the set_non_client_color() macro.)  In this case NULL is returned
147  *     for both pointers.  (Use process color model color.)
148  * 3.  The device color is a 'pattern'.  Return pointers to both the current
149  *     color space and the ccolor (client color) field in the device color
150  *     structure.  Note:  For the shfill opeartor, a pattern color space will
151  *     be used to build the device color.  However the current color space
152  *     will not be the pattern color space.
153  * 4.  All other cases: the current color space is the color space used to
154  *     build the device color.  A pointer to the current color space is
155  *     returned.  The client color pointer will be NULL.
156  *
157  * The status returned indicates if the color space information is valid
158  * (non valid --> use_process_color) and whether the color space is
159  * a pattern or non pattern).
160  */
161 gx_hld_get_color_space_and_ccolor_status gx_hld_get_color_space_and_ccolor(
162 		const gs_imager_state * pis, const gx_device_color * pdevc,
163 		const gs_color_space ** ppcs, const gs_client_color ** ppcc);
164 
165 /*
166  * This routine will return the number of components in the current color
167  * space.
168  *
169  * The routine will return -1 if the imager state does not point to a
170  * graphics state (and thus we cannot get the current color space).
171  */
172 int gx_hld_get_number_color_components(const gs_imager_state * pis);
173 
174 /*
175  * This defines sthe possible status to be returned from get_color_component.
176  */
177 typedef enum {
178     valid_result = 1,
179     invalid_color_info = 2,
180     invalid_component_requested = 3
181 } gx_hld_get_color_component_status;
182 
183 /*
184  * Get the requested high level color value.
185  *
186  * This routine will get the specified high level color if it is available.
187  * If the value is not available (status equal either invalid_color_info or
188  * invalid_component_requested).  In this case, it is suggested that the
189  * device fall back to using the process color model.
190  */
191 gx_hld_get_color_component_status gx_hld_get_color_component(
192 		const gs_imager_state * pis, const gx_device_color * pdevc,
193 		int comp_numi, float * output);
194 
195 #endif
196 
197