summaryrefslogtreecommitdiff
path: root/prnt/hpijs/ljm1005.cpp
blob: 72635542165df300a51e1369632d72651c40e85c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*****************************************************************************\
  ljm1005.cpp : Implementation for the LJM1005 class

  Copyright (c) 1996 - 2006, Hewlett-Packard Co.
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  3. Neither the name of Hewlett-Packard nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*****************************************************************************/

#ifdef APDK_LJM1005

#include "header.h"
#include "io_defs.h"
#include "printerproxy.h"
#include "resources.h"
#include "ljzjs.h"
#include "ljm1005.h"

APDK_BEGIN_NAMESPACE

extern uint32_t ulMapGRAY_K_6x6x1[9 * 9 * 9];

extern uint32_t ulMapDJ600_CCM_K[9 * 9 * 9];

LJM1005::LJM1005 (SystemServices* pSS, int numfonts, BOOL proto)
    : LJZjs (pSS, numfonts, proto)
{

	ePen = BLACK_PEN;

    pMode[GRAYMODE_INDEX]    = new LJM1005DraftGrayMode ();
    pMode[DEFAULTMODE_INDEX] = new LJM1005NormalGrayMode ();
    ModeCount = 2;

    CMYMap = NULL;
#ifdef  APDK_AUTODUPLEX
    m_bRotateBackPage = FALSE;  // Lasers don't require back side image to be rotated
#endif
    m_pszInputRasterData = NULL;
    m_dwCurrentRaster = 0;
    m_cmColorMode = GREY_K;
    m_bStartPageSent = FALSE;
	m_iPlaneNumber = 0;
	m_iBPP = 2;
	for (int i = 1; i < 4; i++)
	{
		m_iP[i] = i - 1; //{3, 0, 1, 2};
	}
    m_iP[0] = 0;
    m_bIamColor = FALSE;
    m_iPrinterType = eLJM1005;
}

LJM1005::~LJM1005 ()
{
}

LJM1005DraftGrayMode::LJM1005DraftGrayMode ()
: GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
{
    ResolutionX[0] =
    ResolutionY[0] = 600;
    BaseResX =
    BaseResY = 600;
    MixedRes = FALSE;
    bFontCapable = FALSE;
    theQuality = qualityDraft;
    pmQuality = QUALITY_DRAFT;
    Config.bCompress = FALSE;
}

LJM1005NormalGrayMode::LJM1005NormalGrayMode ()
: GrayMode(/*ulMapDJ600_CCM_K*/ulMapGRAY_K_6x6x1)
{

    ResolutionX[0] =
    ResolutionY[0] = 600;
    BaseResX =
    BaseResY = 600;
	TextRes  = 600;
    MixedRes = FALSE;
    bFontCapable = FALSE;
    Config.bCompress = FALSE;
}

DRIVER_ERROR LJM1005::Encapsulate (const RASTERDATA *pRasterData, BOOL bLastPlane)
{
	if (pRasterData != NULL)
	{
        for (int i = 0; i < pRasterData->rastersize[COLORTYPE_COLOR]; i++)
        {
            m_pszCurPtr[i*m_iBPP]   = szByte1[pRasterData->rasterdata[COLORTYPE_COLOR][i]];
            m_pszCurPtr[i*m_iBPP+1] = szByte2[pRasterData->rasterdata[COLORTYPE_COLOR][i]];
            m_pszCurPtr[i*m_iBPP]   |= (m_pszCurPtr[i*m_iBPP] >> 1);
            m_pszCurPtr[i*m_iBPP+1] |= (m_pszCurPtr[i*m_iBPP+1] >> 1);
        }
	}

	m_dwCurrentRaster++;
	m_pszCurPtr += (m_iBPP * m_dwWidth);
    if (m_dwCurrentRaster == m_dwLastRaster)
    {
        JbigCompress ();
    }
    return NO_ERROR;
}

DRIVER_ERROR LJM1005::EndPage ()
{
    DRIVER_ERROR        err = NO_ERROR;
    BYTE                szStr[16];

    memset (szStr, 0, 16);
    szStr[3] = 0x06;
    szStr[11] = 0x04;
    err = Send ((const BYTE *) szStr, 16);

    m_bStartPageSent = FALSE;

    m_dwCurrentRaster = 0;
    m_pszCurPtr = m_pszInputRasterData;

    return err;
}

DRIVER_ERROR    LJM1005::SendPlaneData (int iPlaneNumber, HPLJZjsJbgEncSt *se, HPLJZjcBuff *pcBuff, BOOL bLastStride)
{
    DRIVER_ERROR        err = NO_ERROR;
    BYTE                szStr[128];
    int                 i = 0;

/*
 *  Send JBIG header info
 */

    memset (szStr, 0x0, 128);
    szStr[3] = 0x05;
    szStr[7] = 0x04;
    i = 8;
    i += SendIntItem (szStr+i, 0x80000000, 0x04, 0x40);
    i += SendIntItem (szStr+i, 0x40000000, 0x04, 0x00);
    i += SendIntItem (szStr+i, 0x40000002, 0x14, 0x00);
    i -= 4;
    szStr[i++] = se->dl;
    szStr[i++] = se->d;
    szStr[i++] = se->planes;
    szStr[i++] = 0;
    for (int j = 3; j >= 0; j--)
    {
        szStr[i] = (BYTE) ((se->xd  >> (8 * j)) & 0xFF);
        szStr[4+i] = (BYTE) ((se->yd  >> (8 * j)) & 0xFF);
        szStr[8+i] = (BYTE) ((se->l0  >> (8 * j)) & 0xFF);
        i++;
    }
    i = 56;
    szStr[i++] = se->mx;
    szStr[i++] = se->my;
    szStr[i++] = se->order;
    szStr[i++] = se->options;
    i += SendIntItem (szStr+i, 0x80000001, 0x04, 0xDEADBEEF);

    BYTE    *p = pcBuff->pszCompressedData + 20;
    int     iDataSize = pcBuff->dwTotalSize - 20;
    char    szTmpStr[32];
    memset (szTmpStr, 0x0, 32);
    szTmpStr[3] = 0x07;
    szTmpStr[5] = 0x01;
    szTmpStr[19] = 0x06;
    szTmpStr[27] = 0x04;
    while (iDataSize > 65536)
    {
        err = Send ((const BYTE *) szStr, i);
        ERRCHECK;
        err = Send ((const BYTE *) szTmpStr, 8);
        ERRCHECK;
        err = Send ((const BYTE *) p, 65536);
        ERRCHECK;
        iDataSize -= 65536;
        p += 65536;
//        err = Send ((const BYTE *) szTmpStr+16, 16);
    }
    if (iDataSize > 0)
    {
        err = Send ((const BYTE *) szStr, i);
        ERRCHECK;
        szTmpStr[5] = (char) ((iDataSize >> 16) & 0xFF);
        szTmpStr[6] = (char) ((iDataSize >> 8) & 0xFF);
        szTmpStr[7] = (char) (iDataSize & 0xFF);
        err = Send ((const BYTE *) szTmpStr, 8);
        ERRCHECK;
        err = Send ((const BYTE *) p, iDataSize);
        ERRCHECK;
//        err = Send ((const BYTE *) szTmpStr+16, 16);
    }

    return err;
}

DRIVER_ERROR LJM1005::VerifyPenInfo()
{
    ePen = BLACK_PEN;
    return NO_ERROR;
}

DRIVER_ERROR LJM1005::ParsePenInfo (PEN_TYPE& ePen, BOOL QueryPrinter)
{
    ePen = BLACK_PEN;

    return NO_ERROR;
}

APDK_END_NAMESPACE

#endif  // APDK_LJM1005