Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / ljzjsmono.cpp
1 /*****************************************************************************\
2   ljzjsmono.cpp : Implementation for the LJZjsMono class
3
4   Copyright (c) 1996 - 2007, 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 #ifdef APDK_LJZJS_MONO
32
33 #include "header.h"
34 #include "io_defs.h"
35 #include "printerproxy.h"
36 #include "resources.h"
37 #include "ljzjs.h"
38 #include "ljzjsmono.h"
39
40 APDK_BEGIN_NAMESPACE
41
42 extern uint32_t ulMapGRAY_K_6x6x1[9 * 9 * 9];
43
44 extern uint32_t ulMapDJ600_CCM_K[9 * 9 * 9];
45
46 LJZjsMono::LJZjsMono (SystemServices* pSS, int numfonts, BOOL proto)
47     : LJZjs (pSS, numfonts, proto)
48 {
49
50     ePen = BLACK_PEN;
51
52     pMode[GRAYMODE_INDEX]    = new LJZjsMonoDraftGrayMode ();
53     pMode[DEFAULTMODE_INDEX] = new LJZjsMonoNormalGrayMode ();
54     ModeCount = 2;
55
56     CMYMap = NULL;
57 #ifdef  APDK_AUTODUPLEX
58     m_bRotateBackPage = FALSE;  // Lasers don't require back side image to be rotated
59 #endif
60     m_pszInputRasterData = NULL;
61     m_dwCurrentRaster = 0;
62     m_cmColorMode = GREY_K;
63     m_bStartPageSent = FALSE;
64     m_iPlaneNumber = 0;
65     m_iBPP = 1;
66     for (int i = 1; i < 4; i++)
67     {
68         m_iP[i] = i - 1; //{3, 0, 1, 2};
69     }
70     m_iP[0] = 0;
71     m_bIamColor = FALSE;
72     m_iPrinterType = eLJZjsMono;
73 }
74
75 LJZjsMono::~LJZjsMono ()
76 {
77 }
78
79 LJZjsMonoDraftGrayMode::LJZjsMonoDraftGrayMode ()
80 : GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
81 {
82
83     ResolutionX[0] =
84     ResolutionY[0] = 600;
85     BaseResX =
86     BaseResY = 600;
87     MixedRes = FALSE;
88     bFontCapable = FALSE;
89     theQuality = qualityDraft;
90     pmQuality = QUALITY_DRAFT;
91 #ifdef APDK_AUTODUPLEX
92     bDuplexCapable = TRUE;
93 #endif
94     Config.bCompress = FALSE;
95     medium = mediaAuto;    // compatible with any media type
96 }
97
98 LJZjsMonoNormalGrayMode::LJZjsMonoNormalGrayMode ()
99 : GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
100 {
101
102     ResolutionX[0] =
103     ResolutionY[0] = 600;
104     BaseResX =
105     BaseResY = 600;
106     TextRes  = 600;
107     MixedRes = FALSE;
108     bFontCapable = FALSE;
109 #ifdef APDK_AUTODUPLEX
110     bDuplexCapable = TRUE;
111 #endif
112     Config.bCompress = FALSE;
113     medium = mediaAuto;    // compatible with any media type
114 }
115
116 DRIVER_ERROR LJZjsMono::Encapsulate (const RASTERDATA *pRasterData, BOOL bLastPlane)
117 {
118     if (pRasterData != NULL)
119     {
120         memcpy (m_pszCurPtr, pRasterData->rasterdata[COLORTYPE_COLOR],
121                 pRasterData->rastersize[COLORTYPE_COLOR]);
122     }
123
124     m_dwCurrentRaster++;
125     m_pszCurPtr += m_dwWidth;
126     if (m_dwCurrentRaster == m_dwLastRaster)
127     {
128         JbigCompress ();
129     }
130     return NO_ERROR;
131 }
132
133 DRIVER_ERROR LJZjsMono::EndPage ()
134 {
135     DRIVER_ERROR        err = NO_ERROR;
136     BYTE                szStr[16];
137
138     SendChunkHeader (szStr, 16, ZJT_END_PAGE, 0);
139     err = Send ((const BYTE *) szStr, 16);
140
141     m_bStartPageSent = FALSE;
142
143     m_dwCurrentRaster = 0;
144     m_pszCurPtr = m_pszInputRasterData;
145
146     return err;
147 }
148
149 DRIVER_ERROR    LJZjsMono::SendPlaneData (int iPlaneNumber, HPLJZjsJbgEncSt *se, HPLJZjcBuff *pcBuff, BOOL bLastStride)
150 {
151     DRIVER_ERROR        err = NO_ERROR;
152     BYTE                szStr[36];
153     int                 i = 0;
154
155 /*
156  *  Send JBIG header info
157  */
158
159     i = SendChunkHeader (szStr, 36, ZJT_JBIG_BIH, 0);
160
161     memcpy (szStr + 16, pcBuff->pszCompressedData, 20);
162     err = Send ((const BYTE *) szStr, 36);
163     ERRCHECK;
164
165     pcBuff->dwTotalSize -= 20;
166     int     iPadCount = 0;
167     if (pcBuff->dwTotalSize % 16)
168     {
169         iPadCount = ((pcBuff->dwTotalSize / 16 + 1) * 16) - pcBuff->dwTotalSize;
170     }
171     DWORD    dwTotal = pcBuff->dwTotalSize;
172     BYTE     *p = pcBuff->pszCompressedData + 20;
173     i = dwTotal / 65536;
174     for (int j = 0; j < i; j++)
175     {
176         SendChunkHeader (szStr, 16 + 65536, ZJT_JBIG_HID, 0);
177         err = Send ((const BYTE *) szStr, 16);
178         err = Send ((const BYTE *) p, 65536);
179         dwTotal -= 65536;
180         p += 65536;
181     }
182     i = SendChunkHeader (szStr, 16 + dwTotal + iPadCount, ZJT_JBIG_HID, 0);
183     err = Send ((const BYTE *) szStr, 16);
184     err = Send ((const BYTE *) p, dwTotal);
185     ERRCHECK;
186     if (iPadCount != 0)
187     {
188         memset (szStr, 0, iPadCount);
189         err = Send ((const BYTE *) szStr, iPadCount);
190     }
191     i = SendChunkHeader (szStr, 16, ZJT_END_JBIG, 0);
192     err = Send ((const BYTE *) szStr, 16);
193     return err;
194 }
195
196 DRIVER_ERROR LJZjsMono::VerifyPenInfo()
197 {
198     ePen = BLACK_PEN;
199     return NO_ERROR;
200 }
201
202 DRIVER_ERROR LJZjsMono::ParsePenInfo (PEN_TYPE& ePen, BOOL QueryPrinter)
203 {
204     ePen = BLACK_PEN;
205
206     return NO_ERROR;
207 }
208
209 APDK_END_NAMESPACE
210
211 #endif  // APDK_LJZJS_MONO