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: gdevstc3.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 RGB-algorithm for
22 the stcolor-driver. It is available via
23
24 gs -sDEVICE=stcolor -sDithering=gsrgb ...
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_gsrgb(stcolor_device * sdev,int npixel,byte * ip,byte * buf,byte * out)46 stc_gsrgb(stcolor_device *sdev,int npixel,byte *ip,byte *buf,byte *out)
47 {
48
49 int error = 0;
50
51 /*
52 * There are basically 3 Types of calls:
53 * npixel < 0 => initialize buf, if this is required
54 * (happens only if requested)
55 * npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
56 * in == NULL signals, that the basic-driver has decided
57 * that this scanline is white. (Useful for really dithering
58 * drivers)
59 */
60
61 /* ============================================================= */
62 if(npixel > 0) { /* npixel > 0 -> scanline-processing */
63 /* ============================================================= */
64
65 int p;
66
67 /*
68 * simply merge the color-values into a single byte
69 * (RED, GREEN, BLUE are defined in gdevstc.h)
70 */
71 for(p = 0; p < npixel; ++p,++out) { /* loop over pixels */
72
73 *out = 0;
74 if(*ip++) *out |= RED;
75 if(*ip++) *out |= GREEN;
76 if(*ip++) *out |= BLUE;
77
78 } /* loop over pixels */
79
80 /* ============================================================= */
81 } else { /* npixel <= 0 -> initialisation */
82 /* ============================================================= */
83 /*
84 * besides buffer-Initialisation, one may check the parameters in
85 * the algorithm-table of the driver.
86 */
87
88 /* we didn't check for the white-calls above, so they would cause errors */
89 if(sdev->stc.dither->flags & STC_WHITE) error = -1;
90
91 /* if we're not setup for bytes, this is an error too */
92 if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) error = -2;
93
94 /* and rgb-mode is the only supported mode */
95 if(sdev->color_info.num_components != 3) error = -3;
96
97 /* we can't deal with ghostscript-data directly. */
98 if(sdev->stc.dither->flags & STC_DIRECT) error = -4;
99
100 /* ============================================================= */
101 } /* scanline-processing or initialisation */
102 /* ============================================================= */
103
104 return error;
105 }
106