Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / halftoner.h
1 /*****************************************************************************\
2   halftoner.h : Interface for the Halftoner 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_HALFTONER_H
33 #define APDK_HALFTONER_H
34 //===========================================================================
35 //
36 //  Filename     :  Halftoner.h
37 //
38 //  Module       :  Open Source Imaging
39 //
40 //  Description  :  This file contains the class declaration for Imaging.
41 //
42 //===========================================================================
43
44 #ifndef HPTYPES_H
45 #include "hptypes.h"
46 #endif
47
48 APDK_BEGIN_NAMESPACE
49
50 // used to encourage consistent ordering of color planes
51 #define K   0
52 #define C   1
53 #define M   2
54 #define Y   3
55 #define Clight  4
56 #define Mlight  5
57
58 #define RANDSEED 77
59
60 ////////////////////////////////////////////////////////////////////////////
61 // UMPQUA
62 //
63 // Encapsulation of buffers and data needed by Halftoner color-matching and
64 // halftoning code.
65
66 class Halftoner : public Processor
67 {
68 public:
69     Halftoner(SystemServices* pSys,
70         PrintMode* pPM,
71         unsigned int iInputWidth,
72         unsigned int iNumRows[],        // for mixed-res cases
73         unsigned int HiResFactor,        // when base-res is multiple of 300
74         BOOL matrixbased
75         );
76     virtual ~Halftoner();
77
78     virtual BOOL Process(RASTERDATA* pbyInputKRGBRaster=NULL) = 0;
79     virtual void Flush();
80
81     DRIVER_ERROR constructor_error;
82
83     virtual void Restart();         // set up for new page or blanks
84
85     // items required by Processor
86     unsigned int GetOutputWidth(COLORTYPE  rastercolor);
87     unsigned int GetMaxOutputWidth(COLORTYPE  rastercolor);
88     BYTE* NextOutputRaster(COLORTYPE  rastercolor);
89     BOOL LastPlane();
90     BOOL FirstPlane();
91     unsigned int PlaneSize()
92         { return OutputWidth[iColor] / 8 + (OutputWidth[iColor] % 8); }
93
94     unsigned int ColorPlaneCount;
95     unsigned int InputWidth;    // # of pixels input per colorplane
96     unsigned int OutputWidth[MAXCOLORPLANES];   // # of pixels output per colorplane
97     unsigned char ColorDepth[MAXCOLORPLANES];
98     // how many rows needed relative to base resolution -- all 1 unless mixed-res
99     unsigned char NumRows[MAXCOLORPLANES];
100     // color plane data
101     // for current interface, we must maintain mapping of
102     //  0=K, 1=C, 2=M, 3=Y
103     BYTE* ColorPlane[MAXCOLORPLANES][MAXCOLORROWS][MAXCOLORDEPTH];
104
105     unsigned int StartPlane;    // since planes are ordered KCMY, if no K, this is 1
106     unsigned int EndPlane;      // usually Y, could be Mlight
107     unsigned int ResBoost;
108
109 protected:
110
111     SystemServices* pSS;    // needed for memory management
112
113     void FreeBuffers();
114
115     HPBool Forward16PixelsNonWhite(HPBytePtr inputPtr)
116     {
117 //        return ((*(HPUInt32Ptr)(inputPtr) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) + 1) != 0x0)  ||
118 //            (*(((HPUInt32Ptr)(inputPtr)) + 2) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) + 3) != 0x0));
119         for (int i=0; i < 16; i++)
120         {
121             if ((*inputPtr++) != 0)
122             {
123                 return TRUE;
124             }
125         }
126         return FALSE;
127     }
128
129     HPBool Backward16PixelsNonWhite(HPBytePtr inputPtr)
130     {
131 //        return ((*(HPUInt32Ptr)(inputPtr) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) - 1) != 0x0)  ||
132 //            (*(((HPUInt32Ptr)(inputPtr)) - 2) != 0x0) || (*(((HPUInt32Ptr)(inputPtr)) - 3) != 0x0));
133         for (int i=0; i < 16; i++)
134         {
135             if ((*inputPtr--) !=0 )
136             {
137                 return TRUE;
138             }
139         }
140         return FALSE;
141     }
142
143
144     short* ErrBuff[6];
145
146     short   nNextRaster;
147
148     short          fRasterOdd;
149     unsigned char* fBlackFEDResPtr;
150     unsigned char* fColorFEDResPtr;
151
152     unsigned int AdjustedInputWidth;    // InputWidth padded to be divisible by 8
153     void PixelMultiply(unsigned char* buffer, unsigned int width, unsigned int factor);
154
155     unsigned int iColor, iRow, iPlane;
156     unsigned int PlaneCount();          // tells how many layers (colors,hifipe,multirow)
157
158     BOOL started;
159
160     BYTE* tempBuffer;
161     BYTE* tempBuffer2;
162         BYTE* originalKData;
163     unsigned int oddbits;
164     void CleanOddBits(unsigned int iColor, unsigned int iRow);
165
166     HPUInt32 hold_random;
167     inline BYTE RandomNumber()
168     {
169        hold_random = (hold_random * 214013) + 2531011;
170        return (BYTE)((hold_random >> 16) & 0xFF);
171     } //RandomNumber
172
173
174     typedef struct THTDitherParms
175     {
176         HPUInt16    fNumPix;            // Dirty Pixels to be dithered
177         HPBytePtr   fInput;             // Pixel array to dither
178         HPBytePtr   fOutput1;           // Output raster binary & hifipe plane 1
179         HPBytePtr   fOutput2;           // Output raster hifipe plane 2 (2-bit)
180         HPBytePtr   fOutput3;           // Output raster hifipe plane 3 (3-bit)
181
182         HPCBytePtr  fFEDResPtr;         // brkpnt table
183
184         kSpringsErrorTypePtr    fErr;            // Current error buffer
185         HPInt16                 fRasterEvenOrOdd;// Serpentine (Forward/Backward)
186
187         HPBool                  fSymmetricFlag;   // Are we symmetric
188
189         HPBool                  fHifipe;          // Are we doing Hifipe?
190
191         HPUInt16                fMatrixRowSize;
192         HPBytePtr               fMatrixV1;
193         HPUInt16                fDitherCellOffset;
194         HPUInt16                fSqueezeOffset;
195
196         HPCInt16Ptr             fWeightTablePtr; // Error Diffusion threshold table
197         HPInt16                 fOffsetPick;     // Random# offset for threshold
198         HPBool                  fVerticalExpFlag; // Are we vertically expanding
199     } THTDitherParms, ENVPTR(THTDitherParmsPtr);
200
201     BOOL usematrix;
202
203     DRIVER_ERROR HTMATRIXHI_KCMY(THTDitherParmsPtr ditherParmsPtr, HPUInt16 count);
204
205 }; //Halftoner
206
207 APDK_END_NAMESPACE
208
209 #endif //APDK_HALFTONER_H