Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / ljm1005.cpp
1 /*****************************************************************************\
2   ljm1005.cpp : Implementation for the LJM1005 class
3
4   Copyright (c) 1996 - 2006, 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_LJM1005
32
33 #include "header.h"
34 #include "io_defs.h"
35 #include "printerproxy.h"
36 #include "resources.h"
37 #include "ljzjs.h"
38 #include "ljm1005.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 LJM1005::LJM1005 (SystemServices* pSS, int numfonts, BOOL proto)
47     : LJZjs (pSS, numfonts, proto)
48 {
49
50         ePen = BLACK_PEN;
51
52     pMode[GRAYMODE_INDEX]    = new LJM1005DraftGrayMode ();
53     pMode[DEFAULTMODE_INDEX] = new LJM1005NormalGrayMode ();
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 = 2;
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 = eLJM1005;
73 }
74
75 LJM1005::~LJM1005 ()
76 {
77 }
78
79 LJM1005DraftGrayMode::LJM1005DraftGrayMode ()
80 : GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
81 {
82     ResolutionX[0] =
83     ResolutionY[0] = 600;
84     BaseResX =
85     BaseResY = 600;
86     MixedRes = FALSE;
87     bFontCapable = FALSE;
88     theQuality = qualityDraft;
89     pmQuality = QUALITY_DRAFT;
90     Config.bCompress = FALSE;
91 }
92
93 LJM1005NormalGrayMode::LJM1005NormalGrayMode ()
94 : GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
95 {
96
97     ResolutionX[0] =
98     ResolutionY[0] = 600;
99     BaseResX =
100     BaseResY = 600;
101         TextRes  = 600;
102     MixedRes = FALSE;
103     bFontCapable = FALSE;
104     Config.bCompress = FALSE;
105 }
106 \r
107 DRIVER_ERROR LJM1005::Encapsulate (const RASTERDATA *pRasterData, BOOL bLastPlane)
108 {
109         if (pRasterData != NULL)
110         {
111         for (int i = 0; i < pRasterData->rastersize[COLORTYPE_COLOR]; i++)
112         {
113             m_pszCurPtr[i*m_iBPP]   = szByte1[pRasterData->rasterdata[COLORTYPE_COLOR][i]];
114             m_pszCurPtr[i*m_iBPP+1] = szByte2[pRasterData->rasterdata[COLORTYPE_COLOR][i]];
115             m_pszCurPtr[i*m_iBPP]   |= (m_pszCurPtr[i*m_iBPP] >> 1);
116             m_pszCurPtr[i*m_iBPP+1] |= (m_pszCurPtr[i*m_iBPP+1] >> 1);
117         }
118         }
119
120         m_dwCurrentRaster++;
121         m_pszCurPtr += (m_iBPP * m_dwWidth);
122     if (m_dwCurrentRaster == m_dwLastRaster)
123     {
124         JbigCompress ();
125     }
126     return NO_ERROR;
127 }
128
129 DRIVER_ERROR LJM1005::EndPage ()
130 {
131     DRIVER_ERROR        err = NO_ERROR;
132     BYTE                szStr[16];
133
134     memset (szStr, 0, 16);
135     szStr[3] = 0x06;
136     szStr[11] = 0x04;
137     err = Send ((const BYTE *) szStr, 16);
138
139     m_bStartPageSent = FALSE;
140
141     m_dwCurrentRaster = 0;
142     m_pszCurPtr = m_pszInputRasterData;
143
144     return err;
145 }
146
147 DRIVER_ERROR    LJM1005::SendPlaneData (int iPlaneNumber, HPLJZjsJbgEncSt *se, HPLJZjcBuff *pcBuff, BOOL bLastStride)
148 {
149     DRIVER_ERROR        err = NO_ERROR;
150     BYTE                szStr[128];
151     int                 i = 0;
152
153 /*
154  *  Send JBIG header info
155  */
156
157     memset (szStr, 0x0, 128);
158     szStr[3] = 0x05;
159     szStr[7] = 0x04;
160     i = 8;
161     i += SendIntItem (szStr+i, 0x80000000, 0x04, 0x40);
162     i += SendIntItem (szStr+i, 0x40000000, 0x04, 0x00);
163     i += SendIntItem (szStr+i, 0x40000002, 0x14, 0x00);
164     i -= 4;
165     szStr[i++] = se->dl;
166     szStr[i++] = se->d;
167     szStr[i++] = se->planes;
168     szStr[i++] = 0;
169     for (int j = 3; j >= 0; j--)
170     {
171         szStr[i] = (BYTE) ((se->xd  >> (8 * j)) & 0xFF);
172         szStr[4+i] = (BYTE) ((se->yd  >> (8 * j)) & 0xFF);
173         szStr[8+i] = (BYTE) ((se->l0  >> (8 * j)) & 0xFF);
174         i++;
175     }
176     i = 56;
177     szStr[i++] = se->mx;
178     szStr[i++] = se->my;
179     szStr[i++] = se->order;
180     szStr[i++] = se->options;
181     i += SendIntItem (szStr+i, 0x80000001, 0x04, 0xDEADBEEF);
182
183     BYTE    *p = pcBuff->pszCompressedData + 20;
184     int     iDataSize = pcBuff->dwTotalSize - 20;
185     char    szTmpStr[32];
186     memset (szTmpStr, 0x0, 32);
187     szTmpStr[3] = 0x07;
188     szTmpStr[5] = 0x01;
189     szTmpStr[19] = 0x06;
190     szTmpStr[27] = 0x04;
191     while (iDataSize > 65536)
192     {
193         err = Send ((const BYTE *) szStr, i);
194         ERRCHECK;
195         err = Send ((const BYTE *) szTmpStr, 8);
196         ERRCHECK;
197         err = Send ((const BYTE *) p, 65536);
198         ERRCHECK;
199         iDataSize -= 65536;
200         p += 65536;
201 //        err = Send ((const BYTE *) szTmpStr+16, 16);
202     }
203     if (iDataSize > 0)
204     {
205         err = Send ((const BYTE *) szStr, i);
206         ERRCHECK;
207         szTmpStr[5] = (char) ((iDataSize >> 16) & 0xFF);
208         szTmpStr[6] = (char) ((iDataSize >> 8) & 0xFF);
209         szTmpStr[7] = (char) (iDataSize & 0xFF);
210         err = Send ((const BYTE *) szTmpStr, 8);
211         ERRCHECK;
212         err = Send ((const BYTE *) p, iDataSize);
213         ERRCHECK;
214 //        err = Send ((const BYTE *) szTmpStr+16, 16);
215     }
216
217     return err;
218 }
219
220 DRIVER_ERROR LJM1005::VerifyPenInfo()
221 {
222     ePen = BLACK_PEN;
223     return NO_ERROR;
224 }
225
226 DRIVER_ERROR LJM1005::ParsePenInfo (PEN_TYPE& ePen, BOOL QueryPrinter)
227 {
228     ePen = BLACK_PEN;
229
230     return NO_ERROR;
231 }
232
233 APDK_END_NAMESPACE
234
235 #endif  // APDK_LJM1005
236