File: Hbpl1.cpp

package info (click to toggle)
hplip 3.22.10%2Bdfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 171,296 kB
  • sloc: python: 83,373; ansic: 71,016; cpp: 65,202; sh: 4,408; perl: 4,397; makefile: 937
file content (253 lines) | stat: -rw-r--r-- 8,568 bytes parent folder | download | duplicates (2)
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*****************************************************************************\
  Hbpl1.cpp : Implementation for the Hbpl1 class

  Copyright (c) 1996 - 2015, HP 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 HP 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.

  Author(s): Suma Byrappa
  Contributor(s): Sanjay Kumar, Goutam Kodu

\*****************************************************************************/


#include <dlfcn.h>
#include "Hbpl1.h"
#include "utils.h"
#define ZJC_BAND_HEIGHT    100
#define ON 1
#define OFF 0
#define COLOR 0
#define BLACKONLY 1
#define GRAYSCALE 2

Hbpl1Wrapper* (*fptr_create)(Hbpl1* const m_Hbpl1);
void (*fptr_destroy)(Hbpl1Wrapper*);
Hbpl1::Hbpl1 () : Encapsulator ()
{
    memset(&m_PM, 0, sizeof(m_PM));
    strcpy(m_szLanguage, "HBPL1");
    dbglog("Hbpl1 constructor : m_szLanguage = %s", m_szLanguage);
    m_numScanLines = -1; // value checked for allocating buffer
    m_nScanLineCount = 0;
    m_nStripSize = 0;
    m_nStripHeight = HBPL1_DEFAULT_STRIP_HEIGHT;
    m_nBandCount = 0;
    m_pbyStripData = NULL;
    m_init = false;
    m_ColorMode = COLORTYPE_BOTH; //Grayscale
    m_ColorTheme = NONE;

    /*m_hHPLibHandle = load_plugin_library(UTILS_PRINT_PLUGIN_LIBRARY, PRNT_PLUGIN_HBPL1);
    if (m_hHPLibHandle)
    {
        dlerror ();
        fptr_create = (Hbpl1Wrapper* (*)(Hbpl1*))get_library_symbol(m_hHPLibHandle, "create_object");
        fptr_destroy = (void (*)(Hbpl1Wrapper*))get_library_symbol(m_hHPLibHandle, "destroy_object");
        if (fptr_create != NULL && fptr_destroy!= NULL )
            m_init = true;

        if ((m_pHbpl1Wrapper = fptr_create(this)) == NULL)
             m_init = false;
    }*/
    m_pHbpl1Wrapper = new Hbpl1Wrapper(this);
    if(m_pHbpl1Wrapper == NULL)
	m_init = false;
    else
	m_init = true;
}

Hbpl1::~Hbpl1()
{
    if (m_pbyStripData)
    {
	delete [] m_pbyStripData;
	m_pbyStripData = NULL;
    }

    // unloading the library and delete Hbpl1Wrapper
    if(m_init)
    {
        if(fptr_destroy)
            fptr_destroy( m_pHbpl1Wrapper );

        //unload_library(m_hHPLibHandle);
        //m_hHPLibHandle = NULL;
    }
}


DRIVER_ERROR Hbpl1::addJobSettings()
{
    DRIVER_ERROR err = NO_ERROR;
    return err;
}


DRIVER_ERROR Hbpl1::Configure(Pipeline **pipeline)
{
    DRIVER_ERROR err = NO_ERROR;
    return err;
}

DRIVER_ERROR Hbpl1::StartJob(SystemServices *pSystemServices, JobAttributes *pJA)
{
    DRIVER_ERROR        err = NO_ERROR;

    if (!m_init)
    {
        return PLUGIN_LIBRARY_MISSING;
    }

    memcpy(&m_JA, pJA,sizeof(m_JA));
    m_nScanLineSize = m_JA.media_attributes.printable_width;
    m_nStripSize = m_nScanLineSize * 3 * m_nStripHeight;
    m_numStrips = m_JA.media_attributes.printable_height/m_nStripHeight;
   	m_Economode = (m_JA.integer_values[2] == ON) ? true : false;  //Economode
    m_ColorTheme = (COLORTHEME)m_JA.integer_values[5]; // cupsInteger5 value
    m_PrintinGrayscale = m_JA.integer_values[3]; // cupsInterger3 value
    m_pSystemServices = pSystemServices; //Reset and UEL not required
    err = m_pHbpl1Wrapper->StartJob((void**)&m_pOutBuffer, &m_OutBuffSize);
    err = sendBuffer(static_cast<const BYTE *>(m_pOutBuffer), m_OutBuffSize);
    m_pHbpl1Wrapper->FreeBuffer(m_pOutBuffer, m_OutBuffSize);
    
    if (m_PrintinGrayscale ==  ON){  //Grayscale = ON
        m_ColorMode = COLORTYPE_BOTH;
    } else if(m_JA.color_mode == COLOR){ // if color cartridge && Grayscale = OFF
        m_ColorMode = COLORTYPE_COLOR;
    } else if(m_JA.color_mode == BLACKONLY){ // if black cartridge && Grayscale = OFF
        m_ColorMode = COLORTYPE_BLACK;
    } else
        m_ColorMode = COLORTYPE_BOTH; //Grayscale

    return err;
}


DRIVER_ERROR Hbpl1::EndJob()
{
    DRIVER_ERROR        err = NO_ERROR;

     if (!m_init)
    {
        return PLUGIN_LIBRARY_MISSING;
    }

    err = m_pHbpl1Wrapper->EndJob((void**)&m_pOutBuffer, &m_OutBuffSize);
    err = sendBuffer(static_cast<const BYTE *>(m_pOutBuffer), m_OutBuffSize);
    m_pHbpl1Wrapper->FreeBuffer(m_pOutBuffer, m_OutBuffSize);
    return err;
}


DRIVER_ERROR Hbpl1::StartPage (JobAttributes *pJA)
{
    DRIVER_ERROR        err = NO_ERROR;

    err = m_pHbpl1Wrapper->StartPage((void**)&m_pOutBuffer, &m_OutBuffSize);
    err = sendBuffer(static_cast<const BYTE *>(m_pOutBuffer), m_OutBuffSize);
    m_pHbpl1Wrapper->FreeBuffer(m_pOutBuffer, m_OutBuffSize);
    return err;
}

// EndPage() will be called in FormFeed()


DRIVER_ERROR Hbpl1::sendBlankBands()
{
    DRIVER_ERROR err = NO_ERROR;
    return err;
}
/***********************************************************************************
FormFeed writes any remaining raster data at the end of the page.
For cases when the lines remaining at the end of the page are less than strip height,
FormFeed will put all such remaing lines from input raster into the OutBuffer.
And will reset scan lines counter to zero for next page(HPLIP-1041).
************************************************************************************/
DRIVER_ERROR Hbpl1::FormFeed ()
{

    if (0 != m_numScanLines && m_pbyStripData && 0 != m_nStripSize)
	{
		++m_nBandCount;
		m_pHbpl1Wrapper->Encapsulate(m_pbyStripData, m_nStripSize, m_nStripHeight, (void**)&m_pOutBuffer, &m_OutBuffSize);
		sendBuffer(m_pOutBuffer, m_OutBuffSize);
		memset(m_pbyStripData,0xFF,m_nStripSize);
	}

	while(m_nBandCount < m_numStrips)
	{
		++m_nBandCount;
		m_pHbpl1Wrapper->Encapsulate(m_pbyStripData, m_nStripSize, m_nStripHeight, (void**)&m_pOutBuffer, &m_OutBuffSize);
		sendBuffer(m_pOutBuffer, m_OutBuffSize);
	}

	m_pHbpl1Wrapper->EndPage((void**)&m_pOutBuffer, &m_OutBuffSize);
	sendBuffer(m_pOutBuffer, m_OutBuffSize);
    m_pHbpl1Wrapper->FreeBuffer(m_pOutBuffer,m_OutBuffSize);
	m_nBandCount = 0;
	m_numScanLines = 0;

	return NO_ERROR;

}

/***********************************************************************************
Encapsulate reads one strip at a time and puts it in the Out Buffer.
For a strip height of 128 we iterate through input StripData one scanline at a time
************************************************************************************/
DRIVER_ERROR    Hbpl1::Encapsulate (RASTERDATA *InputRaster, bool bLastPlane)
{
    DRIVER_ERROR    err = NO_ERROR;

    ++m_nScanLineCount;

    if ( m_numScanLines == -1)
    {
        if((int)m_JA.media_attributes.printable_height % m_nStripHeight)
        m_numStrips++;
        err = m_pHbpl1Wrapper->InitStripBuffer(m_nScanLineSize * 3 * m_nStripHeight);
    }

    if (m_numScanLines < m_nStripHeight && m_pbyStripData)
    {
        memcpy((BYTE*)&(m_pbyStripData[m_numScanLines * m_nScanLineSize * 3]),InputRaster->rasterdata[COLORTYPE_COLOR],InputRaster->rastersize[COLORTYPE_COLOR]);
        m_numScanLines++;
    }

    if (m_numScanLines >= m_nStripHeight && m_pbyStripData)
    {
        ++m_nBandCount;
        m_pHbpl1Wrapper->Encapsulate(m_pbyStripData, m_nStripSize, m_nStripHeight, (void**)&m_pOutBuffer, &m_OutBuffSize);
        memset(m_pbyStripData,0xFF,m_nStripSize);
        m_numScanLines = 0;
        err = sendBuffer(static_cast<const BYTE *>(m_pOutBuffer), m_OutBuffSize);
        m_pHbpl1Wrapper->FreeBuffer(m_pOutBuffer, m_OutBuffSize);
    }

    return err;
}