1 /*****************************************************************************\
2 Job.cpp : Implementation of Job class
4 Copyright (c) 1996 - 2001, 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 \*****************************************************************************/
46 DRIVER_ERROR Job::Init(SystemServices *pSystemServices, JobAttributes *job_attrs, Encapsulator *encap_intf)
48 DRIVER_ERROR err = NO_ERROR;
50 if (encap_intf == NULL) {
51 return NO_PRINTER_SELECTED;
54 m_pEncap = encap_intf;
55 m_pSys = pSystemServices;
57 //m_job_attributes = job_attrs;
58 memcpy(&m_job_attributes, job_attrs, sizeof(m_job_attributes));
60 err = m_pEncap->StartJob(m_pSys, &m_job_attributes);
65 // Setup the blank raster used by sendrasters
67 err = setBlankRaster();
71 /*! Allows the encapsulator to prepare for a new page
75 DRIVER_ERROR Job::StartPage(JobAttributes *job_attrs)
79 memcpy(&m_job_attributes, job_attrs, sizeof(m_job_attributes));
81 return m_pEncap->StartPage(&m_job_attributes);
84 DRIVER_ERROR Job::Cleanup()
86 // Client isn't required to call NewPage at end of last page, so
87 // we may need to eject a page now.
88 DRIVER_ERROR err = NO_ERROR;
91 * Let the encapsulator cleanup, such as sending previous page if speed mech
96 err = m_pEncap->Cleanup();
99 if (err != NO_ERROR) {
103 if (m_bDataSent || err != NO_ERROR) {
107 // Tell printer that job is over.
114 void Job::CancelJob()
117 m_pEncap->CancelJob();
122 if (m_pBlackRaster) {
123 delete [] m_pBlackRaster;
126 if (m_pBlankRaster) {
127 delete [] m_pBlankRaster;
147 void Job::unpackBits(BYTE *BlackImageData)
149 // Convert K from 1-bit raster to 8-bit raster.
150 unsigned char bitflag[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
151 int width = (m_job_attributes.media_attributes.printable_width + 7) / 8;
152 for (int i = 0; i < width; i++)
154 for (int j = 0; j < 8; j++)
156 if (BlackImageData[i] & bitflag[j])
157 m_pBlackRaster[i*8+j] = 1;
162 DRIVER_ERROR Job::SendRasters(BYTE* BlackImageData, BYTE* ColorImageData)
164 DRIVER_ERROR err = NO_ERROR;
165 if (m_pPipeline == NULL) {
169 if (BlackImageData == NULL && ColorImageData == NULL) {
170 if (m_pEncap->CanSkipRasters()) {
174 ColorImageData = m_pBlankRaster;
178 m_pPipeline->Flush();
179 err = m_pEncap->SendCAPy(skipcount);
184 if (BlackImageData || ColorImageData)
188 if (m_pEncap->UnpackBits())
190 err = setBlackRaster();
192 unpackBits(BlackImageData);
193 BlackImageData = m_pBlackRaster;
195 m_pPipeline->Exec->raster.rastersize[COLORTYPE_BLACK] = m_job_attributes.media_attributes.printable_width;
196 m_pPipeline->Exec->raster.rasterdata[COLORTYPE_BLACK] = BlackImageData;
200 m_pPipeline->Exec->raster.rastersize[COLORTYPE_BLACK] = 0;
201 m_pPipeline->Exec->raster.rasterdata[COLORTYPE_BLACK] = NULL;
205 m_pPipeline->Exec->raster.rastersize[COLORTYPE_COLOR] = m_job_attributes.media_attributes.printable_width * 3;
206 m_pPipeline->Exec->raster.rasterdata[COLORTYPE_COLOR] = ColorImageData;
210 m_pPipeline->Exec->raster.rastersize[COLORTYPE_COLOR] = 0;
211 m_pPipeline->Exec->raster.rasterdata[COLORTYPE_COLOR] = NULL;
213 err = m_pPipeline->Execute(&(m_pPipeline->Exec->raster));
219 DRIVER_ERROR Job::NewPage()
222 m_pEncap->SetLastBand();
224 if (!m_bDataSent && skipcount > 0) {
226 SendRasters(NULL, m_pBlankRaster);
228 m_pPipeline->Flush();
229 err = m_pEncap->FormFeed();
232 // reset flag used to see if formfeed needed
239 DRIVER_ERROR Job::Configure()
241 // mode has been set -- now set up rasterwidths and pipeline
242 DRIVER_ERROR err = NO_ERROR;
246 // Ask Encapsulator to configure itself
248 err = m_pEncap->Configure(&m_pPipeline);
254 // always end pipeline with RasterSender
255 // create RasterSender object
256 RasterSender *pSender;
257 pSender = new RasterSender(m_pEncap);
259 p = new Pipeline(pSender);
262 m_pPipeline->AddPhase(p);
270 DRIVER_ERROR Job::setBlackRaster()
272 if (!m_pBlackRaster) {
273 m_pBlackRaster = new BYTE[m_job_attributes.media_attributes.printable_width];
274 NEWCHECK(m_pBlackRaster);
276 memset(m_pBlackRaster, 0, m_job_attributes.media_attributes.printable_width);
281 DRIVER_ERROR Job::setBlankRaster()
283 if (m_pBlankRaster) {
284 delete m_pBlankRaster;
286 size_t size = m_job_attributes.media_attributes.printable_width * 3;
287 m_pBlankRaster = new BYTE[size];
288 NEWCHECK(m_pBlankRaster);
289 memset(m_pBlankRaster, 0xFF, size);
293 DRIVER_ERROR Job::preProcessRasterData(cups_raster_t **ppcups_raster, cups_page_header2_t* firstpage_cups_header, char* pPreProcessedRasterFile)
295 dbglog ("DEBUG: Job::preProcessRasterData.............. \n");
296 return m_pEncap->preProcessRasterData(ppcups_raster, firstpage_cups_header, pPreProcessedRasterFile);