~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gsequivc.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/*$Id: gsequivc.c 11619 2010-08-10 16:20:19Z mvrhel $ */
 
14
/*$Id$ */
15
15
/* Routines for determining equivalent color for spot colors */
16
16
 
17
17
#include "math_.h"
25
25
#include "gsstate.h"
26
26
#include "gscspace.h"
27
27
#include "gxcspace.h"
 
28
#include "gsicc_manage.h"
28
29
 
29
30
/*
30
31
 * These routines are part of the logic for determining an equivalent
103
104
 
104
105
#define compare_color_names(name, name_size, str, str_size) \
105
106
    (name_size == str_size && \
106
 
        (strncmp((const char *)name, (const char *)str, name_size) == 0))
 
107
        (strncmp((const char *)name, (const char *)str, name_size) == 0))
107
108
 
108
109
static void
109
110
update_Separation_spot_equivalent_cmyk_colors(gx_device * pdev,
110
 
                    const gs_state * pgs, const gs_color_space * pcs,
111
 
                    gs_devn_params * pdevn_params,
112
 
                    equivalent_cmyk_color_params * pparams)
 
111
                    const gs_state * pgs, const gs_color_space * pcs,
 
112
                    gs_devn_params * pdevn_params,
 
113
                    equivalent_cmyk_color_params * pparams)
113
114
{
114
115
    int i;
115
116
 
116
 
    /* 
 
117
    /*
117
118
     * Check if the color space's separation name matches any of the
118
119
     * separations for which we need an equivalent CMYK color.
119
120
     */
120
121
    for (i = 0; i < pdevn_params->separations.num_separations; i++) {
121
 
        if (pparams->color[i].color_info_valid == false) {
122
 
            const devn_separation_name * dev_sep_name =
123
 
                            &(pdevn_params->separations.names[i]);
124
 
            unsigned int cs_sep_name_size;
125
 
            unsigned char * pcs_sep_name;
126
 
 
127
 
            pcs->params.separation.get_colorname_string
128
 
                (pdev->memory, pcs->params.separation.sep_name, &pcs_sep_name,
129
 
                 &cs_sep_name_size);
130
 
            if (compare_color_names(dev_sep_name->data, dev_sep_name->size,
131
 
                            pcs_sep_name, cs_sep_name_size)) {
132
 
                gs_color_space temp_cs = *pcs;
133
 
                gs_client_color client_color;
134
 
 
135
 
                /*
136
 
                 * Create a copy of the color space and then modify it
137
 
                 * to force the use of the alternate color space.
138
 
                 */
139
 
                temp_cs.params.separation.use_alt_cspace = true;
140
 
                client_color.paint.values[0] = 1.0;
141
 
                capture_spot_equivalent_cmyk_colors(pdev, pgs, &client_color,
142
 
                                            &temp_cs, i, pparams);
143
 
                break;
144
 
            }
145
 
        }
 
122
        if (pparams->color[i].color_info_valid == false) {
 
123
            const devn_separation_name * dev_sep_name =
 
124
                            &(pdevn_params->separations.names[i]);
 
125
            unsigned int cs_sep_name_size;
 
126
            unsigned char * pcs_sep_name;
 
127
 
 
128
            pcs->params.separation.get_colorname_string
 
129
                (pdev->memory, pcs->params.separation.sep_name, &pcs_sep_name,
 
130
                 &cs_sep_name_size);
 
131
            if (compare_color_names(dev_sep_name->data, dev_sep_name->size,
 
132
                            pcs_sep_name, cs_sep_name_size)) {
 
133
                gs_color_space temp_cs = *pcs;
 
134
                gs_client_color client_color;
 
135
 
 
136
                /*
 
137
                 * Create a copy of the color space and then modify it
 
138
                 * to force the use of the alternate color space.
 
139
                 */
 
140
                temp_cs.params.separation.use_alt_cspace = true;
 
141
                client_color.paint.values[0] = 1.0;
 
142
                capture_spot_equivalent_cmyk_colors(pdev, pgs, &client_color,
 
143
                                            &temp_cs, i, pparams);
 
144
                break;
 
145
            }
 
146
        }
146
147
    }
147
148
}
148
149
 
149
150
static void
150
151
update_DeviceN_spot_equivalent_cmyk_colors(gx_device * pdev,
151
 
                    const gs_state * pgs, const gs_color_space * pcs,
152
 
                    gs_devn_params * pdevn_params,
153
 
                    equivalent_cmyk_color_params * pparams)
 
152
                    const gs_state * pgs, const gs_color_space * pcs,
 
153
                    gs_devn_params * pdevn_params,
 
154
                    equivalent_cmyk_color_params * pparams)
154
155
{
155
156
    int i;
156
157
    unsigned int j;
162
163
     * our capture logic does not work properly.  When present, the 'None'
163
164
     * components contain alternate color information.  However this info is
164
165
     * specified as part of the 'color' and not part of the color space.  Thus
165
 
     * we do not have this data when this routine is called.  See the 
 
166
     * we do not have this data when this routine is called.  See the
166
167
     * description of DeviceN color spaces in section 4.5 of the PDF spec.
167
168
     * In this situation we exit rather than produce invalid values.
168
169
     */
169
170
     for (j = 0; j < pcs->params.device_n.num_components; j++) {
170
 
        pcs->params.device_n.get_colorname_string
171
 
            (pdev->memory, pcs->params.device_n.names[j],  
172
 
             &pcs_sep_name, &cs_sep_name_size);
173
 
        if (compare_color_names("None", 4, pcs_sep_name, cs_sep_name_size))
174
 
            return;
 
171
        pcs->params.device_n.get_colorname_string
 
172
            (pdev->memory, pcs->params.device_n.names[j],
 
173
             &pcs_sep_name, &cs_sep_name_size);
 
174
        if (compare_color_names("None", 4, pcs_sep_name, cs_sep_name_size))
 
175
            return;
175
176
    }
176
177
 
177
 
    /* 
 
178
    /*
178
179
     * Check if the color space's separation names matches any of the
179
180
     * separations for which we need an equivalent CMYK color.
180
181
     */
181
182
    for (i = 0; i < pdevn_params->separations.num_separations; i++) {
182
 
        if (pparams->color[i].color_info_valid == false) {
183
 
            const devn_separation_name * dev_sep_name =
184
 
                            &(pdevn_params->separations.names[i]);
185
 
 
186
 
            for (j = 0; j < pcs->params.device_n.num_components; j++) {
187
 
                pcs->params.device_n.get_colorname_string
188
 
                    (pdev->memory, pcs->params.device_n.names[j], &pcs_sep_name,
189
 
                     &cs_sep_name_size);
190
 
                if (compare_color_names(dev_sep_name->data, dev_sep_name->size,
191
 
                            pcs_sep_name, cs_sep_name_size)) {
192
 
                    gs_color_space temp_cs = *pcs;
193
 
                    gs_client_color client_color;
194
 
 
195
 
                    /*
196
 
                     * Create a copy of the color space and then modify it
197
 
                     * to force the use of the alternate color space.
198
 
                     */
199
 
                    memset(&client_color, 0, sizeof(client_color));
200
 
                    temp_cs.params.device_n.use_alt_cspace = true;
201
 
                    client_color.paint.values[j] = 1.0;
202
 
                    capture_spot_equivalent_cmyk_colors(pdev, pgs, &client_color,
203
 
                                            &temp_cs, i, pparams);
204
 
                    break;
205
 
                }
206
 
            }
207
 
        }
 
183
        if (pparams->color[i].color_info_valid == false) {
 
184
            const devn_separation_name * dev_sep_name =
 
185
                            &(pdevn_params->separations.names[i]);
 
186
 
 
187
            for (j = 0; j < pcs->params.device_n.num_components; j++) {
 
188
                pcs->params.device_n.get_colorname_string
 
189
                    (pdev->memory, pcs->params.device_n.names[j], &pcs_sep_name,
 
190
                     &cs_sep_name_size);
 
191
                if (compare_color_names(dev_sep_name->data, dev_sep_name->size,
 
192
                            pcs_sep_name, cs_sep_name_size)) {
 
193
                    gs_color_space temp_cs = *pcs;
 
194
                    gs_client_color client_color;
 
195
 
 
196
                    /*
 
197
                     * Create a copy of the color space and then modify it
 
198
                     * to force the use of the alternate color space.
 
199
                     */
 
200
                    memset(&client_color, 0, sizeof(client_color));
 
201
                    temp_cs.params.device_n.use_alt_cspace = true;
 
202
                    client_color.paint.values[j] = 1.0;
 
203
                    capture_spot_equivalent_cmyk_colors(pdev, pgs, &client_color,
 
204
                                            &temp_cs, i, pparams);
 
205
                    break;
 
206
                }
 
207
            }
 
208
        }
208
209
    }
209
210
}
210
211
 
211
212
static bool check_all_colors_known(int num_spot,
212
 
                equivalent_cmyk_color_params * pparams)
 
213
                equivalent_cmyk_color_params * pparams)
213
214
{
214
215
    for (num_spot--; num_spot >= 0; num_spot--)
215
 
        if (pparams->color[num_spot].color_info_valid == false)
216
 
            return false;
 
216
        if (pparams->color[num_spot].color_info_valid == false)
 
217
            return false;
217
218
    return true;
218
219
}
219
220
 
226
227
 
227
228
    /* If all of the color_info is valid then there is nothing to do. */
228
229
    if (pparams->all_color_info_valid)
229
 
        return;
 
230
        return;
230
231
 
231
232
    /* Verify that we really have some separations. */
232
233
    if (pdevn_params->separations.num_separations == 0) {
233
 
        pparams->all_color_info_valid = true;
234
 
        return;
 
234
        pparams->all_color_info_valid = true;
 
235
        return;
235
236
    }
236
237
    /*
237
238
     * Verify that the given color space is a Separation or a DeviceN color
240
241
     */
241
242
    pcs = gs_currentcolorspace_inline(pgs);
242
243
    if (pcs != NULL) {
243
 
        if (pcs->type->index == gs_color_space_index_Separation) {
244
 
            update_Separation_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
245
 
                                                pdevn_params, pparams);
246
 
            pparams->all_color_info_valid = check_all_colors_known
247
 
                    (pdevn_params->separations.num_separations, pparams);
248
 
        }
249
 
        else if (pcs->type->index == gs_color_space_index_DeviceN) {
250
 
            update_DeviceN_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
251
 
                                                pdevn_params, pparams);
252
 
            pparams->all_color_info_valid = check_all_colors_known
253
 
                    (pdevn_params->separations.num_separations, pparams);
254
 
        }
 
244
        if (pcs->type->index == gs_color_space_index_Separation) {
 
245
            update_Separation_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
 
246
                                                pdevn_params, pparams);
 
247
            pparams->all_color_info_valid = check_all_colors_known
 
248
                    (pdevn_params->separations.num_separations, pparams);
 
249
        }
 
250
        else if (pcs->type->index == gs_color_space_index_DeviceN) {
 
251
            update_DeviceN_spot_equivalent_cmyk_colors(pdev, pgs, pcs,
 
252
                                                pdevn_params, pparams);
 
253
            pparams->all_color_info_valid = check_all_colors_known
 
254
                    (pdevn_params->separations.num_separations, pparams);
 
255
        }
255
256
    }
256
257
}
257
258
 
258
259
static void
259
260
save_spot_equivalent_cmyk_color(int sep_num,
260
 
                equivalent_cmyk_color_params * pparams, frac cmyk[4])
 
261
                equivalent_cmyk_color_params * pparams, frac cmyk[4])
261
262
{
262
263
    pparams->color[sep_num].c = cmyk[0];
263
264
    pparams->color[sep_num].m = cmyk[1];
291
292
static cmap_proc_devicen(cmap_devicen_capture_cmyk_color);
292
293
 
293
294
static const gx_color_map_procs cmap_capture_cmyk_color = {
294
 
    cmap_gray_capture_cmyk_color, 
295
 
    cmap_rgb_capture_cmyk_color, 
 
295
    cmap_gray_capture_cmyk_color,
 
296
    cmap_rgb_capture_cmyk_color,
296
297
    cmap_cmyk_capture_cmyk_color,
297
298
    cmap_rgb_alpha_capture_cmyk_color,
298
299
    cmap_separation_capture_cmyk_color,
301
302
 
302
303
static void
303
304
cmap_gray_capture_cmyk_color(frac gray, gx_device_color * pdc,
304
 
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
 
305
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
305
306
{
306
307
    equivalent_cmyk_color_params * pparams =
307
 
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
 
308
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
308
309
    int sep_num = ((color_capture_device *)dev)->sep_num;
309
310
    frac cmyk[4];
310
311
 
318
319
     const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
319
320
{
320
321
    equivalent_cmyk_color_params * pparams =
321
 
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
 
322
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
322
323
    int sep_num = ((color_capture_device *)dev)->sep_num;
323
324
    frac cmyk[4];
324
325
 
331
332
     const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
332
333
{
333
334
    equivalent_cmyk_color_params * pparams =
334
 
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
 
335
            ((color_capture_device *)dev)->pequiv_cmyk_colors;
335
336
    int sep_num = ((color_capture_device *)dev)->sep_num;
336
337
    frac cmyk[4];
337
338
 
344
345
 
345
346
static void
346
347
cmap_rgb_alpha_capture_cmyk_color(frac r, frac g, frac b, frac alpha,
347
 
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
348
 
                         gs_color_select_t select)
 
348
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
 
349
                         gs_color_select_t select)
349
350
{
350
351
    cmap_rgb_capture_cmyk_color(r, g, b, pdc, pis, dev, select);
351
352
}
376
377
    gs_imager_state temp_state = *((const gs_imager_state *)pgs);
377
378
    color_capture_device temp_device = { 0 };
378
379
    gx_device_color dev_color;
 
380
    gsicc_rendering_intents_t rendering_intent;
 
381
    int code;
 
382
    cmm_dev_profile_t *dev_profile;
 
383
    cmm_profile_t *curr_output_profile;
 
384
    cmm_dev_profile_t temp_profile;
379
385
 
 
386
    code = dev_proc(pdev, get_profile)(pdev, &dev_profile);
 
387
    gsicc_extract_profile(pdev->graphics_type_tag,
 
388
                          dev_profile, &(curr_output_profile),
 
389
                          &rendering_intent);
380
390
    /*
381
391
     * Create a temp device.  The primary purpose of this device is pass the
382
392
     * separation number and a pointer to the original device's equivalent
383
393
     * color parameters.  Since we only using this device for a very specific
384
 
     * purpose, we only set up the color_info structure and and our data.
 
394
     * purpose, we only set up the color_info structure and our data.
385
395
     */
386
396
    temp_device.color_info = pdev->color_info;
387
397
    temp_device.sep_num = sep_num;
388
398
    temp_device.pequiv_cmyk_colors = pparams;
389
399
    temp_device.memory = pgs->memory;
390
 
    temp_device.device_icc_profile = pdev->device_icc_profile;
 
400
 
 
401
    temp_profile.device_profile[0] = curr_output_profile;
 
402
    temp_profile.device_profile[1] = NULL;
 
403
    temp_profile.device_profile[2] = NULL;
 
404
    temp_profile.device_profile[2] = NULL;
 
405
    temp_device.icc_array = &temp_profile;
 
406
    set_dev_proc(&temp_device, get_profile, gx_default_get_profile);
 
407
 
391
408
    /*
392
409
     * Create a temp copy of the imager state.  We do this so that we
393
410
     * can modify the color space mapping (cmap) procs.  We use our
400
417
 
401
418
    /* Now capture the color */
402
419
    pcs->type->remap_color (pcc, pcs, &dev_color, &temp_state,
403
 
                    (gx_device *)&temp_device, gs_color_select_texture);
 
420
                    (gx_device *)&temp_device, gs_color_select_texture);
404
421
}