xref: /plan9-contrib/sys/src/cmd/gs/src/gdevstc3.c (revision d46c239f8612929b7dbade67d0d071633df3a15d)
1 /* Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
2 
3   This file is part of AFPL Ghostscript.
4 
5   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
6   distributor accepts any responsibility for the consequences of using it, or
7   for whether it serves any particular purpose or works at all, unless he or
8   she says so in writing.  Refer to the Aladdin Free Public License (the
9   "License") for full details.
10 
11   Every copy of AFPL Ghostscript must include a copy of the License, normally
12   in a plain ASCII text file named PUBLIC.  The License grants you the right
13   to copy, modify and redistribute AFPL Ghostscript, but only under certain
14   conditions described in the License.  Among other things, the License
15   requires that the copyright notice and this notice be preserved on all
16   copies.
17 */
18 
19 /*$Id: gdevstc3.c,v 1.2 2000/09/19 19:00:22 lpd Exp $*/
20 /* Epson Stylus-Color Printer-Driver */
21 
22 /***
23      This file holds the sample-implementation of a RGB-algorithm for
24      the stcolor-driver. It is available via
25 
26           gs -sDEVICE=stcolor -sDithering=gsrgb ...
27 
28      Actually this is no dithering-algorithm, it lets ghostscript do the job.
29      This achieved, by requesting BYTE-Values between 0 and 1 to be delivered,
30      which causes a depth of 1-Bit by default.
31 
32  ***/
33 
34 /*
35  * gdevstc.h holds all the includes and the driver-specific definitions, so
36  * it is the only include you need. To add a new algorthim, STC_MODI in
37  * gdevstc.h should be extended. (see the instructions there)
38  */
39 
40 #include "gdevstc.h"
41 
42 /*
43  * the routine required.
44  */
45 
46 /*ARGSUSED*/
47 int
48 stc_gsrgb(stcolor_device *sdev,int npixel,byte *ip,byte *buf,byte *out)
49 {
50 
51    int   error = 0;
52 
53 /*
54  * There are basically 3 Types of calls:
55  * npixel < 0    => initialize buf, if this is required
56  *                  (happens only if requested)
57  * npixel > 0    => process next scanline, if the flag STC_WHITE is set, then
58  *                  in == NULL signals, that the basic-driver has decided
59  *                  that this scanline is white. (Useful for really dithering
60  *                  drivers)
61  */
62 
63 /* ============================================================= */
64    if(npixel > 0) {  /* npixel >  0 -> scanline-processing       */
65 /* ============================================================= */
66 
67       int p;
68 
69 /*
70  *    simply merge the color-values into a single byte
71  *    (RED, GREEN, BLUE are defined in gdevstc.h)
72  */
73       for(p = 0; p < npixel; ++p,++out) { /* loop over pixels */
74 
75          *out = 0;
76          if(*ip++) *out |= RED;
77          if(*ip++) *out |= GREEN;
78          if(*ip++) *out |= BLUE;
79 
80       }                                   /* loop over pixels */
81 
82 /* ============================================================= */
83    } else {          /* npixel <= 0 -> initialisation            */
84 /* ============================================================= */
85 /*
86  * besides buffer-Initialisation, one may check the parameters in
87  * the algorithm-table of the driver.
88  */
89 
90 /*    we didn't check for the white-calls above, so they would cause errors */
91       if(sdev->stc.dither->flags & STC_WHITE)              error = -1;
92 
93 /*    if we're not setup for bytes, this is an error too */
94       if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) error = -2;
95 
96 /*    and rgb-mode is the only supported mode */
97       if(sdev->color_info.num_components != 3)             error = -3;
98 
99 /*    we can't deal with ghostscript-data directly. */
100       if(sdev->stc.dither->flags & STC_DIRECT)             error = -4;
101 
102 /* ============================================================= */
103    } /* scanline-processing or initialisation */
104 /* ============================================================= */
105 
106    return error;
107 }
108