Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / filterhpa.h
1 /*****************************************************************************\
2   filterhpa.h : Interface for the TErnieFilter 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_FILTERHPA_H
33 #define APDK_FILTERHPA_H
34
35 #if defined(APDK_DJ9xxVIP) && defined(APDK_VIP_COLORFILTERING)
36
37 APDK_BEGIN_NAMESPACE
38
39 /*  flags that track the block formations use bits which are specified in the
40     following enumeration. The first number is the horizontal block size. The
41     second number is the vertical block size. Then north (upper) or south (lower)
42     and west (left) or east (right) are specified when appropriate. Finally if a
43     location sequence number is needed then it is listed.
44 */
45
46 enum eBlockType
47 {
48     eDone   = 0x0,
49     e11n    = 0x00000001,
50     e11s    = 0x00000002,
51     e12     = 0x00000004,
52     e14n    = 0x00000008,
53     e14s    = 0x00000010,
54     e21nw   = 0x00000020,
55     e21ne   = 0x00000040,
56     e21sw   = 0x00000080,
57     e21se   = 0x00000100,
58     e22w    = 0x00000200,
59     e22e    = 0x00000400,
60     e24nw   = 0x00000800,
61     e24ne   = 0x00001000,
62     e24sw   = 0x00002000,
63     e24se   = 0x00004000,
64     e41ni   = 0x00008000,
65     e41n    = 0x00010000,
66     e41si   = 0x00020000,
67     e41s    = 0x00040000,
68     e42i    = 0x00080000,
69     e42     = 0x00100000,
70     e44ni   = 0x00200000,
71     e44n    = 0x00400000,
72     e44si   = 0x00800000,
73     e44s    = 0x01000000,
74     e84ni   = 0x02000000,
75     e84n    = 0x04000000,
76     e84si   = 0x08000000,
77     e84s    = 0x10000000,
78
79     eNorths = e11n | e21nw | e21ne | e41ni | e41n,
80     eSouths = e11s | e21sw | e21se | e41si | e41s,
81     eTheRest = ~(eNorths|eSouths),
82
83     eTopLeftOfBlocks = e12 | e14n | e21nw | e21sw | e22w | e24nw | e41ni | e41si | e42i | e44ni | e84ni
84 };
85
86 #define isOdd(x) (x & 0x01)
87 #define isWhite(x) (((x) & kWhite) == kWhite)
88
89 #define kMemWritesOptimize  0   // disables mem write optimizations.
90
91 //#ifndef kGatherStats
92 //#error "must define kGatherStats. Try including platform.h"
93 //#endif
94
95 #if kGatherStats == 1
96
97 // Used now to track blocks being formed. These enums are only used in gathering
98 // statistics for the developer to look at later. These are not critical to the actual
99 // functioning of the algorithms.
100
101 enum StatisticBlocks
102 {
103     es11n   = 0,
104     es11s,
105     es12,
106     es14n,
107     es14s,
108     es21nw,
109     es21ne,
110     es21sw,
111     es21se,
112     es22w,
113     es22e,
114     es24nw,
115     es24ne,
116     es24sw,
117     es24se,
118     es41ni,
119     es41n,
120     es41si,
121     es41s,
122     es42i,
123     es42,
124     es44ni,
125     es44n,
126     es44si,
127     es44s,
128     es84ni,
129     es84n,
130     es84si,
131     es84s,
132
133     esDoneStat,
134     esWhiteFound,
135
136     eLastAveragingFlagPosition
137 };
138
139 #endif
140
141 enum pixelTypes
142 {
143     eBGRPixelData = 0
144 };
145
146 class TErnieFilter : public Processor
147 {
148 public:
149     TErnieFilter(int rowWidthInPixels, pixelTypes pixelType, unsigned int maxErrorForTwoPixels, int bytesPerPixel = 3);
150     virtual ~TErnieFilter();
151
152     void submitRowToFilter(unsigned char *rowPtr);
153     void writeBufferedRows();
154
155      // Processor interface  /////////////////////////////////////
156     BOOL Process(RASTERDATA* InputRaster=NULL);
157     void Flush();
158     unsigned int GetOutputWidth(COLORTYPE  rastercolor);
159     unsigned int GetInputWidth();
160     BYTE* NextOutputRaster(COLORTYPE  rastercolor);
161     /////////////////////////////////////////////////////////////
162
163 private:
164     uint32_t            *fRowBuf[4];
165     unsigned char       *fRowPtr[4];
166         BYTE                *fBlackRowPtr[4];
167         unsigned int        BlackRasterSize[4];
168     unsigned char       *fCompressionOutBuf;
169     unsigned int        *fPixelFilteredFlags[2];
170
171     int                 fNumberOfBufferedRows;
172     int                 fPixelOffset[8];
173     int                 fPixelOffsetIndex;
174     int                 fRowWidthInPixels;
175     int                 fRowWidthInBytes;
176     int                 fInternalBufferPixelSize;
177     int                 fOriginalPixelSize;
178     unsigned int        fMaxErrorForTwoPixels;
179
180         int                 RowIndex;
181
182     void Filter1RawRow(unsigned char *currPtr, int rowWidthInPixels, unsigned int *flagsPtr);
183     void Filter2RawRows(unsigned char *currPtr, unsigned char *upPtr, int rowWidthInPixels, unsigned int *flagsPtr);
184     void Filter2PairsOfFilteredRows(unsigned char *row1Ptr, unsigned char *row2Ptr, unsigned char *row3Ptr, unsigned char *row4Ptr);
185     void Filter3FilteredRows(unsigned char *row1Ptr, unsigned char *row2Ptr, unsigned char *row3Ptr);
186     inline unsigned int DeltaE(int dr0, int dr1, int dg0, int dg1, int db0, int db1);
187     inline bool NewDeltaE(int dr0, int dr1, int dg0, int dg1, int db0, int db1, int tolerance);
188     inline unsigned int GradDeltaE(int dr, int dg, int db);
189
190 #if kMemWritesOptimize == 1
191     void WriteBlockPixels();
192 #endif
193
194     enum
195     {
196         eBufferedPixelWidthInBytes = 4
197     };
198 }; //TErnieFilter
199
200 APDK_END_NAMESPACE
201
202 #endif //APDK_DJ9xxVIP && APDK_VIP_COLORFILTERING
203 #endif //APDK_FILTERHPA_H