xref: /plan9/sys/src/cmd/gs/src/gdevstc.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
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: gdevstc.h,v 1.5 2002/06/16 07:25:26 lpd Exp $*/
18 /* Epson Stylus-Color Printer-Driver */
19 #ifndef   gdevstc_INCLUDED
20 #  define gdevstc_INCLUDED
21 
22 /***
23  *** This holds most of the declarations used by gdevstc.c/stcolor.
24  *** It should be included by the dithering-routines and should be
25  *** modified to include the separately compilable routines.
26  ***/
27 
28 /*** Ghostscript-Headers ***/
29 
30 #include "gdevprn.h"
31 #include "gsparam.h"
32 #include "gsstate.h"
33 
34 /*** Private Type for 32Bit-Pixels ***/
35 #if     arch_log2_sizeof_int < 2  /* int is too small */
36    typedef unsigned long stc_pixel;
37 #else                             /* int is sufficient */
38    typedef unsigned int  stc_pixel;
39 #endif                            /* use int or long ? */
40 
41 /*** Auxillary-Device Structure ***/
42 
43 typedef struct stc_s {
44    long            flags;      /* some mode-flags */
45    int             bits;       /* the number of bits per component */
46    const struct stc_dither_s  *dither;     /* dithering-mode */
47    float          *am;         /* 3/9/16-E. vector/matrix */
48 
49    float          *extc[4];    /* Given arrays for stccode */
50    uint            sizc[4];    /* Size of extcode-arrays */
51    gx_color_value *code[4];    /* cv -> internal */
52 
53    float          *extv[4];    /* Given arrays for stcvals */
54    uint            sizv[4];    /* Size of extvals-arrays */
55    byte           *vals[4];    /* internal -> dithering */
56 
57    stc_pixel  white_run[3];    /* the white-pattern */
58    stc_pixel  white_end[3];    /* the white-Trailer */
59    gs_param_string_array
60                    algorithms; /* Names of the available algorithms */
61 
62    gs_param_string escp_init;     /* Initialization-Sequence */
63    gs_param_string escp_release;  /* Initialization-Sequence */
64    int             escp_width; /* Number of Pixels printed */
65    int             escp_height;/* Height send to the Printer */
66    int             escp_top;   /* Top-Margin, send to the printer */
67    int             escp_bottom;/* Bottom-Margin, send to the printer */
68 
69    int             alg_item;   /* Size of the items used by the algorithm */
70 
71    int             prt_buf;    /* Number of buffers */
72    int             prt_size;   /* Size of the Printer-buffer */
73    int             escp_size;  /* Size of the ESC/P2-buffer */
74    int             seed_size;  /* Size of the seed-buffers */
75 
76    int             escp_u;     /* print-resolution (3600 / ydpi )*/
77    int             escp_c;     /* selected color */
78    int             escp_v;     /* spacing within band */
79    int             escp_h;     /* 3600 / xdpi */
80    int             escp_m;     /* number of heads */
81    int             escp_lf;    /* linefeed in units */
82 
83    int             prt_y;      /* print-coordinate */
84    int             stc_y;      /* Next line 2b printed */
85    int             buf_y;      /* Next line 2b loaded into the buffer */
86    int             prt_scans;  /* number of lines printed */
87 
88 
89    int            *prt_width;  /* Width of buffered lines */
90    byte          **prt_data;   /* Buffered printer-lines */
91    byte           *escp_data;  /* Buffer for ESC/P2-Data */
92    byte           *seed_row[4];/* Buffer for delta-row compression (prt_size) */
93 
94 } stc_t;
95 
96 /*** Main-Device Structure ***/
97 
98 typedef struct stcolor_device_s {
99 	gx_device_common;
100 	gx_prn_device_common;
101         stc_t stc;
102 } stcolor_device;
103 
104 #define STCDFLAG0  0x000001L /* Algorithm-Bit 0 */
105 #define STCDFLAG1  0x000002L /* Algorithm-Bit 1 */
106 #define STCDFLAG2  0x000004L /* Algorithm-Bit 2 */
107 #define STCDFLAG3  0x000008L /* Algorithm-Bit 3 */
108 #define STCDFLAG4  0x000010L /* Algorithm-Bit 4 */
109 #define STCCMYK10  0x000020L /* CMYK10-Coding active */
110 
111 #define STCUNIDIR  0x000040L /* Unidirectional, if set */
112 #define STCUWEAVE  0x000080L /* Hardware Microweave */
113 #define STCNWEAVE  0x000100L /* Software Microweave disabled */
114 
115 #define STCOK4GO   0x000200L /* stc_put_params was o.k. */
116 
117 #define STCCOMP    0x000C00L /* RLE, Plain (>= 1.18) */
118 #define STCPLAIN   0x000400L /* No compression */
119 #define STCDELTA   0x000800L /* Delta-Row */
120 
121 #define STCMODEL   0x00f000L /* STC, ST800 */
122 #define STCST800   0x001000L /* Monochrome-Variant */
123 #define STCSTCII   0x002000L /* Stylus Color II */
124 
125 #define STCBAND    0x010000L /* Initialization defined */
126 #define STCHEIGHT  0x020000L /* Page-Length set */
127 #define STCWIDTH   0x040000L /* Page-Length set */
128 #define STCTOP     0x080000L /* Top-Margin set */
129 #define STCBOTTOM  0x100000L /* Bottom-Margin set */
130 #define STCINIT    0x200000L /* Initialization defined */
131 #define STCRELEASE 0x400000L /* Release defined */
132 
133 #define STCPRINT   0x800000L /* Data printed */
134 
135 /*** Datatype for the array of dithering-Algorithms ***/
136 
137 #define stc_proc_dither(name) \
138  int name(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
139 
140 typedef struct stc_dither_s {
141   const char *name; /* Mode-Name for Dithering */
142   stc_proc_dither((*fun));
143   uint        flags;
144   uint        bufadd;
145   double      minmax[2];
146 } stc_dither_t;
147 
148 /*
149  * Color-Values for the output
150  */
151 #define BLACK   1 /* in monochrome-Mode as well as in CMYK-Mode */
152 #define RED     4 /* in RGB-Mode */
153 #define GREEN   2
154 #define BLUE    1
155 #define CYAN    8 /* in CMYK-Mode */
156 #define MAGENTA 4
157 #define YELLOW  2
158 
159 /*** A Macro to ease Type-depending things with the stc_p-union ***/
160 
161 #define STC_TYPESWITCH(Dither,Action)             \
162    switch((Dither)->flags & STC_TYPE)  {          \
163    case STC_BYTE: Action(byte); break;            \
164    case STC_LONG: Action(long); break;            \
165    default:       Action(float); break;}
166 
167 /***
168  *** MODIFY HERE to include your routine:
169  ***
170  *** 1. Declare it here
171  *** 2. Add it to the definition of STC_MODI
172  *** 3. Add your file to the dependency-list in the Makefile & devices.mak
173  ***/
174 
175 /* Step 1. */
176 stc_proc_dither(stc_gsmono);  /* resides in gdevstc1.c */
177 stc_proc_dither(stc_fs);      /* resides in gdevstc2.c */
178 stc_proc_dither(stc_fscmyk);  /* resides in gdevstc2.c too */
179 stc_proc_dither(stc_gsrgb);   /* resides in gdevstc3.c */
180 stc_proc_dither(stc_fs2);     /* resides in gdevstc4.c */
181 
182 
183 /* Values used to assemble flags */
184 #define DeviceGray  1 /* ProcessColorModel = DeviceGray  */
185 #define DeviceRGB   3 /* ProcessColorModel = DeviceRGB   */
186 #define DeviceCMYK  4 /* ProcessColorModel = DeviceCMYK  */
187 
188 #define STC_BYTE    8 /* Pass Bytes  to the Dithering-Routine */
189 #define STC_LONG   16 /* Pass Longs  to the Dithering-Routine */
190 #define STC_FLOAT  24 /* Pass Floats to the Dithering-Routine */
191 #define STC_TYPE   24 /* all the type-bits */
192 
193 #define STC_CMYK10 32 /* Special 32-Bit CMYK-Coding */
194 #define STC_DIRECT 64 /* Suppress conversion of Scanlines */
195 #define STC_WHITE 128 /* Call Algorithm for white lines too (out == NULL) */
196 #define STC_SCAN  256 /* multiply by number of scanlines in buffer */
197 
198 /* Step 2. */
199 /* Items: 1. Name to activate it
200           2. Name of the dithering-function
201           3. Several flags ored together, including # of buffered scanlines
202           4. Additional buffer-space (bytes/longs/floats)
203           5. Array of double with minimum and maximum-value
204    Keep the last line as it is.
205  */
206 
207 #define STC_MODI \
208 {"gsmono", stc_gsmono, DeviceGray|STC_BYTE,0,{0.0,1.0}},\
209 {"gsrgb" , stc_gsrgb , DeviceRGB |STC_BYTE,0,{0.0,1.0}},\
210 {"fsmono", stc_fs, \
211   DeviceGray|STC_LONG|1*STC_SCAN,3+3*1,{0.0,16777215.0}},\
212 {"fsrgb",  stc_fs, \
213   DeviceRGB |STC_LONG|1*STC_SCAN,3+3*3,{0.0,16777215.0}},\
214 {"fsx4",   stc_fs, \
215   DeviceCMYK|STC_LONG|1*STC_SCAN,3+3*4,{0.0,16777215.0}},\
216 {"fscmyk", stc_fscmyk, \
217   DeviceCMYK|STC_LONG|1*STC_SCAN,3+3*4,{0.0,16777215.0}},\
218 {"fs2", stc_fs2, \
219   DeviceRGB |STC_BYTE|STC_WHITE|1*STC_SCAN,0,{0.0,255.0}},
220 
221 
222 #ifndef   X_DPI
223 #define   X_DPI   360
224 #endif /* X_DPI */
225 #ifndef   Y_DPI
226 #define   Y_DPI   360
227 #endif /* Y_DPI */
228 
229 #ifndef   STC_L_MARGIN
230 #  define STC_L_MARGIN 0.125 /* yields 45 Pixel@360DpI */
231 #endif /* STC_L_MARGIN */
232 #ifndef   STC_B_MARGIN
233 #  define STC_B_MARGIN 0.555 /* yields 198 Pixel@#60DpI (looses 1mm) */
234 #endif /* STC_B_MARGIN */
235 /*
236  * Right-Margin: Should match maximum print-width of 8".
237  */
238 
239 #ifndef   STC_R_MARGIN
240 #  ifdef A4
241 #    define STC_R_MARGIN 0.175 /* Yields 63 Pixel@360DpI */
242 #  else
243 #    define STC_R_MARGIN 0.375 /* 135 Pixel */
244 #  endif
245 #endif /* STC_R_MARGIN */
246 #ifndef   STC_T_MARGIN
247 #  define STC_T_MARGIN 0.125
248 #endif /* STC_T_MARGIN */
249 
250 #endif
251