1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gxctable.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* Color table lookup and interpolation */
21
/* See gxctable.h for the API and structure definitions. */
24
* Define an implementation that simply picks the nearest value without
28
gx_color_interpolate_nearest(const fixed * pi,
29
const gx_color_lookup_table * pclt, frac * pv)
31
const int *pdim = pclt->dims;
33
const gs_const_string *table = pclt->table;
36
table += fixed2int_var_rounded(pi[0]) * pdim[1];
39
int ic = fixed2int_var_rounded(pi[2]);
40
int ib = fixed2int_var_rounded(pi[1]);
41
int ia = fixed2int_var_rounded(pi[0]);
42
const byte *p = pclt->table[ia].data + (ib * pdim[2] + ic) * m;
45
for (j = 0; j < m; ++j, ++p)
46
pv[j] = byte2frac(*p);
51
* Define an implementation that uses trilinear interpolation.
54
interpolate_accum(const fixed * pi, const gx_color_lookup_table * pclt,
55
frac * pv, fixed factor)
57
const int *pdim = pclt->dims;
61
/* Do two 3-D interpolations, interpolating between them. */
62
gx_color_lookup_table clt3;
63
int ix = fixed2int_var(pi[0]);
64
fixed fx = fixed_fraction(pi[0]);
67
clt3.dims[0] = pdim[1]; /* needed only for range checking */
68
clt3.dims[1] = pdim[2];
69
clt3.dims[2] = pdim[3];
71
clt3.table = pclt->table + ix * pdim[1];
72
interpolate_accum(pi + 1, &clt3, pv, fixed_1);
73
if (ix == pdim[0] - 1)
75
clt3.table += pdim[1];
76
interpolate_accum(pi + 1, &clt3, pv, fx);
78
int ic = fixed2int_var(pi[2]);
79
fixed fc = fixed_fraction(pi[2]);
80
uint dc1 = (ic == pdim[2] - 1 ? 0 : m);
81
int ib = fixed2int_var(pi[1]);
82
fixed fb = fixed_fraction(pi[1]);
83
uint db1 = (ib == pdim[1] - 1 ? 0 : pdim[2] * m);
84
uint dbc = (ib * pdim[2] + ic) * m;
85
uint dbc1 = db1 + dc1;
86
int ia = fixed2int_var(pi[0]);
87
fixed fa = fixed_fraction(pi[0]);
88
const byte *pa0 = pclt->table[ia].data + dbc;
90
(ia == pdim[0] - 1 ? pa0 : pclt->table[ia + 1].data + dbc);
93
/* The values to be interpolated are */
94
/* pa{0,1}[{0,db1,dc1,dbc1}]. */
95
for (j = 0; j < m; ++j, ++pa0, ++pa1) {
96
frac v000 = byte2frac(pa0[0]);
97
frac v001 = byte2frac(pa0[dc1]);
98
frac v010 = byte2frac(pa0[db1]);
99
frac v011 = byte2frac(pa0[dbc1]);
100
frac v100 = byte2frac(pa1[0]);
101
frac v101 = byte2frac(pa1[dc1]);
102
frac v110 = byte2frac(pa1[db1]);
103
frac v111 = byte2frac(pa1[dbc1]);
107
(frac) arith_rshift((long)fc * (v001 - v000),
110
(frac) arith_rshift((long)fc * (v011 - v010),
113
(frac) arith_rshift((long)fc * (v101 - v100),
116
(frac) arith_rshift((long)fc * (v111 - v110),
120
(frac) arith_rshift((long)fb * (v01 - v00),
123
(frac) arith_rshift((long)fb * (v11 - v10),
127
(frac) arith_rshift((long)fa * (v1 - v0),
129
if (factor == fixed_1)
132
pv[j] += (frac) arith_rshift((long)factor * (rv - pv[j]),
138
gx_color_interpolate_linear(const fixed * pi,
139
const gx_color_lookup_table * pclt, frac * pv)
141
interpolate_accum(pi, pclt, pv, fixed_1);