1 /*****************************************************************************\
2 htmtxhi.cpp : Implimentation for Multilevel (HiFipe) dither matrix
4 Copyright (c) 1994 - 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 \*****************************************************************************/
31 //===========================================================================
33 // Filename : HTMTXHI.CPP
35 // Module : Interlaken
37 // Description : Multilevel(HiFipe) dither matrix based halftoning
39 //============================================================================
41 //=============================================================================
42 // Header file dependencies
43 //=============================================================================
46 #ifndef INCLUDED_HPENVTYP
49 #ifndef INCLUDED_HTINTF
52 #ifndef INCLUDED_HTWORLD
55 #ifndef INCLUDED_HPASSERT
58 #ifndef INCLUDED_HTMATRIX
64 #include "halftoner.h"
68 #define Dither4LevelHiFipe(matrix,bitMask)\
70 tone = (*inputPtr++ );\
71 fedResPtr = fedResTbl + (tone << 2);\
72 level = *fedResPtr++;\
73 if (*(fedResPtr) >= (HPByte)matrix )\
82 rasterByte1 |= bitMask;\
85 rasterByte2 |= bitMask;\
88 rasterByte2 |= bitMask; rasterByte1 |= bitMask;\
91 rasterByte3 |= bitMask;\
94 rasterByte3 |= bitMask; rasterByte1 |= bitMask;\
97 rasterByte3 |= bitMask; rasterByte2 |= bitMask;\
100 rasterByte3 |= bitMask; rasterByte2 |= bitMask; rasterByte1 |= bitMask;\
105 // Each dither matrix has a header of five bytes
106 // 1st byte (Size (in bytes) of row in the matrix) - 1
107 // 2nd byte Size (in bytes) of row in the matrix
108 // 3rd byte Black offset
109 // 4th byte Cyan offset
110 // 5th byte Magenta offset
112 // With matrix actually starting on the 6th Byte.
114 // Black, cyan, and magenta are all offset into different
115 // locations in the dither matrix. (Yellow uses the same offsets as
119 // Ditherparms should be set up as Fed with the following additions
120 // ditherParms->fSqueezeOffset = first dirty pixel, if white has been skipped at the beginning of the row
121 // ditherParmsPtr->fMatrixRowSize = Byte 2 of the Header
122 // ditherParmsPtr->fDitherCellOffset = Black, Cyan, or Magenta Offset respectively
124 // To select the right row of the matrix for each color
126 // ditherParms->fMatrixV1 = ((matrixStart + rasterIndex + DitherCellOffset) % (MatrixRowSize)) * (MatrixRowSize)
128 DRIVER_ERROR Halftoner::HTMATRIXHI_KCMY (THTDitherParmsPtr ditherParmsPtr,
132 #pragma unused(envP1)
135 THTDitherParmsPtr ditherParms = ditherParmsPtr+count;
137 HPUInt8 rasterByte1,rasterByte2, rasterByte3;
141 HPUInt16 numLoop = ditherParms->fNumPix;
142 HPBytePtr inputPtr = ditherParms->fInput;
143 HPBytePtr outputPtr1, outputPtr2, outputPtr3;
145 HPBytePtr fedResTbl = (HPBytePtr)ditherParms->fFEDResPtr;
148 HPBytePtr matrixV = ditherParms->fMatrixV1;
151 HPUInt16 matrixRowSize = ditherParms->fMatrixRowSize;
157 outputPtr1 = ditherParms->fOutput1;
158 outputPtr2 = ditherParms->fOutput2;
159 outputPtr3 = ditherParms->fOutput3;
161 if (!ditherParms->fSymmetricFlag)
162 return SYSTEM_ERROR; // matrixHI_KCMY asymetric not supported
164 index = (ditherParms->fDitherCellOffset + ditherParms->fSqueezeOffset) % (matrixRowSize);
165 matrixH = matrixV + index;
167 for (pixelCount = numLoop + 8; (pixelCount -= 8) > 0; )
169 // if we've reached end of matrix we need to reset
170 // our row pointer to the start of the row
171 if ( index == matrixRowSize )
177 Dither4LevelHiFipe(*matrixH,0x80);
179 Dither4LevelHiFipe(*matrixH,0x40);
181 Dither4LevelHiFipe(*matrixH,0x20);
183 Dither4LevelHiFipe(*matrixH,0x10);
185 Dither4LevelHiFipe(*matrixH,0x08);
187 Dither4LevelHiFipe(*matrixH,0x04);
189 Dither4LevelHiFipe(*matrixH,0x02);
191 Dither4LevelHiFipe(*matrixH,0x01);
194 *outputPtr1++ |= rasterByte1;
196 *outputPtr2++ |= rasterByte2;
205 unsigned char BayerMatrix[] =
207 0x07, 0x08, 0x00, 0x00, 0x00,
208 0x2, 0x82, 0x22, 0xa2, 0xa, 0x8a, 0x2a, 0xaa,
209 0xc2, 0x42, 0xe2, 0x62, 0xca, 0x4a, 0xea, 0x6a,
210 0x32, 0xb2, 0x12, 0x92, 0x3a, 0xba, 0x1a, 0x9a,
211 0xf2, 0x72, 0xd2, 0x52, 0xfa, 0x7a, 0xda, 0x5a,
212 0xe, 0x8e, 0x2e, 0xae, 0x6, 0x86, 0x26, 0xa6,
213 0xce, 0x4e, 0xee, 0x6e, 0xc6, 0x46, 0xe6, 0x66,
214 0x3e, 0xbe, 0x1e, 0x9e, 0x36, 0xb6, 0x16, 0x96,
215 0xfe, 0x7e, 0xde, 0x5e, 0xf6, 0x76, 0xd6, 0x56,