1
/*****************************************************************************\
2
LJZxStream.cpp : Implementation for the LJZxStream class
4
Copyright (c) 1996 - 2009, 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
#include "CommonDefinitions.h"
33
#include "Encapsulator.h"
34
#include "ColorMatcher.h"
35
#include "Halftoner.h"
37
#include "resources.h"
38
#include "ColorMaps.h"
39
#include "PrinterCommands.h"
40
#include "LJZxStream.h"
42
#include "hpjbig_wrapper.h"
44
LJZxStream::LJZxStream () : Encapsulator ()
46
memset(&m_PM, 0, sizeof(m_PM));
47
strcpy(m_szLanguage, "ZJS");
51
LJZxStream::~LJZxStream()
55
DRIVER_ERROR LJZxStream::addJobSettings()
58
strcpy (szStr, "\x1B\x25-12345X@PJL JOB\x0D\x0A");
59
strcpy (szStr+strlen (szStr), "@PJL SET JAMRECOVERY=OFF\x0D\x0A");
60
strcpy (szStr+strlen (szStr), "@PJL SET DENSITY=3\x0D\x0A");
61
strcpy (szStr+strlen (szStr), "@PJL SET RET=MEDIUM\x0D\x0A");
62
strcpy (szStr+strlen (szStr), "@PJL SET ECONOMODE=");
63
if (m_pQA->print_quality == -1)
65
strcpy (szStr+strlen (szStr), "ON\x0D\x0A");
69
strcpy (szStr+strlen (szStr), "OFF\x0D\x0A");
71
addToHeader ((const BYTE *) szStr, strlen (szStr));
73
strcpy (szStr, "\x1B\x25-12345X,XQX");
74
addToHeader ((const BYTE *) szStr, strlen (szStr));
75
memset (szStr, 0x0, 92);
79
i += SendIntItem ((BYTE *) szStr+i, 0x80000000, 0x04, 0x54);
80
i += SendIntItem ((BYTE *) szStr+i, 0x10000005, 0x04, 0x01);
81
i += SendIntItem ((BYTE *) szStr+i, 0x10000001, 0x04, 0x00);
82
i += SendIntItem ((BYTE *) szStr+i, 0x10000002, 0x04, 0x00);
83
i += SendIntItem ((BYTE *) szStr+i, 0x10000000, 0x04, 0x00);
84
i += SendIntItem ((BYTE *) szStr+i, 0x10000003, 0x04, 0x01);
85
i += SendIntItem ((BYTE *) szStr+i, 0x80000001, 0x04, 0xDEADBEEF);
86
addToHeader ((const BYTE *) szStr, i);
87
DRIVER_ERROR err = Cleanup();
91
DRIVER_ERROR LJZxStream::Configure(Pipeline **pipeline)
97
ColorMatcher *pColorMatcher;
98
Halftoner *pHalftoner;
99
int iRows[MAXCOLORPLANES];
100
unsigned int uiResBoost;
104
* I need a flag in the printmode structure to whether create a CMYGraymap
105
* and set the ulMap1 to it.
109
m_PM.ColorDepth[0] = 1;
110
m_PM.cmap.ulMap1 = ulMapDJ600_CCM_K;
111
m_PM.BaseResX = m_pQA->horizontal_resolution;
112
m_PM.BaseResY = m_pQA->vertical_resolution;
114
m_PM.BlackFEDTable = HTBinary_open;
115
m_PM.ColorFEDTable = HTBinary_open;
116
m_PM.MixedRes = false;
118
for (int i = 0; i < MAXCOLORPLANES; i++)
120
m_PM.ResolutionX[i] = m_pQA->horizontal_resolution;
121
m_PM.ResolutionY[i] = m_pQA->vertical_resolution;
122
iRows[i] = m_PM.ResolutionX[i] / m_PM.BaseResX;
124
uiResBoost = m_PM.BaseResX / m_PM.BaseResY;
128
width = m_pMA->printable_width;
130
pColorMatcher = new ColorMatcher(m_PM.cmap, m_PM.dyeCount, width);
131
head = new Pipeline(pColorMatcher);
132
pHalftoner = new Halftoner (&m_PM, width, iRows, uiResBoost, m_PM.eHT == MATRIX);
133
p = new Pipeline(pHalftoner);
135
m_pModeJbig = new ModeJbig(width);
136
p = new Pipeline(m_pModeJbig);
138
m_pModeJbig->myplane = COLORTYPE_COLOR;
139
err = m_pModeJbig->Init(m_pMA->printable_height, 1, 2, ZXSTREAM);
145
DRIVER_ERROR LJZxStream::StartPage (JobAttributes *pJA)
150
int iOutputResolution = m_pJA->integer_values[1];
153
width = ((m_pMA->printable_width + 31) / 32) * 32;
154
if (m_pQA->print_quality == 0)
155
iOutputResolution = m_pQA->vertical_resolution;
156
memset (szStr, 0x0, sizeof (szStr));
159
err = sendBuffer ((const BYTE *) szStr, 8);
161
i += SendIntItem (szStr+i, 0x80000000, 0x04, 0xB4);
162
i += SendIntItem (szStr+i, 0x20000005, 0x04, 0x01);
163
i += SendIntItem (szStr+i, 0x20000006, 0x04, 0x07);
164
i += SendIntItem (szStr+i, 0x20000000, 0x04, 0x01);
165
i += SendIntItem (szStr+i, 0x20000007, 0x04, 0x01);
166
i += SendIntItem (szStr+i, 0x20000008, 0x04, m_pQA->horizontal_resolution);
167
i += SendIntItem (szStr+i, 0x20000009, 0x04, iOutputResolution);
168
i += SendIntItem (szStr+i, 0x2000000D, 0x04, width * 2);
169
i += SendIntItem (szStr+i, 0x2000000E, 0x04, m_pMA->printable_height);
170
i += SendIntItem (szStr+i, 0x2000000A, 0x04, 2);
171
i += SendIntItem (szStr+i, 0x2000000F, 0x04, width);
172
i += SendIntItem (szStr+i, 0x20000010, 0x04, m_pMA->printable_height);
173
i += SendIntItem (szStr+i, 0x20000011, 0x04, 0x01);
174
i += SendIntItem (szStr+i, 0x20000001, 0x04, m_pMA->pcl_id);
175
i += SendIntItem (szStr+i, 0x80000001, 0x04, 0xDEADBEEF);
176
err = sendBuffer ((const BYTE *) szStr, i);
180
DRIVER_ERROR LJZxStream::FormFeed ()
183
memset(szStr, 0, sizeof(szStr));
186
return sendBuffer ((const BYTE *) szStr, 16);
189
DRIVER_ERROR LJZxStream::EndJob()
192
memset(szStr, 0, sizeof(szStr));
194
strcpy (szStr+8, "\x1B\x25-12345X@PJL EOJ\x0D\x0A\x1B\x25-12345X");
195
return this->sendBuffer((const BYTE *) szStr, 8 + strlen(szStr+8));
198
DRIVER_ERROR LJZxStream::Encapsulate (RASTERDATA *raster, bool bLastPlane)
200
DRIVER_ERROR err = NO_ERROR;
203
HPLJZjsJbgEncSt *se = (HPLJZjsJbgEncSt *) (raster->rasterdata[COLORTYPE_COLOR] + raster->rastersize[COLORTYPE_COLOR]);
206
* Send JBIG header info
209
memset (szStr, 0x0, 128);
213
i += SendIntItem (szStr+i, 0x80000000, 0x04, 0x40);
214
i += SendIntItem (szStr+i, 0x40000000, 0x04, 0x00);
215
i += SendIntItem (szStr+i, 0x40000002, 0x14, 0x00);
219
szStr[i++] = se->planes;
221
for (int j = 3; j >= 0; j--)
223
szStr[i] = (BYTE) ((se->xd >> (8 * j)) & 0xFF);
224
szStr[4+i] = (BYTE) ((se->yd >> (8 * j)) & 0xFF);
225
szStr[8+i] = (BYTE) ((se->l0 >> (8 * j)) & 0xFF);
231
szStr[i++] = se->order;
232
szStr[i++] = se->options;
233
i += SendIntItem (szStr+i, 0x80000001, 0x04, 0xDEADBEEF);
235
BYTE *p = raster->rasterdata[COLORTYPE_COLOR] + 20;
236
int iDataSize = raster->rastersize[COLORTYPE_COLOR] - 20;
238
memset (szTmpStr, 0x0, 32);
243
while (iDataSize > 65536)
245
err = sendBuffer ((const BYTE *) szStr, i);
247
err = sendBuffer ((const BYTE *) szTmpStr, 8);
249
err = sendBuffer ((const BYTE *) p, 65536);
253
// err = sendBuffer ((const BYTE *) szTmpStr+16, 16);
257
err = sendBuffer ((const BYTE *) szStr, i);
259
szTmpStr[5] = (char) ((iDataSize >> 16) & 0xFF);
260
szTmpStr[6] = (char) ((iDataSize >> 8) & 0xFF);
261
szTmpStr[7] = (char) (iDataSize & 0xFF);
262
err = sendBuffer ((const BYTE *) szTmpStr, 8);
264
err = sendBuffer ((const BYTE *) p, iDataSize);
266
// err = sendBuffer ((const BYTE *) szTmpStr+16, 16);