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 \*****************************************************************************/
32 #ifndef APDK_HALFTONER_H
33 #define APDK_HALFTONER_H
34 //===========================================================================
36 // Filename : Halftoner.h
38 // Module : Open Source Imaging
40 // Description : This file contains the class declaration for Imaging.
42 //===========================================================================
50 // used to encourage consistent ordering of color planes
60 ////////////////////////////////////////////////////////////////////////////
63 // Encapsulation of buffers and data needed by Halftoner color-matching and
66 class Halftoner : public Processor
69 Halftoner(SystemServices* pSys,
71 unsigned int iInputWidth,
72 unsigned int iNumRows[], // for mixed-res cases
73 unsigned int HiResFactor, // when base-res is multiple of 300
78 virtual BOOL Process(RASTERDATA* pbyInputKRGBRaster=NULL) = 0;
81 DRIVER_ERROR constructor_error;
83 virtual void Restart(); // set up for new page or blanks
85 // items required by Processor
86 unsigned int GetOutputWidth(COLORTYPE rastercolor);
87 unsigned int GetMaxOutputWidth(COLORTYPE rastercolor);
88 BYTE* NextOutputRaster(COLORTYPE rastercolor);
91 unsigned int PlaneSize()
92 { return OutputWidth[iColor] / 8 + (OutputWidth[iColor] % 8); }
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];
101 // for current interface, we must maintain mapping of
102 // 0=K, 1=C, 2=M, 3=Y
103 BYTE* ColorPlane[MAXCOLORPLANES][MAXCOLORROWS][MAXCOLORDEPTH];
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;
111 SystemServices* pSS; // needed for memory management
115 HPBool Forward16PixelsNonWhite(HPBytePtr inputPtr)
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++)
121 if ((*inputPtr++) != 0)
129 HPBool Backward16PixelsNonWhite(HPBytePtr inputPtr)
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++)
135 if ((*inputPtr--) !=0 )
149 unsigned char* fBlackFEDResPtr;
150 unsigned char* fColorFEDResPtr;
152 unsigned int AdjustedInputWidth; // InputWidth padded to be divisible by 8
153 void PixelMultiply(unsigned char* buffer, unsigned int width, unsigned int factor);
155 unsigned int iColor, iRow, iPlane;
156 unsigned int PlaneCount(); // tells how many layers (colors,hifipe,multirow)
163 unsigned int oddbits;
164 void CleanOddBits(unsigned int iColor, unsigned int iRow);
166 HPUInt32 hold_random;
167 inline BYTE RandomNumber()
169 hold_random = (hold_random * 214013) + 2531011;
170 return (BYTE)((hold_random >> 16) & 0xFF);
174 typedef struct THTDitherParms
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)
182 HPCBytePtr fFEDResPtr; // brkpnt table
184 kSpringsErrorTypePtr fErr; // Current error buffer
185 HPInt16 fRasterEvenOrOdd;// Serpentine (Forward/Backward)
187 HPBool fSymmetricFlag; // Are we symmetric
189 HPBool fHifipe; // Are we doing Hifipe?
191 HPUInt16 fMatrixRowSize;
193 HPUInt16 fDitherCellOffset;
194 HPUInt16 fSqueezeOffset;
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);
203 DRIVER_ERROR HTMATRIXHI_KCMY(THTDitherParmsPtr ditherParmsPtr, HPUInt16 count);
209 #endif //APDK_HALFTONER_H