1 /*****************************************************************************\
2 QuickConnect.cpp : Implementation of QuickConnect 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 "Encapsulator.h"
32 #include "QuickConnect.h"
35 QuickConnect::QuickConnect() : Encapsulator()
39 QuickConnect::~QuickConnect()
43 DRIVER_ERROR QuickConnect::StartJob(SystemServices *pSystemServices, JobAttributes *pJA)
45 m_pSystemServices = pSystemServices;
47 m_pMA = &pJA->media_attributes;
48 m_pQA = &pJA->quality_attributes;
52 DRIVER_ERROR QuickConnect::Configure(Pipeline **pipeline)
56 pModeJpeg = new ModeJpeg(m_pMA->printable_width);
57 if (pModeJpeg == NULL)
59 return ALLOCMEM_ERROR;
62 // This is the max jpeg file size value
63 pModeJpeg->myplane = COLORTYPE_COLOR;
64 pModeJpeg->Init(m_pJA->integer_values[1], m_pMA->printable_height);
65 head = new Pipeline(pModeJpeg);
70 DRIVER_ERROR QuickConnect::StartPage(JobAttributes *pJA)
74 const char *szPJLHeader = "\x1B\x45\x1B%-12345X@PJL ENTER LANGUAGE=PHOTOJPEG\012";
75 memset(szStr, 0, 600);
76 err = m_pSystemServices->Send((const BYTE *) szStr, 600);
77 sprintf(szStr, "%s@PJL SET COPIES=%d\012@PJL SET JOBID=%d\012", szPJLHeader, 1, m_pJA->job_id);
78 sprintf(szStr+strlen(szStr),
79 "@PJL SET PAPER=%d\012@PJL SET MEDIATYPE=%d\012@PJL SET PRINTQUALITY=%d\012@PJL SET BORDERLESS=%d\012",
80 m_pMA->pcl_id, m_pQA->media_type, m_pQA->print_quality, m_pJA->integer_values[2]);
81 err = m_pSystemServices->Send((const BYTE *) szStr, strlen(szStr));
85 DRIVER_ERROR QuickConnect::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
88 const char *szPJLEndJob = "\x1B\x45\x1B%-12345X";
90 if (InputRaster->rasterdata[COLORTYPE_COLOR] == NULL)
95 err = sendExifHeader(InputRaster->rasterdata[COLORTYPE_COLOR], &header_size);
100 err = m_pSystemServices->Send((const BYTE *) InputRaster->rasterdata[COLORTYPE_COLOR] + header_size,
101 InputRaster->rastersize[COLORTYPE_COLOR] - header_size);
104 err = m_pSystemServices->Send((const BYTE *) szPJLEndJob, strlen(szPJLEndJob));
109 DRIVER_ERROR QuickConnect::sendExifHeader(BYTE *jpeg_buffer, int *header_size)
112 BYTE *pBuffer = jpeg_buffer;
116 * APP2 Header| Length | Identifier | Version |Number of Tags
117 * -------------------------------------------------------------------------
118 * 0xFF|0xE2 |0x00 | 0x23|0x48|0x50|0x51|0x43|0x00|0x00|0x01|0x00|0x02
119 * Length = No. of Tags * length of tag + length of APP2 marker
120 * -------------------------------------------------------------------------
121 * Tag ID |field Type| Count |Value Offset
122 * -------------------------------------------------------------
123 * 0x00|0x01|0x00|0x03 |0x00|0x00|0x00|0x01|0x00|0x00|0x00|0x01
124 * -------------------------------------------------------------
125 * Field Type 0x0003 stands for short
126 * Count and Value Offset are 4 bytes in TIFF convention.
127 * If the count <=4, Value Offset satisfies. If the count is bigger than 4 bytes,
128 * it will be offset to where data is located.
131 unsigned char App2[] = {"\xFF\xE2\x00\x23\x48\x50\x51\x43\x00\x00\x01\x00\x02"};
132 unsigned char szApp2Markers[2][12];
136 // Things to set are: PhotoFix, RedEyeRemoval
138 iOpts[0] = m_pJA->integer_values[4]; // Red Eye flag
139 iOpts[1] = m_pJA->integer_values[3]; // Photo fix flag
142 unsigned char szTag[] = {"\x00\x01\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01"};
145 for (skey = 1; skey <= 2; skey++)
147 szTag[0] = (BYTE) ((skey & 0xFF) >> 8);
148 szTag[1] = (BYTE) (skey & 0xFF);
151 szTag[8] = (BYTE) ((iVal >> 24) & 0xFF);
152 szTag[9] = (BYTE) ((iVal >> 16) & 0xFF);
153 szTag[10] = (BYTE) ((iVal >> 8) & 0xFF);
154 szTag[11] = (BYTE) (iVal & 0xFF);
155 memcpy (szApp2Markers[iNumTags], szTag, 12);
158 skey = (short) iNumTags * 12 + 11;
159 App2[2] = (BYTE) ((skey >> 8) & 0xFF);
160 App2[3] = (BYTE) (skey & 0xFF);
161 App2[11] = (BYTE) ((iNumTags >> 8) & 0xFF);
162 App2[12] = (BYTE) (iNumTags & 0xFF);
166 * First write the SOI and JFIF header
169 * BYTE SOI[2]; // 00h Start of Image Marker
170 * BYTE APP0[2]; // 02h Application Use Marker
171 * BYTE Length[2]; // 04h Length of APP0 Field
172 * BYTE Identifier[5]; // 06h "JFIF" (zero terminated) Id String
173 * BYTE Version[2]; // 07h JFIF Format Revision
174 * BYTE Units; // 09h Units used for Resolution
175 * BYTE Xdensity[2]; // 0Ah Horizontal Resolution
176 * BYTE Ydensity[2]; // 0Ch Vertical Resolution
177 * BYTE XThumbnail; // 0Eh Horizontal Pixel Count
178 * BYTE YThumbnail; // 0Fh Vertical Pixel Count
181 short sJFIFHeaderSize = ((((short) pBuffer[4]) << 8) | pBuffer[5]) + 4;
182 err = m_pSystemServices->Send ((const BYTE *) pBuffer, sJFIFHeaderSize);
188 *header_size = sJFIFHeaderSize;
192 err = m_pSystemServices->Send ((const BYTE *) App2, 13);
193 for (int i = 0; i < iNumTags; i++)
195 err = m_pSystemServices->Send ((const BYTE *) szApp2Markers[i], 12);