xref: /plan9-contrib/sys/src/cmd/gs/src/gdevstc1.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: gdevstc1.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 monochrome-algorithm for
24      the stcolor-driver. It is available via
25 
26           gs -sDEVICE=stcolor -sDithering=gsmono ...
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_gsmono(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
49 {
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 /*    -----------------------------------------------*/
66       if(in != NULL) { /* normal processing          */
67 /*    -----------------------------------------------*/
68 
69          memcpy(out,in,npixel); /* really simple algorithm */
70 
71 /*    -----------------------------------------------*/
72       } else {                  /* skip-notification */
73 /*    -----------------------------------------------*/
74 
75          /* An algorithm may use the output-line as a buffer.
76             So it might need to be cleared on white-lines.
77          */
78 
79          memset(out,0,npixel);
80 
81 /*    -----------------------------------------------*/
82       }                             /* normal / skip */
83 /*    -----------------------------------------------*/
84 
85 /* ============================================================= */
86    } else {          /* npixel <= 0 -> initialisation            */
87 /* ============================================================= */
88 /*
89  *    the optional buffer is already allocated by the basic-driver, here
90  *    you just need to fill it, for instance, set it all to zeros:
91  */
92      int buf_size;
93 
94 /*
95  * compute the size of the buffer, according to the requested values
96  * the buffer consists of a constant part, e.g. related to the number
97  * of color-components, and a number of arrays, which are multiples of
98  * the size of a scanline times the number of components.
99  * additionally, the size of the scanlines may be expanded by one to the
100  * right and to the left.
101  */
102      buf_size =
103            sdev->stc.dither->bufadd              /* scanline-independend size */
104              + (-npixel)                                     /* pixels */
105                * (sdev->stc.dither->flags/STC_SCAN)          /* * scanlines */
106                * sdev->color_info.num_components;            /* * comp */
107 
108      if(buf_size > 0) { /* we obviously have a buffer */
109         memset(buf,0,buf_size * sdev->stc.alg_item);
110      }                  /* we obviously have a buffer */
111 
112 /*
113  * Usually one should check parameters upon initializaon
114  */
115      if(sdev->color_info.num_components         !=        1) return -1;
116 
117      if((sdev->stc.dither->flags & STC_TYPE)    != STC_BYTE) return -2;
118 
119 /*
120  * must neither have STC_DIRECT nor STC_WHITE
121  */
122       if((sdev->stc.dither->flags & STC_DIRECT) !=        0) return -3;
123 
124    } /* scanline-processing or initialisation */
125 
126    return 0; /* negative values are error-codes, that abort printing */
127 }
128