1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
13
/* $Id: gxhldevc.c 8022 2007-06-05 22:23:38Z giles $ */
14
/* High level device color save/compare procedures */
17
* See comments at the start of gxhldevc.h for more explanation of the
18
* purpose and operation of these procedures.
30
* Initiailze a high level saved color to null
32
void gx_hld_saved_color_init(gx_hl_saved_color * psc)
34
gx_device_color temp_devc;
36
memset(psc, 0, sizeof(*psc)); /* clear the entire structure */
37
psc->color_space_id = psc->pattern_id = gs_no_id;
38
color_set_null(&temp_devc);
39
temp_devc.type->save_dc(&temp_devc, &(psc->saved_dev_color));
43
* Get graphics state pointer (from imager state pointer)
45
const gs_state * gx_hld_get_gstate_ptr(const gs_imager_state * pis)
47
extern_st(st_gs_state); /* only for testing */
49
/* Check to verify the structure type is really st_gs_state */
50
if (pis == NULL || gs_object_type(pis->memory, pis) != &st_gs_state)
53
return (const gs_state *) pis;
57
* Save the device color information including the color space id and
58
* client color data (if available).
60
* More description in src/gxhldevc.h
63
gx_hld_save_color(const gs_imager_state * pis, const gx_device_color * pdevc,
64
gx_hl_saved_color * psc)
66
const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
67
memset(psc, 0, sizeof(*psc)); /* clear the entire structure */
70
/* No device color given, should not happen */
71
gx_hld_saved_color_init(psc); /* revert to unknown color */
73
} else if (pgs == NULL) {
74
/* No color space, simply save device color specific info */
75
psc->color_space_id = psc->pattern_id = gs_no_id;
76
pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
80
* Have color space, save id, ccolor, & device color specific info.
81
* Also save the high level colors since two gx_color_index values
82
* may be the same but for differing high level colors (due to the
83
* usual lower resolution of the gx_color_index values.
85
const gs_color_space * pcs = pgs->color_space;
86
int i = gs_color_space_num_components(pcs);
88
psc->color_space_id = pcs->id;
89
pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
90
if (pdevc->type == gx_dc_type_pattern2)
93
i = -i - 1; /* See gx_num_components_Pattern. */
94
for (i--; i >= 0; i--)
95
psc->ccolor.paint.values[i] = pdevc->ccolor.paint.values[i];
97
/* Save the pattern id - if present */
98
if ((pdevc->type == gx_dc_type_pattern
99
|| pdevc->type == gx_dc_type_pattern2) && pdevc->ccolor_valid)
100
psc->pattern_id = pdevc->ccolor.pattern->pattern_id;
102
psc->pattern_id = gs_no_id;
108
* Compare two saved colors to check if match. Note this routine assumes
109
* unused parts of the saved color have been zeroed. See gx_hld_save_color()
110
* for what is actually being compared.
112
bool gx_hld_saved_color_equal(const gx_hl_saved_color * psc1,
113
const gx_hl_saved_color * psc2)
115
return (memcmp(psc1, psc2, sizeof(*psc1)) == 0);
119
* Check whether two saved colors have same color space.
121
bool gx_hld_saved_color_same_cspace(const gx_hl_saved_color * psc1,
122
const gx_hl_saved_color * psc2)
124
if (psc1->color_space_id != psc2->color_space_id)
126
if (psc1->pattern_id != psc2->pattern_id)
128
if (psc1->ccolor_valid != psc2->ccolor_valid)
130
if (psc1->color_space_id != psc2->color_space_id)
136
* Check if a high level color is availavble.
139
gx_hld_is_hl_color_available(const gs_imager_state * pis,
140
const gx_device_color * pdevc)
142
const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
144
if (pgs != NULL && pdevc != NULL && pdevc->ccolor_valid)
150
* Get pointers to the current color space and client color.
152
* More description in src/gxhldevc.h
154
gx_hld_get_color_space_and_ccolor_status
155
gx_hld_get_color_space_and_ccolor(const gs_imager_state * pis,
156
const gx_device_color * pdevc, const gs_color_space ** ppcs,
157
const gs_client_color ** ppcc)
159
/* Check if the current color space was used to build the device color */
160
if (gx_hld_is_hl_color_available(pis, pdevc)) {
161
const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
162
const gs_color_space * pcs = pgs->color_space;
165
*ppcc = &(pdevc->ccolor);
166
if (pdevc->type == gx_dc_type_pattern
167
|| pdevc->type == &gx_dc_pure_masked
168
|| pdevc->type == gx_dc_type_pattern2)
169
return pattern_color_sapce;
171
return non_pattern_color_space;
177
return use_process_color;
181
* Get the number of components in the current color space.
183
* More description in src/gxhldevc.h
186
gx_hld_get_number_color_components(const gs_imager_state * pis)
188
const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
191
const gs_color_space * pcs = pgs->color_space;
192
int n = gs_color_space_num_components(pcs);
194
return (n >= 0 ? n : -n - 1);
200
* Get the requested high level color value.
202
* More description in src/gxhldevc.h
204
gx_hld_get_color_component_status
205
gx_hld_get_color_component(const gs_imager_state * pis,
206
const gx_device_color * pdevc,
207
int comp_num, float * output)
209
if (pdevc != NULL && pdevc->ccolor_valid) {
210
int ncomp = gx_hld_get_number_color_components(pis);
213
return invalid_color_info;
214
if (comp_num < 0 || comp_num >= ncomp)
215
return invalid_component_requested;
216
*output = pdevc->ccolor.paint.values[comp_num];
219
return invalid_color_info;