1 /*****************************************************************************\
2 colormatcher_open.cpp : Implimentation for the ColorMatcher_Open class
4 Copyright (c) 1996 - 2002, Hewlett-Packard Co.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. Neither the name of Hewlett-Packard nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
33 #include "colormatch.h"
35 #include "colormatcher_open.h"
36 #define INTERPOLATE_5_BITS(a, b, d) a + ( ( ( (long)b - (long)a ) * d) >> 5)
37 #define INTERPOLATE_4_BITS(a, b, d) a + ( ( ( (long)b - (long)a ) * d) >> 4)
39 // Spatial Interpolation
40 #define INTERPOLATE_CUBE(r,g,b, cube, DOCALC) \
41 DOCALC( (DOCALC( (DOCALC( cube[0], cube[4], (r))), \
42 (DOCALC( cube[2], cube[6], (r))), (g))), \
43 (DOCALC( (DOCALC( cube[1], cube[5], (r))), \
44 (DOCALC( cube[3], cube[7], (r))), (g))), \
49 ColorMatcher_Open::ColorMatcher_Open
53 unsigned int DyeCount,
54 unsigned int iInputWidth
55 ) : ColorMatcher(pSys,cm, DyeCount,iInputWidth)
58 ColorMatcher_Open::~ColorMatcher_Open()
62 //#define DOCALC(a, b, d) a + ( ( ( (long)b - (long)a ) * d) >> 5)
65 BYTE DOCALC(BYTE a, BYTE b, BYTE d)
67 return a + ( ( ( (long)b - (long)a ) * d) >> 5);
70 BYTE NewCalc(BYTE color[8], BYTE diff_red, BYTE diff_green, BYTE diff_blue)
72 int dr32 = diff_red - 32;
73 int dg32 = diff_green - 32;
74 int db32 = diff_blue - 32;
77 x = -(color[0] * db32 * dg32 * dr32 + color[1] * diff_blue * (32 - diff_red) * dg32 +
78 color[2] * diff_green * (32 - diff_red) * db32 + color[3] * diff_blue * diff_green * dr32 -
79 diff_red * (color[4] * db32 * dg32 + color[5] * diff_blue * (32 - diff_green) -
80 diff_green * (color[6] * db32 - color[7] * diff_blue))) >> 15;
85 void ColorMatcher_Open::Interpolate
97 static int cube_location[] = {0, 1, 9, 10, 81, 82, 90, 91 };
98 const uint32_t *start;
101 long cyan[8], magenta[8],yellow[8],black[8];
103 BYTE cyan[8], magenta[8],yellow[8],black[8];
105 start = (const uint32_t *)
106 (((r & 0xE0) << 1) + ((r & 0xE0) >> 1) + (r >> 5) +
107 ((g & 0xE0) >> 2) + (g >> 5) + (b >> 5) + map);
110 for (int j = 0; j < 8; j++)
112 cValue = *(start + cube_location[j]);
113 cyan[j] = GetCyanValue (cValue);
114 magenta[j] = GetMagentaValue (cValue);
115 yellow[j] = GetYellowValue (cValue);
116 black[j] = GetBlackValue (cValue);
119 ////////////////this is the 8 bit 9cube operation /////////////
120 BYTE diff_red = r & 0x1f;
121 BYTE diff_green = g & 0x1f;
122 BYTE diff_blue = b & 0x1f;
124 *cyanout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, cyan, INTERPOLATE_5_BITS );
125 *magentaout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, magenta, INTERPOLATE_5_BITS );
126 *yellowout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, yellow, INTERPOLATE_5_BITS );
127 *blackout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, black, INTERPOLATE_5_BITS );
132 void ColorMatcher_Open::Interpolate
134 const unsigned char *map,
145 long cyan[8], magenta[8],yellow[8],black[8];
147 BYTE cyan[8], magenta[8],yellow[8],black[8];
150 // static int cube_location[] = {0, 1, 17, 18, 289, 290, 306, 307};
151 static int cube_location[] = {0, 4, 68, 72, 1156, 1160, 1224, 1228};
156 start = (const unsigned char *)
157 ((((r & 0xF0) << 4) + ((r & 0xF0) << 1) + (r >> 4) +
158 ((g & 0xF0)) + (g >> 4) + (b >> 4)) * 4 + map);
160 // use (start) to determine the surrounding cube values
161 for (int j = 0; j < 8; ++j )
163 node_ptr = (BYTE *) (start + cube_location[j]);
164 black[j] = *node_ptr++;
165 cyan[j] = *node_ptr++;
166 magenta[j] = *node_ptr++;
167 yellow[j] = *node_ptr;
171 // interpolate using the 4 LSBs
172 BYTE diff_red = r & 0x0f;
173 BYTE diff_green = g & 0x0f;
174 BYTE diff_blue = b & 0x0f;
176 *cyanout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, cyan, INTERPOLATE_4_BITS );
177 *magentaout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, magenta, INTERPOLATE_4_BITS );
178 *yellowout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, yellow, INTERPOLATE_4_BITS );
179 *blackout = INTERPOLATE_CUBE(diff_red,diff_green,diff_blue, black, INTERPOLATE_4_BITS );