~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to prnt/hpcups/QuickConnect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-14 20:08:44 UTC
  • mfrom: (2.1.118 lucid)
  • Revision ID: james.westby@ubuntu.com-20091214200844-z8qhqwgppbu3t7ze
Tags: 3.9.10-4
KBSD patch from KiBi (Closes: #560796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************\
 
2
  QuickConnect.cpp : Implementation of QuickConnect 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 "Encapsulator.h"
 
32
#include "QuickConnect.h"
 
33
#include "ModeJpeg.h"
 
34
 
 
35
QuickConnect::QuickConnect() : Encapsulator()
 
36
{
 
37
}
 
38
 
 
39
QuickConnect::~QuickConnect()
 
40
{
 
41
}
 
42
 
 
43
DRIVER_ERROR QuickConnect::StartJob(SystemServices *pSystemServices, JobAttributes *pJA)
 
44
{
 
45
    m_pSystemServices = pSystemServices;
 
46
    m_pJA = pJA;
 
47
    m_pMA = &pJA->media_attributes;
 
48
    m_pQA = &pJA->quality_attributes;
 
49
    return NO_ERROR;
 
50
}
 
51
 
 
52
DRIVER_ERROR QuickConnect::Configure(Pipeline **pipeline)
 
53
{
 
54
    Pipeline    *head;
 
55
    ModeJpeg    *pModeJpeg;
 
56
    pModeJpeg = new ModeJpeg(m_pMA->printable_width);
 
57
    if (pModeJpeg == NULL)
 
58
    {
 
59
        return ALLOCMEM_ERROR;
 
60
    }
 
61
 
 
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);
 
66
    *pipeline = head;
 
67
    return NO_ERROR;
 
68
}
 
69
 
 
70
DRIVER_ERROR QuickConnect::StartPage(JobAttributes *pJA)
 
71
{
 
72
    char    szStr[632];
 
73
    DRIVER_ERROR    err;
 
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));
 
82
    return err;
 
83
}
 
84
 
 
85
DRIVER_ERROR QuickConnect::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
 
86
{
 
87
    DRIVER_ERROR    err;
 
88
    const           char *szPJLEndJob = "\x1B\x45\x1B%-12345X";
 
89
    int             header_size = 0;
 
90
    if (InputRaster->rasterdata[COLORTYPE_COLOR] == NULL)
 
91
    {
 
92
        return NO_ERROR;
 
93
    }
 
94
 
 
95
    err = sendExifHeader(InputRaster->rasterdata[COLORTYPE_COLOR], &header_size);
 
96
    if (err != NO_ERROR)
 
97
    {
 
98
        return err;
 
99
    }
 
100
    err = m_pSystemServices->Send((const BYTE *) InputRaster->rasterdata[COLORTYPE_COLOR] + header_size,
 
101
                                   InputRaster->rastersize[COLORTYPE_COLOR] - header_size);
 
102
    if (err == NO_ERROR)
 
103
    {
 
104
        err = m_pSystemServices->Send((const BYTE *) szPJLEndJob, strlen(szPJLEndJob));
 
105
    }
 
106
    return err;
 
107
}
 
108
 
 
109
DRIVER_ERROR QuickConnect::sendExifHeader(BYTE *jpeg_buffer, int *header_size)
 
110
{
 
111
    DRIVER_ERROR    err;
 
112
    BYTE            *pBuffer = jpeg_buffer;
 
113
 
 
114
/*
 
115
 *  Jpeg APP2 Marker
 
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. 
 
129
 */
 
130
 
 
131
    unsigned char App2[] = {"\xFF\xE2\x00\x23\x48\x50\x51\x43\x00\x00\x01\x00\x02"};
 
132
    unsigned char szApp2Markers[2][12];
 
133
    int     iNumTags = 0;
 
134
    int     iOpts[2];
 
135
 
 
136
// Things to set are: PhotoFix, RedEyeRemoval
 
137
 
 
138
    iOpts[0] = m_pJA->integer_values[4];    // Red Eye flag
 
139
    iOpts[1] = m_pJA->integer_values[3];    // Photo fix flag
 
140
 
 
141
    short   skey;
 
142
    unsigned char szTag[] = {"\x00\x01\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01"};
 
143
    unsigned int iVal;
 
144
 
 
145
    for (skey = 1; skey <= 2; skey++)
 
146
    {
 
147
        szTag[0] = (BYTE) ((skey & 0xFF) >> 8);
 
148
        szTag[1] = (BYTE) (skey & 0xFF);
 
149
 
 
150
        iVal = iOpts[skey];
 
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);
 
156
        iNumTags++;
 
157
 
 
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);
 
163
    }
 
164
 
 
165
/*
 
166
 *  First write the SOI and JFIF header
 
167
 *  File structure is:
 
168
 *
 
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
 
179
 */
 
180
 
 
181
    short sJFIFHeaderSize = ((((short) pBuffer[4]) << 8) | pBuffer[5]) + 4;
 
182
    err = m_pSystemServices->Send ((const BYTE *) pBuffer, sJFIFHeaderSize);
 
183
    if (err != NO_ERROR)
 
184
    {
 
185
        return err;
 
186
    }
 
187
 
 
188
    *header_size = sJFIFHeaderSize;
 
189
 
 
190
    if (iNumTags != 0)
 
191
    {
 
192
        err = m_pSystemServices->Send ((const BYTE *) App2, 13);
 
193
        for (int i = 0; i < iNumTags; i++)
 
194
        {
 
195
            err = m_pSystemServices->Send ((const BYTE *) szApp2Markers[i], 12);
 
196
        }
 
197
    }
 
198
    return err;
 
199
}
 
200