~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gdevsj48.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gdevsj48.c 11097 2010-04-21 18:12:56Z robin $*/
 
14
/* $Id$*/
15
15
/*
16
16
 * StarJet SJ48 printer driver.
17
17
 *
18
18
 * --- derived from gdevbj10.c 1993-10-07
19
19
 *                by Mats kerblom (f86ma@dd.chalmers.se).
20
20
 */
21
 
 
 
21
 
22
22
#include "gdevprn.h"
23
23
 
24
 
 
25
24
/*
26
25
 * The only available resolutions (in the program) are (180,360)x(180,360).
27
26
 *
40
39
static dev_proc_print_page(sj48_print_page);
41
40
gx_device_printer far_data gs_sj48_device =
42
41
  prn_device(prn_std_procs, "sj48",
43
 
        80,                             /* width_10ths, 8" */
44
 
        105,                            /* height_10ths, 10.5" */
45
 
        360,                            /* x_dpi */
46
 
        360,                            /* y_dpi */
47
 
        0,0,0,0,                        /* margins */
48
 
        1, sj48_print_page);
49
 
 
 
42
        80,                             /* width_10ths, 8" */
 
43
        105,                            /* height_10ths, 10.5" */
 
44
        360,                            /* x_dpi */
 
45
        360,                            /* y_dpi */
 
46
        0,0,0,0,                        /* margins */
 
47
        1, sj48_print_page);
50
48
 
51
49
/*   This comes from the bj10/bj200 source. I don't know how it applies
52
50
 *   for a StarJet.  --- Mats kerblom.
60
58
 * for A4 paper, both are 3.4mm (0.13").
61
59
 *
62
60
 * The bottom margin requires a bit of care.  The image is printed
63
 
 * as strips, each about 3.4mm wide.  We can only attain the bottom 
 
61
 * as strips, each about 3.4mm wide.  We can only attain the bottom
64
62
 * margin if the final strip coincides with it.  Note that each strip
65
63
 * is generated using only 48 of the available 64 jets, and the absence
66
64
 * of those bottom 16 jets makes our bottom margin, in effect, about
76
74
 *
77
75
 */
78
76
 
79
 
 
80
77
/* Send the page to the printer. */
81
78
static int
82
79
sj48_print_page(gx_device_printer *pdev, FILE *prn_stream)
83
80
{       int line_size = gx_device_raster((gx_device *)pdev, 0);
84
 
        int xres = pdev->x_pixels_per_inch;
85
 
        int yres = pdev->y_pixels_per_inch;
86
 
        int mode = (yres == 180 ?
87
 
                        (xres == 180 ? 39 : 40) :
88
 
                        (xres == 180 ? 71 : 72));
89
 
        int bytes_per_column = (yres == 180) ? 3 : 6;
90
 
        int bits_per_column = bytes_per_column * 8;
91
 
        int skip_unit = bytes_per_column * (xres == 180 ? 1 : 2); /* Skips in step of 1/180" */
92
 
        byte *in = (byte *)gs_malloc(pdev->memory, 8, line_size, "sj48_print_page(in)");
93
 
        byte *out = (byte *)gs_malloc(pdev->memory, bits_per_column, line_size, "sj48_print_page(out)");
94
 
        int lnum = 0;
95
 
        int skip = 0;
96
 
        int skips;
97
 
        int code = 0;
98
 
        int last_row = dev_print_scan_lines(pdev);
99
 
        int limit = last_row - bits_per_column;
100
 
 
101
 
        if ( in == 0 || out == 0 )
102
 
        {       code = gs_error_VMerror;
103
 
                gs_note_error(code);
104
 
                goto fin;
105
 
        }
106
 
 
107
 
        /* Abort if the requested resolution is unsupported. */
108
 
        if ((xres !=180 && xres != 360) || (yres !=180 && yres != 360))
109
 
        {       code = gs_error_rangecheck;
110
 
                gs_note_error(code);
111
 
                goto fin;
112
 
        }
113
 
 
114
 
        /* Initialize the printer. */
115
 
        fwrite("\033@\000\000", 1, 4, prn_stream);  /* <Printer reset>, <0>, <0>. */
116
 
 
117
 
        /* Transfer pixels to printer.  The last row we can print is defined
118
 
           by "last_row".  Only the bottom of the print head can print at the
119
 
           bottom margin, and so we align the final printing pass.  The print
120
 
           head is kept from moving below "limit", which is exactly one pass
121
 
           above the bottom margin.  Once it reaches this limit, we make our
122
 
           final printing pass of a full "bits_per_column" rows. */
123
 
        while ( lnum < last_row )
124
 
           {    
125
 
                byte *in_data;
126
 
                byte *in_end = in + line_size;
127
 
                byte *out_beg = out;
128
 
                byte *out_end = out + bytes_per_column * pdev->width;
129
 
                byte *outl = out;
130
 
                int bnum;
131
 
 
132
 
                /* Copy 1 scan line and test for all zero. */
133
 
                code = gdev_prn_get_bits(pdev, lnum, in, &in_data);
134
 
                if ( code < 0 ) goto xit;
135
 
                /* The mem... or str... functions should be faster than */
136
 
                /* the following code, but all systems seem to implement */
137
 
                /* them so badly that this code is faster. */
138
 
                   {    register const long *zip = (const long *)in_data;
139
 
                        register int zcnt = line_size;
140
 
                        register const byte *zipb;
141
 
                        for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
142
 
                           {    if ( zip[0] | zip[1] | zip[2] | zip[3] )
143
 
                                        goto notz;
144
 
                           }
145
 
                        zipb = (const byte *)zip;
146
 
                        while ( --zcnt >= 0 )
147
 
                           {
148
 
                                if ( *zipb++ )
149
 
                                        goto notz;
150
 
                           }
151
 
                        /* Line is all zero, skip */
152
 
                        lnum++;
153
 
                        skip++;
154
 
                        continue;
 
81
        int xres = pdev->x_pixels_per_inch;
 
82
        int yres = pdev->y_pixels_per_inch;
 
83
        int mode = (yres == 180 ?
 
84
                        (xres == 180 ? 39 : 40) :
 
85
                        (xres == 180 ? 71 : 72));
 
86
        int bytes_per_column = (yres == 180) ? 3 : 6;
 
87
        int bits_per_column = bytes_per_column * 8;
 
88
        int skip_unit = bytes_per_column * (xres == 180 ? 1 : 2); /* Skips in step of 1/180" */
 
89
        byte *in = (byte *)gs_malloc(pdev->memory, 8, line_size, "sj48_print_page(in)");
 
90
        byte *out = (byte *)gs_malloc(pdev->memory, bits_per_column, line_size, "sj48_print_page(out)");
 
91
        int lnum = 0;
 
92
        int skip = 0;
 
93
        int skips;
 
94
        int code = 0;
 
95
        int last_row = dev_print_scan_lines(pdev);
 
96
        int limit = last_row - bits_per_column;
 
97
 
 
98
        if ( in == 0 || out == 0 )
 
99
        {       code = gs_error_VMerror;
 
100
                gs_note_error(code);
 
101
                goto fin;
 
102
        }
 
103
 
 
104
        /* Abort if the requested resolution is unsupported. */
 
105
        if ((xres !=180 && xres != 360) || (yres !=180 && yres != 360))
 
106
        {       code = gs_error_rangecheck;
 
107
                gs_note_error(code);
 
108
                goto fin;
 
109
        }
 
110
 
 
111
        /* Initialize the printer. */
 
112
        fwrite("\033@\000\000", 1, 4, prn_stream);  /* <Printer reset>, <0>, <0>. */
 
113
 
 
114
        /* Transfer pixels to printer.  The last row we can print is defined
 
115
           by "last_row".  Only the bottom of the print head can print at the
 
116
           bottom margin, and so we align the final printing pass.  The print
 
117
           head is kept from moving below "limit", which is exactly one pass
 
118
           above the bottom margin.  Once it reaches this limit, we make our
 
119
           final printing pass of a full "bits_per_column" rows. */
 
120
        while ( lnum < last_row )
 
121
           {
 
122
                byte *in_data;
 
123
                byte *in_end = in + line_size;
 
124
                byte *out_beg = out;
 
125
                byte *out_end = out + bytes_per_column * pdev->width;
 
126
                byte *outl = out;
 
127
                int bnum;
 
128
 
 
129
                /* Copy 1 scan line and test for all zero. */
 
130
                code = gdev_prn_get_bits(pdev, lnum, in, &in_data);
 
131
                if ( code < 0 ) goto xit;
 
132
                /* The mem... or str... functions should be faster than */
 
133
                /* the following code, but all systems seem to implement */
 
134
                /* them so badly that this code is faster. */
 
135
                   {    register const long *zip = (const long *)in_data;
 
136
                        register int zcnt = line_size;
 
137
                        register const byte *zipb;
 
138
                        for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
 
139
                           {    if ( zip[0] | zip[1] | zip[2] | zip[3] )
 
140
                                        goto notz;
 
141
                           }
 
142
                        zipb = (const byte *)zip;
 
143
                        while ( --zcnt >= 0 )
 
144
                           {
 
145
                                if ( *zipb++ )
 
146
                                        goto notz;
 
147
                           }
 
148
                        /* Line is all zero, skip */
 
149
                        lnum++;
 
150
                        skip++;
 
151
                        continue;
155
152
notz:                   ;
156
 
                   }
157
 
 
158
 
                /* Vertical tab to the appropriate position.  Note here that
159
 
                   we make sure we don't move below limit. */
160
 
                if ( lnum > limit )
161
 
                    {   skip -= (limit - lnum);
162
 
                        lnum = limit;
163
 
                    }
164
 
 
165
 
                /* The SJ48 can only skip in steps of 1/180" */
166
 
                if (yres == 180) {
167
 
                  skips = skip;
168
 
                } else {
169
 
                  if (skip & 1) {
170
 
                    skip--; /* Makes skip even. */
171
 
                    lnum--;
172
 
                  }
 
153
                   }
 
154
 
 
155
                /* Vertical tab to the appropriate position.  Note here that
 
156
                   we make sure we don't move below limit. */
 
157
                if ( lnum > limit )
 
158
                    {   skip -= (limit - lnum);
 
159
                        lnum = limit;
 
160
                    }
 
161
 
 
162
                /* The SJ48 can only skip in steps of 1/180" */
 
163
                if (yres == 180) {
 
164
                  skips = skip;
 
165
                } else {
 
166
                  if (skip & 1) {
 
167
                    skip--; /* Makes skip even. */
 
168
                    lnum--;
 
169
                  }
173
170
                  skips = skip/2;
174
 
                } 
175
 
                    
176
 
                while ( skips > 255 )
177
 
                   {    fputs("\033J\377", prn_stream);
178
 
                        skips -= 255;
179
 
                   }
180
 
                if ( skips )
181
 
                        fprintf(prn_stream, "\033J%c", skips);
182
 
 
183
 
                /* If we've printed as far as "limit", then reset "limit"
184
 
                   to "last_row" for the final printing pass. */
185
 
                if ( lnum == limit )
186
 
                        limit = last_row;
187
 
                skip = 0;
188
 
 
189
 
                /* Transpose in blocks of 8 scan lines. */
190
 
                for ( bnum = 0; bnum < bits_per_column; bnum += 8 )
191
 
                   {    int lcnt = min(8, limit - lnum);
192
 
                        byte *inp = in;
193
 
                        byte *outp = outl;
194
 
                        lcnt = gdev_prn_copy_scan_lines(pdev,
195
 
                                lnum, in, lcnt * line_size);
196
 
                        if ( lcnt < 0 )
197
 
                           {    code = lcnt;
198
 
                                goto xit;
199
 
                           }
200
 
                        if ( lcnt < 8 )
201
 
                                memset(in + lcnt * line_size, 0,
202
 
                                       (8 - lcnt) * line_size);
203
 
                        for ( ; inp < in_end; inp++, outp += bits_per_column )
204
 
                           {    gdev_prn_transpose_8x8(inp, line_size,
205
 
                                        outp, bytes_per_column);
206
 
                           }
207
 
                        outl++;
208
 
                        lnum += lcnt;
209
 
                        skip += lcnt;
210
 
                   }
211
 
 
212
 
                /* Send the bits to the printer.  We alternate horizontal
213
 
                   skips with the data.  The horizontal skips are in units
214
 
                   of 1/180 inches, so we look at the data in groups of
215
 
                   1 or 2 columns depending on resolution (controlled
 
171
                }
 
172
 
 
173
                while ( skips > 255 )
 
174
                   {    fputs("\033J\377", prn_stream);
 
175
                        skips -= 255;
 
176
                   }
 
177
                if ( skips )
 
178
                        fprintf(prn_stream, "\033J%c", skips);
 
179
 
 
180
                /* If we've printed as far as "limit", then reset "limit"
 
181
                   to "last_row" for the final printing pass. */
 
182
                if ( lnum == limit )
 
183
                        limit = last_row;
 
184
                skip = 0;
 
185
 
 
186
                /* Transpose in blocks of 8 scan lines. */
 
187
                for ( bnum = 0; bnum < bits_per_column; bnum += 8 )
 
188
                   {    int lcnt = min(8, limit - lnum);
 
189
                        byte *inp = in;
 
190
                        byte *outp = outl;
 
191
                        lcnt = gdev_prn_copy_scan_lines(pdev,
 
192
                                lnum, in, lcnt * line_size);
 
193
                        if ( lcnt < 0 )
 
194
                           {    code = lcnt;
 
195
                                goto xit;
 
196
                           }
 
197
                        if ( lcnt < 8 )
 
198
                                memset(in + lcnt * line_size, 0,
 
199
                                       (8 - lcnt) * line_size);
 
200
                        for ( ; inp < in_end; inp++, outp += bits_per_column )
 
201
                           {    gdev_prn_transpose_8x8(inp, line_size,
 
202
                                        outp, bytes_per_column);
 
203
                           }
 
204
                        outl++;
 
205
                        lnum += lcnt;
 
206
                        skip += lcnt;
 
207
                   }
 
208
 
 
209
                /* Send the bits to the printer.  We alternate horizontal
 
210
                   skips with the data.  The horizontal skips are in units
 
211
                   of 1/180 inches, so we look at the data in groups of
 
212
                   1 or 2 columns depending on resolution (controlled
216
213
                   by skip_unit).  */
217
 
                outl = out;
218
 
                do
219
 
                   {    int count;
220
 
                        int n;
221
 
                        byte *out_ptr;
222
 
 
223
 
                        /* First look for blank groups of columns. */
224
 
                        while(outl < out_end)
225
 
                           {    n = count = min(out_end - outl, skip_unit);
226
 
                                out_ptr = outl;
227
 
                                while ( --count >= 0 )
228
 
                                   {    if ( *out_ptr++ )
229
 
                                                break;
230
 
                                   }
231
 
                                if ( count >= 0 )
232
 
                                        break;
233
 
                                else
234
 
                                        outl = out_ptr;
235
 
                           }
236
 
                        if (outl >= out_end)
237
 
                                break;
238
 
                        if (outl > out_beg)
239
 
                           {    count = (outl - out_beg) / skip_unit;
240
 
                                fprintf(prn_stream, "\033\\%c%c",
241
 
                                        count & 0xff, count >> 8);
242
 
                           }
243
 
 
244
 
                        /* Next look for non-blank groups of columns. */
245
 
                        out_beg = outl;
246
 
                        outl += n;
247
 
                        while(outl < out_end)
248
 
                           {    n = count = min(out_end - outl, skip_unit);
249
 
                                out_ptr = outl;
250
 
                                while ( --count >= 0 )
251
 
                                   {    if ( *out_ptr++ )
252
 
                                                break;
253
 
                                   }
254
 
                                if ( count < 0 )
255
 
                                        break;
256
 
                                else
257
 
                                        outl += n;
258
 
                           }
259
 
                        count = outl - out_beg;
260
 
                        {
261
 
                          /* What to transmit is the number of columns in the row.
262
 
                             Compare this with the <Esc>|*-command wich expects the
263
 
                             total number of bytes in the graphic row! */
264
 
                          int count1 = count/bytes_per_column;
265
 
                          fprintf(prn_stream, "\033*%c%c%c",
266
 
                                  mode, count1 & 0xff, count1 >> 8);
267
 
                        }
268
 
                        fwrite(out_beg, 1, count, prn_stream);
269
 
                        out_beg = outl;
270
 
                        outl += n;
271
 
                   }
272
 
                while ( out_beg < out_end );
273
 
 
274
 
                fputc('\r', prn_stream);
275
 
                skip = bits_per_column;  /* <CR> only moves to the beginning of the row. */
276
 
           }
277
 
 
278
 
        /* Eject the page */
 
214
                outl = out;
 
215
                do
 
216
                   {    int count;
 
217
                        int n;
 
218
                        byte *out_ptr;
 
219
 
 
220
                        /* First look for blank groups of columns. */
 
221
                        while(outl < out_end)
 
222
                           {    n = count = min(out_end - outl, skip_unit);
 
223
                                out_ptr = outl;
 
224
                                while ( --count >= 0 )
 
225
                                   {    if ( *out_ptr++ )
 
226
                                                break;
 
227
                                   }
 
228
                                if ( count >= 0 )
 
229
                                        break;
 
230
                                else
 
231
                                        outl = out_ptr;
 
232
                           }
 
233
                        if (outl >= out_end)
 
234
                                break;
 
235
                        if (outl > out_beg)
 
236
                           {    count = (outl - out_beg) / skip_unit;
 
237
                                fprintf(prn_stream, "\033\\%c%c",
 
238
                                        count & 0xff, count >> 8);
 
239
                           }
 
240
 
 
241
                        /* Next look for non-blank groups of columns. */
 
242
                        out_beg = outl;
 
243
                        outl += n;
 
244
                        while(outl < out_end)
 
245
                           {    n = count = min(out_end - outl, skip_unit);
 
246
                                out_ptr = outl;
 
247
                                while ( --count >= 0 )
 
248
                                   {    if ( *out_ptr++ )
 
249
                                                break;
 
250
                                   }
 
251
                                if ( count < 0 )
 
252
                                        break;
 
253
                                else
 
254
                                        outl += n;
 
255
                           }
 
256
                        count = outl - out_beg;
 
257
                        {
 
258
                          /* What to transmit is the number of columns in the row.
 
259
                             Compare this with the <Esc>|*-command wich expects the
 
260
                             total number of bytes in the graphic row! */
 
261
                          int count1 = count/bytes_per_column;
 
262
                          fprintf(prn_stream, "\033*%c%c%c",
 
263
                                  mode, count1 & 0xff, count1 >> 8);
 
264
                        }
 
265
                        fwrite(out_beg, 1, count, prn_stream);
 
266
                        out_beg = outl;
 
267
                        outl += n;
 
268
                   }
 
269
                while ( out_beg < out_end );
 
270
 
 
271
                fputc('\r', prn_stream);
 
272
                skip = bits_per_column;  /* <CR> only moves to the beginning of the row. */
 
273
           }
 
274
 
 
275
        /* Eject the page */
279
276
xit:    fputc(014, prn_stream); /* form feed */
280
 
        fflush(prn_stream);
 
277
        fflush(prn_stream);
281
278
fin:    if ( out != 0 )
282
 
                gs_free(pdev->memory, (char *)out, bits_per_column, line_size,
283
 
                        "sj48_print_page(out)");
284
 
        if ( in != 0 )
285
 
                gs_free(pdev->memory, (char *)in, 8, line_size, "sj48_print_page(in)");
286
 
        return code;
 
279
                gs_free(pdev->memory, (char *)out, bits_per_column, line_size,
 
280
                        "sj48_print_page(out)");
 
281
        if ( in != 0 )
 
282
                gs_free(pdev->memory, (char *)in, 8, line_size, "sj48_print_page(in)");
 
283
        return code;
287
284
}