~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to prnt/hpcups/LJZxStream.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-14 20:08:44 UTC
  • mfrom: (2.1.118 lucid)
  • Revision ID: james.westby@ubuntu.com-20091214200844-z8qhqwgppbu3t7ze
Tags: 3.9.10-4
KBSD patch from KiBi (Closes: #560796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************\
 
2
  LJZxStream.cpp : Implementation for the LJZxStream class
 
3
 
 
4
  Copyright (c) 1996 - 2009, 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
#include "CommonDefinitions.h"
 
32
#include "Pipeline.h"
 
33
#include "Encapsulator.h"
 
34
#include "ColorMatcher.h"
 
35
#include "Halftoner.h"
 
36
#include "ModeJbig.h"
 
37
#include "resources.h"
 
38
#include "ColorMaps.h"
 
39
#include "PrinterCommands.h"
 
40
#include "LJZxStream.h"
 
41
#include "Utils.h"
 
42
#include "hpjbig_wrapper.h"
 
43
 
 
44
LJZxStream::LJZxStream () : Encapsulator ()
 
45
{
 
46
    memset(&m_PM, 0, sizeof(m_PM));
 
47
    strcpy(m_szLanguage, "ZJS");
 
48
    m_pModeJbig = NULL;
 
49
}
 
50
 
 
51
LJZxStream::~LJZxStream()
 
52
{
 
53
}
 
54
 
 
55
DRIVER_ERROR LJZxStream::addJobSettings()
 
56
{
 
57
    char    szStr[256];
 
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)
 
64
    {
 
65
        strcpy (szStr+strlen (szStr), "ON\x0D\x0A");
 
66
    }
 
67
    else
 
68
    {
 
69
        strcpy (szStr+strlen (szStr), "OFF\x0D\x0A");
 
70
    }
 
71
    addToHeader ((const BYTE *) szStr, strlen (szStr));
 
72
 
 
73
    strcpy (szStr, "\x1B\x25-12345X,XQX");
 
74
    addToHeader ((const BYTE *) szStr, strlen (szStr));
 
75
    memset (szStr, 0x0, 92);
 
76
    szStr[3] = 0x01;
 
77
    szStr[7] = 0x07;
 
78
    int i = 8;
 
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();
 
88
    return err;
 
89
}
 
90
 
 
91
DRIVER_ERROR LJZxStream::Configure(Pipeline **pipeline)
 
92
{
 
93
    DRIVER_ERROR err;
 
94
    Pipeline    *p = NULL;
 
95
    Pipeline    *head;
 
96
    unsigned int width;
 
97
    ColorMatcher *pColorMatcher;
 
98
    Halftoner    *pHalftoner;
 
99
    int          iRows[MAXCOLORPLANES];
 
100
    unsigned int uiResBoost;
 
101
    head = *pipeline;
 
102
 
 
103
/*
 
104
 *  I need a flag in the printmode structure to whether create a CMYGraymap
 
105
 *  and set the ulMap1 to it.
 
106
 */
 
107
 
 
108
    m_PM.dyeCount = 1;
 
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;
 
113
    m_PM.eHT = FED;
 
114
    m_PM.BlackFEDTable = HTBinary_open;
 
115
    m_PM.ColorFEDTable = HTBinary_open;
 
116
    m_PM.MixedRes = false;
 
117
 
 
118
    for (int i = 0; i < MAXCOLORPLANES; i++)
 
119
    {
 
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;
 
123
    }
 
124
    uiResBoost = m_PM.BaseResX / m_PM.BaseResY;
 
125
    if (uiResBoost == 0)
 
126
        uiResBoost = 1;
 
127
 
 
128
    width = m_pMA->printable_width;
 
129
 
 
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);
 
134
    head->AddPhase(p);
 
135
    m_pModeJbig = new ModeJbig(width);
 
136
    p = new Pipeline(m_pModeJbig);
 
137
    head->AddPhase(p);
 
138
    m_pModeJbig->myplane = COLORTYPE_COLOR;
 
139
    err = m_pModeJbig->Init(m_pMA->printable_height, 1, 2, ZXSTREAM);
 
140
 
 
141
    *pipeline = head;
 
142
    return err;
 
143
}
 
144
 
 
145
DRIVER_ERROR LJZxStream::StartPage (JobAttributes *pJA)
 
146
{
 
147
    DRIVER_ERROR    err;
 
148
    BYTE    szStr[256];
 
149
    int     i;
 
150
    int    iOutputResolution = m_pJA->integer_values[1];
 
151
    int    width;
 
152
 
 
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));
 
157
    szStr[3] = 0x03;
 
158
    szStr[7] = 0x0F;
 
159
    err = sendBuffer ((const BYTE *) szStr, 8);
 
160
    i = 0;
 
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);
 
177
    return err;
 
178
}
 
179
 
 
180
DRIVER_ERROR LJZxStream::FormFeed ()
 
181
{
 
182
    BYTE                szStr[16];
 
183
    memset(szStr, 0, sizeof(szStr));
 
184
    szStr[3] = 0x06;
 
185
    szStr[11] = 0x04;
 
186
    return sendBuffer ((const BYTE *) szStr, 16);
 
187
}
 
188
 
 
189
DRIVER_ERROR LJZxStream::EndJob()
 
190
{
 
191
    char    szStr[64];
 
192
    memset(szStr, 0, sizeof(szStr));
 
193
    szStr[3] = 2;
 
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));
 
196
}
 
197
 
 
198
DRIVER_ERROR    LJZxStream::Encapsulate (RASTERDATA *raster, bool bLastPlane)
 
199
{
 
200
    DRIVER_ERROR        err = NO_ERROR;
 
201
    BYTE                szStr[128];
 
202
    int                 i = 0;
 
203
    HPLJZjsJbgEncSt     *se = (HPLJZjsJbgEncSt *) (raster->rasterdata[COLORTYPE_COLOR] + raster->rastersize[COLORTYPE_COLOR]);
 
204
 
 
205
/*
 
206
 *  Send JBIG header info
 
207
 */
 
208
 
 
209
    memset (szStr, 0x0, 128);
 
210
    szStr[3] = 0x05;
 
211
    szStr[7] = 0x04;
 
212
    i = 8;
 
213
    i += SendIntItem (szStr+i, 0x80000000, 0x04, 0x40);
 
214
    i += SendIntItem (szStr+i, 0x40000000, 0x04, 0x00);
 
215
    i += SendIntItem (szStr+i, 0x40000002, 0x14, 0x00);
 
216
    i -= 4;
 
217
    szStr[i++] = se->dl;
 
218
    szStr[i++] = se->d;
 
219
    szStr[i++] = se->planes;
 
220
    szStr[i++] = 0;
 
221
    for (int j = 3; j >= 0; j--)
 
222
    {
 
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);
 
226
        i++;
 
227
    }
 
228
    i = 56;
 
229
    szStr[i++] = se->mx;
 
230
    szStr[i++] = se->my;
 
231
    szStr[i++] = se->order;
 
232
    szStr[i++] = se->options;
 
233
    i += SendIntItem (szStr+i, 0x80000001, 0x04, 0xDEADBEEF);
 
234
 
 
235
    BYTE    *p = raster->rasterdata[COLORTYPE_COLOR] + 20;
 
236
    int     iDataSize = raster->rastersize[COLORTYPE_COLOR] - 20;
 
237
    char    szTmpStr[32];
 
238
    memset (szTmpStr, 0x0, 32);
 
239
    szTmpStr[3] = 0x07;
 
240
    szTmpStr[5] = 0x01;
 
241
    szTmpStr[19] = 0x06;
 
242
    szTmpStr[27] = 0x04;
 
243
    while (iDataSize > 65536)
 
244
    {
 
245
        err = sendBuffer ((const BYTE *) szStr, i);
 
246
        ERRCHECK;
 
247
        err = sendBuffer ((const BYTE *) szTmpStr, 8);
 
248
        ERRCHECK;
 
249
        err = sendBuffer ((const BYTE *) p, 65536);
 
250
        ERRCHECK;
 
251
        iDataSize -= 65536;
 
252
        p += 65536;
 
253
//        err = sendBuffer ((const BYTE *) szTmpStr+16, 16);
 
254
    }
 
255
    if (iDataSize > 0)
 
256
    {
 
257
        err = sendBuffer ((const BYTE *) szStr, i);
 
258
        ERRCHECK;
 
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);
 
263
        ERRCHECK;
 
264
        err = sendBuffer ((const BYTE *) p, iDataSize);
 
265
        ERRCHECK;
 
266
//        err = sendBuffer ((const BYTE *) szTmpStr+16, 16);
 
267
    }
 
268
 
 
269
    return err;
 
270
}
 
271