1
////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 1996 - 2008, Hewlett-Packard Development Company, L.P.
3
// All rights reserved.
5
// This software is licensed solely for use with HP products. Redistribution
6
// and use with HP products in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
9
// - Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// - Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
// - Neither the name of Hewlett-Packard nor the names of its contributors
15
// may be used to endorse or promote products derived from this software
16
// without specific prior written permission.
17
// - Redistributors making defect corrections to source code grant to
18
// Hewlett-Packard the right to use and redistribute such defect
21
// This software contains technology licensed from third parties; use with
22
// non-HP products is at your own risk and may require a royalty.
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
// 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL HEWLETT-PACKARD OR ITS
28
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
////////////////////////////////////////////////////////////////////////////////
41
#include "CommonDefinitions.h"
42
#include "Processor.h"
45
/* flags that track the block formations use bits which are specified in the
46
following enumeration. The first number is the horizontal block size. The
47
second number is the vertical block size. Then north (upper) or south (lower)
48
and west (left) or east (right) are specified when appropriate. Finally if a
49
location sequence number is needed then it is listed.
52
// Slow down the system and gather stats or not.
53
#define kGatherStats 0
54
#define kDecompressStats 0
89
eNorths = e11n | e21nw | e21ne | e41ni | e41n,
90
eSouths = e11s | e21sw | e21se | e41si | e41s,
91
eTheRest = ~(eNorths|eSouths),
93
eTopLeftOfBlocks = e12 | e14n | e21nw | e21sw | e22w | e24nw | e41ni | e41si | e42i | e44ni | e84ni
96
#define isOdd(x) (x & 0x01)
97
#define isWhite(x) (((x) & kWhite) == kWhite)
99
#define kMemWritesOptimize 1 // disables mem write optimizations.
101
//#ifndef kGatherStats
102
//#error "must define kGatherStats. Try including platform.h"
105
#if kGatherStats == 1
107
// Used now to track blocks being formed. These enums are only used in gathering
108
// statistics for the developer to look at later. These are not critical to the actual
109
// functioning of the algorithms.
146
eLastAveragingFlagPosition
156
class ErnieFilter : public Processor
159
ErnieFilter(int rowWidthInPixels, pixelTypes pixelType, unsigned int maxErrorForTwoPixels);
160
virtual ~ErnieFilter();
162
// Processor interface /////////////////////////////////////
163
bool Process(RASTERDATA* InputRaster=NULL);
165
unsigned int GetMaxOutputWidth();
166
bool NextOutputRaster(RASTERDATA& next_raster);
167
/////////////////////////////////////////////////////////////
170
uint32_t *m_row_bufs[4];
171
unsigned char *m_row_ptrs[4];
172
BYTE *m_black_row_ptrs[4];
173
unsigned int m_black_raster_sizes[4];
174
unsigned char *m_compression_out_buf;
175
unsigned int *m_pixel_filtered_flags[2];
177
int m_buffered_row_count;
178
int m_pixel_offsets[8];
179
int m_pixel_offsets_index;
180
int m_row_width_in_pixels;
181
int m_row_width_in_bytes;
182
int m_internal_bytes_per_pixel;
183
int m_input_bytes_per_pixel;
184
unsigned int m_max_error_for_two_pixels;
187
void submitRowToFilter(unsigned char *rowPtr);
188
void writeBufferedRows();
189
void Filter1RawRow(unsigned char *currPtr, int rowWidthInPixels, unsigned int *flagsPtr);
190
void Filter2RawRows(unsigned char *currPtr, unsigned char *upPtr, int rowWidthInPixels, unsigned int *flagsPtr);
191
void Filter2PairsOfFilteredRows(unsigned char *row1Ptr, unsigned char *row2Ptr, unsigned char *row3Ptr, unsigned char *row4Ptr);
192
void Filter3FilteredRows(unsigned char *row1Ptr, unsigned char *row2Ptr, unsigned char *row3Ptr);
193
inline unsigned int DeltaE(int dr0, int dr1, int dg0, int dg1, int db0, int db1);
194
inline bool NewDeltaE(int dr0, int dr1, int dg0, int dg1, int db0, int db1, int tolerance);
195
inline unsigned int GradDeltaE(int dr, int dg, int db);
197
#if kMemWritesOptimize == 1
198
void WriteBlockPixels();
203
eBufferedPixelWidthInBytes = 4
206
ENDIAN_TYPE m_eEndian;
208
inline uint32_t get4Pixel(unsigned char *pixAddress)
210
#ifdef APDK_LITTLE_ENDIAN
211
return (((unsigned int*)pixAddress)[0]) & kWhite;
213
return (((unsigned int*)pixAddress)[0]) & 0xFFFFFF00;
217
inline uint32_t get4Pixel(unsigned char *pixAddress, int pixelOffset)
219
#ifdef APDK_LITTLE_ENDIAN
220
return *(((unsigned int*)pixAddress)+pixelOffset) & kWhite;
222
return *(((unsigned int*)pixAddress)+pixelOffset) & 0xFFFFFF00;
226
inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, uint32_t pixel)
228
#ifdef APDK_LITTLE_ENDIAN
229
*(((unsigned int*)pixAddress)+pixelOffset) = pixel & kWhite;
231
*(((unsigned int*)pixAddress)+pixelOffset) = pixel & 0xFFFFFF00;
237
#endif // ERNIEFILTER_H