1 /* Copyright (C) 1993, 2000 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: zcolor1.c,v 1.3.6.1.2.1 2003/01/17 00:49:05 giles Exp $ */
20 /* Level 1 extended color operators */
21 #include "ghost.h"
22 #include "oper.h"
23 #include "estack.h"
24 #include "ialloc.h"
25 #include "igstate.h"
26 #include "iutil.h"
27 #include "store.h"
28 #include "gxfixed.h"
29 #include "gxmatrix.h"
30 #include "gzstate.h"
31 #include "gxdevice.h"
32 #include "gxcmap.h"
33 #include "gscolor1.h"
34 #include "gscssub.h"
35 #include "gxcspace.h"
36 #include "icolor.h"
37 #include "iimage.h"
38 
39 /* - currentblackgeneration <proc> */
40 private int
zcurrentblackgeneration(i_ctx_t * i_ctx_p)41 zcurrentblackgeneration(i_ctx_t *i_ctx_p)
42 {
43     os_ptr op = osp;
44 
45     push(1);
46     *op = istate->black_generation;
47     return 0;
48 }
49 
50 /* - currentcmykcolor <cyan> <magenta> <yellow> <black> */
51 private int
zcurrentcmykcolor(i_ctx_t * i_ctx_p)52 zcurrentcmykcolor(i_ctx_t *i_ctx_p)
53 {
54     os_ptr op = osp;
55     float par[4];
56     int code = gs_currentcmykcolor(igs, par);
57 
58     if (code < 0)
59 	return code;
60     push(4);
61     make_floats(op - 3, par, 4);
62     return 0;
63 }
64 
65 /* - currentcolortransfer <redproc> <greenproc> <blueproc> <grayproc> */
66 private int
zcurrentcolortransfer(i_ctx_t * i_ctx_p)67 zcurrentcolortransfer(i_ctx_t *i_ctx_p)
68 {
69     os_ptr op = osp;
70 
71     push(4);
72     op[-3] = istate->transfer_procs.colored.red;
73     op[-2] = istate->transfer_procs.colored.green;
74     op[-1] = istate->transfer_procs.colored.blue;
75     *op = istate->transfer_procs.colored.gray;
76     return 0;
77 }
78 
79 /* - currentundercolorremoval <proc> */
80 private int
zcurrentundercolorremoval(i_ctx_t * i_ctx_p)81 zcurrentundercolorremoval(i_ctx_t *i_ctx_p)
82 {
83     os_ptr op = osp;
84 
85     push(1);
86     *op = istate->undercolor_removal;
87     return 0;
88 }
89 
90 /* <proc> setblackgeneration - */
91 private int
zsetblackgeneration(i_ctx_t * i_ctx_p)92 zsetblackgeneration(i_ctx_t *i_ctx_p)
93 {
94     os_ptr op = osp;
95     int code;
96 
97     check_proc(*op);
98     check_ostack(zcolor_remap_one_ostack - 1);
99     check_estack(1 + zcolor_remap_one_estack);
100     code = gs_setblackgeneration_remap(igs, gs_mapped_transfer, false);
101     if (code < 0)
102 	return code;
103     istate->black_generation = *op;
104     pop(1);
105     push_op_estack(zcolor_remap_color);
106     return zcolor_remap_one(i_ctx_p, &istate->black_generation,
107 			    igs->black_generation, igs,
108 			    zcolor_remap_one_finish);
109 }
110 
111 /* <cyan> <magenta> <yellow> <black> setcmykcolor - */
112 private int
zsetcmykcolor(i_ctx_t * i_ctx_p)113 zsetcmykcolor(i_ctx_t *i_ctx_p)
114 {
115     os_ptr op = osp;
116     double par[4];
117     int code;
118 
119     if ((code = num_params(op, 4, par)) < 0 ||
120 	(code = gs_setcmykcolor(igs, par[0], par[1], par[2], par[3])) < 0
121 	)
122 	return code;
123     make_null(&istate->colorspace.array);
124     pop(4);
125     return 0;
126 }
127 
128 /* <redproc> <greenproc> <blueproc> <grayproc> setcolortransfer - */
129 private int
zsetcolortransfer(i_ctx_t * i_ctx_p)130 zsetcolortransfer(i_ctx_t *i_ctx_p)
131 {
132     os_ptr op = osp;
133     int code;
134 
135     check_proc(op[-3]);
136     check_proc(op[-2]);
137     check_proc(op[-1]);
138     check_proc(*op);
139     check_ostack(zcolor_remap_one_ostack * 4 - 4);
140     check_estack(1 + zcolor_remap_one_estack * 4);
141     istate->transfer_procs.colored.red = op[-3];
142     istate->transfer_procs.colored.green = op[-2];
143     istate->transfer_procs.colored.blue = op[-1];
144     istate->transfer_procs.colored.gray = *op;
145     if ((code = gs_setcolortransfer_remap(igs,
146 				     gs_mapped_transfer, gs_mapped_transfer,
147 				     gs_mapped_transfer, gs_mapped_transfer,
148 					  false)) < 0
149 	)
150 	return code;
151     /* Use osp rather than op here, because zcolor_remap_one pushes. */
152     pop(4);
153     push_op_estack(zcolor_reset_transfer);
154     if ((code = zcolor_remap_one(i_ctx_p,
155 				 &istate->transfer_procs.colored.red,
156 				 igs->set_transfer.colored.red, igs,
157 				 zcolor_remap_one_finish)) < 0 ||
158 	(code = zcolor_remap_one(i_ctx_p,
159 				 &istate->transfer_procs.colored.green,
160 				 igs->set_transfer.colored.green, igs,
161 				 zcolor_remap_one_finish)) < 0 ||
162 	(code = zcolor_remap_one(i_ctx_p,
163 				 &istate->transfer_procs.colored.blue,
164 				 igs->set_transfer.colored.blue, igs,
165 				 zcolor_remap_one_finish)) < 0 ||
166 	(code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.colored.gray,
167 				 igs->set_transfer.colored.gray, igs,
168 				 zcolor_remap_one_finish)) < 0
169 	)
170 	return code;
171     return o_push_estack;
172 }
173 
174 /* <proc> setundercolorremoval - */
175 private int
zsetundercolorremoval(i_ctx_t * i_ctx_p)176 zsetundercolorremoval(i_ctx_t *i_ctx_p)
177 {
178     os_ptr op = osp;
179     int code;
180 
181     check_proc(*op);
182     check_ostack(zcolor_remap_one_ostack - 1);
183     check_estack(1 + zcolor_remap_one_estack);
184     code = gs_setundercolorremoval_remap(igs, gs_mapped_transfer, false);
185     if (code < 0)
186 	return code;
187     istate->undercolor_removal = *op;
188     pop(1);
189     push_op_estack(zcolor_remap_color);
190     return zcolor_remap_one(i_ctx_p, &istate->undercolor_removal,
191 			    igs->undercolor_removal, igs,
192 			    zcolor_remap_one_signed_finish);
193 }
194 
195 /* <width> <height> <bits/comp> <matrix> */
196 /*      <datasrc_0> ... <datasrc_ncomp-1> true <ncomp> colorimage - */
197 /*      <datasrc> false <ncomp> colorimage - */
198 private int
zcolorimage(i_ctx_t * i_ctx_p)199 zcolorimage(i_ctx_t *i_ctx_p)
200 {
201     return zimage_multiple(i_ctx_p, false);
202 }
203 
204 /* ------ Initialization procedure ------ */
205 
206 const op_def zcolor1_op_defs[] =
207 {
208     {"0currentblackgeneration", zcurrentblackgeneration},
209     {"0currentcmykcolor", zcurrentcmykcolor},
210     {"0currentcolortransfer", zcurrentcolortransfer},
211     {"0currentundercolorremoval", zcurrentundercolorremoval},
212     {"1setblackgeneration", zsetblackgeneration},
213     {"4setcmykcolor", zsetcmykcolor},
214     {"4setcolortransfer", zsetcolortransfer},
215     {"1setundercolorremoval", zsetundercolorremoval},
216     {"7colorimage", zcolorimage},
217     op_def_end(0)
218 };
219