1 /*****************************************************************************\
2 Pcl3Gui.cpp : Implementation of Pcl3Gui class
4 Copyright (c) 1996 - 2009, 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 \*****************************************************************************/
31 #include "CommonDefinitions.h"
33 #include "ColorMatcher.h"
34 #include "Halftoner.h"
36 #include "resources.h"
37 #include "ColorMaps.h"
38 #include "PrinterCommands.h"
39 #include "Pcl3GuiPrintModes.h"
41 Pcl3Gui::Pcl3Gui() : Encapsulator()
44 strcpy(m_szLanguage, "PCL3GUI");
51 DRIVER_ERROR Pcl3Gui::Configure(Pipeline **pipeline)
56 ColorMatcher *pColorMatcher;
58 int iRows[MAXCOLORPLANES];
59 unsigned int uiResBoost;
63 * I need a flag in the printmode structure to whether create a CMYGraymap
64 * and set the ulMap1 to it.
67 if (!selectPrintMode())
69 dbglog("selectPrintMode failed, PrintMode name = %s", m_pQA->print_mode_name);
70 return UNSUPPORTED_PRINTMODE;
72 if (m_pPM->BaseResX != m_pQA->horizontal_resolution ||
73 m_pPM->BaseResY != m_pQA->vertical_resolution)
75 dbglog("Requested resolution not supported with requested printmode");
76 return UNSUPPORTED_PRINTMODE;
79 for (int i = 0; i < MAXCOLORPLANES; i++)
81 iRows[i] = m_pPM->ResolutionX[i] / m_pPM->BaseResX;
83 uiResBoost = m_pPM->BaseResX / m_pPM->BaseResY;
87 width = m_pMA->printable_width;
88 // unsigned int SeedBufferSize = m_pMA->printable_width * 3;
90 pColorMatcher = new ColorMatcher(m_pPM->cmap, m_pPM->dyeCount, width);
91 head = new Pipeline(pColorMatcher);
93 m_pHalftoner = new Halftoner (m_pPM, width, iRows, uiResBoost, m_pPM->eHT == MATRIX);
94 p = new Pipeline(m_pHalftoner);
97 pMode2 = new Mode2(width);
98 p = new Pipeline(pMode2);
100 pMode2->myplane = COLORTYPE_COLOR;
106 DRIVER_ERROR Pcl3Gui::StartPage(JobAttributes *pJA)
108 DRIVER_ERROR err = NO_ERROR;
113 // Under windows, pJA address may have changed, re-init here.
116 m_pMA = &pJA->media_attributes;
117 m_pQA = &pJA->quality_attributes;
119 // Set media source, type, size and quality modes.
121 sprintf(szStr, "\033&l%dH\033&l%dM\033&l%dA\033*o%dM", m_pJA->media_source, m_pQA->media_type,
122 m_pMA->pcl_id, m_pQA->print_quality);
124 // Now add media subtype
126 int i = strlen(szStr);
127 memcpy(szStr+i, MediaSubtypeSeq, sizeof(MediaSubtypeSeq));
128 i += sizeof(MediaSubtypeSeq);
129 szStr[i++] = (char) (m_pQA->media_subtype & 0xFFFF) >> 8;
130 szStr[i++] = (char) m_pQA->media_subtype & 0xFF;
131 addToHeader((const BYTE *) szStr, i);
133 if (m_pJA->e_duplex_mode != DUPLEXMODE_NONE) {
134 addToHeader((const BYTE *) EnableDuplex, sizeof(EnableDuplex));
137 configureRasterData();
139 if (m_pJA->color_mode != 0) {
140 // GrayscaleSeq[9] = m_pJA->color_mode;
141 addToHeader((const BYTE *) GrayscaleSeq, 9);
142 *cur_pcl_buffer_ptr++ = (BYTE) m_pJA->color_mode;
145 if (!m_pPM->MixedRes)
147 sprintf(szStr,"\033&u%dD", m_pPM->BaseResX);
148 addToHeader((const BYTE *) szStr, strlen(szStr));
149 sprintf(szStr,"\033*t%dR", m_pPM->BaseResY);
150 addToHeader((const BYTE *) szStr, strlen(szStr));
153 // another command that helps PCLviewer
154 unsigned int width = m_pMA->printable_width;
155 sprintf(szStr, "\033*r%dS", width);
156 addToHeader((const BYTE *) szStr, strlen(szStr));
159 * Custom papersize command
162 if (m_pMA->pcl_id == CUSTOM_MEDIA_SIZE) {
163 short sWidth, sHeight;
165 sWidth = static_cast<short>(m_pMA->physical_width);
166 sHeight = static_cast<short>(m_pMA->physical_height);
167 memcpy (szStr, "\x1B*o5W\x0E\x05\x00\x00\x00\x1B*o5W\x0E\x06\x00\x00\x00", 20);
168 b1 = (BYTE) ((sWidth & 0xFF00) >> 8);
169 b2 = (BYTE) (sWidth & 0xFF);
172 b1 = (BYTE) ((sHeight & 0xFF00) >> 8);
173 b2 = (BYTE) (sHeight & 0xFF);
176 addToHeader((const BYTE *) szStr, 20);
179 addToHeader((const BYTE *) grafStart, sizeof(grafStart));
180 addToHeader((const BYTE *) grafMode2, sizeof(grafMode2));
181 addToHeader((const BYTE *) seedSame, sizeof(seedSame));
183 top_margin = m_pMA->printable_start_y - ((m_pJA->mech_offset * m_pQA->actual_vertical_resolution)/1000);
184 sprintf(szStr, "\x1b*p%dY", top_margin);
185 addToHeader((const BYTE *) szStr, strlen(szStr));
187 // Now send media pre-load command
188 addToHeader((const BYTE *) "\033&l-2H", 6);
190 err = sendBuffer(static_cast<const BYTE *>(pcl_buffer), (cur_pcl_buffer_ptr - pcl_buffer));
191 cur_pcl_buffer_ptr = pcl_buffer;
195 DRIVER_ERROR Pcl3Gui::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
197 DRIVER_ERROR err = NO_ERROR;
200 BYTE c = m_pHalftoner->LastPlane() ? 'W' : 'V';
202 iLen = sprintf (tmpStr, "\x1b*b%u%c", InputRaster->rastersize[COLORTYPE_COLOR], c);
203 err = this->Send((const BYTE *) tmpStr, iLen);
204 if (err == NO_ERROR && InputRaster->rastersize[COLORTYPE_COLOR] > 0)
206 err = this->Send(InputRaster->rasterdata[COLORTYPE_COLOR],
207 InputRaster->rastersize[COLORTYPE_COLOR]);
212 int Pcl3Gui::colorLevels(int color_plane)
214 int bit_depth = m_pPM->ColorDepth[color_plane];
216 for (int i = 0; i < bit_depth; i++)
223 void Pcl3Gui::configureRasterData()
227 dbglog("configureRasterData: m_pPM is NULL");
230 BYTE *p = cur_pcl_buffer_ptr;
235 p += sprintf((char *) p, "%d", m_pPM->dyeCount * MAXCOLORPLANES + 2);
237 *p++ = 2; // crdFormat
238 *p++ = m_pPM->dyeCount;
240 if (m_pPM->dyeCount == 3)
244 for (unsigned int color = start; color < (start + m_pPM->dyeCount); color++)
246 *p++ = m_pPM->ResolutionX[color] / 256;
247 *p++ = m_pPM->ResolutionX[color] % 256;
248 *p++ = m_pPM->ResolutionY[color] / 256;
249 *p++ = m_pPM->ResolutionY[color] % 256;
250 depth = colorLevels(color);
255 cur_pcl_buffer_ptr = p;
256 } //configureRasterData
258 bool Pcl3Gui::selectPrintMode()
260 if (m_pJA->printer_platform[0] == 0)
262 dbglog("printer_platform is undefined");
265 for (unsigned int i = 0; i < sizeof(pcl3_gui_print_modes_table) / sizeof(pcl3_gui_print_modes_table[0]); i++)
267 if (!strcmp(m_pJA->printer_platform, pcl3_gui_print_modes_table[i].printer_platform_name))
269 return selectPrintMode(i);
272 dbglog("Unsupported printer_platform: %s", m_pJA->printer_platform);
276 bool Pcl3Gui::selectPrintMode(int index)
278 PrintMode *p = pcl3_gui_print_modes_table[index].print_modes;
279 for (int i = 0; i < pcl3_gui_print_modes_table[index].count; i++, p++)
281 if (!strcmp(m_pJA->quality_attributes.print_mode_name, p->name))