1 /* Copyright (C) 1993, 2000 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: zcolor1.c,v 1.6 2002/08/22 07:12:29 henrys Exp $ */
18 /* Level 1 extended color operators */
19 #include "ghost.h"
20 #include "oper.h"
21 #include "estack.h"
22 #include "ialloc.h"
23 #include "igstate.h"
24 #include "iutil.h"
25 #include "store.h"
26 #include "gxfixed.h"
27 #include "gxmatrix.h"
28 #include "gzstate.h"
29 #include "gxdevice.h"
30 #include "gxcmap.h"
31 #include "gscolor1.h"
32 #include "gxcspace.h"
33 #include "icolor.h"
34 #include "iimage.h"
35
36 /* - currentblackgeneration <proc> */
37 private int
zcurrentblackgeneration(i_ctx_t * i_ctx_p)38 zcurrentblackgeneration(i_ctx_t *i_ctx_p)
39 {
40 os_ptr op = osp;
41
42 push(1);
43 *op = istate->black_generation;
44 return 0;
45 }
46
47 /* - currentcolortransfer <redproc> <greenproc> <blueproc> <grayproc> */
48 private int
zcurrentcolortransfer(i_ctx_t * i_ctx_p)49 zcurrentcolortransfer(i_ctx_t *i_ctx_p)
50 {
51 os_ptr op = osp;
52
53 push(4);
54 op[-3] = istate->transfer_procs.red;
55 op[-2] = istate->transfer_procs.green;
56 op[-1] = istate->transfer_procs.blue;
57 *op = istate->transfer_procs.gray;
58 return 0;
59 }
60
61 /* - currentundercolorremoval <proc> */
62 private int
zcurrentundercolorremoval(i_ctx_t * i_ctx_p)63 zcurrentundercolorremoval(i_ctx_t *i_ctx_p)
64 {
65 os_ptr op = osp;
66
67 push(1);
68 *op = istate->undercolor_removal;
69 return 0;
70 }
71
72 /* <proc> setblackgeneration - */
73 private int
zsetblackgeneration(i_ctx_t * i_ctx_p)74 zsetblackgeneration(i_ctx_t *i_ctx_p)
75 {
76 os_ptr op = osp;
77 int code;
78
79 check_proc(*op);
80 check_ostack(zcolor_remap_one_ostack - 1);
81 check_estack(1 + zcolor_remap_one_estack);
82 code = gs_setblackgeneration_remap(igs, gs_mapped_transfer, false);
83 if (code < 0)
84 return code;
85 istate->black_generation = *op;
86 pop(1);
87 push_op_estack(zcolor_remap_color);
88 return zcolor_remap_one(i_ctx_p, &istate->black_generation,
89 igs->black_generation, igs,
90 zcolor_remap_one_finish);
91 }
92
93 /* <redproc> <greenproc> <blueproc> <grayproc> setcolortransfer - */
94 private int
zsetcolortransfer(i_ctx_t * i_ctx_p)95 zsetcolortransfer(i_ctx_t *i_ctx_p)
96 {
97 os_ptr op = osp;
98 int code;
99
100 check_proc(op[-3]);
101 check_proc(op[-2]);
102 check_proc(op[-1]);
103 check_proc(*op);
104 check_ostack(zcolor_remap_one_ostack * 4 - 4);
105 check_estack(1 + zcolor_remap_one_estack * 4);
106 istate->transfer_procs.red = op[-3];
107 istate->transfer_procs.green = op[-2];
108 istate->transfer_procs.blue = op[-1];
109 istate->transfer_procs.gray = *op;
110 if ((code = gs_setcolortransfer_remap(igs,
111 gs_mapped_transfer, gs_mapped_transfer,
112 gs_mapped_transfer, gs_mapped_transfer,
113 false)) < 0
114 )
115 return code;
116 /* Use osp rather than op here, because zcolor_remap_one pushes. */
117 pop(4);
118 push_op_estack(zcolor_reset_transfer);
119 if ((code = zcolor_remap_one(i_ctx_p,
120 &istate->transfer_procs.red,
121 igs->set_transfer.red, igs,
122 zcolor_remap_one_finish)) < 0 ||
123 (code = zcolor_remap_one(i_ctx_p,
124 &istate->transfer_procs.green,
125 igs->set_transfer.green, igs,
126 zcolor_remap_one_finish)) < 0 ||
127 (code = zcolor_remap_one(i_ctx_p,
128 &istate->transfer_procs.blue,
129 igs->set_transfer.blue, igs,
130 zcolor_remap_one_finish)) < 0 ||
131 (code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.gray,
132 igs->set_transfer.gray, igs,
133 zcolor_remap_one_finish)) < 0
134 )
135 return code;
136 return o_push_estack;
137 }
138
139 /* <proc> setundercolorremoval - */
140 private int
zsetundercolorremoval(i_ctx_t * i_ctx_p)141 zsetundercolorremoval(i_ctx_t *i_ctx_p)
142 {
143 os_ptr op = osp;
144 int code;
145
146 check_proc(*op);
147 check_ostack(zcolor_remap_one_ostack - 1);
148 check_estack(1 + zcolor_remap_one_estack);
149 code = gs_setundercolorremoval_remap(igs, gs_mapped_transfer, false);
150 if (code < 0)
151 return code;
152 istate->undercolor_removal = *op;
153 pop(1);
154 push_op_estack(zcolor_remap_color);
155 return zcolor_remap_one(i_ctx_p, &istate->undercolor_removal,
156 igs->undercolor_removal, igs,
157 zcolor_remap_one_signed_finish);
158 }
159
160
161 /* ------ Initialization procedure ------ */
162
163 const op_def zcolor1_op_defs[] =
164 {
165 {"0currentblackgeneration", zcurrentblackgeneration},
166 {"0currentcolortransfer", zcurrentcolortransfer},
167 {"0currentundercolorremoval", zcurrentundercolorremoval},
168 {"1setblackgeneration", zsetblackgeneration},
169 {"4setcolortransfer", zsetcolortransfer},
170 {"1setundercolorremoval", zsetundercolorremoval},
171 op_def_end(0)
172 };
173