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

« back to all changes in this revision

Viewing changes to prnt/hpcups/LJColor.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
  LJColor.cpp : Implementation of LJColor 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 "LJColor.h"
 
33
#include "ColorMatcher.h"
 
34
#include "Halftoner.h"
 
35
#include "Mode2.h"
 
36
#include "Mode3.h"
 
37
#include "resources.h"
 
38
#include "ColorMaps.h"
 
39
#include "PrinterCommands.h"
 
40
 
 
41
LJColor::LJColor() : Encapsulator()
 
42
{
 
43
    memset(&m_PM, 0, sizeof(m_PM));
 
44
    strcpy(m_szLanguage, "PCL");
 
45
}
 
46
 
 
47
LJColor::~LJColor()
 
48
{
 
49
}
 
50
 
 
51
DRIVER_ERROR LJColor::addJobSettings()
 
52
{
 
53
    cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
 
54
        "@PJL SET PAGEPROTECT=AUTO\012@PJL SET RESOLUTION=%d\012@PJL SET DENSITY=5\012", m_pQA->horizontal_resolution);
 
55
    if (m_pQA->print_quality == -1)
 
56
    {
 
57
        cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
 
58
        "@PJL SET RET=OFF\012@PJL SET ECONOMODE=ON\012");
 
59
    }
 
60
    if (m_pJA->e_duplex_mode != DUPLEXMODE_NONE)
 
61
    {
 
62
        cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr,
 
63
            "@PJL SET DUPLEX=ON\012@PJL SET BINDING=%s\012",
 
64
            (m_pJA->e_duplex_mode == DUPLEXMODE_BOOK) ? "LONGEDGE" :
 
65
                                                        "SHORTEDGE");
 
66
    }
 
67
    else
 
68
    {
 
69
        addToHeader("@PJL SET DUPLEX=OFF\012", 19);
 
70
    }
 
71
    cur_pcl_buffer_ptr += sprintf((char *) cur_pcl_buffer_ptr, "@PJL ENTER LANGUAGE=PCL\012");
 
72
    sendJobHeader();
 
73
    DRIVER_ERROR err = Cleanup();
 
74
    return err;
 
75
}
 
76
 
 
77
DRIVER_ERROR LJColor::Configure(Pipeline **pipeline)
 
78
{
 
79
    Pipeline    *p = NULL;
 
80
    Pipeline    *head;
 
81
    unsigned int width;
 
82
    head = *pipeline;
 
83
    width = m_pMA->printable_width;
 
84
 
 
85
/*
 
86
 *  I need a flag in the printmode structure to whether create a CMYGraymap
 
87
 *  and set the ulMap1 to it.
 
88
 */
 
89
 
 
90
 
 
91
//  color_mode: 0 - color, 1 - grey_cmy, 2 - grey_k
 
92
 
 
93
    m_PM.BaseResX = m_pQA->horizontal_resolution;
 
94
    m_PM.BaseResY = m_pQA->vertical_resolution;
 
95
    if (m_pJA->color_mode != 0)
 
96
    {
 
97
        ColorMatcher *pColorMatcher;
 
98
        Mode2        *pMode2;
 
99
        int          iRows[MAXCOLORPLANES];
 
100
        unsigned int uiResBoost;
 
101
        m_PM.dyeCount = 1;
 
102
        m_PM.ColorDepth[0] = 1;
 
103
        m_PM.cmap.ulMap1 = ulMapDJ600_CCM_K;
 
104
        m_PM.eHT = FED;
 
105
        m_PM.BlackFEDTable = HTBinary_open;
 
106
        m_PM.ColorFEDTable = HTBinary_open;
 
107
        m_PM.MixedRes = false;
 
108
 
 
109
        for (int i = 0; i < MAXCOLORPLANES; i++)
 
110
        {
 
111
            m_PM.ResolutionX[i] = m_pQA->horizontal_resolution;
 
112
            m_PM.ResolutionY[i] = m_pQA->vertical_resolution;
 
113
            iRows[i] = m_PM.ResolutionX[i] / m_PM.BaseResX;
 
114
        }
 
115
        uiResBoost = m_PM.BaseResX / m_PM.BaseResY;
 
116
        if (uiResBoost == 0)
 
117
            uiResBoost = 1;
 
118
 
 
119
        pColorMatcher = new ColorMatcher(m_PM.cmap, m_PM.dyeCount, width);
 
120
        head = new Pipeline(pColorMatcher);
 
121
        m_pHalftoner = new Halftoner (&m_PM, width, iRows, uiResBoost, m_PM.eHT == MATRIX);
 
122
        p = new Pipeline(m_pHalftoner);
 
123
        head->AddPhase(p);
 
124
        pMode2 = new Mode2(width);
 
125
        p = new Pipeline(pMode2);
 
126
        head->AddPhase(p);
 
127
        pMode2->myplane = COLORTYPE_COLOR;
 
128
    }
 
129
    else
 
130
    {
 
131
        m_pMode3 = new Mode3(width * 3);
 
132
        head = new Pipeline(m_pMode3);
 
133
        m_pMode3->myplane = COLORTYPE_COLOR;
 
134
    }
 
135
 
 
136
    *pipeline = head;
 
137
    return NO_ERROR;
 
138
}
 
139
 
 
140
DRIVER_ERROR LJColor::StartPage(JobAttributes *pJA)
 
141
{
 
142
    m_pJA = pJA;
 
143
    m_pMA = &pJA->media_attributes;
 
144
    m_pQA = &pJA->quality_attributes;
 
145
    page_number++;
 
146
    return NO_ERROR;
 
147
}
 
148
 
 
149
DRIVER_ERROR LJColor::FormFeed()
 
150
{
 
151
    DRIVER_ERROR    err;
 
152
    err = Cleanup();
 
153
    err = m_pSystemServices->Send((const BYTE *) "\x0C", 1);
 
154
    return err;
 
155
}
 
156
 
 
157
DRIVER_ERROR LJColor::EndJob()
 
158
{
 
159
    DRIVER_ERROR    err = NO_ERROR;
 
160
    err = Cleanup();
 
161
    err = m_pSystemServices->Send((const BYTE *) "\x1B*rC", 4);
 
162
    err = m_pSystemServices->Send(Reset, sizeof(Reset));
 
163
    if (err == NO_ERROR)
 
164
        err = m_pSystemServices->Send(UEL, sizeof(UEL));
 
165
    return err;
 
166
}
 
167
 
 
168
DRIVER_ERROR LJColor::Encapsulate(RASTERDATA *InputRaster, bool bLastPlane)
 
169
{
 
170
    DRIVER_ERROR    err = NO_ERROR;
 
171
    char            tmpStr[16];
 
172
    int             iLen;
 
173
    m_iYPos++;
 
174
    iLen = sprintf (tmpStr, "\x1b*b%uW", InputRaster->rastersize[COLORTYPE_COLOR]);
 
175
    err = this->Send((const BYTE *) tmpStr, iLen);
 
176
    if (err == NO_ERROR && InputRaster->rastersize[COLORTYPE_COLOR] > 0)
 
177
    {
 
178
        err = this->Send(InputRaster->rasterdata[COLORTYPE_COLOR],
 
179
                         InputRaster->rastersize[COLORTYPE_COLOR]);
 
180
    }
 
181
 
 
182
/*
 
183
 *  Printers with low memory (64 MB or less) can run out of memory during decompressing
 
184
 *  the image data and will abort the job. To prevent this, restart raster command.
 
185
 *  Raghu
 
186
 */
 
187
 
 
188
    if (m_pJA->color_mode == 0 &&
 
189
        m_pQA->horizontal_resolution >= 600 &&
 
190
        m_iYPos % 1200 == 0)
 
191
    {
 
192
        // Reset seed our seed row
 
193
        m_pMode3->Flush();
 
194
        err = this->Send ((const BYTE *) "\033*rC\033*r1A\033*b3M", 14);
 
195
    }
 
196
 
 
197
    return err;
 
198
}
 
199
 
 
200
void LJColor::configureRasterData()
 
201
{
 
202
 
 
203
/*
 
204
 *  Configure image data - ESC*v#W - # = 6 bytes
 
205
 *  02 - RGB colorspace (00 - Device RGB)
 
206
 *  03 - Direct pixel
 
207
 *  08 - bits per index - ignored for direct pixel
 
208
 *  08, 08, 08 - bits per primary each
 
209
 */
 
210
 
 
211
    addToHeader ((const BYTE *) "\033*v6W\00\03\010\010\010\010", 11);
 
212
 
 
213
//  Continues tone dither
 
214
//  Logical operation - 0
 
215
 
 
216
    addToHeader ((const BYTE *) "\033*t18J", 6);
 
217
 
 
218
/*
 
219
 *  Driver Configuration Command - ESC*#W - # = 3 bytes
 
220
 *  device id - 6 = color HP LaserJet Printer
 
221
 *  func index - 4 = Select Colormap
 
222
 *  argument - 2   = Vivid Graphics
 
223
 */
 
224
 
 
225
    addToHeader ((const BYTE *) "\033*o3W\06\04\06", 8);
 
226
 
 
227
/*
 
228
 *  Program color palette entries
 
229
 */
 
230
    addToHeader ((const BYTE *) "\033*v255A\033*v255B\033*v255C\033*v0I", 26);
 
231
    addToHeader ((const BYTE *) "\033*v255A\033*v0B\033*v0C\033*v6I", 22);
 
232
    addToHeader ((const BYTE *) "\033*v0A\033*v255B\033*v0C\033*v5I", 22);
 
233
    addToHeader ((const BYTE *) "\033*v0A\033*v0B\033*v255C\033*v3I", 22);
 
234
    addToHeader ((const BYTE *) "\033*v255A\033*v255B\033*v0C\033*v4I", 24);
 
235
    addToHeader ((const BYTE *) "\033*v255A\033*v0B\033*v255C\033*v2I", 24);
 
236
    addToHeader ((const BYTE *) "\033*v0A\033*v255B\033*v255C\033*v1I", 24);
 
237
    addToHeader ((const BYTE *) "\033*v0A\033*v0B\033*v0C\033*v7I", 20);
 
238
 
 
239
//  Foreground color
 
240
 
 
241
    addToHeader ((const BYTE *) "\033*v7S", 5);
 
242
}
 
243