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: gsnamecl.c 8764 2008-05-21 18:27:42Z mvrhel $ */
14
/* Callback mechanism for handling color spaces containing named colors. */
17
* This module has been created to provide a callback mechanism for special
18
* processing of DeviceN and Separation color spaces. One possible application
19
* of this callback mechanism is to provide a means for special handling of
20
* PANTONE or SWOP colors.
22
* This implementation consists of four routines. There are a pair of
23
* routines for both Separation and DeviceN color spaces. Each pair consists
24
* of a routine that is called when the color space is installed and a
25
* second routine that is called to transform colors in that color space
26
* into device colorant values. The routines named_color_install_Separation
27
* and named_color_install_DeviceN are called when a Separation or DeviceN
28
* color space is installed. These routines determine if the given color space
29
* meets some criteria decided by the client. These routines return true if the
30
* colors in the color space should be processed via the second routine.
43
#include "gsnamecl.h" /* Custom color call back define */
45
#if ENABLE_CUSTOM_COLOR_CALLBACK /* Defined in src/gsnamecl.h */
48
* Check if we want to use the callback color processing logic for the given
49
* Separation color space.
52
custom_color_callback_install_Separation(gs_color_space * pcs, gs_state * pgs)
54
client_custom_color_params_t * pcb =
55
(client_custom_color_params_t *) pgs->memory->gs_lib_ctx->custom_color_callback;
57
return (pcb == NULL) ? false
58
: pcb->client_procs->install_Separation(pcb, pcs, pgs);
62
* Check if we want to use the callback color processing logic for the given
63
* DeviceN color space.
66
custom_color_callback_install_DeviceN(gs_color_space * pcs, gs_state * pgs)
68
client_custom_color_params_t * pcb =
69
(client_custom_color_params_t *) pgs->memory->gs_lib_ctx->custom_color_callback;
71
return (pcb == NULL) ? false
72
: pcb->client_procs->install_DeviceN(pcb, pcs, pgs);
76
* Convert a Separation color using the 'custom color' callback into
80
gx_remap_concrete_custom_color_Separation(const frac * pconc,
81
const gs_color_space * pcs, gx_device_color * pdc,
82
const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
84
client_custom_color_params_t * pcb =
85
(client_custom_color_params_t *) pis->memory->gs_lib_ctx->custom_color_callback;
88
return_error(gs_error_rangecheck);
91
return pcb->client_procs->remap_Separation(pcb, pconc,
92
pcs, pdc, pis, dev, select);
96
* Convert a DeviceN color using the 'custom color' callback into device
100
gx_remap_concrete_custom_color_DeviceN(const frac * pconc,
101
const gs_color_space * pcs, gx_device_color * pdc,
102
const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
104
client_custom_color_params_t * pcb =
105
(client_custom_color_params_t *) pis->memory->gs_lib_ctx->custom_color_callback;
108
return_error(gs_error_rangecheck);
111
return pcb->client_procs->remap_DeviceN(pcb, pconc,
112
pcs, pdc, pis, dev, select);
116
* Get the 'custom color' client callback parameter block pointer. This value
117
* is passed as a string type device paramter. A string is being used since
118
* PostScript does not support pointers as a type. Note: An integer type
119
* is not being used since PS intergers are nominally 32 bits. Thus there
120
* would be a problem using integers to pass pointer values on 64 bit systems.
123
custom_color_callback_get_params(gs_state * pgs, gs_param_list * plist)
125
/* Convert our pointer to a PostScript hex string */
126
char buf[64] = "16#";
128
gs_param_string custom_color_param;
133
idx = ((int)sizeof(size_t)) * 8 - 4;
134
iptr = (size_t)(pgs->memory->gs_lib_ctx->custom_color_callback);
136
val = (int)(iptr >> idx) & 0xf;
138
buf[buf_pos++] = '0' + val;
140
buf[buf_pos++] = 'a' - 10 + val;
143
param_string_from_transient_string(custom_color_param, buf);
145
return param_write_string(plist, CustomColorCallbackParamName,
146
&custom_color_param);
150
* Put the 'custom color' client callback parameter block pointer. This value
151
* is passed as a string type device paramter. A string is being used since
152
* PostScript does not support pointers as a type. Note: An integer type
153
* is not being used since PS integers are nominally 32 bits. Thus there
154
* would be a problem using integers to pass pointer values on 64 bit systems.
157
custom_color_callback_put_params(gs_state * pgs, gs_param_list * plist)
160
size_t iptr = (size_t)(pgs->memory->gs_lib_ctx->custom_color_callback);
161
gs_param_string dh = { 0 };
163
switch (code = param_read_string(plist, CustomColorCallbackParamName, &dh)) {
167
* Convert from a string to a pointer.
168
* It is assumed that size_t has the same size as a pointer.
169
* Allow formats (1234), (10#1234) or (16#04d2).
175
for (i = 0; i < dh.size; i++) {
177
if ((val >= '0') && (val <= '9'))
179
else if ((val >= 'A') && (val <= 'F'))
180
val = val - 'A' + 10;
181
else if ((val >= 'a') && (val <= 'f'))
182
val = val - 'a' + 10;
183
else if (val == '#' && ((iptr == 10) || (iptr == 16))) {
189
code = gs_error_rangecheck;
192
iptr = iptr * base + val;
202
param_signal_error(plist, "CustomColorCallback", code);
204
else if (pgs->memory->gs_lib_ctx->custom_color_callback != (void *)iptr) {
205
pgs->memory->gs_lib_ctx->custom_color_callback = (void *)iptr;
207
* Custom color processing can depend upon the type of object
208
* being imaged so we enable object type tagging.
210
gs_enable_object_tagging();
216
#endif /* ENABLE_CUSTOM_COLOR_CALLBACK */