1 /*****************************************************************************\
2 Pcl3.cpp : Implementation of Pcl3 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 "Pcl3PrintModes.h"
41 Pcl3::Pcl3() : Encapsulator()
44 strcpy(m_szLanguage, "PCL3");
51 DRIVER_ERROR Pcl3::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);
92 m_pHalftoner = new Halftoner (m_pPM, width, iRows, uiResBoost, m_pPM->eHT == MATRIX);
93 p = new Pipeline(m_pHalftoner);
95 pMode9 = new Mode9(width, false);
96 p = new Pipeline(pMode9);
98 pMode9->myplane = COLORTYPE_COLOR;
104 DRIVER_ERROR Pcl3::StartPage(JobAttributes *pJA)
106 DRIVER_ERROR err = NO_ERROR;
111 // Under windows, pJA address may have changed, re-init here.
114 m_pMA = &pJA->media_attributes;
115 m_pQA = &pJA->quality_attributes;
117 // Set media source, type, size and quality modes.
119 sprintf(szStr, "\033&l%dH\033&l%dM\033&l%dA\033*o%dM", m_pJA->media_source, m_pQA->media_type,
120 m_pMA->pcl_id, m_pQA->print_quality);
122 // Now add media subtype
124 int i = strlen(szStr);
125 memcpy(szStr+i, MediaSubtypeSeq, sizeof(MediaSubtypeSeq));
126 i += sizeof(MediaSubtypeSeq);
127 szStr[i++] = (char) (m_pQA->media_subtype & 0xFFFF) >> 8;
128 szStr[i++] = (char) m_pQA->media_subtype & 0xFF;
129 addToHeader((const BYTE *) szStr, i);
131 configureRasterData();
133 addToHeader("\033&u%dD\033*t%dR", m_pPM->BaseResX, m_pPM->BaseResY);
135 // another command that helps PCLviewer
136 unsigned int width = m_pMA->printable_width;
137 addToHeader("\033*r%dS", width);
140 * Custom papersize command
143 if (m_pMA->pcl_id == CUSTOM_MEDIA_SIZE) {
144 short sWidth, sHeight;
146 sWidth = static_cast<short>(m_pMA->physical_width);
147 sHeight = static_cast<short>(m_pMA->physical_height);
148 memcpy (szStr, "\x1B*o5W\x0E\x05\x00\x00\x00\x1B*o5W\x0E\x06\x00\x00\x00", 20);
149 b1 = (BYTE) ((sWidth & 0xFF00) >> 8);
150 b2 = (BYTE) (sWidth & 0xFF);
153 b1 = (BYTE) ((sHeight & 0xFF00) >> 8);
154 b2 = (BYTE) (sHeight & 0xFF);
157 addToHeader((const BYTE *) szStr, 20);
160 if (m_pPM->dyeCount != 3)
162 addToHeader((const BYTE *) black_extract_off, sizeof(black_extract_off));
165 addToHeader("\x1B&l0L", 5); // perforation skip off
168 * Calculate top margin:
169 * This is given in terms of text line spacing, the smallest available
170 * granularity of which is 48.
171 * There is a starting unprintable distance, which is platform dependent.
172 * So our formula is: marginvalue = granularity * (startY/verticalres - unprintable)
175 top_margin = m_pMA->printable_start_y - ((m_pJA->mech_offset * m_pQA->actual_vertical_resolution)/1000);
176 top_margin = (top_margin * 48) / m_pQA->actual_vertical_resolution;
177 addToHeader("\x1B&l48D", 6); // granularity
178 addToHeader("\x1B&l%dE", top_margin);
179 addToHeader((const BYTE *) grafStart, sizeof(grafStart));
180 addToHeader((const BYTE *) grafMode9, sizeof(grafMode9));
181 addToHeader((const BYTE *) seedSame, sizeof(seedSame));
183 addToHeader("\x1b*p0Y", 5);
185 // Now send media pre-load command
186 addToHeader((const BYTE *) "\033&l-2H", 6);
192 DRIVER_ERROR Pcl3::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
194 DRIVER_ERROR err = NO_ERROR;
197 BYTE c = m_pHalftoner->LastPlane() ? 'W' : 'V';
198 iLen = sprintf (tmpStr, "\x1b*b%u%c", InputRaster->rastersize[COLORTYPE_COLOR], c);
199 err = this->Send((const BYTE *) tmpStr, iLen);
200 if (err == NO_ERROR && InputRaster->rastersize[COLORTYPE_COLOR] > 0)
202 err = this->Send(InputRaster->rasterdata[COLORTYPE_COLOR],
203 InputRaster->rastersize[COLORTYPE_COLOR]);
208 int Pcl3::colorLevels(int color_plane)
210 int bit_depth = m_pPM->ColorDepth[color_plane];
212 for (int i = 0; i < bit_depth; i++)
219 void Pcl3::configureRasterData()
223 dbglog("configureRasterData: m_pPM is NULL");
226 BYTE *p = cur_pcl_buffer_ptr;
231 p += sprintf((char *) p, "%d", m_pPM->dyeCount * MAXCOLORPLANES + 2);
233 *p++ = 2; // crdFormat
234 *p++ = m_pPM->dyeCount;
236 if (m_pPM->dyeCount == 3)
240 for (unsigned int color = start; color < (start + m_pPM->dyeCount); color++)
242 *p++ = m_pPM->ResolutionX[color] / 256;
243 *p++ = m_pPM->ResolutionX[color] % 256;
244 *p++ = m_pPM->ResolutionY[color] / 256;
245 *p++ = m_pPM->ResolutionY[color] % 256;
246 depth = colorLevels(color);
251 cur_pcl_buffer_ptr = p;
252 } //configureRasterData
254 bool Pcl3::selectPrintMode()
256 if (m_pJA->printer_platform[0] == 0)
258 dbglog("printer_platform is undefined");
261 for (unsigned int i = 0; i < sizeof(pcl3_print_modes_table) / sizeof(pcl3_print_modes_table[0]); i++)
263 if (!strcmp(m_pJA->printer_platform, pcl3_print_modes_table[i].printer_platform_name))
265 return selectPrintMode(i);
268 dbglog("Unsupported printer_platform: %s", m_pJA->printer_platform);
272 bool Pcl3::selectPrintMode(int index)
274 PrintMode *p = pcl3_print_modes_table[index].print_modes;
275 for (int i = 0; i < pcl3_print_modes_table[index].count; i++, p++)
277 if (!strcmp(m_pJA->quality_attributes.print_mode_name, p->name))