1
/* Copyright (C) 2001-2012 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied,
8
modified or distributed except as expressly authorized under the terms
9
of the license contained in the file LICENSE in this distribution.
11
Refer to licensing information at http://www.artifex.com or contact
12
Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13
CA 94903, U.S.A., +1(415)492-9861, for further information.
16
/* High-res 24Dot-matrix printer driver */
19
* NEC P6 and similar, implemented by Andreas Schwab (schwab@ls5.informatik.uni-dortmund.de)
20
* Epson LQ850, implemented by Christian Felsch (felsch@tu-harburg.d400.de)
25
/* Driver for NEC P6 */
26
static dev_proc_print_page (necp6_print_page);
27
const gx_device_printer far_data gs_necp6_device =
28
prn_device (prn_std_procs, "necp6",
29
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
31
0, 0, 0.5, 0, /* margins */
34
/* Driver for Epson LQ850 */
35
/* I've tested this driver on a BJ300 with LQ850 emulation and there it produce correct 360x360dpi output. */
36
static dev_proc_print_page (lq850_print_page);
37
const gx_device_printer gs_lq850_device =
38
prn_device (prn_std_procs, "lq850",
39
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
41
0, 0, 0.5, 0, /* margins */
44
/* ------ Internal routines ------ */
46
/* Forward references */
47
static void dot24_output_run (byte *, int, int, FILE *);
48
static void dot24_improve_bitmap (byte *, int);
50
/* Send the page to the printer. */
52
dot24_print_page (gx_device_printer *pdev, FILE *prn_stream, char *init_string, int init_len)
54
int xres = (int)pdev->x_pixels_per_inch;
55
int yres = (int)pdev->y_pixels_per_inch;
56
int x_high = (xres == 360);
57
int y_high = (yres == 360);
58
int bits_per_column = (y_high ? 48 : 24);
59
uint line_size = gdev_prn_raster (pdev);
60
uint in_size = line_size * bits_per_column;
61
byte *in = (byte *) gs_malloc (pdev->memory, in_size, 1, "dot24_print_page (in)");
62
uint out_size = ((pdev->width + 7) & -8) * 3;
63
byte *out = (byte *) gs_malloc (pdev->memory, out_size, 1, "dot24_print_page (out)");
64
int y_passes = (y_high ? 2 : 1);
65
int dots_per_space = xres / 10; /* pica space = 1/10" */
66
int bytes_per_space = dots_per_space * 3;
67
int skip = 0, lnum = 0, ypass;
69
/* Check allocations */
70
if (in == 0 || out == 0)
73
gs_free (pdev->memory, (char *) out, out_size, 1, "dot24_print_page (out)");
75
gs_free (pdev->memory, (char *) in, in_size, 1, "dot24_print_page (in)");
76
return_error (gs_error_VMerror);
79
/* Initialize the printer and reset the margins. */
80
fwrite (init_string, init_len - 1, sizeof (char), prn_stream);
81
fputc ((int) (pdev->width / pdev->x_pixels_per_inch * 10) + 2,
84
/* Print lines of graphics */
85
while (lnum < pdev->height)
94
/* Copy 1 scan line and test for all zero. */
95
gdev_prn_copy_scan_lines (pdev, lnum, in, line_size);
97
&& !memcmp ((char *) in, (char *) in + 1, line_size - 1))
104
/* Vertical tab to the appropriate position. */
105
while ((skip >> 1) > 255)
107
fputs ("\033J\377", prn_stream);
114
fprintf (prn_stream, "\033J%c", skip >> 1);
116
fputc ('\n', prn_stream);
119
/* Copy the rest of the scan lines. */
122
inp = in + line_size;
123
for (lcnt = 1; lcnt < 24; lcnt++, inp += line_size)
124
if (!gdev_prn_copy_scan_lines (pdev, lnum + lcnt * 2, inp,
127
memset (inp, 0, (24 - lcnt) * line_size);
130
inp = in + line_size * 24;
131
for (lcnt = 0; lcnt < 24; lcnt++, inp += line_size)
132
if (!gdev_prn_copy_scan_lines (pdev, lnum + lcnt * 2 + 1, inp,
135
memset (inp, 0, (24 - lcnt) * line_size);
141
lcnt = 1 + gdev_prn_copy_scan_lines (pdev, lnum + 1, in + line_size,
142
in_size - line_size);
144
/* Pad with lines of zeros. */
145
memset (in + lcnt * line_size, 0, in_size - lcnt * line_size);
148
for (ypass = 0; ypass < y_passes; ypass++)
153
inp += line_size * 24;
154
in_end = inp + line_size;
156
for (; inp < in_end; inp++, out_end += 24)
158
memflip8x8 (inp, line_size, out_end, 3);
159
memflip8x8 (inp + line_size * 8, line_size, out_end + 1, 3);
160
memflip8x8 (inp + line_size * 16, line_size, out_end + 2, 3);
162
/* Remove trailing 0s. */
163
while (out_end - 3 >= out && out_end[-1] == 0
164
&& out_end[-2] == 0 && out_end[-3] == 0)
167
for (out_blk = outp = out; outp < out_end;)
169
/* Skip a run of leading 0s. */
170
/* At least 10 are needed to make tabbing worth it. */
172
if (outp[0] == 0 && outp + 12 <= out_end
173
&& outp[1] == 0 && outp[2] == 0
174
&& outp[3] == 0 && outp[4] == 0 && outp[5] == 0
175
&& outp[6] == 0 && outp[7] == 0 && outp[8] == 0
176
&& outp[9] == 0 && outp[10] == 0 && outp[11] == 0)
182
while (outp + 3 <= out_end
183
&& outp[0] == 0 && outp[1] == 0 && outp[2] == 0)
185
tpos = (outp - out) / bytes_per_space;
186
newp = out + tpos * bytes_per_space;
189
/* Output preceding bit data. */
190
/* only false at beginning of line */
194
dot24_improve_bitmap (out_blk, (int) (zp - out_blk));
195
dot24_output_run (out_blk, (int) (zp - out_blk),
198
/* Tab over to the appropriate position. */
199
fprintf (prn_stream, "\033D%c%c\t", tpos, 0);
200
out_blk = outp = newp;
209
dot24_improve_bitmap (out_blk, (int) (outp - out_blk));
210
dot24_output_run (out_blk, (int) (outp - out_blk), x_high,
214
fputc ('\r', prn_stream);
215
if (ypass < y_passes - 1)
216
fputc ('\n', prn_stream);
219
lnum += bits_per_column;
222
/* Eject the page and reinitialize the printer */
223
fputs ("\f\033@", prn_stream);
226
gs_free (pdev->memory, (char *) out, out_size, 1, "dot24_print_page (out)");
227
gs_free (pdev->memory, (char *) in, in_size, 1, "dot24_print_page (in)");
232
/* Output a single graphics command. */
234
dot24_output_run (byte *data, int count, int x_high, FILE *prn_stream)
236
int xcount = count / 3;
237
fputc (033, prn_stream);
238
fputc ('*', prn_stream);
239
fputc ((x_high ? 40 : 39), prn_stream);
240
fputc (xcount & 0xff, prn_stream);
241
fputc (xcount >> 8, prn_stream);
242
fwrite (data, 1, count, prn_stream);
245
/* If xdpi == 360, the P6 / LQ850 cannot print adjacent pixels. Clear the
246
second last pixel of every run of set pixels, so that the last pixel
247
is always printed. */
249
dot24_improve_bitmap (byte *data, int count)
252
register byte *p = data + 6;
254
for (i = 6; i < count; i += 3, p += 3)
256
p[-6] &= ~(~p[0] & p[-3]);
257
p[-5] &= ~(~p[1] & p[-2]);
258
p[-4] &= ~(~p[2] & p[-1]);
267
necp6_print_page(gx_device_printer *pdev, FILE *prn_stream)
269
char necp6_init_string [] = "\033@\033P\033l\000\r\034\063\001\033Q";
271
return dot24_print_page(pdev, prn_stream, necp6_init_string, sizeof(necp6_init_string));
275
lq850_print_page(gx_device_printer *pdev, FILE *prn_stream)
277
char lq850_init_string [] = "\033@\033P\033l\000\r\033\053\001\033Q";
279
return dot24_print_page(pdev, prn_stream, lq850_init_string, sizeof(lq850_init_string));