Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / colormatch.h
1 /*****************************************************************************\
2   colormatch.h : Interface for the ColorMatcher class
3
4   Copyright (c) 1996 - 2001, 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
32 #ifndef APDK_COLORMATCH_H
33 #define APDK_COLORMATCH_H
34
35 #define TESTMODE 0
36 #define MAP17CUBE 1
37 #define OCT_MASK1 0x10
38 #define OCT_MASK2 0x8
39 #define OCT_MASK3 0x4
40 #define OCT_MASK4 0x2
41 #define OCT_MASK5 0x1
42
43 APDK_BEGIN_NAMESPACE
44
45 /*!
46 \internal
47 */
48 class ColorMatcher : public Processor
49 {
50 public:
51     ColorMatcher(SystemServices* pSys,
52         ColorMap cm,unsigned int DyeCount,
53         unsigned int iInputWidth);
54     virtual ~ColorMatcher();
55
56     //virtual BOOL Process(BYTE* pbyInputRGBRaster=NULL, unsigned int size=0);
57         virtual BOOL Process(RASTERDATA* InputRaster=NULL);
58     virtual void Flush();
59
60     DRIVER_ERROR constructor_error;
61
62     virtual void Restart();         // set up for new page or blanks
63
64     // items required by Processor
65     unsigned int GetOutputWidth(COLORTYPE  rastercolor);
66     unsigned int GetMaxOutputWidth(COLORTYPE  rastercolor);
67     BYTE* NextOutputRaster(COLORTYPE  rastercolor);
68
69     unsigned int ColorPlaneCount;
70     unsigned int InputWidth;    // # of pixels input
71     unsigned int StartPlane;    // since planes are ordered KCMY, if no K, this is 1
72     unsigned int EndPlane;      // usually Y, could be Mlight
73     unsigned int ResBoost;
74
75     DRIVER_ERROR MakeGrayMap(const uint32_t *colormap, uint32_t* graymap);
76
77 protected:
78
79     SystemServices* pSS;    // needed for memory management
80
81     void FreeBuffers();
82     void ColorMatch( unsigned long width, const uint32_t *map, unsigned char *rgb,
83         unsigned char *kplane, unsigned char *cplane, unsigned char *mplane,
84         unsigned char *yplane );
85     // open/proprietary differ in this routine
86     virtual void Interpolate(const uint32_t *map,
87         unsigned char r,unsigned char g,unsigned char b,
88         unsigned char *blackout, unsigned char *cyanout,
89         unsigned char *magentaout, unsigned char *yellowout)=0;
90
91 #ifdef APDK_DJ3320
92     void ColorMatch( unsigned long width, const unsigned char *map, unsigned char *rgb,
93         unsigned char *kplane, unsigned char *cplane, unsigned char *mplane,
94         unsigned char *yplane );
95     // open/proprietary differ in this routine
96     virtual void Interpolate(const unsigned char *map,
97         unsigned char r,unsigned char g,unsigned char b,
98         unsigned char *blackout, unsigned char *cyanout,
99         unsigned char *magentaout, unsigned char *yellowout)=0;
100 #endif
101
102
103     inline unsigned char GetYellowValue(uint32_t cmyk)
104     { return( ((unsigned char)((cmyk)>>24) & 0xFF) ); }
105
106     inline unsigned char GetMagentaValue(uint32_t cmyk)
107     { return( ((unsigned char)((cmyk)>>16) & 0xFF) ); }
108
109     inline unsigned char GetCyanValue(uint32_t cmyk)
110     { return( ((unsigned char)(((int)(cmyk))>>8) & 0xFF) ); }
111
112     inline unsigned char GetBlackValue(uint32_t cmyk)
113     { return( ((unsigned char)(cmyk) & 0xFF) ); }
114
115     HPBool Forward16PixelsNonWhite(HPBytePtr inputPtr)
116     {
117 //        return ((*(HPUInt32Ptr)(inputPtr) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) + 1) != 0x0)  ||
118 //            (*(((HPUInt32Ptr)(inputPtr)) + 2) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) + 3) != 0x0));
119     for (int i=0; i < 16; i++)
120     {
121         if ((*inputPtr++)!=0)
122             return TRUE;
123     }
124
125     return FALSE;
126     }
127
128     HPBool Backward16PixelsNonWhite(HPBytePtr inputPtr)
129     {
130 //        return ((*(HPUInt32Ptr)(inputPtr) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) - 1) != 0x0)  ||
131 //            (*(((HPUInt32Ptr)(inputPtr)) - 2) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) - 3) != 0x0));
132     for (int i=0; i < 16; i++)
133     {
134         if ((*inputPtr--)!=0)
135             return TRUE;
136     }
137
138     return FALSE;
139     }
140
141
142     unsigned char* Contone; // containing byte-per-pixel CMYK values
143
144     ColorMap cmap;
145
146 //    void PixelMultiply(unsigned char* buffer, unsigned int width, unsigned int factor);
147
148     unsigned int PlaneCount();          // tells how many layers (colors,hifipe,multirow)
149
150     BOOL started;
151
152 }; //ColorMatcher
153
154 APDK_END_NAMESPACE
155
156 #endif  //APDK_COLORMATCH_H