Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / colormatcher_open.cpp
1 /*****************************************************************************\
2   colormatcher_open.cpp : Implimentation for the ColorMatcher_Open class
3
4   Copyright (c) 1996 - 2002, Hewlett-Packard Co.
5   All rights reserved.
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
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.
18
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 \*****************************************************************************/
30
31 #include "header.h"
32 #include "hptypes.h"
33 #include "colormatch.h"
34
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)
38
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))), \
45             (b))
46
47 APDK_BEGIN_NAMESPACE
48
49 ColorMatcher_Open::ColorMatcher_Open
50 (
51     SystemServices* pSys,
52     ColorMap cm,
53     unsigned int DyeCount,
54     unsigned int iInputWidth
55 ) : ColorMatcher(pSys,cm, DyeCount,iInputWidth)
56 {  }
57
58 ColorMatcher_Open::~ColorMatcher_Open()
59 { }
60
61
62 //#define DOCALC(a, b, d)     a + ( ( ( (long)b - (long)a ) * d) >> 5)
63
64 /*
65 BYTE DOCALC(BYTE a, BYTE b, BYTE d)
66 {
67     return a + ( ( ( (long)b - (long)a ) * d) >> 5);
68 }
69
70 BYTE NewCalc(BYTE color[8], BYTE diff_red, BYTE diff_green, BYTE diff_blue)
71 {
72     int dr32 = diff_red - 32;
73     int dg32 = diff_green - 32;
74     int db32 = diff_blue - 32;
75
76     int x;
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;
81     return x;
82 }
83 */
84
85 void ColorMatcher_Open::Interpolate
86 (
87     const uint32_t *map,
88     BYTE r,
89     BYTE g,
90     BYTE b,
91     BYTE *blackout,
92     BYTE *cyanout,
93     BYTE *magentaout,
94     BYTE *yellowout
95 )
96 {
97     static int cube_location[]  = {0, 1,  9, 10,  81,  82,  90,  91 };
98     const uint32_t *start;
99
100 #ifdef  _WIN32_WCE
101     long    cyan[8], magenta[8],yellow[8],black[8];
102 #else
103     BYTE    cyan[8], magenta[8],yellow[8],black[8];
104 #endif
105     start = (const uint32_t *)
106         (((r & 0xE0) << 1) + ((r & 0xE0) >> 1) + (r >> 5) +
107         ((g & 0xE0) >> 2) + (g >> 5) + (b >> 5) + map);
108
109     uint32_t    cValue;
110     for (int j = 0; j < 8; j++)
111     {
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);
117     }
118
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;
123
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 );
128 }
129
130 #ifdef APDK_DJ3320
131
132 void ColorMatcher_Open::Interpolate
133 (
134     const unsigned char *map,
135     BYTE r,
136     BYTE g,
137     BYTE b,
138     BYTE *blackout,
139     BYTE *cyanout,
140     BYTE *magentaout,
141     BYTE *yellowout
142 )
143 {
144 #ifdef  _WIN32_WCE
145     long    cyan[8], magenta[8],yellow[8],black[8];
146 #else
147     BYTE    cyan[8], magenta[8],yellow[8],black[8];
148 #endif
149
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};
152     const   BYTE    *start;
153
154     BYTE *node_ptr;
155
156     start = (const unsigned char *)
157         ((((r & 0xF0) << 4) + ((r & 0xF0) << 1) + (r >> 4) +
158         ((g & 0xF0)) + (g >> 4) + (b >> 4)) * 4 + map);
159
160     // use (start) to determine the surrounding cube values
161     for (int j = 0; j < 8; ++j )
162     {
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;
168     }
169
170
171     // interpolate using the 4 LSBs
172     BYTE diff_red   = r & 0x0f;
173     BYTE diff_green = g & 0x0f;
174     BYTE diff_blue  = b & 0x0f;
175
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 );
180 }
181
182 #endif
183
184 APDK_END_NAMESPACE