~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/gdevdjtc.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
 
   All Rights Reserved.
3
 
  
4
 
   This software is provided AS-IS with no warranty, either express or
5
 
   implied.
6
 
 
7
 
   This software is distributed under license and may not be copied, modified
8
 
   or distributed except as expressly authorized under the terms of that
9
 
   license.  Refer to licensing information at http://www.artifex.com/
10
 
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
 
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
 
*/
13
 
/* $Id: gdevdjtc.c 8250 2007-09-25 13:31:24Z giles $*/
14
 
/* HP DeskJet 500C driver */
15
 
#include "gdevprn.h"
16
 
#include "gdevpcl.h"
17
 
#include "malloc_.h"
18
 
 
19
 
/***
20
 
 *** Note: this driver was contributed by a user, Alfred Kayser:
21
 
 ***       please contact AKayser@et.tudelft.nl if you have questions.
22
 
 ***/
23
 
                                              
24
 
#ifndef SHINGLING        /* Interlaced, multi-pass printing */
25
 
#define SHINGLING 1      /* 0 = none, 1 = 50%, 2 = 25%, 2 is best & slowest */
26
 
#endif
27
 
 
28
 
#ifndef DEPLETION        /* 'Intelligent' dot-removal */ 
29
 
#define DEPLETION 1      /* 0 = none, 1 = 25%, 2 = 50%, 1 best for graphics? */
30
 
#endif                   /* Use 0 for transparencies */
31
 
 
32
 
#define X_DPI 300
33
 
#define Y_DPI 300
34
 
/* bytes per line for DeskJet Color */
35
 
#define LINE_SIZE ((X_DPI * 85 / 10 + 63) / 64 * 8)
36
 
 
37
 
/* The device descriptors */
38
 
static dev_proc_print_page(djet500c_print_page);
39
 
 
40
 
static gx_device_procs djet500c_procs =
41
 
  prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
42
 
    gdev_pcl_3bit_map_rgb_color, gdev_pcl_3bit_map_color_rgb);
43
 
 
44
 
const gx_device_printer far_data gs_djet500c_device =
45
 
  prn_device(djet500c_procs, "djet500c",
46
 
    85,                /* width_10ths, 8.5" */
47
 
    120,                /* height_10ths, 12" */
48
 
    X_DPI, Y_DPI,
49
 
    0.25, 0.25, 0.25, 0.25,        /* margins */
50
 
    3, djet500c_print_page);
51
 
 
52
 
/* Forward references */
53
 
static int djet500c_print_page(gx_device_printer *, FILE *);
54
 
 
55
 
static int mode2compress(byte *row, byte *end_row, byte *compressed);
56
 
 
57
 
/* The DeskJet 500C uses additive colors in separate planes. */
58
 
/* We only keep one bit of color, with 1 = R, 2 = G, 4 = B. */
59
 
/* Because the buffering routines assume 0 = white, */
60
 
/* we complement all the color components. */
61
 
 
62
 
/* Send the page to the printer.  For speed, compress each scan line, */
63
 
/* since computer-to-printer communication time is often a bottleneck. */
64
 
/* The DeskJet Color can compress (mode 2) */
65
 
 
66
 
static int
67
 
djet500c_print_page(gx_device_printer *pdev, FILE *fprn)
68
 
{
69
 
    byte *bitData=NULL;
70
 
    byte *plane1=NULL;
71
 
    byte *plane2=NULL;
72
 
    byte *plane3=NULL;
73
 
    int bitSize=0;
74
 
    int planeSize=0;
75
 
 
76
 
    /* select the most compressed mode available & clear tmp storage */
77
 
    /* put printer in known state */
78
 
    fputs("\033E",fprn);
79
 
    
80
 
    /* ends raster graphics to set raster graphics resolution */
81
 
    fputs("\033*rbC", fprn);    /*  was \033*rB  */
82
 
 
83
 
    /* set raster graphics resolution -- 300 dpi */
84
 
    fputs("\033*t300R", fprn);                                           
85
 
    
86
 
    /* A4, skip perf, def. paper tray */ 
87
 
    fputs("\033&l26a0l1H", fprn); 
88
 
 
89
 
    /* RGB Mode */
90
 
    fputs("\033*r3U", fprn);    
91
 
    
92
 
    /* set depletion level */
93
 
    fprintf(fprn, "\033*o%dD", DEPLETION);
94
 
    
95
 
    /* set shingling level */
96
 
    fprintf(fprn, "\033*o%dQ", SHINGLING);
97
 
    
98
 
    /* move to top left of page & set current position */
99
 
    fputs("\033*p0x0Y", fprn); /* cursor pos: 0,0 */
100
 
     
101
 
    fputs("\033*b2M", fprn);    /*  mode 2 compression for now  */
102
 
    
103
 
    fputs("\033*r0A", fprn);  /* start graf. left */
104
 
    
105
 
    /* Send each scan line in turn */
106
 
       {    int lnum;
107
 
        int num_blank_lines = 0;
108
 
        int lineSize = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
109
 
        if (lineSize>bitSize)
110
 
        {                         
111
 
            if (bitData) free(bitData);
112
 
            bitSize=lineSize;
113
 
            bitData=(byte*)malloc(bitSize+16);
114
 
        }
115
 
        for (lnum=0; lnum<pdev->height; lnum++)
116
 
        {    
117
 
            byte *endData;
118
 
            
119
 
            gdev_prn_copy_scan_lines(pdev, lnum, bitData, lineSize);
120
 
 
121
 
            /* Remove trailing 0s. */
122
 
            endData = bitData + lineSize;
123
 
            while ( (endData>bitData) && (endData[-1] == 0) )
124
 
                endData--;
125
 
            if (endData == bitData)
126
 
                num_blank_lines++;
127
 
            else
128
 
            {    int count, k, i, lineLen;
129
 
 
130
 
                /* Pad with 0s to fill out the last */
131
 
                /* block of 8 bytes. */
132
 
                memset(endData, 0, 7);
133
 
                              
134
 
                lineLen=((endData-bitData)+7)/8;    /* Round to next 8multiple */           
135
 
                if (planeSize<lineLen)                             
136
 
                {
137
 
                    if (plane1) free(plane1);
138
 
                    if (plane2) free(plane2);
139
 
                    if (plane3) free(plane3);
140
 
                    planeSize=lineLen;
141
 
                    plane1=(byte*)malloc(planeSize+8);
142
 
                    plane2=(byte*)malloc(planeSize+8);
143
 
                    plane3=(byte*)malloc(planeSize+8);
144
 
                }
145
 
                /* Transpose the data to get pixel planes. */
146
 
                for (k=i=0; k<lineLen; i+=8, k++)
147
 
                { 
148
 
                   register ushort t, c;
149
 
                   
150
 
                   /* Three smaller loops are better optimizable and use less
151
 
                      vars, so most of them can be in registers even on pc's */
152
 
                   for (c=t=0;t<8;t++)
153
 
                        c = (c<<1) | (bitData[t+i]&4);
154
 
                   plane3[k] = ~(byte)(c>>2);
155
 
                   for (c=t=0;t<8;t++)
156
 
                        c = (c<<1) | (bitData[t+i]&2);
157
 
                   plane2[k] = ~(byte)(c>>1);
158
 
                   for (c=t=0;t<8;t++)
159
 
                        c = (c<<1) | (bitData[t+i]&1);
160
 
                   plane1[k] = ~(byte)(c);
161
 
                }           
162
 
 
163
 
                /* Skip blank lines if any */
164
 
                if (num_blank_lines > 0)
165
 
                {    /* move down from current position */
166
 
                    fprintf(fprn, "\033*b%dY", num_blank_lines);
167
 
                    num_blank_lines = 0;
168
 
                }
169
 
 
170
 
                /* Transfer raster graphics */
171
 
                /* in the order R, G, B. */
172
 
                /* lineLen is at least bitSize/8, so bitData can easily be used to store
173
 
                   lineLen of bytes */
174
 
                /* P.s. mode9 compression is akward(??) to use, because the lineLenght's
175
 
                   are different, so we are stuck with mode 2, which is good enough */
176
 
                   
177
 
                /* set the line width */
178
 
                fprintf(fprn, "\033*r%dS", lineLen*8);
179
 
 
180
 
                count = mode2compress(plane1, plane1 + lineLen, bitData);
181
 
                fprintf(fprn, "\033*b%dV", count);
182
 
                fwrite(bitData, sizeof(byte), count, fprn); 
183
 
                count = mode2compress(plane2, plane2 + lineLen, bitData);
184
 
                fprintf(fprn, "\033*b%dV", count);
185
 
                fwrite(bitData, sizeof(byte), count, fprn); 
186
 
                count = mode2compress(plane3, plane3 + lineLen, bitData);
187
 
                fprintf(fprn, "\033*b%dW", count);
188
 
                fwrite(bitData, sizeof(byte), count, fprn); 
189
 
            }
190
 
        }
191
 
    }
192
 
    /* end raster graphics */
193
 
    fputs("\033*rbC", fprn);    /*  was \033*rB  */
194
 
    fputs("\033*r1U", fprn);    /*  back to 1 plane  */
195
 
 
196
 
       /* put printer in known state */
197
 
    fputs("\033E",fprn);
198
 
    
199
 
    /* eject page */
200
 
    fputs("\033&l0H", fprn);        
201
 
    
202
 
    /* release allocated memory */
203
 
    if (bitData) free(bitData);
204
 
    if (plane1) free(plane1);
205
 
    if (plane2) free(plane2);
206
 
    if (plane3) free(plane3);
207
 
 
208
 
    return 0;
209
 
}
210
 
 
211
 
 
212
 
/*
213
 
 * Mode 2 Row compression routine for the HP DeskJet & LaserJet IIp.
214
 
 * Compresses data from row up to end_row, storing the result
215
 
 * starting at compressed.  Returns the number of bytes stored.
216
 
 * Runs of K<=127 literal bytes are encoded as K-1 followed by
217
 
 * the bytes; runs of 2<=K<=127 identical bytes are encoded as
218
 
 * 257-K followed by the byte.
219
 
 * In the worst case, the result is N+(N/127)+1 bytes long,
220
 
 * where N is the original byte count (end_row - row).
221
 
 * I can't use the general pcl version, because it assume even linelength's
222
 
 */
223
 
 
224
 
static int
225
 
mode2compress(byte *row, byte *end_row, byte *compressed)
226
 
{    
227
 
    register byte *exam; /* word being examined in the row to compress */
228
 
    register byte *cptr = compressed; /* output pointer into compressed bytes */
229
 
    int i, count, len;
230
 
    byte test;
231
 
 
232
 
    exam = row;
233
 
    while (1)
234
 
    {                        
235
 
        test = *exam++;
236
 
        /* Advance exam until test==*exam  or exam==end_row */
237
 
        while ((test != *exam) && (exam < end_row))
238
 
            test = *exam++;                    
239
 
        /* row points to start of differing bytes,
240
 
           exam points to start of consequtive series 
241
 
                    or to end of row */
242
 
        if (exam<end_row) exam--;
243
 
        len=exam-row;   
244
 
        while (len>0)
245
 
        {
246
 
            count=len;
247
 
            if (count>127) count=127;
248
 
            *cptr++=count-1;  
249
 
            for (i=0;i<count;i++) *cptr++ = *row++;
250
 
            len-=count;
251
 
        }     
252
 
        if (exam>=end_row) break;     /* done */             
253
 
        exam++;     /* skip first same byte */
254
 
        while ((test == *exam) && (exam < end_row))  /* skip all same bytes */
255
 
            exam++;
256
 
        /* exam points now first different word or to end of data */
257
 
        len = exam-row;
258
 
        while (len>0)
259
 
        {     
260
 
            count=len;
261
 
            if (count>127) count=127;
262
 
            *cptr++=(257-count);
263
 
            *cptr++=test;             
264
 
            len-=count;
265
 
        }                
266
 
        if (exam>=end_row) break;            /* end of data */
267
 
        row = exam;    /* row points to first dissimular byte */
268
 
    }                                          
269
 
    return (cptr-compressed);
270
 
}