summaryrefslogtreecommitdiff
path: root/gs/base/gscrdp.c
blob: 15daa608658a549e78872f0cf67a393d88b667bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/* Copyright (C) 2001-2006 Artifex Software, Inc.
   All Rights Reserved.
  
   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
*/

/* $Id$ */
/* CIE color rendering dictionary creation */
#include "math_.h"
#include "memory_.h"
#include "string_.h"
#include "gx.h"
#include "gsdevice.h"
#include "gserrors.h"
#include "gsmatrix.h"		/* for gscolor2.h */
#include "gsstruct.h"
#include "gxcspace.h"
#include "gscolor2.h"		/* for gs_set/currentcolorrendering */
#include "gscrdp.h"
#include "gxarith.h"

/* ---------------- Writing ---------------- */

/* Internal procedures for writing parameter values. */
static void
store_vector3(float *p, const gs_vector3 * pvec)
{
    p[0] = pvec->u, p[1] = pvec->v, p[2] = pvec->w;
}
static int
write_floats(gs_param_list * plist, gs_param_name key,
	     const float *values, int size, gs_memory_t * mem)
{
    float *p = (float *)
	gs_alloc_byte_array(mem, size, sizeof(float), "write_floats");
    gs_param_float_array fa;

    if (p == 0)
	return_error(gs_error_VMerror);
    memcpy(p, values, size * sizeof(float));

    fa.data = p;
    fa.size = size;
    fa.persistent = true;
    return param_write_float_array(plist, key, &fa);
}
static int
write_vector3(gs_param_list * plist, gs_param_name key,
	      const gs_vector3 * pvec, gs_memory_t * mem)
{
    float values[3];

    store_vector3(values, pvec);
    return write_floats(plist, key, values, 3, mem);
}
static int
write_matrix3(gs_param_list * plist, gs_param_name key,
	      const gs_matrix3 * pmat, gs_memory_t * mem)
{
    float values[9];

    if (!memcmp(pmat, &Matrix3_default, sizeof(*pmat)))
	return 0;
    store_vector3(values, &pmat->cu);
    store_vector3(values + 3, &pmat->cv);
    store_vector3(values + 6, &pmat->cw);
    return write_floats(plist, key, values, 9, mem);
}
static int
write_range3(gs_param_list * plist, gs_param_name key,
	     const gs_range3 * prange, gs_memory_t * mem)
{
    float values[6];

    if (!memcmp(prange, &Range3_default, sizeof(*prange)))
	return 0;
    values[0] = prange->ranges[0].rmin, values[1] = prange->ranges[0].rmax;
    values[2] = prange->ranges[1].rmin, values[3] = prange->ranges[1].rmax;
    values[4] = prange->ranges[2].rmin, values[5] = prange->ranges[2].rmax;
    return write_floats(plist, key, values, 6, mem);
}
static int
write_proc3(gs_param_list * plist, gs_param_name key,
	    const gs_cie_render * pcrd, const gs_cie_render_proc3 * procs,
	    const gs_range3 * domain, gs_memory_t * mem)
{
    float *values;
    uint size = gx_cie_cache_size;
    gs_param_float_array fa;
    int i;

    if (!memcmp(procs, &Encode_default, sizeof(*procs)))
	return 0;
    values = (float *)gs_alloc_byte_array(mem, size * 3, sizeof(float),
					  "write_proc3");

    if (values == 0)
	return_error(gs_error_VMerror);
    for (i = 0; i < 3; ++i) {
	double base = domain->ranges[i].rmin;
	double scale = (domain->ranges[i].rmax - base) / (size - 1);
	int j;

	for (j = 0; j < size; ++j)
	    values[i * size + j] =
		(*procs->procs[i]) (j * scale + base, pcrd);
    }
    fa.data = values;
    fa.size = size * 3;
    fa.persistent = true;
    return param_write_float_array(plist, key, &fa);
}

/* Write a CRD as a device parameter. */
int
param_write_cie_render1(gs_param_list * plist, gs_param_name key,
			gs_cie_render * pcrd, gs_memory_t * mem)
{
    gs_param_dict dict;
    int code, dcode;

    dict.size = 20;
    if ((code = param_begin_write_dict(plist, key, &dict, false)) < 0)
	return code;
    code = param_put_cie_render1(dict.list, pcrd, mem);
    dcode = param_end_write_dict(plist, key, &dict);
    return (code < 0 ? code : dcode);
}

/* Write a CRD directly to a parameter list. */
int
param_put_cie_render1(gs_param_list * plist, gs_cie_render * pcrd,
		      gs_memory_t * mem)
{
    int crd_type = GX_DEVICE_CRD1_TYPE;
    int code = gs_cie_render_sample(pcrd); /* we need RenderTableT_is_id' */

    if (code < 0)
	return code;
    if (pcrd->TransformPQR.proc_name) {
	gs_param_string pn, pd;

	param_string_from_string(pn, pcrd->TransformPQR.proc_name);
	pn.size++;		/* include terminating null */
	pd.data = pcrd->TransformPQR.proc_data.data;
	pd.size = pcrd->TransformPQR.proc_data.size;
	pd.persistent = true;  /****** WRONG ******/
	if ((code = param_write_name(plist, "TransformPQRName", &pn)) < 0 ||
	    (code = param_write_string(plist, "TransformPQRData", &pd)) < 0
	    )
	    return code;
    }
    else if (pcrd->TransformPQR.proc != TransformPQR_default.proc) {
	/* We have no way to represent the procedure, so return an error. */
	return_error(gs_error_rangecheck);
    }
    if ((code = param_write_int(plist, "ColorRenderingType", &crd_type)) < 0 ||
	(code = write_vector3(plist, "WhitePoint", &pcrd->points.WhitePoint, mem)) < 0
	)
	return code;
    if (memcmp(&pcrd->points.BlackPoint, &BlackPoint_default,
	       sizeof(pcrd->points.BlackPoint))) {
	if ((code = write_vector3(plist, "BlackPoint", &pcrd->points.BlackPoint, mem)) < 0)
	    return code;
    }
    if ((code = write_matrix3(plist, "MatrixPQR", &pcrd->MatrixPQR, mem)) < 0 ||
	(code = write_range3(plist, "RangePQR", &pcrd->RangePQR, mem)) < 0 ||
    /* TransformPQR is handled separately */
    (code = write_matrix3(plist, "MatrixLMN", &pcrd->MatrixLMN, mem)) < 0 ||
	(code = write_proc3(plist, "EncodeLMNValues", pcrd,
			    &pcrd->EncodeLMN, &pcrd->DomainLMN, mem)) < 0 ||
	(code = write_range3(plist, "RangeLMN", &pcrd->RangeLMN, mem)) < 0 ||
    (code = write_matrix3(plist, "MatrixABC", &pcrd->MatrixABC, mem)) < 0 ||
	(code = write_proc3(plist, "EncodeABCValues", pcrd,
			    &pcrd->EncodeABC, &pcrd->DomainABC, mem)) < 0 ||
	(code = write_range3(plist, "RangeABC", &pcrd->RangeABC, mem)) < 0
	)
	return code;
    if (pcrd->RenderTable.lookup.table) {
	int n = pcrd->RenderTable.lookup.n;
	int m = pcrd->RenderTable.lookup.m;
	int na = pcrd->RenderTable.lookup.dims[0];
	int *size = (int *)
	    gs_alloc_byte_array(mem, n + 1, sizeof(int), "RenderTableSize");

	/*
	 * In principle, we should use gs_alloc_struct_array with a
	 * type descriptor for gs_param_string.  However, it is widely
	 * assumed that parameter lists are transient, and don't require
	 * accurate GC information; so we can get away with allocating
	 * the string table as bytes.
	 */
	gs_param_string *table =
	    (gs_param_string *)
	    gs_alloc_byte_array(mem, na, sizeof(gs_param_string),
				"RenderTableTable");
	gs_param_int_array ia;

	if (size == 0 || table == 0)
	    code = gs_note_error(gs_error_VMerror);
	else {
	    memcpy(size, pcrd->RenderTable.lookup.dims, sizeof(int) * n);

	    size[n] = m;
	    ia.data = size;
	    ia.size = n + 1;
	    ia.persistent = true;
	    code = param_write_int_array(plist, "RenderTableSize", &ia);
	}
	if (code >= 0) {
	    gs_param_string_array sa;
	    int a;

	    for (a = 0; a < na; ++a)
		table[a].data = pcrd->RenderTable.lookup.table[a].data,
		    table[a].size = pcrd->RenderTable.lookup.table[a].size,
		    table[a].persistent = true;
	    sa.data = table;
	    sa.size = na;
	    sa.persistent = true;
	    code = param_write_string_array(plist, "RenderTableTable", &sa);
	    if (code >= 0 && !pcrd->caches.RenderTableT_is_identity) {
		/****** WRITE RenderTableTValues LIKE write_proc3 ******/
		uint size = gx_cie_cache_size;
		float *values =
		    (float *)gs_alloc_byte_array(mem, size * m,
						 sizeof(float),
						 "write_proc3");
		gs_param_float_array fa;
		int i;

		if (values == 0)
		    return_error(gs_error_VMerror);
		for (i = 0; i < m; ++i) {
		    double scale = 255.0 / (size - 1);
		    int j;

		    for (j = 0; j < size; ++j)
			values[i * size + j] =
			    frac2float((*pcrd->RenderTable.T.procs[i])
				       ((byte)(j * scale), pcrd));
		}
		fa.data = values;
		fa.size = size * m;
		fa.persistent = true;
		code = param_write_float_array(plist, "RenderTableTValues",
					       &fa);
	    }
	}
	if (code < 0) {
	    gs_free_object(mem, table, "RenderTableTable");
	    gs_free_object(mem, size, "RenderTableSize");
	    return code;
	}
    }
    return code;
}

/* ---------------- Reading ---------------- */

/* Internal procedures for reading parameter values. */
static void
load_vector3(gs_vector3 * pvec, const float *p)
{
    pvec->u = p[0], pvec->v = p[1], pvec->w = p[2];
}
static int
read_floats(gs_param_list * plist, gs_param_name key, float *values, int count)
{
    gs_param_float_array fa;
    int code = param_read_float_array(plist, key, &fa);

    if (code)
	return code;
    if (fa.size != count)
	return_error(gs_error_rangecheck);
    memcpy(values, fa.data, sizeof(float) * count);

    return 0;
}
static int
read_vector3(gs_param_list * plist, gs_param_name key,
	     gs_vector3 * pvec, const gs_vector3 * dflt)
{
    float values[3];
    int code = read_floats(plist, key, values, 3);

    switch (code) {
	case 1:		/* not defined */
	    if (dflt)
		*pvec = *dflt;
	    break;
	case 0:
	    load_vector3(pvec, values);
	default:		/* error */
	    break;
    }
    return code;
}
static int
read_matrix3(gs_param_list * plist, gs_param_name key, gs_matrix3 * pmat)
{
    float values[9];
    int code = read_floats(plist, key, values, 9);

    switch (code) {
	case 1:		/* not defined */
	    *pmat = Matrix3_default;
	    break;
	case 0:
	    load_vector3(&pmat->cu, values);
	    load_vector3(&pmat->cv, values + 3);
	    load_vector3(&pmat->cw, values + 6);
	default:		/* error */
	    break;
    }
    return code;
}
static int
read_range3(gs_param_list * plist, gs_param_name key, gs_range3 * prange)
{
    float values[6];
    int code = read_floats(plist, key, values, 6);

    switch (code) {
	case 1:		/* not defined */
	    *prange = Range3_default;
	    break;
	case 0:
	    prange->ranges[0].rmin = values[0];
	    prange->ranges[0].rmax = values[1];
	    prange->ranges[1].rmin = values[2];
	    prange->ranges[1].rmax = values[3];
	    prange->ranges[2].rmin = values[4];
	    prange->ranges[2].rmax = values[5];
	default:		/* error */
	    break;
    }
    return code;
}
static int
read_proc3(gs_param_list * plist, gs_param_name key,
	   float values[gx_cie_cache_size * 3])
{
    return read_floats(plist, key, values, gx_cie_cache_size * 3);
}

/* Read a CRD from a device parameter. */
int
gs_cie_render1_param_initialize(gs_cie_render * pcrd, gs_param_list * plist,
				gs_param_name key, gx_device * dev)
{
    gs_param_dict dict;
    int code = param_begin_read_dict(plist, key, &dict, false);
    int dcode;

    if (code < 0)
	return code;
    code = param_get_cie_render1(pcrd, dict.list, dev);
    dcode = param_end_read_dict(plist, key, &dict);
    if (code < 0)
	return code;
    if (dcode < 0)
	return dcode;
    gs_cie_render_init(pcrd);
    gs_cie_render_sample(pcrd);
    return gs_cie_render_complete(pcrd);
}

/* Define the structure for passing Encode values as "client data". */
typedef struct encode_data_s {
    float lmn[gx_cie_cache_size * 3]; /* EncodeLMN */
    float abc[gx_cie_cache_size * 3]; /* EncodeABC */
    float t[gx_cie_cache_size * 4]; /* RenderTable.T */
} encode_data_t;

/* Define procedures that retrieve the Encode values read from the list. */
static float
encode_from_data(floatp v, const float values[gx_cie_cache_size],
		 const gs_range * range)
{
    return (v <= range->rmin ? values[0] :
	    v >= range->rmax ? values[gx_cie_cache_size - 1] :
	    values[(int)((v - range->rmin) / (range->rmax - range->rmin) *
			 (gx_cie_cache_size - 1) + 0.5)]);
}
/*
 * The repetitive boilerplate in the next 10 procedures really sticks in
 * my craw, but I've got a mandate not to use macros....
 */
static float
encode_lmn_0_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->lmn[0],
			    &pcrd->DomainLMN.ranges[0]);
}
static float
encode_lmn_1_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->lmn[gx_cie_cache_size],
			    &pcrd->DomainLMN.ranges[1]);
}
static float
encode_lmn_2_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->lmn[gx_cie_cache_size * 2],
			    &pcrd->DomainLMN.ranges[2]);
}
static float
encode_abc_0_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->abc[0],
			    &pcrd->DomainABC.ranges[0]);
}
static float
encode_abc_1_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->abc[gx_cie_cache_size],
			    &pcrd->DomainABC.ranges[1]);
}
static float
encode_abc_2_from_data(floatp v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return encode_from_data(v, &data->abc[gx_cie_cache_size * 2],
			    &pcrd->DomainABC.ranges[2]);
}
static frac
render_table_t_0_from_data(byte v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return float2frac(encode_from_data(v / 255.0,
				       &data->t[0],
				       &Range3_default.ranges[0]));
}
static frac
render_table_t_1_from_data(byte v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return float2frac(encode_from_data(v / 255.0,
				       &data->t[gx_cie_cache_size],
				       &Range3_default.ranges[0]));
}
static frac
render_table_t_2_from_data(byte v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return float2frac(encode_from_data(v / 255.0,
				       &data->t[gx_cie_cache_size * 2],
				       &Range3_default.ranges[0]));
}
static frac
render_table_t_3_from_data(byte v, const gs_cie_render * pcrd)
{
    const encode_data_t *data = pcrd->client_data;

    return float2frac(encode_from_data(v / 255.0,
				       &data->t[gx_cie_cache_size * 3],
				       &Range3_default.ranges[0]));
}
static const gs_cie_render_proc3 EncodeLMN_from_data = {
    {encode_lmn_0_from_data, encode_lmn_1_from_data, encode_lmn_2_from_data}
};
static const gs_cie_render_proc3 EncodeABC_from_data = {
    {encode_abc_0_from_data, encode_abc_1_from_data, encode_abc_2_from_data}
};
static const gs_cie_render_table_procs RenderTableT_from_data = {
    {render_table_t_0_from_data, render_table_t_1_from_data,
     render_table_t_2_from_data, render_table_t_3_from_data
    }
};

/* Read a CRD directly from a parameter list. */
int
param_get_cie_render1(gs_cie_render * pcrd, gs_param_list * plist,
		      gx_device * dev)
{
    encode_data_t data;
    gs_param_int_array rt_size;
    int crd_type;
    int code, code_lmn, code_abc, code_rt, code_t;
    gs_param_string pname, pdata;

    /* Reset the status to invalidate cached information. */
    pcrd->status = CIE_RENDER_STATUS_BUILT;
    if ((code = param_read_int(plist, "ColorRenderingType", &crd_type)) < 0 ||
	crd_type != GX_DEVICE_CRD1_TYPE ||
	(code = read_vector3(plist, "WhitePoint", &pcrd->points.WhitePoint,
			     NULL)) < 0 ||
	(code = read_vector3(plist, "BlackPoint", &pcrd->points.BlackPoint,
			     &BlackPoint_default)) < 0 ||
	(code = read_matrix3(plist, "MatrixPQR", &pcrd->MatrixPQR)) < 0 ||
	(code = read_range3(plist, "RangePQR", &pcrd->RangePQR)) < 0 ||
	/* TransformPQR is handled specially below. */
	(code = read_matrix3(plist, "MatrixLMN", &pcrd->MatrixLMN)) < 0 ||
	(code_lmn = code =
	 read_proc3(plist, "EncodeLMNValues", data.lmn)) < 0 ||
	(code = read_range3(plist, "RangeLMN", &pcrd->RangeLMN)) < 0 ||
	(code = read_matrix3(plist, "MatrixABC", &pcrd->MatrixABC)) < 0 ||
	(code_abc = code =
	 read_proc3(plist, "EncodeABCValues", data.abc)) < 0 ||
	(code = read_range3(plist, "RangeABC", &pcrd->RangeABC)) < 0
	)
	return code;
    /* Handle the sampled functions. */
    switch (code = param_read_string(plist, "TransformPQRName", &pname)) {
	default:		/* error */
	    return code;
	case 1:			/* missing */
	    pcrd->TransformPQR = TransformPQR_default;
	    break;
	case 0:			/* specified */
	    /* The procedure name must be null-terminated: */
	    /* see param_put_cie_render1 above. */
	    if (pname.size < 1 || pname.data[pname.size - 1] != 0)
		return_error(gs_error_rangecheck);
	    pcrd->TransformPQR.proc = TransformPQR_lookup_proc_name;
	    pcrd->TransformPQR.proc_name = (const char *)pname.data;
	    switch (code = param_read_string(plist, "TransformPQRData", &pdata)) {
		default:	/* error */
		    return code;
		case 1:		/* missing */
		    pcrd->TransformPQR.proc_data.data = 0;
		    pcrd->TransformPQR.proc_data.size = 0;
		    break;
		case 0:
		    pcrd->TransformPQR.proc_data.data = pdata.data;
		    pcrd->TransformPQR.proc_data.size = pdata.size;
	    }
	    pcrd->TransformPQR.driver_name = gs_devicename(dev);
	    break;
    }
    pcrd->client_data = &data;
    if (code_lmn > 0)
	pcrd->EncodeLMN = Encode_default;
    else
	pcrd->EncodeLMN = EncodeLMN_from_data;
    if (code_abc > 0)
	pcrd->EncodeABC = Encode_default;
    else
	pcrd->EncodeABC = EncodeABC_from_data;
    code_rt = code = param_read_int_array(plist, "RenderTableSize", &rt_size);
    if (code == 1) {
	if (pcrd->RenderTable.lookup.table) {
	    gs_free_object(pcrd->rc.memory,
		(void *)pcrd->RenderTable.lookup.table, /* break const */
		"param_get_cie_render1(RenderTable)");
	    pcrd->RenderTable.lookup.table = 0;
	}
	pcrd->RenderTable.T = RenderTableT_default;
	code_t = 1;
    } else if (code < 0)
	return code;
    else if (rt_size.size != 4)
	return_error(gs_error_rangecheck);
    else {
	gs_param_string_array rt_values;
	gs_const_string *table;
	int n, m, j;

	for (j = 0; j < rt_size.size; ++j)
	    if (rt_size.data[j] < 1)
		return_error(gs_error_rangecheck);
	code = param_read_string_array(plist, "RenderTableTable", &rt_values);
	if (code < 0)
	    return code;
	if (code > 0 || rt_values.size != rt_size.data[0])
	    return_error(gs_error_rangecheck);
	/* Note: currently n = 3 (rt_size.size = 4) always. */
	for (j = 0; j < rt_values.size; ++j)
	    if (rt_values.data[j].size !=
		rt_size.data[1] * rt_size.data[2] * rt_size.data[3])
		return_error(gs_error_rangecheck);
	pcrd->RenderTable.lookup.n = n = rt_size.size - 1;
	pcrd->RenderTable.lookup.m = m = rt_size.data[n];
	if (n > 4 || m > 4)
	    return_error(gs_error_rangecheck);
	memcpy(pcrd->RenderTable.lookup.dims, rt_size.data, n * sizeof(int));
	table =
	    gs_alloc_struct_array(pcrd->rc.memory,
				  pcrd->RenderTable.lookup.dims[0],
				  gs_const_string, &st_const_string_element,
				  "RenderTable table");
	if (table == 0)
	    return_error(gs_error_VMerror);
	for (j = 0; j < pcrd->RenderTable.lookup.dims[0]; ++j) {
	    table[j].data = rt_values.data[j].data;
	    table[j].size = rt_values.data[j].size;
	}
	pcrd->RenderTable.lookup.table = table;
	pcrd->RenderTable.T = RenderTableT_from_data;
	code_t = code = read_floats(plist, "RenderTableTValues", data.t,
				    gx_cie_cache_size * m);
	if (code > 0)
	    pcrd->RenderTable.T = RenderTableT_default;
	else if (code == 0)
	    pcrd->RenderTable.T = RenderTableT_from_data;
    }
    if ((code = gs_cie_render_init(pcrd)) >= 0 &&
	(code = gs_cie_render_sample(pcrd)) >= 0
	)
	code = gs_cie_render_complete(pcrd);
    /* Clean up before exiting. */
    pcrd->client_data = 0;
    if (code_lmn == 0)
	pcrd->EncodeLMN = EncodeLMN_from_cache;
    if (code_abc == 0)
	pcrd->EncodeABC = EncodeABC_from_cache;
    if (code_t == 0)
	pcrd->RenderTable.T = RenderTableT_from_cache;
    return code;
}