~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to prnt/hpcups/ErnieFilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-14 20:08:44 UTC
  • mfrom: (2.1.118 lucid)
  • Revision ID: james.westby@ubuntu.com-20091214200844-z8qhqwgppbu3t7ze
Tags: 3.9.10-4
KBSD patch from KiBi (Closes: #560796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//    Copyright (c) 1996 - 2008, Hewlett-Packard Development Company, L.P.
 
3
//    All rights reserved.
 
4
//    
 
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:
 
8
//    
 
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
 
19
//        corrections.
 
20
//    
 
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.
 
23
//    
 
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
////////////////////////////////////////////////////////////////////////////////
 
36
 
 
37
 
 
38
#ifndef ERNIEFILTER_H
 
39
#define ERNIEFILTER_H
 
40
 
 
41
#include "CommonDefinitions.h"
 
42
#include "Processor.h"
 
43
 
 
44
 
 
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.
 
50
*/
 
51
 
 
52
// Slow down the system and gather stats or not.
 
53
#define kGatherStats    0
 
54
#define kDecompressStats 0
 
55
 
 
56
enum eBlockType
 
57
{
 
58
    eDone   = 0x0,
 
59
    e11n    = 0x00000001,
 
60
    e11s    = 0x00000002,
 
61
    e12     = 0x00000004,
 
62
    e14n    = 0x00000008,
 
63
    e14s    = 0x00000010,
 
64
    e21nw   = 0x00000020,
 
65
    e21ne   = 0x00000040,
 
66
    e21sw   = 0x00000080,
 
67
    e21se   = 0x00000100,
 
68
    e22w    = 0x00000200,
 
69
    e22e    = 0x00000400,
 
70
    e24nw   = 0x00000800,
 
71
    e24ne   = 0x00001000,
 
72
    e24sw   = 0x00002000,
 
73
    e24se   = 0x00004000,
 
74
    e41ni   = 0x00008000,
 
75
    e41n    = 0x00010000,
 
76
    e41si   = 0x00020000,
 
77
    e41s    = 0x00040000,
 
78
    e42i    = 0x00080000,
 
79
    e42     = 0x00100000,
 
80
    e44ni   = 0x00200000,
 
81
    e44n    = 0x00400000,
 
82
    e44si   = 0x00800000,
 
83
    e44s    = 0x01000000,
 
84
    e84ni   = 0x02000000,
 
85
    e84n    = 0x04000000,
 
86
    e84si   = 0x08000000,
 
87
    e84s    = 0x10000000,
 
88
 
 
89
    eNorths = e11n | e21nw | e21ne | e41ni | e41n,
 
90
    eSouths = e11s | e21sw | e21se | e41si | e41s,
 
91
    eTheRest = ~(eNorths|eSouths),
 
92
 
 
93
    eTopLeftOfBlocks = e12 | e14n | e21nw | e21sw | e22w | e24nw | e41ni | e41si | e42i | e44ni | e84ni
 
94
};
 
95
 
 
96
#define isOdd(x) (x & 0x01)
 
97
#define isWhite(x) (((x) & kWhite) == kWhite)
 
98
 
 
99
#define kMemWritesOptimize  1   // disables mem write optimizations.
 
100
 
 
101
//#ifndef kGatherStats
 
102
//#error "must define kGatherStats. Try including platform.h"
 
103
//#endif
 
104
 
 
105
#if kGatherStats == 1
 
106
 
 
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.
 
110
 
 
111
enum StatisticBlocks
 
112
{
 
113
    es11n   = 0,
 
114
    es11s,
 
115
    es12,
 
116
    es14n,
 
117
    es14s,
 
118
    es21nw,
 
119
    es21ne,
 
120
    es21sw,
 
121
    es21se,
 
122
    es22w,
 
123
    es22e,
 
124
    es24nw,
 
125
    es24ne,
 
126
    es24sw,
 
127
    es24se,
 
128
    es41ni,
 
129
    es41n,
 
130
    es41si,
 
131
    es41s,
 
132
    es42i,
 
133
    es42,
 
134
    es44ni,
 
135
    es44n,
 
136
    es44si,
 
137
    es44s,
 
138
    es84ni,
 
139
    es84n,
 
140
    es84si,
 
141
    es84s,
 
142
 
 
143
    esDoneStat,
 
144
    esWhiteFound,
 
145
 
 
146
    eLastAveragingFlagPosition
 
147
};
 
148
 
 
149
#endif
 
150
 
 
151
enum pixelTypes
 
152
{
 
153
    eBGRPixelData = 0
 
154
};
 
155
 
 
156
class ErnieFilter : public Processor
 
157
{
 
158
public:
 
159
    ErnieFilter(int rowWidthInPixels, pixelTypes pixelType, unsigned int maxErrorForTwoPixels);
 
160
    virtual ~ErnieFilter();
 
161
 
 
162
     // Processor interface  /////////////////////////////////////
 
163
    bool Process(RASTERDATA* InputRaster=NULL);
 
164
    void Flush();
 
165
    unsigned int GetMaxOutputWidth();
 
166
    bool NextOutputRaster(RASTERDATA& next_raster);
 
167
    /////////////////////////////////////////////////////////////
 
168
 
 
169
private:
 
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];
 
176
 
 
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;
 
185
    int                 m_row_index;
 
186
 
 
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);
 
196
 
 
197
#if kMemWritesOptimize == 1
 
198
    void WriteBlockPixels();
 
199
#endif
 
200
 
 
201
    enum
 
202
    {
 
203
        eBufferedPixelWidthInBytes = 4
 
204
    };
 
205
 
 
206
    ENDIAN_TYPE    m_eEndian;
 
207
 
 
208
    inline uint32_t get4Pixel(unsigned char *pixAddress)
 
209
    {
 
210
    #ifdef APDK_LITTLE_ENDIAN
 
211
            return (((unsigned int*)pixAddress)[0]) & kWhite;
 
212
    #else
 
213
            return (((unsigned int*)pixAddress)[0]) & 0xFFFFFF00;
 
214
    #endif
 
215
    }
 
216
    
 
217
    inline uint32_t get4Pixel(unsigned char *pixAddress, int pixelOffset)
 
218
    {
 
219
    #ifdef APDK_LITTLE_ENDIAN
 
220
            return *(((unsigned int*)pixAddress)+pixelOffset) & kWhite;
 
221
    #else
 
222
            return *(((unsigned int*)pixAddress)+pixelOffset) & 0xFFFFFF00;
 
223
    #endif
 
224
    }
 
225
    
 
226
    inline void put4Pixel(unsigned char *pixAddress, int pixelOffset, uint32_t pixel)
 
227
    {
 
228
    #ifdef APDK_LITTLE_ENDIAN
 
229
            *(((unsigned int*)pixAddress)+pixelOffset) = pixel & kWhite;
 
230
    #else
 
231
            *(((unsigned int*)pixAddress)+pixelOffset) = pixel & 0xFFFFFF00;
 
232
    #endif
 
233
    }
 
234
 
 
235
}; // ErnieFilter
 
236
 
 
237
#endif // ERNIEFILTER_H
 
238