1
/* Copyright (C) 2001-2006 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, 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.
14
/* $Id: gdevstc1.c 8022 2007-06-05 22:23:38Z giles $*/
15
/* Epson Stylus-Color Printer-Driver */
18
This file holds the sample-implementation of a monochrome-algorithm for
19
the stcolor-driver. It is available via
21
gs -sDEVICE=stcolor -sDithering=gsmono ...
23
Actually this is no dithering-algorithm, it lets ghostscript do the job.
24
This achieved, by requesting BYTE-Values between 0 and 1 to be delivered,
25
which causes a depth of 1-Bit by default.
30
* gdevstc.h holds all the includes and the driver-specific definitions, so
31
* it is the only include you need. To add a new algorthim, STC_MODI in
32
* gdevstc.h should be extended. (see the instructions there)
38
* the routine required.
43
stc_gsmono(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
47
* There are basically 3 Types of calls:
48
* npixel < 0 => initialize buf, if this is required
49
* (happens only if requested)
50
* npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
51
* in == NULL signals, that the basic-driver has decided
52
* that this scanline is white. (Useful for really dithering
56
/* ============================================================= */
57
if(npixel > 0) { /* npixel > 0 -> scanline-processing */
58
/* ============================================================= */
60
/* -----------------------------------------------*/
61
if(in != NULL) { /* normal processing */
62
/* -----------------------------------------------*/
64
memcpy(out,in,npixel); /* really simple algorithm */
66
/* -----------------------------------------------*/
67
} else { /* skip-notification */
68
/* -----------------------------------------------*/
70
/* An algorithm may use the output-line as a buffer.
71
So it might need to be cleared on white-lines.
76
/* -----------------------------------------------*/
78
/* -----------------------------------------------*/
80
/* ============================================================= */
81
} else { /* npixel <= 0 -> initialisation */
82
/* ============================================================= */
84
* the optional buffer is already allocated by the basic-driver, here
85
* you just need to fill it, for instance, set it all to zeros:
90
* compute the size of the buffer, according to the requested values
91
* the buffer consists of a constant part, e.g. related to the number
92
* of color-components, and a number of arrays, which are multiples of
93
* the size of a scanline times the number of components.
94
* additionally, the size of the scanlines may be expanded by one to the
95
* right and to the left.
98
sdev->stc.dither->bufadd /* scanline-independend size */
99
+ (-npixel) /* pixels */
100
* (sdev->stc.dither->flags/STC_SCAN) /* * scanlines */
101
* sdev->color_info.num_components; /* * comp */
103
if(buf_size > 0) { /* we obviously have a buffer */
104
memset(buf,0,buf_size * sdev->stc.alg_item);
105
} /* we obviously have a buffer */
108
* Usually one should check parameters upon initializaon
110
if(sdev->color_info.num_components != 1) return -1;
112
if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) return -2;
115
* must neither have STC_DIRECT nor STC_WHITE
117
if((sdev->stc.dither->flags & STC_DIRECT) != 0) return -3;
119
} /* scanline-processing or initialisation */
121
return 0; /* negative values are error-codes, that abort printing */