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

« back to all changes in this revision

Viewing changes to base/gsncdummy.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:
10
10
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
 
/* $Id: gsncdummy.c 8945 2008-08-06 19:57:07Z giles $ */
 
13
/* $Id$ */
14
14
/* Sample implementation for client custom processing of color spaces. */
15
15
 
16
16
/*
74
74
#include "gxcie.h"
75
75
#include "gsncdummy.h"
76
76
 
77
 
 
78
77
#if ENABLE_CUSTOM_COLOR_CALLBACK                /* Defined in src/gsnamecl.h */
79
78
 
80
79
/*
106
105
/* Compare two names */
107
106
#define compare_names(name1, name_size1, name2, name_size2) \
108
107
    (name_size1 == name_size2 && \
109
 
        (memcmp((const char *)name1, (const char *)name2, name_size1) == 0))
 
108
        (memcmp((const char *)name1, (const char *)name2, name_size1) == 0))
110
109
 
111
110
/*
112
111
 * Define a structure for holding our client specific data.  In our demo,
136
135
     */
137
136
    int color_index[GS_CLIENT_COLOR_MAX_COMPONENTS];
138
137
    gs_imager_state *CIEtoXYZ_pis;      /* Used to map CIE spaces to XYZ */
139
 
                                        /* refer to gx_cie_to_xyz_alloc  */
 
138
                                        /* refer to gx_cie_to_xyz_alloc  */
140
139
} demo_color_space_data_t;
141
140
 
142
141
gs_private_st_ptrs1(st_demo_color_space_data, demo_color_space_data_t,
143
 
            "demo_color_space_data_t", demo_color_space_enum_ptrs,
144
 
            demo_color_space_reloc_ptrs, CIEtoXYZ_pis);
 
142
            "demo_color_space_data_t", demo_color_space_enum_ptrs,
 
143
            demo_color_space_reloc_ptrs, CIEtoXYZ_pis);
145
144
 
146
145
/*
147
146
 * Dummy install routine for color spaces which are not handled by the client.
148
147
 */
149
148
static bool
150
149
client_install_no_op(client_custom_color_params_t * pparams,
151
 
            gs_color_space * pcs, gs_state * pgs)
 
150
            gs_color_space * pcs, gs_state * pgs)
152
151
{
153
152
    return false;       /* Do nothing */
154
153
}
161
160
client_adjust_cspace_count(const gs_color_space * pcs, int delta)
162
161
{
163
162
    demo_color_space_data_t * pdata =
164
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
163
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
165
164
 
166
165
    pdata->ref_count += delta;
167
166
    if (pdata->ref_count <= 0) {
168
 
        /* Free up the CIE to XYZ imager state if it was allocated */
169
 
        if (pdata->CIEtoXYZ_pis) {
170
 
            gx_cie_to_xyz_free(pdata->CIEtoXYZ_pis);
171
 
        }
172
 
        gs_free_object(pdata->memory, pdata, "client_adjust_cspace_count(pdata)");
 
167
        /* Free up the CIE to XYZ imager state if it was allocated */
 
168
        if (pdata->CIEtoXYZ_pis) {
 
169
            gx_cie_to_xyz_free(pdata->CIEtoXYZ_pis);
 
170
        }
 
171
        gs_free_object(pdata->memory, pdata, "client_adjust_cspace_count(pdata)");
173
172
    }
174
173
}
175
174
 
191
190
     * See client_adjust_cspace_count.
192
191
     */
193
192
    demo_color_space_data_t * pdata =
194
 
        (demo_color_space_data_t *)gs_alloc_struct(mem, demo_color_space_data_t,
195
 
                        &st_demo_color_space_data, "allocate_client_data_block(pdata)");
 
193
        (demo_color_space_data_t *)gs_alloc_struct(mem, demo_color_space_data_t,
 
194
                        &st_demo_color_space_data, "allocate_client_data_block(pdata)");
196
195
 
197
196
    if (pdata != NULL) {
198
 
        memset(pdata, 0, sizeof(demo_color_space_data_t));
199
 
        /*
200
 
         * All client color space data blocks must have a pointer to a
201
 
         * reference count adjust routine as their first field.
202
 
         */
203
 
        pdata->client_adjust_cspace_count = client_adjust_cspace_count;
204
 
        pdata->ref_count = 1;
205
 
        pdata->memory = mem;
 
197
        memset(pdata, 0, sizeof(demo_color_space_data_t));
 
198
        /*
 
199
         * All client color space data blocks must have a pointer to a
 
200
         * reference count adjust routine as their first field.
 
201
         */
 
202
        pdata->client_adjust_cspace_count = client_adjust_cspace_count;
 
203
        pdata->ref_count = 1;
 
204
        pdata->memory = mem;
206
205
    }
207
206
 
208
207
    return pdata;
210
209
 
211
210
static bool
212
211
client_install_generic(client_custom_color_params_t * pparams,
213
 
            gs_color_space * pcs, gs_state * pgs)
 
212
            gs_color_space * pcs, gs_state * pgs)
214
213
{
215
 
        demo_color_space_data_t * pclient_data;
216
 
 
217
 
        /* Exit if we have already installed this color space. */
218
 
        if (pcs->pclient_color_space_data != NULL)
219
 
                return true;
220
 
 
221
 
        pclient_data = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
222
 
        pcs->pclient_color_space_data = (client_color_space_data_t *) pclient_data;
223
 
        if (pclient_data)
224
 
        {
225
 
                pclient_data->client_is_going_to_handle_color_space = 1;
226
 
                return true;
227
 
        }
228
 
        return false;
 
214
        demo_color_space_data_t * pclient_data;
 
215
 
 
216
        /* Exit if we have already installed this color space. */
 
217
        if (pcs->pclient_color_space_data != NULL)
 
218
                return true;
 
219
 
 
220
        pclient_data = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
 
221
        pcs->pclient_color_space_data = (client_color_space_data_t *) pclient_data;
 
222
        if (pclient_data)
 
223
        {
 
224
                pclient_data->client_is_going_to_handle_color_space = 1;
 
225
                return true;
 
226
        }
 
227
        return false;
229
228
}
230
229
 
231
230
/*
234
233
 */
235
234
static bool
236
235
client_pantone_install_Separation(client_custom_color_params_t * pparam,
237
 
                        gs_color_space * pcs, gs_state * pgs)
 
236
                        gs_color_space * pcs, gs_state * pgs)
238
237
{
239
238
    const gs_separation_name name = pcs->params.separation.sep_name;
240
239
    int pan_index;
246
245
 
247
246
    /* Exit if we have already installed this color space. */
248
247
    if (pcs->pclient_color_space_data != NULL)
249
 
                return true;
 
248
                return true;
250
249
 
251
250
    /*
252
251
     * Get the character string and length for the component name.
253
252
     */
254
253
    pcs->params.separation.get_colorname_string(dev->memory, name,
255
 
                                                &pname, &name_size);
 
254
                                                &pname, &name_size);
256
255
    /*
257
256
    * Compare the colorant name to those in our PANTONE color list.
258
257
    */
259
258
    for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
260
 
        const char * pan_name = pantone_list[pan_index].name;
 
259
        const char * pan_name = pantone_list[pan_index].name;
261
260
 
262
 
        if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
263
 
            use_custom_color_callback = true;
264
 
            break;
265
 
        }
 
261
        if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
 
262
            use_custom_color_callback = true;
 
263
            break;
 
264
        }
266
265
    }
267
266
 
268
267
    if (use_custom_color_callback) {
269
268
        demo_color_space_data_t * pclient_data =
270
 
                allocate_client_data_block(1, pcs->rc.memory->stable_memory);
 
269
                allocate_client_data_block(1, pcs->rc.memory->stable_memory);
271
270
 
272
 
        if (pclient_data == NULL)
273
 
                return false;
274
 
        pclient_data->color_index[0] = pan_index;
 
271
        if (pclient_data == NULL)
 
272
                return false;
 
273
        pclient_data->color_index[0] = pan_index;
275
274
        pcs->pclient_color_space_data =
276
 
               (client_color_space_data_t *) pclient_data;
 
275
               (client_color_space_data_t *) pclient_data;
277
276
    }
278
277
    return use_custom_color_callback;
279
278
}
284
283
 */
285
284
static bool
286
285
client_pantone_install_DeviceN(client_custom_color_params_t * pparam,
287
 
                        gs_color_space * pcs, gs_state * pgs)
 
286
                        gs_color_space * pcs, gs_state * pgs)
288
287
{
289
288
    const gs_separation_name *names = pcs->params.device_n.names;
290
289
    int num_comp = pcs->params.device_n.num_components;
311
310
 
312
311
    /* Exit if we have already installed this color space. */
313
312
    if (pcs->pclient_color_space_data != NULL)
314
 
                return true;
 
313
                return true;
315
314
 
316
315
    /*
317
316
     * Now check the names of the color components.
318
317
     */
319
318
    for(i = 0; i < num_comp; i++ ) {
320
 
        bool match = false;
 
319
        bool match = false;
321
320
 
322
 
        /*
323
 
         * Get the character string and length for the component name.
324
 
         */
325
 
        pcs->params.device_n.get_colorname_string(dev->memory, names[i],
326
 
                                                        &pname, &name_size);
327
 
        /*
 
321
        /*
 
322
         * Get the character string and length for the component name.
 
323
         */
 
324
        pcs->params.device_n.get_colorname_string(dev->memory, names[i],
 
325
                                                        &pname, &name_size);
 
326
        /*
328
327
         * Postscript does not include /None as a color component but it is
329
328
         * allowed in PDF so we accept it.  We simply skip components named
330
 
         * 'None'.
331
 
         */
332
 
        if (compare_names(none_str, none_size, pname, name_size)) {
333
 
            pantone_color_index[i] = PANTONE_NONE;
334
 
            continue;
335
 
        }
336
 
        /*
337
 
         * Check if our color space includes the CMYK process colors.
338
 
         */
339
 
        if (compare_names(cyan_str, cyan_size, pname, name_size)) {
340
 
            pantone_color_index[i] = PANTONE_CYAN;
341
 
            continue;
342
 
        }
343
 
        if (compare_names(magenta_str, magenta_size, pname, name_size)) {
344
 
            pantone_color_index[i] = PANTONE_MAGENTA;
345
 
            continue;
346
 
        }
347
 
        if (compare_names(yellow_str, yellow_size, pname, name_size)) {
348
 
            pantone_color_index[i] = PANTONE_YELLOW;
349
 
            continue;
350
 
        }
351
 
        if (compare_names(black_str, black_size, pname, name_size)) {
352
 
            pantone_color_index[i] = PANTONE_BLACK;
353
 
            continue;
354
 
        }
355
 
        /*
356
 
         * Compare the colorant name to those in our Pantone color list.
357
 
         */
358
 
        for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
359
 
            const char * pan_name = pantone_list[pan_index].name;
 
329
         * 'None'.
 
330
         */
 
331
        if (compare_names(none_str, none_size, pname, name_size)) {
 
332
            pantone_color_index[i] = PANTONE_NONE;
 
333
            continue;
 
334
        }
 
335
        /*
 
336
         * Check if our color space includes the CMYK process colors.
 
337
         */
 
338
        if (compare_names(cyan_str, cyan_size, pname, name_size)) {
 
339
            pantone_color_index[i] = PANTONE_CYAN;
 
340
            continue;
 
341
        }
 
342
        if (compare_names(magenta_str, magenta_size, pname, name_size)) {
 
343
            pantone_color_index[i] = PANTONE_MAGENTA;
 
344
            continue;
 
345
        }
 
346
        if (compare_names(yellow_str, yellow_size, pname, name_size)) {
 
347
            pantone_color_index[i] = PANTONE_YELLOW;
 
348
            continue;
 
349
        }
 
350
        if (compare_names(black_str, black_size, pname, name_size)) {
 
351
            pantone_color_index[i] = PANTONE_BLACK;
 
352
            continue;
 
353
        }
 
354
        /*
 
355
         * Compare the colorant name to those in our Pantone color list.
 
356
         */
 
357
        for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
 
358
            const char * pan_name = pantone_list[pan_index].name;
360
359
 
361
 
            if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
362
 
                pantone_color_index[i] = pan_index;
363
 
                match = pantone_found = true;
364
 
                break;
365
 
            }
366
 
        }
367
 
        if (!match) {           /* Exit if we find a non Pantone color */
368
 
            other_separation_found = true;
369
 
            break;
370
 
        }
 
360
            if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
 
361
                pantone_color_index[i] = pan_index;
 
362
                match = pantone_found = true;
 
363
                break;
 
364
            }
 
365
        }
 
366
        if (!match) {           /* Exit if we find a non Pantone color */
 
367
            other_separation_found = true;
 
368
            break;
 
369
        }
371
370
    }
372
371
    /*
373
372
     * Handle this color space as a 'pantone color space' if we have only
377
376
    use_pantone = pantone_found && !other_separation_found;
378
377
    if (use_pantone) {
379
378
        demo_color_space_data_t * pclient_data =
380
 
                allocate_client_data_block(1, pcs->rc.memory->stable_memory);
 
379
                allocate_client_data_block(1, pcs->rc.memory->stable_memory);
381
380
 
382
381
        if (pclient_data == NULL)
383
 
            return false;
 
382
            return false;
384
383
        for(i = 0; i < num_comp; i++ )
385
 
            pclient_data->color_index[i] = pantone_color_index[i];
 
384
            pclient_data->color_index[i] = pantone_color_index[i];
386
385
        pcs->pclient_color_space_data =
387
 
               (client_color_space_data_t *) pclient_data;
 
386
               (client_color_space_data_t *) pclient_data;
388
387
    }
389
388
    return use_pantone;
390
389
}
391
390
 
392
 
 
393
391
/*
394
392
 * Convert a set of color values in a 'PANTONE color space' into a device
395
393
 * color values.
405
403
 */
406
404
static int
407
405
client_pantone_remap_color(client_custom_color_params_t * pparam,
408
 
        const frac * pconc, const demo_color_space_data_t * pparams,
409
 
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
410
 
        gs_color_select_t select, int num_comp)
 
406
        const frac * pconc, const demo_color_space_data_t * pparams,
 
407
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
 
408
        gs_color_select_t select, int num_comp)
411
409
{
412
410
    int i, pantone_index, cvalue;
413
411
    int cyan = 0;
423
421
     * its normal color space processing.
424
422
     */
425
423
    if (pparams == NULL)
426
 
        return_error(gs_error_rangecheck);
 
424
        return_error(gs_error_rangecheck);
427
425
 
428
426
    /*
429
427
     * Create a CMYK representation of the various colors in our color space.
432
430
     * left to the user.
433
431
     */
434
432
    for (i = 0; i < num_comp; i++) {
435
 
        cvalue = pconc[i];
436
 
        pantone_index = pparams->color_index[i];
437
 
        switch (pantone_index) {
438
 
            case PANTONE_NONE:
439
 
                break;
440
 
            case PANTONE_CYAN:
441
 
                cyan += cvalue;
442
 
                break;
443
 
            case PANTONE_MAGENTA:
444
 
                magenta += cvalue;
445
 
                break;
446
 
            case PANTONE_YELLOW:
447
 
                yellow += cvalue;
448
 
                break;
449
 
            case PANTONE_BLACK:
450
 
                black += cvalue;
451
 
                break;
452
 
            default:
453
 
                plist = &(pantone_list[pantone_index]);
454
 
                cyan += (int) floor(cvalue * plist->c);
455
 
                magenta += (int) floor(cvalue * plist->m);
456
 
                yellow += (int) floor(cvalue * plist->y);
457
 
                black += (int) floor(cvalue * plist->k);
458
 
                break;
459
 
        }
 
433
        cvalue = pconc[i];
 
434
        pantone_index = pparams->color_index[i];
 
435
        switch (pantone_index) {
 
436
            case PANTONE_NONE:
 
437
                break;
 
438
            case PANTONE_CYAN:
 
439
                cyan += cvalue;
 
440
                break;
 
441
            case PANTONE_MAGENTA:
 
442
                magenta += cvalue;
 
443
                break;
 
444
            case PANTONE_YELLOW:
 
445
                yellow += cvalue;
 
446
                break;
 
447
            case PANTONE_BLACK:
 
448
                black += cvalue;
 
449
                break;
 
450
            default:
 
451
                plist = &(pantone_list[pantone_index]);
 
452
                cyan += (int) floor(cvalue * plist->c);
 
453
                magenta += (int) floor(cvalue * plist->m);
 
454
                yellow += (int) floor(cvalue * plist->y);
 
455
                black += (int) floor(cvalue * plist->k);
 
456
                break;
 
457
        }
460
458
    }
461
459
    /* Clamp our color values */
462
460
    cc = (cyan > frac_1) ? frac_1 : (cyan < frac_0) ? frac_0 : cyan;
472
470
 */
473
471
static int
474
472
client_pantone_remap_Separation(client_custom_color_params_t * pparam,
475
 
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
476
 
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
 
473
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
 
474
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
477
475
{
478
476
    return client_pantone_remap_color(pparam, pconc,
479
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data),
480
 
        pdc, pis, dev, select, 1);
 
477
        (demo_color_space_data_t *)(pcs->pclient_color_space_data),
 
478
        pdc, pis, dev, select, 1);
481
479
}
482
480
 
483
481
/*
485
483
 */
486
484
static int
487
485
client_pantone_remap_DeviceN(client_custom_color_params_t * pparam,
488
 
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
489
 
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
 
486
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
 
487
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
490
488
{
491
 
        return client_pantone_remap_color(pparam, pconc,
492
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data),
493
 
        pdc, pis, dev, select, gs_color_space_num_components(pcs));
 
489
        return client_pantone_remap_color(pparam, pconc,
 
490
        (demo_color_space_data_t *)(pcs->pclient_color_space_data),
 
491
        pdc, pis, dev, select, gs_color_space_num_components(pcs));
494
492
}
495
493
 
496
 
 
497
494
#if !PANTONE_ONLY
498
495
 
499
496
/*
501
498
 */
502
499
static bool
503
500
client_install_DeviceGray(client_custom_color_params_t * pparams,
504
 
            gs_color_space * pcs, gs_state * pgs)
 
501
            gs_color_space * pcs, gs_state * pgs)
505
502
{
506
503
    /* Nothing to do in our demo */
507
504
    return true;
513
510
 */
514
511
static int
515
512
convert_intensity_into_device_color(const frac intensity,
516
 
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
517
 
        gs_color_select_t select)
 
513
        gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
 
514
        gs_color_select_t select)
518
515
{
519
516
    frac cc, cm, cy, ck;
520
517
 
521
 
    switch (pis->object_tag) {
522
 
        case GS_TEXT_TAG:               /* Make text red. */
523
 
                cc = ck = 0;
524
 
                cm = cy = frac_1 - intensity;
525
 
                break;
526
 
        case GS_IMAGE_TAG:              /* Make images green. */
527
 
                cm = ck = 0;
528
 
                cc = cy = frac_1 - intensity;
529
 
                break;
530
 
        case GS_PATH_TAG:               /* Make lines and fills blue. */
531
 
        default:
532
 
                cy = ck = 0;
533
 
                cc = cm = frac_1 - intensity;
534
 
                break;
 
518
    switch (dev->graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS) {
 
519
        case GS_TEXT_TAG:               /* Make text red. */
 
520
                cc = ck = 0;
 
521
                cm = cy = frac_1 - intensity;
 
522
                break;
 
523
        case GS_IMAGE_TAG:              /* Make images green. */
 
524
                cm = ck = 0;
 
525
                cc = cy = frac_1 - intensity;
 
526
                break;
 
527
        case GS_PATH_TAG:               /* Make lines and fills blue. */
 
528
        default:
 
529
                cy = ck = 0;
 
530
                cc = cm = frac_1 - intensity;
 
531
                break;
535
532
    }
536
533
 
537
534
    /* Send CMYK colors to the device */
548
545
    const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
549
546
{
550
547
 
551
 
        #if OBJECT_TYPE_EXAMPLE
552
 
 
553
 
                 /* For demo and debug purposes, make our colors a function of the
554
 
                 * intensity of the given colors and the object type. */
555
 
 
556
 
                frac intensity = pconc[0];
557
 
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select); 
558
 
 
559
 
        #else
560
 
 
561
 
                /* If desired, replace with your own color transformation */
562
 
 
563
 
                gx_remap_concrete_gray(pconc[0], pdc, pis, dev, select);
564
 
 
565
 
        #endif
566
 
 
 
548
        #if OBJECT_TYPE_EXAMPLE
 
549
 
 
550
                 /* For demo and debug purposes, make our colors a function of the
 
551
                 * intensity of the given colors and the object type. */
 
552
 
 
553
                frac intensity = pconc[0];
 
554
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
 
555
 
 
556
        #else
 
557
 
 
558
                /* If desired, replace with your own color transformation */
 
559
 
 
560
                gx_remap_concrete_gray(pconc[0], pdc, pis, dev, select);
 
561
 
 
562
        #endif
567
563
 
568
564
    return 0;
569
565
}
573
569
 */
574
570
static bool
575
571
client_install_DeviceRGB(client_custom_color_params_t * pparams,
576
 
            gs_color_space * pcs, gs_state * pgs)
 
572
            gs_color_space * pcs, gs_state * pgs)
577
573
{
578
574
    /* Nothing to do in our demo */
579
575
    dlprintf1("client_install_DeviceRGB ri = %d\n", pgs->renderingintent);
585
581
 */
586
582
static int
587
583
client_remap_DeviceRGB(client_custom_color_params_t * pparams,
588
 
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
589
 
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
 
584
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
 
585
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
590
586
{
591
587
 
592
 
        #if OBJECT_TYPE_EXAMPLE
593
 
 
594
 
                /* For demo and debug purposes, make our colors a function of the
595
 
                 * intensity of the given colors and the object type. */
596
 
 
597
 
                frac intensity = (frac)(pconc[0] * 0.30 + pconc[1] * 0.59 + pconc[2] * 0.11);
598
 
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
599
 
 
600
 
        #else
601
 
 
602
 
                 /* If desired, replace with your own color transformation */
603
 
 
604
 
                 gx_remap_concrete_rgb(pconc[0], pconc[1], pconc[2], pdc, pis, dev, select);
605
 
 
606
 
        #endif
 
588
        #if OBJECT_TYPE_EXAMPLE
 
589
 
 
590
                /* For demo and debug purposes, make our colors a function of the
 
591
                 * intensity of the given colors and the object type. */
 
592
 
 
593
                frac intensity = (frac)(pconc[0] * 0.30 + pconc[1] * 0.59 + pconc[2] * 0.11);
 
594
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
 
595
 
 
596
        #else
 
597
 
 
598
                 /* If desired, replace with your own color transformation */
 
599
 
 
600
                 gx_remap_concrete_rgb(pconc[0], pconc[1], pconc[2], pdc, pis, dev, select);
 
601
 
 
602
        #endif
607
603
 
608
604
    return 0;
609
605
}
613
609
 */
614
610
static bool
615
611
client_install_DeviceCMYK(client_custom_color_params_t * pparams,
616
 
            gs_color_space * pcs, gs_state * pgs)
 
612
            gs_color_space * pcs, gs_state * pgs)
617
613
{
618
614
    /* Nothing to do in our demo */
619
615
    return true;
624
620
 */
625
621
static int
626
622
client_remap_DeviceCMYK(client_custom_color_params_t * pparams,
627
 
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
628
 
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
 
623
        const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
 
624
        const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
629
625
{
630
626
 
631
 
        #if OBJECT_TYPE_EXAMPLE
632
 
 
633
 
           /*
634
 
                 * For demo and debug purposes, make our colors a function of the
635
 
                 * intensity of the given colors and the object type.  */
636
 
 
637
 
                frac intensity = frac_1 - (frac)(pconc[0] * 0.30 + pconc[1] * 0.59
638
 
                                + pconc[2] * 0.11 + pconc[3]);
639
 
 
640
 
                if (intensity < frac_0)
641
 
                intensity = frac_0;
642
 
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select);          
643
 
 
644
 
        #else
645
 
 
646
 
                 /* If desired, replace with your own color transformation */
647
 
                 gx_remap_concrete_cmyk(pconc[0], pconc[1], pconc[2], pconc[3],pdc, pis, dev, select);
648
 
 
649
 
        #endif
 
627
        #if OBJECT_TYPE_EXAMPLE
 
628
 
 
629
           /*
 
630
                 * For demo and debug purposes, make our colors a function of the
 
631
                 * intensity of the given colors and the object type.  */
 
632
 
 
633
                frac intensity = frac_1 - (frac)(pconc[0] * 0.30 + pconc[1] * 0.59
 
634
                                + pconc[2] * 0.11 + pconc[3]);
 
635
 
 
636
                if (intensity < frac_0)
 
637
                intensity = frac_0;
 
638
                convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
 
639
 
 
640
        #else
 
641
 
 
642
                 /* If desired, replace with your own color transformation */
 
643
                 gx_remap_concrete_cmyk(pconc[0], pconc[1], pconc[2], pconc[3],pdc, pis, dev, select);
 
644
 
 
645
        #endif
650
646
 
651
647
    return 0;
652
648
}
656
652
 * given a specified floating point range.
657
653
 */
658
654
#define convert2frac(color, range) \
659
 
        (color <= range.rmin) ? frac_0 \
660
 
            : (color >= range.rmax)  ? frac_1 \
661
 
                : (frac) (frac_1 * \
662
 
                        (color - range.rmin) / (range.rmax - range.rmin))
 
655
        (color <= range.rmin) ? frac_0 \
 
656
            : (color >= range.rmax)  ? frac_1 \
 
657
                : (frac) (frac_1 * \
 
658
                        (color - range.rmin) / (range.rmax - range.rmin))
663
659
 
664
660
static bool
665
661
client_install_CIEtoA(client_custom_color_params_t * pparams,
666
 
            gs_color_space * pcs, gs_state * pgs)
 
662
            gs_color_space * pcs, gs_state * pgs)
667
663
{
668
664
    /* get ready for converting to XYZ */
669
665
    demo_color_space_data_t * pdata;
670
666
 
671
667
    /* Exit if we have already installed this color space. */
672
668
    if (pcs->pclient_color_space_data != NULL)
673
 
        return true;
 
669
        return true;
674
670
 
675
671
    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
676
672
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
677
673
    if (pdata)
678
674
    {
679
 
        int code;
680
 
        gs_cie_a *pcie = pcs->params.a;
681
 
        gs_sample_loop_params_t lp;
682
 
        int i;
683
 
 
684
 
        pdata->client_is_going_to_handle_color_space = 1;
685
 
 
686
 
        /* Fill the caches we need in the CIE color space */
687
 
        gs_cie_cache_init(&pcie->caches.DecodeA.floats.params, &lp,
688
 
                          &pcie->RangeA, "DecodeA");
689
 
        for (i = 0; i <= lp.N; ++i) {
690
 
            float in = SAMPLE_LOOP_VALUE(i, lp);
691
 
 
692
 
            pcie->caches.DecodeA.floats.values[i] = (*pcie->DecodeA)(in, pcie);
693
 
        }
694
 
        gx_cie_load_common_cache(&pcie->common, pgs);
695
 
        gs_cie_a_complete(pcie);
696
 
        if ((code=gs_cie_cs_complete(pgs, true)) >= 0) {
697
 
            /* Now allocate the conversion imager state in stable_memory */
698
 
            /* so that the garbage collector won't free it               */
699
 
            code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
700
 
                                        pcs->rc.memory->stable_memory);
701
 
        }
702
 
        if (code < 0) {
703
 
            client_adjust_cspace_count(pcs, -1);  /* free it up */
704
 
            return false;
705
 
        }
 
675
        int code;
 
676
        gs_cie_a *pcie = pcs->params.a;
 
677
        gs_sample_loop_params_t lp;
 
678
        int i;
 
679
 
 
680
        pdata->client_is_going_to_handle_color_space = 1;
 
681
 
 
682
        /* Fill the caches we need in the CIE color space */
 
683
        gs_cie_cache_init(&pcie->caches.DecodeA.floats.params, &lp,
 
684
                          &pcie->RangeA, "DecodeA");
 
685
        for (i = 0; i <= lp.N; ++i) {
 
686
            float in = SAMPLE_LOOP_VALUE(i, lp);
 
687
 
 
688
            pcie->caches.DecodeA.floats.values[i] = (*pcie->DecodeA)(in, pcie);
 
689
        }
 
690
        gx_cie_load_common_cache(&pcie->common, pgs);
 
691
        gs_cie_a_complete(pcie);
 
692
        if ((code=gs_cie_cs_complete(pgs, true)) >= 0) {
 
693
            /* Now allocate the conversion imager state in stable_memory */
 
694
            /* so that the garbage collector won't free it               */
 
695
            code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
 
696
                                        pcs->rc.memory->stable_memory);
 
697
        }
 
698
        if (code < 0) {
 
699
            client_adjust_cspace_count(pcs, -1);  /* free it up */
 
700
            return false;
 
701
        }
706
702
    }
707
703
    return true;
708
704
}
709
705
 
710
706
static bool
711
707
client_install_CIEtoXYZ(client_custom_color_params_t * pparams,
712
 
            gs_color_space * pcs, gs_state * pgs)
 
708
            gs_color_space * pcs, gs_state * pgs)
713
709
{
714
710
    /* get ready for converting to XYZ */
715
711
    demo_color_space_data_t * pdata;
716
712
 
717
713
    /* Exit if we have already installed this color space. */
718
714
    if (pcs->pclient_color_space_data != NULL)
719
 
        return true;
 
715
        return true;
720
716
 
721
717
    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
722
718
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
723
719
    if (pdata)
724
720
    {
725
 
        int code;
726
 
        const gs_cie_abc *pcie;
 
721
        int code;
 
722
        const gs_cie_abc *pcie;
727
723
 
728
 
        pdata->client_is_going_to_handle_color_space = 1;
 
724
        pdata->client_is_going_to_handle_color_space = 1;
729
725
        switch (pcs->type->index) {
730
 
          case gs_color_space_index_CIEDEF: {
731
 
            gs_cie_def *pcie_def = pcs->params.def;
732
 
 
733
 
            pcie = (gs_cie_abc *)pcie_def;
734
 
            CIE_LOAD_CACHE_BODY(pcie_def->caches_def.DecodeDEF, pcie_def->RangeDEF.ranges,
735
 
                            &pcie_def->DecodeDEF, DecodeDEF_default, pcie_def,
736
 
                            "DecodeDEF");
737
 
            break;
738
 
          }
739
 
          case gs_color_space_index_CIEDEFG: {
740
 
            gs_cie_defg *pcie_defg = pcs->params.defg;
741
 
 
742
 
            pcie = (gs_cie_abc *)pcie_defg;
743
 
            CIE_LOAD_CACHE_BODY(pcie_defg->caches_defg.DecodeDEFG, pcie_defg->RangeDEFG.ranges,
744
 
                            &pcie_defg->DecodeDEFG, DecodeDEFG_default, pcie_defg,
745
 
                            "DecodeDEFG");
746
 
            break;
747
 
          }
748
 
          case gs_color_space_index_CIEABC: {
749
 
            pcie = pcs->params.abc;
750
 
            break;
751
 
          }
752
 
          default:
753
 
            /* can't happen since we only come here for certain color spaces */
754
 
            return false;
755
 
        }
756
 
        /* Fill the caches we need in the CIE color space */
 
726
          case gs_color_space_index_CIEDEF: {
 
727
            gs_cie_def *pcie_def = pcs->params.def;
 
728
 
 
729
            pcie = (gs_cie_abc *)pcie_def;
 
730
            CIE_LOAD_CACHE_BODY(pcie_def->caches_def.DecodeDEF, pcie_def->RangeDEF.ranges,
 
731
                            &pcie_def->DecodeDEF, DecodeDEF_default, pcie_def,
 
732
                            "DecodeDEF");
 
733
            break;
 
734
          }
 
735
          case gs_color_space_index_CIEDEFG: {
 
736
            gs_cie_defg *pcie_defg = pcs->params.defg;
 
737
 
 
738
            pcie = (gs_cie_abc *)pcie_defg;
 
739
            CIE_LOAD_CACHE_BODY(pcie_defg->caches_defg.DecodeDEFG, pcie_defg->RangeDEFG.ranges,
 
740
                            &pcie_defg->DecodeDEFG, DecodeDEFG_default, pcie_defg,
 
741
                            "DecodeDEFG");
 
742
            break;
 
743
          }
 
744
          case gs_color_space_index_CIEABC: {
 
745
            pcie = pcs->params.abc;
 
746
            break;
 
747
          }
 
748
          default:
 
749
            /* can't happen since we only come here for certain color spaces */
 
750
            return false;
 
751
        }
 
752
        /* Fill the caches we need in the CIE color space */
757
753
        if ((code=gx_install_cie_abc((gs_cie_abc *)pcie, pgs)) >= 0) {
758
 
            /* Now allocate the conversion imager state in stable_memory */
759
 
            /* so that the garbage collector won't free it               */
760
 
            code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
761
 
                                    pcs->rc.memory->stable_memory);
762
 
        }
763
 
        if (code < 0) {
764
 
            client_adjust_cspace_count(pcs, -1);  /* free it up */
765
 
            return false;
766
 
        }
 
754
            /* Now allocate the conversion imager state in stable_memory */
 
755
            /* so that the garbage collector won't free it               */
 
756
            code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
 
757
                                    pcs->rc.memory->stable_memory);
 
758
        }
 
759
        if (code < 0) {
 
760
            client_adjust_cspace_count(pcs, -1);  /* free it up */
 
761
            return false;
 
762
        }
767
763
    }
768
764
    return true;
769
765
}
770
766
 
771
 
 
772
767
static bool
773
768
client_install_ICCtoXYZ(client_custom_color_params_t * pparams,
774
 
            gs_color_space * pcs, gs_state * pgs)
 
769
            gs_color_space * pcs, gs_state * pgs)
775
770
{
776
771
    int code;
777
772
    const gs_icc_params * picc_params = (const gs_icc_params *)&pcs->params.icc;
779
774
    demo_color_space_data_t * pdata;
780
775
 
781
776
    if (pcs->pclient_color_space_data != NULL)
782
 
        return true;
 
777
        return true;
783
778
 
784
779
    pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
785
780
    pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
786
781
 
787
 
        /* Need to initialize the client data.  The imager_state is what is needed in pdata->CIEtoXZY_ps */
 
782
        /* Need to initialize the client data.  The imager_state is what is needed in pdata->CIEtoXZY_ps */
788
783
 
789
784
    /* update the stub information used by the joint caches  */
790
785
    gx_cie_load_common_cache(&picc_info->common, pgs);
791
786
    gx_cie_common_complete(&picc_info->common);
792
787
 
793
788
    if ((code=gs_cie_cs_complete(pgs, true)) < 0) {
794
 
        client_adjust_cspace_count(pcs, -1);  /* free it up  */
795
 
        return false;
 
789
        client_adjust_cspace_count(pcs, -1);  /* free it up  */
 
790
        return false;
796
791
    }
797
792
 
798
 
        /* Now allocate the conversion imager state in stable_memory    */
799
 
        /* so that the garbage collector won't free it                  */
800
 
        code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
801
 
                                pcs->rc.memory->stable_memory);
 
793
        /* Now allocate the conversion imager state in stable_memory    */
 
794
        /* so that the garbage collector won't free it                  */
 
795
        code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
 
796
                                pcs->rc.memory->stable_memory);
802
797
 
803
 
        if (code < 0) {
804
 
            client_adjust_cspace_count(pcs, -1);  /* free it up */
805
 
            return false;
806
 
        }
 
798
        if (code < 0) {
 
799
            client_adjust_cspace_count(pcs, -1);  /* free it up */
 
800
            return false;
 
801
        }
807
802
 
808
803
    return true;
809
804
}
810
805
 
811
 
 
812
806
/*
813
807
 * Convert a CIEBasedA color into device color.
814
808
 */
819
813
    gs_color_select_t select)
820
814
{
821
815
    demo_color_space_data_t * pdata =
822
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
816
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
823
817
    frac gray = convert2frac(pc->paint.values[0], pcs->params.a->RangeA);
824
818
 
825
819
    /*** Demonstrate method to convert to XYZ ***/
826
820
    if (pdata->CIEtoXYZ_pis) {
827
 
        frac xyz[3];
 
821
        frac xyz[3];
828
822
 
829
 
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
830
 
        /* We don't really do anything with these values, but this */
831
 
        /* is where a real client could convert to a device color  */
832
 
        if_debug4('|', "[c]client_remap CIEA [%g] -> XYZ [%g, %g, %g]\n",
833
 
                  pc->paint.values[0],
834
 
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
 
823
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
 
824
        /* We don't really do anything with these values, but this */
 
825
        /* is where a real client could convert to a device color  */
 
826
        if_debug4('|', "[c]client_remap CIEA [%g] -> XYZ [%g, %g, %g]\n",
 
827
                  pc->paint.values[0],
 
828
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
835
829
 
836
830
    }
837
831
    /*
851
845
    gs_color_select_t select)
852
846
{
853
847
    demo_color_space_data_t * pdata =
854
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
848
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
855
849
    frac rgb[3];
856
850
    int i;
857
851
 
858
852
    /*** Demonstrate method to convert to XYZ ***/
859
853
    if (pdata->CIEtoXYZ_pis) {
860
 
        frac xyz[3];
 
854
        frac xyz[3];
861
855
 
862
 
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
863
 
        /* We don't really do anything with these values, but this */
864
 
        /* is where a real client could convert to a device color  */
865
 
        if_debug6('|', "[c]client_remap CIEABC [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
866
 
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
867
 
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
 
856
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
 
857
        /* We don't really do anything with these values, but this */
 
858
        /* is where a real client could convert to a device color  */
 
859
        if_debug6('|', "[c]client_remap CIEABC [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
 
860
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
 
861
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
868
862
    }
869
863
    /*
870
864
     * For demo and debug purposes, make our colors a function of the
873
867
     * that they are RGB values.
874
868
     */
875
869
    for (i = 0; i < 3; i++)
876
 
        rgb[i] = convert2frac(pc->paint.values[i],
877
 
                        pcs->params.abc->RangeABC.ranges[i]);
 
870
        rgb[i] = convert2frac(pc->paint.values[i],
 
871
                        pcs->params.abc->RangeABC.ranges[i]);
878
872
    return client_remap_DeviceRGB(pparams, rgb, pcs, pdc, pis, dev, select);
879
873
}
880
874
 
888
882
    gs_color_select_t select)
889
883
{
890
884
    demo_color_space_data_t * pdata =
891
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
885
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
892
886
    frac rgb[3];
893
887
    int i;
894
888
 
895
889
    /*** Demonstrate method to convert to XYZ ***/
896
890
    if (pdata->CIEtoXYZ_pis) {
897
 
        frac xyz[3];
 
891
        frac xyz[3];
898
892
 
899
 
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
900
 
        /* We don't really do anything with these values, but this */
901
 
        /* is where a real client could convert to a device color  */
902
 
        if_debug6('|', "[c]client_remap CIEDEF [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
903
 
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
904
 
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
 
893
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
 
894
        /* We don't really do anything with these values, but this */
 
895
        /* is where a real client could convert to a device color  */
 
896
        if_debug6('|', "[c]client_remap CIEDEF [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
 
897
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
 
898
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
905
899
    }
906
900
    /*
907
901
     * For demo and debug purposes, make our colors a function of the
910
904
     * that they are RGB values.
911
905
     */
912
906
    for (i = 0; i < 3; i++)
913
 
        rgb[i] = convert2frac(pc->paint.values[i],
914
 
                        pcs->params.def->RangeDEF.ranges[i]);
 
907
        rgb[i] = convert2frac(pc->paint.values[i],
 
908
                        pcs->params.def->RangeDEF.ranges[i]);
915
909
    return client_remap_DeviceRGB(pparams, rgb, pcs, pdc, pis, dev, select);
916
910
}
917
911
 
925
919
    gs_color_select_t select)
926
920
{
927
921
    demo_color_space_data_t * pdata =
928
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
922
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
929
923
    frac cmyk[4];
930
924
    int i;
931
925
 
932
926
    /*** Demonstrate method to convert to XYZ ***/
933
927
    if (pdata->CIEtoXYZ_pis) {
934
 
        frac xyz[3];
 
928
        frac xyz[3];
935
929
 
936
 
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
937
 
        /* We don't really do anything with these values, but this */
938
 
        /* is where a real client could convert to a device color  */
939
 
        if_debug7('|', "[c]client_remap CIEDEFG [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
940
 
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
941
 
                  pc->paint.values[3],
942
 
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
 
930
        cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
 
931
        /* We don't really do anything with these values, but this */
 
932
        /* is where a real client could convert to a device color  */
 
933
        if_debug7('|', "[c]client_remap CIEDEFG [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
 
934
                  pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
 
935
                  pc->paint.values[3],
 
936
                  frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
943
937
    }
944
938
    /*
945
939
     * For demo and debug purposes, make our colors a function of the
948
942
     * that they are CMYK values.
949
943
     */
950
944
    for (i = 0; i < 4; i++)
951
 
        cmyk[i] = convert2frac(pc->paint.values[i],
952
 
                        pcs->params.defg->RangeDEFG.ranges[i]);
 
945
        cmyk[i] = convert2frac(pc->paint.values[i],
 
946
                        pcs->params.defg->RangeDEFG.ranges[i]);
953
947
    return client_remap_DeviceRGB(pparams, cmyk, pcs, pdc, pis, dev, select);
954
948
}
955
949
 
963
957
    gs_color_select_t select)
964
958
{
965
959
    demo_color_space_data_t * pdata =
966
 
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
 
960
        (demo_color_space_data_t *)(pcs->pclient_color_space_data);
967
961
    frac frac_color[GS_CLIENT_COLOR_MAX_COMPONENTS];
968
962
    int i, num_values = pcs->params.icc.picc_info->num_components;
969
963
 
970
964
    /*** Demonstrate method to convert to XYZ ***/
971
965
    if (pdata->CIEtoXYZ_pis) {
972
966
 
973
 
                frac xyz[3];
 
967
                frac xyz[3];
974
968
 
975
 
                cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
976
 
                /* We don't really do anything with these values, but this */
977
 
                /* is where a real client could convert to a device color  */
978
 
                if_debug6('|', "[c]client_remap ICCBased [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
979
 
                          pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
980
 
                          frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
 
969
                cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
 
970
                /* We don't really do anything with these values, but this */
 
971
                /* is where a real client could convert to a device color  */
 
972
                if_debug6('|', "[c]client_remap ICCBased [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
 
973
                          pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
 
974
                          frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
981
975
    }
982
976
 
983
977
    /*
988
982
     * gray, RGB, or CMYK values.
989
983
     */
990
984
    for (i = 0; i < num_values; i++)
991
 
        frac_color[i] = convert2frac(pc->paint.values[i],
992
 
                        pcs->params.icc.picc_info->Range.ranges[i]);
 
985
        frac_color[i] = convert2frac(pc->paint.values[i],
 
986
                        pcs->params.icc.picc_info->Range.ranges[i]);
993
987
    switch (num_values) {
994
 
        case 0:
995
 
        case 2:
996
 
            return_error(gs_error_rangecheck);
997
 
        case 1:
998
 
            return client_remap_DeviceGray(pparams, frac_color, pcs,
999
 
                                         pdc, pis, dev, select);
1000
 
        case 3:
1001
 
            return client_remap_DeviceRGB(pparams, frac_color, pcs,
1002
 
                                         pdc, pis, dev, select);
1003
 
        case 4:
1004
 
        default:
1005
 
            return client_remap_DeviceCMYK(pparams, frac_color, pcs,
1006
 
                                         pdc, pis, dev, select);
 
988
        case 0:
 
989
        case 2:
 
990
            return_error(gs_error_rangecheck);
 
991
        case 1:
 
992
            return client_remap_DeviceGray(pparams, frac_color, pcs,
 
993
                                         pdc, pis, dev, select);
 
994
        case 3:
 
995
            return client_remap_DeviceRGB(pparams, frac_color, pcs,
 
996
                                         pdc, pis, dev, select);
 
997
        case 4:
 
998
        default:
 
999
            return client_remap_DeviceCMYK(pparams, frac_color, pcs,
 
1000
                                         pdc, pis, dev, select);
1007
1001
    }
1008
1002
}
1009
1003
 
1013
1007
 
1014
1008
#if PANTONE_ONLY
1015
1009
 
1016
 
        /*
1017
 
         * For PANTONE colors, we only need to handle Separation and DeviceN
1018
 
         * color spaces.  These are the only color spaces that can have PANTONE
1019
 
         * colors.
1020
 
         */
1021
 
        client_custom_color_procs_t demo_procs = {
1022
 
                client_install_no_op,           /* DeviceGray */
1023
 
                NULL,
1024
 
                client_install_no_op,           /* DeviceRGB */
1025
 
                NULL,
1026
 
                client_install_no_op,           /* DeviceCMYK */
1027
 
                NULL,
1028
 
                client_pantone_install_Separation,      /* Separation */
1029
 
                client_pantone_remap_Separation,
1030
 
                client_pantone_install_DeviceN, /* DeviceN */
1031
 
                client_pantone_remap_DeviceN,
1032
 
                client_install_no_op,           /* CIEBasedA */
1033
 
                NULL,
1034
 
                client_install_no_op,           /* CIEBasedABC */
1035
 
                NULL,
1036
 
                client_install_no_op,           /* CIEBasedDEF */
1037
 
                NULL,
1038
 
                client_install_no_op,           /* CIEBasedDEFG */
1039
 
                NULL,
1040
 
                client_install_no_op,           /* ICCBased */
1041
 
                NULL
1042
 
        };
 
1010
        /*
 
1011
         * For PANTONE colors, we only need to handle Separation and DeviceN
 
1012
         * color spaces.  These are the only color spaces that can have PANTONE
 
1013
         * colors.
 
1014
         */
 
1015
        client_custom_color_procs_t demo_procs = {
 
1016
                client_install_no_op,           /* DeviceGray */
 
1017
                NULL,
 
1018
                client_install_no_op,           /* DeviceRGB */
 
1019
                NULL,
 
1020
                client_install_no_op,           /* DeviceCMYK */
 
1021
                NULL,
 
1022
                client_pantone_install_Separation,      /* Separation */
 
1023
                client_pantone_remap_Separation,
 
1024
                client_pantone_install_DeviceN, /* DeviceN */
 
1025
                client_pantone_remap_DeviceN,
 
1026
                client_install_no_op,           /* CIEBasedA */
 
1027
                NULL,
 
1028
                client_install_no_op,           /* CIEBasedABC */
 
1029
                NULL,
 
1030
                client_install_no_op,           /* CIEBasedDEF */
 
1031
                NULL,
 
1032
                client_install_no_op,           /* CIEBasedDEFG */
 
1033
                NULL,
 
1034
                client_install_no_op,           /* ICCBased */
 
1035
                NULL
 
1036
        };
1043
1037
 
1044
1038
#else                   /* Not PANTONE_ONLY special */
1045
1039