1 /* Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: gdevstc1.c,v 1.4 2002/02/21 22:24:52 giles Exp $*/
18 /* Epson Stylus-Color Printer-Driver */
19
20 /***
21 This file holds the sample-implementation of a monochrome-algorithm for
22 the stcolor-driver. It is available via
23
24 gs -sDEVICE=stcolor -sDithering=gsmono ...
25
26 Actually this is no dithering-algorithm, it lets ghostscript do the job.
27 This achieved, by requesting BYTE-Values between 0 and 1 to be delivered,
28 which causes a depth of 1-Bit by default.
29
30 ***/
31
32 /*
33 * gdevstc.h holds all the includes and the driver-specific definitions, so
34 * it is the only include you need. To add a new algorthim, STC_MODI in
35 * gdevstc.h should be extended. (see the instructions there)
36 */
37
38 #include "gdevstc.h"
39
40 /*
41 * the routine required.
42 */
43
44 /*ARGSUSED*/
45 int
stc_gsmono(stcolor_device * sdev,int npixel,byte * in,byte * buf,byte * out)46 stc_gsmono(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
47 {
48
49 /*
50 * There are basically 3 Types of calls:
51 * npixel < 0 => initialize buf, if this is required
52 * (happens only if requested)
53 * npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
54 * in == NULL signals, that the basic-driver has decided
55 * that this scanline is white. (Useful for really dithering
56 * drivers)
57 */
58
59 /* ============================================================= */
60 if(npixel > 0) { /* npixel > 0 -> scanline-processing */
61 /* ============================================================= */
62
63 /* -----------------------------------------------*/
64 if(in != NULL) { /* normal processing */
65 /* -----------------------------------------------*/
66
67 memcpy(out,in,npixel); /* really simple algorithm */
68
69 /* -----------------------------------------------*/
70 } else { /* skip-notification */
71 /* -----------------------------------------------*/
72
73 /* An algorithm may use the output-line as a buffer.
74 So it might need to be cleared on white-lines.
75 */
76
77 memset(out,0,npixel);
78
79 /* -----------------------------------------------*/
80 } /* normal / skip */
81 /* -----------------------------------------------*/
82
83 /* ============================================================= */
84 } else { /* npixel <= 0 -> initialisation */
85 /* ============================================================= */
86 /*
87 * the optional buffer is already allocated by the basic-driver, here
88 * you just need to fill it, for instance, set it all to zeros:
89 */
90 int buf_size;
91
92 /*
93 * compute the size of the buffer, according to the requested values
94 * the buffer consists of a constant part, e.g. related to the number
95 * of color-components, and a number of arrays, which are multiples of
96 * the size of a scanline times the number of components.
97 * additionally, the size of the scanlines may be expanded by one to the
98 * right and to the left.
99 */
100 buf_size =
101 sdev->stc.dither->bufadd /* scanline-independend size */
102 + (-npixel) /* pixels */
103 * (sdev->stc.dither->flags/STC_SCAN) /* * scanlines */
104 * sdev->color_info.num_components; /* * comp */
105
106 if(buf_size > 0) { /* we obviously have a buffer */
107 memset(buf,0,buf_size * sdev->stc.alg_item);
108 } /* we obviously have a buffer */
109
110 /*
111 * Usually one should check parameters upon initializaon
112 */
113 if(sdev->color_info.num_components != 1) return -1;
114
115 if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) return -2;
116
117 /*
118 * must neither have STC_DIRECT nor STC_WHITE
119 */
120 if((sdev->stc.dither->flags & STC_DIRECT) != 0) return -3;
121
122 } /* scanline-processing or initialisation */
123
124 return 0; /* negative values are error-codes, that abort printing */
125 }
126