1
/*****************************************************************************\
2
LJZjStream.cpp : Implementation for the LJZjStream 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 "LJZjStream.h"
42
#include "hpjbig_wrapper.h"
44
#define ZJC_BAND_HEIGHT 100
46
LJZjStream::LJZjStream () : Encapsulator ()
48
memset(&m_PM, 0, sizeof(m_PM));
49
strcpy(m_szLanguage, "ZJS");
54
LJZjStream::~LJZjStream()
58
DRIVER_ERROR LJZjStream::addJobSettings()
60
BYTE cItems[3] = {ZJI_DMCOLLATE, ZJI_PAGECOUNT, ZJI_DMDUPLEX};
61
addToHeader("%s", "\x1B\x25-12345X@PJL ENTER LANGUAGE=ZJS\x0AJZJZ");
62
BYTE *p = cur_pcl_buffer_ptr;
70
for (int j = 0; j < 3; j++)
74
p[i + 6] = ZJIT_UINT32;
78
cur_pcl_buffer_ptr += i;
79
DRIVER_ERROR err = Cleanup();
83
DRIVER_ERROR LJZjStream::Configure(Pipeline **pipeline)
89
ColorMatcher *pColorMatcher;
90
Halftoner *pHalftoner;
91
int iRows[MAXCOLORPLANES];
92
unsigned int uiResBoost;
96
* I need a flag in the printmode structure to whether create a CMYGraymap
97
* and set the ulMap1 to it.
100
m_PM.BaseResX = m_pQA->horizontal_resolution;
101
m_PM.BaseResY = m_pQA->vertical_resolution;
103
m_PM.MixedRes = false;
104
m_PM.BlackFEDTable = HTBinary_open;
105
if (m_pJA->color_mode == 0)
107
m_PM.cmap.ulMap1 = NULL;
108
m_PM.cmap.ulMap2 = NULL;
109
m_PM.cmap.ulMap3 = ucMapDJ4100_KCMY_Photo_BestA_12x12x1;
111
m_PM.ColorFEDTable = HT1200x1200x1PhotoBest_open;
115
m_PM.cmap.ulMap1 = ulMapDJ600_CCM_K;
117
m_PM.ColorFEDTable = HTBinary_open;
120
for (int i = 0; i < MAXCOLORPLANES; i++)
122
m_PM.ColorDepth[i] = 1;
123
m_PM.ResolutionX[i] = m_pQA->horizontal_resolution;
124
m_PM.ResolutionY[i] = m_pQA->vertical_resolution;
125
iRows[i] = m_PM.ResolutionX[i] / m_PM.BaseResX;
128
uiResBoost = m_PM.BaseResX / m_PM.BaseResY;
132
width = m_pMA->printable_width;
134
pColorMatcher = new ColorMatcher(m_PM.cmap, m_PM.dyeCount, width);
135
head = new Pipeline(pColorMatcher);
136
pHalftoner = new Halftoner (&m_PM, width, iRows, uiResBoost, m_PM.eHT == MATRIX);
137
p = new Pipeline(pHalftoner);
139
m_pModeJbig = new ModeJbig(width);
140
p = new Pipeline(m_pModeJbig);
142
m_pModeJbig->myplane = COLORTYPE_COLOR;
146
int height = m_pMA->printable_height;
147
ZJPLATFORM ezj_platform = ZJSTREAM;
148
if (!strcmp(m_pJA->printer_platform, "ljzjscolor"))
151
ezj_platform = ZJCOLOR;
152
if (m_pJA->color_mode == 0)
156
height = ZJC_BAND_HEIGHT;
158
err = m_pModeJbig->Init(height, m_iPlanes, m_iBpp, ezj_platform);
164
DRIVER_ERROR LJZjStream::StartPage (JobAttributes *pJA)
166
DRIVER_ERROR err = NO_ERROR;
167
DWORD dwNumItems = 14;
168
BYTE szStr[16 + 15 * 12];
175
width = ((m_pMA->printable_width + 31) / 32) * 32;
176
if (m_pJA->color_mode == 0)
180
i += SendChunkHeader (szStr, 16 + dwNumItems * 12, ZJT_START_PAGE, dwNumItems);
181
if (m_pJA->color_mode == 0)
183
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_PLANE, m_iPlanes);
186
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_DMPAPER, m_pMA->pcl_id);
187
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_DMCOPIES, 1);
188
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_DMDEFAULTSOURCE, m_pJA->media_source);
189
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_DMMEDIATYPE, m_pQA->media_type);
190
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_NBIE, m_iPlanes);
191
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_RESOLUTION_X, m_pQA->horizontal_resolution);
192
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_RESOLUTION_Y, m_pQA->vertical_resolution);
193
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_RASTER_X, width * m_iBpp);
194
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_RASTER_Y, m_pMA->printable_height);
195
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_VIDEO_BPP, m_iBpp);
196
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_VIDEO_X, width);
197
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_VIDEO_Y, m_pMA->printable_height);
198
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_RET, RET_ON);
199
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_TONER_SAVE, (m_pQA->print_quality == -1) ? 1 : 0);
201
err = sendBuffer ((const BYTE *) szStr, i);
205
DRIVER_ERROR LJZjStream::sendBlankBands()
207
if (strcmp(m_pJA->printer_platform, "ljzjscolor"))
211
DRIVER_ERROR err = NO_ERROR;
212
int remaining_rasters = m_pMA->printable_height - m_iCurRaster;
213
int num_planes = (m_pJA->color_mode == 0) ? 4 : 1;
214
if (remaining_rasters <= 0)
219
RASTERDATA raster_data;
220
if (remaining_rasters < ZJC_BAND_HEIGHT)
222
memset(&raster_data, 0, sizeof(raster_data));
223
m_pModeJbig->SetBandHeight(remaining_rasters);
224
for (int k = 0; k < num_planes; k++)
226
m_pModeJbig->Flush();
227
m_pModeJbig->NextOutputRaster(raster_data);
228
err = Encapsulate(&raster_data, true);
232
m_pModeJbig->SetBandHeight(ZJC_BAND_HEIGHT);
236
memset(&raster_data, 0, sizeof(raster_data));
237
m_pModeJbig->Process(&raster_data);
238
m_pModeJbig->Flush();
239
m_pModeJbig->NextOutputRaster(raster_data);
240
while (remaining_rasters > 0)
242
for (int k = 0; k < num_planes; k++)
244
err = Encapsulate(&raster_data, true);
250
remaining_rasters -= ZJC_BAND_HEIGHT;
252
if (remaining_rasters <= 0)
257
memset(&raster_data, 0, sizeof(raster_data));
258
m_pModeJbig->SetBandHeight(remaining_rasters);
259
m_pModeJbig->Process(&raster_data);
260
m_pModeJbig->Flush();
261
m_pModeJbig->NextOutputRaster(raster_data);
262
for (int k = 0; k < num_planes; k++)
264
err = Encapsulate(&raster_data, true);
266
m_pModeJbig->SetBandHeight(ZJC_BAND_HEIGHT);
271
DRIVER_ERROR LJZjStream::FormFeed ()
273
DRIVER_ERROR err = NO_ERROR;
277
err = sendBlankBands();
281
SendChunkHeader (szStr, 16, ZJT_END_PAGE, 0);
282
if (!strcmp(m_pJA->printer_platform, "ljzjscolor"))
285
int iCol = (m_pJA->color_mode == 0) ? 1 : 0;
287
memset(szStr, 0, sizeof(szStr));
288
i = SendChunkHeader (szStr, 112, ZJT_END_PAGE, 8);
289
for (int j = 0; j < 8; j++)
291
i += SendItem (szStr+i, ZJIT_UINT32, 0x8200+j, (j % 4 == 3) ? 1 : iCol);
296
err = sendBuffer ((const BYTE *) szStr, size);
301
DRIVER_ERROR LJZjStream::EndJob()
304
memset(szStr, 0, sizeof(szStr));
306
szStr[7] = ZJT_END_DOC;
309
return this->sendBuffer((const BYTE *) szStr, 16);
312
DRIVER_ERROR LJZjStream::Encapsulate (RASTERDATA *raster, bool bLastPlane)
314
if (raster->rasterdata[COLORTYPE_COLOR] == NULL || raster->rastersize[COLORTYPE_COLOR] == 0)
318
if (!strcmp(m_pJA->printer_platform, "ljzjscolor"))
320
return encapsulateColor(raster);
323
DRIVER_ERROR err = NO_ERROR;
326
int iTotalSize = raster->rastersize[COLORTYPE_COLOR];
329
* Send JBIG header info
332
i = SendChunkHeader (szStr, 36, ZJT_JBIG_BIH, 0);
334
memcpy (szStr + 16, raster->rasterdata[COLORTYPE_COLOR], 20);
335
err = sendBuffer ((const BYTE *) szStr, 36);
342
iPadCount = ((iTotalSize / 16 + 1) * 16) - iTotalSize;
344
int dwTotal = iTotalSize;
345
BYTE *p = raster->rasterdata[COLORTYPE_COLOR] + 20;
348
for (int j = 0; j < i; j++)
350
SendChunkHeader (szStr, 16 + 65536, ZJT_JBIG_HID, 0);
351
err = sendBuffer ((const BYTE *) szStr, 16);
353
err = sendBuffer ((const BYTE *) p, 65536);
358
i = SendChunkHeader (szStr, 16 + dwTotal + iPadCount, ZJT_JBIG_HID, 0);
359
err = sendBuffer ((const BYTE *) szStr, 16);
361
err = sendBuffer ((const BYTE *) p, dwTotal);
365
memset (szStr, 0, iPadCount);
366
err = sendBuffer ((const BYTE *) szStr, iPadCount);
368
i = SendChunkHeader (szStr, 16, ZJT_END_JBIG, 0);
370
err = sendBuffer ((const BYTE *) szStr, 16);
375
DRIVER_ERROR LJZjStream::encapsulateColor (RASTERDATA *raster)
377
bool bLastStride = true;
379
DRIVER_ERROR err = NO_ERROR;
383
HPLJZjsJbgEncSt *se = (HPLJZjsJbgEncSt *) (raster->rasterdata[COLORTYPE_COLOR] + raster->rastersize[COLORTYPE_COLOR]);
385
if (m_pJA->color_mode == 0)
389
if (m_iPlaneNumber == 0 || m_pJA->color_mode != 0)
390
m_iCurRaster += se->yd;
391
if (m_iCurRaster < m_pMA->printable_height)
398
* Send JBIG header info
401
// Send out the JBIG header if first plane and it hasn't already been sent out yet.
402
if (m_iPlaneNumber == 0 && m_bNotSent)
406
for (int k = 1; k < kEnd; k++)
408
i = SendChunkHeader (szStr, 132, ZJT_BITMAP, 8);
410
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_TYPE, 1);
411
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_PIXELS, se->xd);
412
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_STRIDE, se->xd);
413
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_LINES, se->yd);
414
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_BPP, 1);
415
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_VIDEO_BPP, m_iBpp);
416
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_PLANE,
417
(m_pJA->color_mode == 0) ? k : 4);
418
i += SendItemExtra (szStr+i, ZJIT_BYTELUT, ZJI_ENCODING_DATA, 20, 20);
421
szStr[i++] = se->planes;
423
for (int j = 3; j >= 0; j--)
425
szStr[i] = (BYTE) ((se->xd >> (8 * j)) & 0xFF);
426
szStr[4+i] = (BYTE) ((se->yd >> (8 * j)) & 0xFF);
427
szStr[8+i] = (BYTE) ((se->l0 >> (8 * j)) & 0xFF);
434
szStr[i++] = se->order;
435
szStr[i++] = se->options;
436
err = sendBuffer ((const BYTE *) szStr, 132);
441
BYTE *p = raster->rasterdata[COLORTYPE_COLOR] + 20;
445
DWORD dwTotalSize = raster->rastersize[COLORTYPE_COLOR];
452
iPadCount = ((dwTotalSize / 4 + 1) * 4) - dwTotalSize;
455
dwSize = 16 + dwTotalSize + iPadCount;
462
dwSize += (dwNumItems * 12);
463
i = SendChunkHeader (szStr, dwSize, ZJT_BITMAP, dwNumItems);
464
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_PLANE, (kEnd == 5) ? m_iPlaneNumber+1 : 4);
467
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_BITMAP_LINES, se->yd);
468
i += SendItem (szStr+i, ZJIT_UINT32, ZJI_END_PLANE, bLastStride);
470
err = sendBuffer ((const BYTE *) szStr, i);
473
err = sendBuffer ((const BYTE *) p, dwTotalSize);
477
memset (szStr, 0, iPadCount);
478
err = sendBuffer ((const BYTE *) szStr, iPadCount);
481
if (m_pJA->color_mode == 0)
484
if (m_iPlaneNumber == 4)