1 /*****************************************************************************\
2 filterhpa.h : Interface for the TErnieFilter class
4 Copyright (c) 1996 - 2001, 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 \*****************************************************************************/
32 #ifndef APDK_FILTERHPA_H
33 #define APDK_FILTERHPA_H
35 #if defined(APDK_DJ9xxVIP) && defined(APDK_VIP_COLORFILTERING)
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.
79 eNorths = e11n | e21nw | e21ne | e41ni | e41n,
80 eSouths = e11s | e21sw | e21se | e41si | e41s,
81 eTheRest = ~(eNorths|eSouths),
83 eTopLeftOfBlocks = e12 | e14n | e21nw | e21sw | e22w | e24nw | e41ni | e41si | e42i | e44ni | e84ni
86 #define isOdd(x) (x & 0x01)
87 #define isWhite(x) (((x) & kWhite) == kWhite)
89 #define kMemWritesOptimize 0 // disables mem write optimizations.
91 //#ifndef kGatherStats
92 //#error "must define kGatherStats. Try including platform.h"
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.
136 eLastAveragingFlagPosition
146 class TErnieFilter : public Processor
149 TErnieFilter(int rowWidthInPixels, pixelTypes pixelType, unsigned int maxErrorForTwoPixels, int bytesPerPixel = 3);
150 virtual ~TErnieFilter();
152 void submitRowToFilter(unsigned char *rowPtr);
153 void writeBufferedRows();
155 // Processor interface /////////////////////////////////////
156 BOOL Process(RASTERDATA* InputRaster=NULL);
158 unsigned int GetOutputWidth(COLORTYPE rastercolor);
159 unsigned int GetInputWidth();
160 BYTE* NextOutputRaster(COLORTYPE rastercolor);
161 /////////////////////////////////////////////////////////////
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];
171 int fNumberOfBufferedRows;
173 int fPixelOffsetIndex;
174 int fRowWidthInPixels;
175 int fRowWidthInBytes;
176 int fInternalBufferPixelSize;
177 int fOriginalPixelSize;
178 unsigned int fMaxErrorForTwoPixels;
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);
190 #if kMemWritesOptimize == 1
191 void WriteBlockPixels();
196 eBufferedPixelWidthInBytes = 4
202 #endif //APDK_DJ9xxVIP && APDK_VIP_COLORFILTERING
203 #endif //APDK_FILTERHPA_H