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