1 /*****************************************************************************\
2 Halftoner.h : Interface for the Halftoner 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 \*****************************************************************************/
35 ////////////////////////////////////////////////////////////////////////////
38 // Encapsulation of buffers and data needed by Halftoner color-matching and
41 class Halftoner : public Processor
44 Halftoner(PrintMode* pPM,
45 unsigned int iInputWidth,
46 int iNumRows[], // for mixed-res cases
47 int HiResFactor, // when base-res is multiple of 300
52 bool Process(RASTERDATA* pbyInputKRGBRaster);
54 void Restart(); // set up for new page or blanks
56 // items required by Processor
57 unsigned int GetMaxOutputWidth();
58 bool NextOutputRaster(RASTERDATA &next_raster);
61 unsigned int PlaneSize()
62 { return OutputWidth[iColor] / 8 + (OutputWidth[iColor] % 8); }
64 unsigned int ColorPlaneCount;
65 unsigned int InputWidth; // # of pixels input per colorplane
66 unsigned int OutputWidth[MAXCOLORPLANES]; // # of pixels output per colorplane
67 unsigned char ColorDepth[MAXCOLORPLANES];
68 // how many rows needed relative to base resolution -- all 1 unless mixed-res
69 unsigned char NumRows[MAXCOLORPLANES];
71 // for current interface, we must maintain mapping of
73 BYTE* ColorPlane[MAXCOLORPLANES][MAXCOLORROWS][MAXCOLORDEPTH];
75 unsigned int StartPlane; // since planes are ordered KCMY, if no K, this is 1
76 unsigned int EndPlane; // usually Y, could be Mlight
80 void Interpolate(const uint32_t *start,const unsigned long i,
81 unsigned char r,unsigned char g,unsigned char b,
82 unsigned char *blackout, unsigned char *cyanout,
83 unsigned char *magentaout, unsigned char *yellowout, bool);
86 bool Forward16PixelsNonWhite(BYTE * inputPtr)
88 // return ((*(uint32_t *)(inputPtr) != 0x0) || (*(((uint32_t *)(inputPtr)) + 1) != 0x0) ||
89 // (*(((uint32_t *)(inputPtr)) + 2) != 0x0) || (*(((uint32_t *)(inputPtr)) + 3) != 0x0));
90 for (int i=0; i < 16; i++)
92 if ((*inputPtr++) != 0)
100 bool Backward16PixelsNonWhite(BYTE * inputPtr)
102 // return ((*(uint32_t *)(inputPtr) != 0x0) || (*(((uint32_t *)(inputPtr)) - 1) != 0x0) ||
103 // (*(((uint32_t *)(inputPtr)) - 2) != 0x0) || (*(((uint32_t *)(inputPtr)) - 3) != 0x0));
104 for (int i=0; i < 16; i++)
106 if ((*inputPtr--) !=0 )
113 unsigned int getOutputWidth();
120 const unsigned char* fBlackFEDResPtr;
121 const unsigned char* fColorFEDResPtr;
123 unsigned int AdjustedInputWidth; // InputWidth padded to be divisible by 8
124 void PixelMultiply(unsigned char* buffer, unsigned int width, unsigned int factor);
126 unsigned int iColor, iRow, iPlane;
127 unsigned int PlaneCount(); // tells how many layers (colors,hifipe,multirow)
134 unsigned int oddbits;
135 void CleanOddBits(unsigned int iColor, unsigned int iRow);
137 uint32_t hold_random;
138 inline BYTE RandomNumber()
140 hold_random = (hold_random * 214013) + 2531011;
141 return (BYTE)((hold_random >> 16) & 0xFF);
145 typedef struct THTDitherParms
147 unsigned short fNumPix; // Dirty Pixels to be dithered
148 BYTE * fInput; // Pixel array to dither
149 BYTE * fOutput1; // Output raster binary & hifipe plane 1
150 BYTE * fOutput2; // Output raster hifipe plane 2 (2-bit)
151 BYTE * fOutput3; // Output raster hifipe plane 3 (3-bit)
153 const BYTE * fFEDResPtr; // brkpnt table
155 short * fErr; // Current error buffer
156 short fRasterEvenOrOdd;// Serpentine (Forward/Backward)
158 bool fSymmetricFlag; // Are we symmetric
160 bool fHifipe; // Are we doing Hifipe?
162 unsigned short fMatrixRowSize;
164 unsigned short fDitherCellOffset;
165 unsigned short fSqueezeOffset;
167 short * fWeightTablePtr; // Error Diffusion threshold table
168 short fOffsetPick; // Random# offset for threshold
169 bool fVerticalExpFlag; // Are we vertically expanding
170 } THTDitherParms, *THTDitherParmsPtr;
174 DRIVER_ERROR HTMATRIXHI_KCMY(THTDitherParmsPtr ditherParmsPtr, unsigned short count);
176 BYTE HPRand() // normalize to 5..79
177 { BYTE b=RandomNumber() % 74; b+= 5; return b; }
180 void HTEDiffOpen (THTDitherParmsPtr ditherParmsPtr,
181 unsigned short count);
183 THTDitherParms fDitherParms[6];
185 THTDitherParmsPtr ditherParms;
187 short *diffusionErrorPtr;
189 BYTE rasterByte1, rasterByte2, rasterByte3;
195 unsigned short numLoop;
202 const BYTE *fedResTbl;
203 const BYTE *fedResPtr;
211 void BACKWARD_FED(short thresholdValue, unsigned int bitMask);
212 void FORWARD_FED(short thresholdValue, unsigned int bitMask);
215 #endif // HALFTONER_H