Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpcups / LJMono.cpp
1 /*****************************************************************************\
2   LJMono.cpp : Implementation of LJMono 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 "LJMono.h"
33 #include "ColorMatcher.h"
34 #include "Halftoner.h"
35 #include "Mode2.h"
36 #include "resources.h"
37 #include "ColorMaps.h"
38 #include "PrinterCommands.h"
39
40 LJMono::LJMono() : Encapsulator()
41 {
42     memset(&m_PM, 0, sizeof(m_PM));
43     strcpy(m_szLanguage, "PCL");
44 }
45
46 LJMono::~LJMono()
47 {
48 }
49
50 DRIVER_ERROR LJMono::addJobSettings()
51 {
52     cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
53         "@PJL SET PAGEPROTECT=AUTO\012@PJL SET RESOLUTION=%d\012@PJL SET DENSITY=5\012", m_pQA->horizontal_resolution);
54     if (m_pQA->print_quality == -1)
55     {
56         cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
57                               "@PJL SET RET=OFF\012@PJL SET ECONOMODE=ON\012");
58     }
59     if (m_pJA->e_duplex_mode != DUPLEXMODE_NONE)
60     {
61         cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
62             "@PJL SET DUPLEX=ON\012@PJL SET BINDING=%s\012",
63             (m_pJA->e_duplex_mode == DUPLEXMODE_BOOK) ? "LONGEDGE" :
64                                                         "SHORTEDGE");
65     }
66     else
67     {
68         addToHeader("@PJL SET DUPLEX=OFF\012", 19);
69     }
70     cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr, "@PJL ENTER LANGUAGE=%s\012", m_szLanguage);
71     sendJobHeader();
72     DRIVER_ERROR err = Cleanup();
73     return err;
74 }
75
76 DRIVER_ERROR LJMono::Configure(Pipeline **pipeline)
77 {
78     Pipeline    *p = NULL;
79     Pipeline    *head;
80     unsigned int width;
81     ColorMatcher *pColorMatcher;
82     Mode2        *pMode2;
83     int          iRows[MAXCOLORPLANES];
84     unsigned int uiResBoost;
85     head = *pipeline;
86
87 /*
88  *  I need a flag in the printmode structure to whether create a CMYGraymap
89  *  and set the ulMap1 to it.
90  */
91
92     m_PM.dyeCount = 1;
93     m_PM.ColorDepth[0] = 1;
94     m_PM.cmap.ulMap1 = ulMapDJ600_CCM_K;
95     m_PM.BaseResX = m_pQA->horizontal_resolution;
96     m_PM.BaseResY = m_pQA->vertical_resolution;
97     m_PM.eHT = FED;
98     m_PM.BlackFEDTable = HTBinary_open;
99     m_PM.ColorFEDTable = HTBinary_open;
100     m_PM.MixedRes = false;
101
102     for (int i = 0; i < MAXCOLORPLANES; i++)
103     {
104         m_PM.ResolutionX[i] = m_pQA->horizontal_resolution;
105         m_PM.ResolutionY[i] = m_pQA->vertical_resolution;
106         iRows[i] = m_PM.ResolutionX[i] / m_PM.BaseResX;
107     }
108     uiResBoost = m_PM.BaseResX / m_PM.BaseResY;
109     if (uiResBoost == 0)
110         uiResBoost = 1;
111
112     width = m_pMA->printable_width;
113 //    unsigned int SeedBufferSize = m_pMA->printable_width * 3;
114
115     pColorMatcher = new ColorMatcher(m_PM.cmap, m_PM.dyeCount, width);
116     head = new Pipeline(pColorMatcher);
117     m_pHalftoner = new Halftoner (&m_PM, width, iRows, uiResBoost, m_PM.eHT == MATRIX);
118     p = new Pipeline(m_pHalftoner);
119     head->AddPhase(p);
120     pMode2 = new Mode2(width);
121     p = new Pipeline(pMode2);
122     head->AddPhase(p);
123     pMode2->myplane = COLORTYPE_COLOR;
124
125     *pipeline = head;
126     return NO_ERROR;
127 }
128
129 DRIVER_ERROR LJMono::StartPage(JobAttributes *pJA)
130 {
131     m_pJA = pJA;
132     m_pMA = &pJA->media_attributes;
133     m_pQA = &pJA->quality_attributes;
134     page_number++;
135     return NO_ERROR;
136 }
137
138 DRIVER_ERROR LJMono::FormFeed()
139 {
140     DRIVER_ERROR    err;
141     err = Cleanup();
142     err = m_pSystemServices->Send((const BYTE *) "\x0C", 1);
143     return err;
144 }
145
146 DRIVER_ERROR LJMono::EndJob()
147 {
148     DRIVER_ERROR    err = NO_ERROR;
149     err = Cleanup();
150     err = m_pSystemServices->Send((const BYTE *) "\x1B*rC", 4);
151     err = m_pSystemServices->Send(Reset, sizeof(Reset));
152     if (err == NO_ERROR)
153         err = m_pSystemServices->Send(UEL, sizeof(UEL));
154     return err;
155 }
156
157 DRIVER_ERROR LJMono::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
158 {
159     DRIVER_ERROR    err = NO_ERROR;
160     char            tmpStr[16];
161     int             iLen;
162     BYTE            c = m_pHalftoner->LastPlane() ? 'W' : 'V';
163     iLen = sprintf (tmpStr, "\x1b*b%u%c", InputRaster->rastersize[COLORTYPE_COLOR], c);
164     err = this->Send((const BYTE *) tmpStr, iLen);
165     if (err == NO_ERROR && InputRaster->rastersize[COLORTYPE_COLOR] > 0)
166     {
167         err = this->Send(InputRaster->rasterdata[COLORTYPE_COLOR],
168                          InputRaster->rastersize[COLORTYPE_COLOR]);
169     }
170     return err;
171 }
172