1
/*****************************************************************************\
2
ljcolor.cpp : Implimentation for the LJColor class
4
Copyright (c) 1996 - 2015, HP 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 HP 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
\*****************************************************************************/
37
#include "printerproxy.h"
38
#include "resources.h"
42
extern uint32_t ulMapDJ600_CCM_K[ 9 * 9 * 9 ];
43
extern uint32_t ulMapGRAY_K_6x6x1[9 * 9 * 9];
45
LJColor::LJColor (SystemServices* pSS, int numfonts, BOOL proto)
46
: Printer(pSS, numfonts, proto)
49
if ((!proto) && (IOMode.bDevID))
51
constructor_error = VerifyPenInfo();
54
else ePen = BOTH_PENS; // matches default mode
56
pMode[GRAYMODE_INDEX] = new LJColorGrayMode ();
57
pMode[DEFAULTMODE_INDEX] = new LJColor300DPIMode ();
58
pMode[SPECIALMODE_INDEX] = new LJColor600DPIMode ();
59
pMode[SPECIALMODE_INDEX+1] = new LJColor150DPIMode ();
60
pMode[SPECIALMODE_INDEX+2] = new LJColorKDraftMode ();
65
m_bJobStarted = FALSE;
66
#ifdef APDK_AUTODUPLEX
67
m_bRotateBackPage = FALSE; // Lasers don't require back side image to be rotated
69
#ifdef APDK_EXTENDED_MEDIASIZE
70
pMode[SPECIALMODE_INDEX+3] = new LJColorPlainBestMode ();
76
DBG1("LJColor created\n");
81
DISPLAY_STATUS eDispStatus;
82
if (IOMode.bStatus && m_bJobStarted)
84
for (int i = 0; i < 5; i++)
87
eDispStatus = ParseError (0);
88
if (eDispStatus == DISPLAY_PRINTING_COMPLETE)
90
pSS->DisplayPrinterStatus (eDispStatus);
97
LJColorKDraftMode::LJColorKDraftMode ()
98
: GrayMode (ulMapDJ600_CCM_K)
100
theQuality = qualityDraft;
101
pmQuality = QUALITY_DRAFT;
103
#ifdef APDK_AUTODUPLEX
104
bDuplexCapable = TRUE;
108
LJColorGrayMode::LJColorGrayMode () : GrayMode (ulMapGRAY_K_6x6x1)
115
#ifdef APDK_AUTODUPLEX
116
bDuplexCapable = TRUE;
120
LJColor150DPIMode::LJColor150DPIMode ()
123
ResolutionX[0] = ResolutionY[0] = 150;
124
BaseResX = BaseResY = 150;
126
Config.bColorImage = FALSE;
127
theQuality = qualityDraft;
128
pmQuality = QUALITY_DRAFT;
129
#ifdef APDK_AUTODUPLEX
130
bDuplexCapable = TRUE;
134
LJColor300DPIMode::LJColor300DPIMode ()
137
ResolutionX[0] = 300;
138
ResolutionY[0] = 300;
139
BaseResX = BaseResY = 300;
141
Config.bColorImage = FALSE;
142
theQuality = qualityNormal;
145
pmQuality = QUALITY_NORMAL;
146
Config.bColorImage = FALSE;
147
#ifdef APDK_AUTODUPLEX
148
bDuplexCapable = TRUE;
152
LJColor600DPIMode::LJColor600DPIMode ()
155
ResolutionX[0] = 600;
156
ResolutionY[0] = 600;
157
BaseResX = BaseResY = 600;
158
Config.bColorImage = FALSE;
159
theQuality = qualityPresentation;
161
pmQuality = QUALITY_BEST;
162
pmMediaType = MEDIA_PHOTO;
163
#ifdef APDK_AUTODUPLEX
164
bDuplexCapable = TRUE;
168
#ifdef APDK_EXTENDED_MEDIASIZE
169
LJColorPlainBestMode::LJColorPlainBestMode ()
172
ResolutionX[0] = 600;
173
ResolutionY[0] = 600;
174
BaseResX = BaseResY = 600;
176
Config.bColorImage = FALSE;
177
theQuality = qualityPresentation;
179
pmQuality = QUALITY_BEST;
180
#ifdef APDK_AUTODUPLEX
181
bDuplexCapable = TRUE;
186
HeaderLJColor::HeaderLJColor (Printer* p, PrintContext* pc)
190
DRIVER_ERROR HeaderLJColor::Send ()
195
COLORMODE eC = COLOR;
200
((LJColor *)thePrinter)->bGrey_K = FALSE;
201
if ((thePrintContext->GetPrintModeSettings (eQ, eM, eC, bD)) == NO_ERROR &&
204
((LJColor *)thePrinter)->bGrey_K = TRUE;
213
* Configure image data - ESC*v#W - # = 6 bytes
214
* 02 - RGB colorspace (00 - Device RGB)
216
* 08 - bits per index - ignored for direct pixel
217
* 08, 08, 08 - bits per primary each
220
err = thePrinter->Send ((const BYTE *) "\033*v6W\00\03\010\010\010\010", 11);
223
// Continues tone dither
224
// Logical operation - 0
226
// err = thePrinter->Send ((const BYTE *) "\033*t18J\033*l204O", 13);
227
err = thePrinter->Send ((const BYTE *) "\033*t18J", 6);
232
* Driver Configuration Command - ESC*#W - # = 3 bytes
233
* device id - 6 = color HP LaserJet Printer
234
* func index - 4 = Select Colormap
235
* argument - 2 = Vivid Graphics
238
err = thePrinter->Send ((const BYTE *) "\033*o3W\06\04\06", 8);
242
* Program color palette entries
244
err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v255B\033*v255C\033*v0I", 26);
247
err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v0B\033*v0C\033*v6I", 22);
249
err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v255B\033*v0C\033*v5I", 22);
251
err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v0B\033*v255C\033*v3I", 22);
253
err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v255B\033*v0C\033*v4I", 24);
255
err = thePrinter->Send ((const BYTE *) "\033*v255A\033*v0B\033*v255C\033*v2I", 24);
257
err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v255B\033*v255C\033*v1I", 24);
259
err = thePrinter->Send ((const BYTE *) "\033*v0A\033*v0B\033*v0C\033*v7I", 20);
263
sprintf (uom, "\033*r%dS", thePrintContext->OutputPixelsPerRow ());
264
err = thePrinter->Send ((const BYTE*)uom, strlen (uom));
267
err = Graphics (); // start raster graphics and set compression mode
272
DRIVER_ERROR HeaderLJColor::StartSend ()
278
iRes = thePrintContext->EffectiveResolutionY ();
280
err = thePrinter->Send ((const BYTE*)UEL,sizeof(UEL));
283
sprintf (res, "@PJL SET PAGEPROTECT=AUTO@PJL SET RESOLUTION=%d\015\012", iRes);
284
err = thePrinter->Send ((const BYTE *) res, strlen (res));
287
if (thePrinter->IOMode.bStatus)
289
sprintf (res, "@PJL JOB NAME = \"%ld\"\015\012", (long) (thePrinter));
290
err = thePrinter->Send ((const BYTE *) res, strlen (res));
294
QUALITY_MODE eQ = QUALITY_NORMAL;
299
thePrintContext->GetPrintModeSettings (eQ, eM, eC, bD);
301
if (eQ == QUALITY_DRAFT)
303
strcpy (res, "@PJL SET RET=OFF\015\012@PJL SET ECONOMODE=ON\015\012");
304
err = thePrinter->Send ((const BYTE *) res, strlen (res));
308
if (thePrinter->IOMode.bStatus)
310
strcpy (res, "@PJL USTATUSOFF\015\012@PJL USTATUS DEVICE = ON\015\012@PJL USTATUS JOB = ON\015\012");
311
err = thePrinter->Send ((const BYTE *) res, strlen (res));
315
// Duplexing directive
317
strcpy (res, "@PJL SET DUPLEX=OFF\015\012");
319
#ifdef APDK_AUTODUPLEX
320
DUPLEXMODE dupmode = thePrintContext->QueryDuplexMode ();
321
if (dupmode != DUPLEXMODE_NONE)
323
strcpy (res, "@PJL SET DUPLEX=ON\015\012@PJL SET BINDING=");
324
if (dupmode == DUPLEXMODE_BOOK)
325
strcat (res, "LONGEDGE\015\012");
327
strcat (res, "SHORTEDGE\015\012");
331
err = thePrinter->Send ((const BYTE *) res, strlen (res));
335
strcpy (res, "@PJL SET BINDING=LONGEDGE\015\012");
337
#ifdef APDK_AUTODUPLEX
338
if (thePrintContext->QueryDuplexMode () == DUPLEXMODE_TABLET)
340
strcpy (res, "@PJL SET BINDING=SHORTEDGE\015\012");
344
err = thePrinter->Send ((const BYTE *) res, strlen (res));
347
err = thePrinter->Send ((const BYTE*) EnterLanguage, sizeof (EnterLanguage));
350
err = thePrinter->Send ((const BYTE*) "PCL\015\012", 5);
353
err = thePrinter->Send ((const BYTE*) Reset,sizeof (Reset));
356
sprintf (res, "\033&l%dH", thePrintContext->GetMediaSource ());
357
err = thePrinter->Send ((const BYTE *) res, strlen (res)); // Source
360
// Media size, vertical spacing between lines and top margin
362
memcpy (res, mediasize, mscount - 1);
363
strcpy (res+mscount-1, "a8c0E");
364
err = thePrinter->Send ((const BYTE *) res, strlen (res));
367
sprintf (res, "\033*t%dR\033&u%dD", iRes, iRes);
368
err=thePrinter->Send ((const BYTE*) res, strlen (res));
375
// Default is single sided printing
377
strcpy (res, "\033&l0S");
379
#ifdef APDK_AUTODUPLEX
380
DUPLEXMODE eDupMode = thePrintContext->QueryDuplexMode ();
381
if (eDupMode != DUPLEXMODE_NONE)
383
sprintf (res, "\033&l%dS", (eDupMode == DUPLEXMODE_BOOK) ? 1 : 2);
386
err = thePrinter->Send ((const BYTE *) res, strlen (res));
390
* Set orientation to Portrait. APDK supports printing in Portrait mode only.
391
* If users desire Landscape printing, application/gluecode will have to
392
* rearrange the rasters appropriately.
395
err = thePrinter->Send ((const BYTE *) "\033&l0O", 5);
398
sprintf (res, "\033&l%dX", thePrintContext->GetCopyCount ());
399
err = thePrinter->Send ((const BYTE *) res, strlen (res));
405
DRIVER_ERROR HeaderLJColor::Graphics ()
409
err = thePrinter->Send ((const BYTE*) grafStart, sizeof (grafStart));
412
if (((LJColor *) thePrinter)->bGrey_K)
414
err = thePrinter->Send ((const BYTE*) "\033*b2M", 5);
419
err = thePrinter->Send ((const BYTE*) "\033*b3M", 5);
425
DRIVER_ERROR HeaderLJColor::EndJob ()
428
DRIVER_ERROR err = NO_ERROR;
429
if (thePrinter->IOMode.bStatus)
431
sprintf (szBuff, "\033E\033%%-12345X@PJL EOJ NAME = \"%ld\"\015\012@PJL RESET\015\012",
432
(long) (thePrinter));
433
err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
436
strcpy (szBuff, "\033%-12345X");
437
err = thePrinter->Send ((const BYTE *) szBuff, strlen (szBuff));
442
DRIVER_ERROR HeaderLJColor::FormFeed ()
444
((LJColor *)thePrinter)->bFGColorSet = FALSE;
445
((LJColor *)thePrinter)->m_iYPos = 0;
447
return (thePrinter->Send ((const BYTE *) "\014", 1));
450
DRIVER_ERROR HeaderLJColor::SendCAPy (unsigned int iAbsY)
454
return thePrinter->Send ((const BYTE *) "\033*p0Y", 5);
459
DRIVER_ERROR LJColor::Encapsulate (const RASTERDATA* InputRaster, BOOL bLastPlane)
461
char szScratchStr[16];
464
if (bFGColorSet == FALSE)
466
Send ((const BYTE *) "\033*v7S", 5);
469
sprintf (szScratchStr, "\033*b%uW", InputRaster->rastersize[COLORTYPE_COLOR]);
470
err = Send ((const BYTE *) szScratchStr, strlen (szScratchStr));
473
err = Send (InputRaster->rasterdata[COLORTYPE_COLOR], InputRaster->rastersize[COLORTYPE_COLOR]);
477
* Printers with low memory (64 MB or less) can run out of memory during decompressing
478
* the image data and will abort the job. To prevent this, restart raster command.
483
m_iYResolution == 600 &&
487
err = Send ((const BYTE *) "\033*rC\033*r1A\033*b3M", 14);
493
DRIVER_ERROR LJColor::SkipRasters (int nBlankRasters)
495
char szScratchStr[16];
496
DRIVER_ERROR err = NO_ERROR;
499
m_pCompressor->Flush ();
501
if (nBlankRasters > 0)
503
m_iYPos += nBlankRasters;
504
sprintf (szScratchStr, "\033*p%dY", m_iYPos);
505
err = Send ((const BYTE *) szScratchStr, strlen (szScratchStr));
511
Header* LJColor::SelectHeader (PrintContext *pc)
513
m_iYResolution = pc->EffectiveResolutionY ();
514
return new HeaderLJColor (this, pc);
517
DRIVER_ERROR LJColor::VerifyPenInfo()
520
DRIVER_ERROR err = NO_ERROR;
522
if(IOMode.bDevID == FALSE)
531
DRIVER_ERROR LJColor::ParsePenInfo(PEN_TYPE& ePen, BOOL QueryPrinter)
534
// DRIVER_ERROR err = SetPenInfo(str, QueryPrinter);
542
Compressor* LJColor::CreateCompressor (unsigned int RasterSize)
546
return new Mode2 (pSS, RasterSize);
548
m_pCompressor = new Mode3 (pSS, this, RasterSize);
549
return m_pCompressor;
553
* Function name: ParseError
555
* Owner: Darrell Walker
557
* Purpose: To determine what error state the printer is in.
561
* Parameters on entry: status_reg is the contents of the centronics
562
* status register (at the time the error was
565
* Parameters on exit: unchanged
567
* Return Values: The proper DISPLAY_STATUS to reflect the printer
572
/* We have to override the base class's (Printer) ParseError function due
573
to the fact that the 8XX series returns a status byte of F8 when it's out of
574
paper. Unfortunately, the 600 series returns F8 when they're turned off.
575
The way things are structured in Printer::ParseError, we used to check only
576
for DEVICE_IS_OOP. This would return true even if we were connected to a
577
600 series printer that was turned off, causing the Out of paper status
578
message to be displayed. This change also reflects a corresponding change
579
in IO_defs.h, where I split DEVICE_IS_OOP into DEVICE_IS_OOP, DJ400_IS_OOP, and
580
DJ8XX_IS_OOP and we now check for DJ8XX_IS_OOP in the DJ8xx class's
581
ParseError function below. 05/11/99 DGC.
584
DISPLAY_STATUS LJColor::ParseError(BYTE status_reg)
586
DBG1("LJColor: parsing error info\n");
588
DRIVER_ERROR err = NO_ERROR;
589
BYTE szReadBuff[256];
590
DWORD iReadCount = 256;
591
DISPLAY_STATUS eStatus = (DISPLAY_STATUS) status_reg;
598
memset (szReadBuff, 0, 256);
599
err = pSS->FromDevice (szReadBuff, &iReadCount);
600
if (err == NO_ERROR && iReadCount == 0)
603
if (strstr ((char *) szReadBuff, "JOB"))
605
if (!(tmpStr = strstr ((char *) szReadBuff, "NAME")))
606
return DISPLAY_PRINTING;
608
while (*tmpStr < '0' || *tmpStr > '9')
610
sscanf (tmpStr, "%d", &iErrorCode);
611
if (iErrorCode != (long) (this))
612
return DISPLAY_PRINTING;
615
if (strstr ((char *) szReadBuff, "END"))
617
return DISPLAY_PRINTING_COMPLETE;
621
if (strstr ((char *) szReadBuff, "CANCEL"))
622
return DISPLAY_PRINTING_CANCELED;
624
if (!(tmpStr = strstr ((char *) szReadBuff, "CODE")))
628
while (*tmpStr < '0' || *tmpStr > '9')
630
sscanf (tmpStr, "%d", &iErrorCode);
632
if (iErrorCode < 32000)
633
return DISPLAY_PRINTING;
635
if (iErrorCode == 40010 || iErrorCode == 40020)
636
return DISPLAY_NO_PENS; // Actually, out of toner
638
if (iErrorCode == 40021)
639
return DISPLAY_TOP_COVER_OPEN;
641
if ((iErrorCode / 100) == 419)
642
return DISPLAY_OUT_OF_PAPER;
644
if ((iErrorCode / 1000) == 42 || iErrorCode == 40022)
646
DBG1("Paper Jammed\n");
647
return DISPLAY_PAPER_JAMMED;
650
if (iErrorCode > 40049 && iErrorCode < 41000)
653
return DISPLAY_ERROR_TRAP;
656
if (iErrorCode == 40079)
657
return DISPLAY_OFFLINE;
659
return DISPLAY_ERROR_TRAP;
664
#endif // defined APDK_LJCOLOR