/src/ghostpdl/base/gdevrops.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* RasterOp source device */ |
18 | | #include "gx.h" |
19 | | #include "gserrors.h" |
20 | | #include "gxdcolor.h" |
21 | | #include "gxdevice.h" |
22 | | #include "gdevmrop.h" |
23 | | |
24 | | /* GC procedures */ |
25 | | private_st_device_rop_texture(); |
26 | 0 | static ENUM_PTRS_BEGIN(device_rop_texture_enum_ptrs) { |
27 | 0 | if (index < st_device_color_max_ptrs) { |
28 | 0 | gs_ptr_type_t ptype = |
29 | 0 | ENUM_SUPER_ELT(gx_device_rop_texture, st_device_color, texture, 0); |
30 | |
|
31 | 0 | if (ptype) |
32 | 0 | return ptype; |
33 | 0 | return ENUM_OBJ(NULL); /* don't stop early */ |
34 | 0 | } |
35 | 0 | ENUM_PREFIX(st_device_forward, st_device_color_max_ptrs); |
36 | 0 | } ENUM_PTRS_END |
37 | 0 | static RELOC_PTRS_BEGIN(device_rop_texture_reloc_ptrs) { |
38 | 0 | RELOC_PREFIX(st_device_forward); |
39 | 0 | RELOC_SUPER(gx_device_rop_texture, st_device_color, texture); |
40 | 0 | } RELOC_PTRS_END |
41 | | |
42 | | /* Device for providing source data for RasterOp. */ |
43 | | static dev_proc_fill_rectangle(rop_texture_fill_rectangle); |
44 | | static dev_proc_copy_mono(rop_texture_copy_mono); |
45 | | static dev_proc_copy_color(rop_texture_copy_color); |
46 | | static dev_proc_copy_planes(rop_texture_copy_planes); |
47 | | |
48 | | /* The device descriptor. */ |
49 | | static void |
50 | | rop_texture_initialize_device_procs(gx_device *dev) |
51 | 0 | { |
52 | 0 | set_dev_proc(dev, get_initial_matrix,gx_forward_get_initial_matrix); |
53 | 0 | set_dev_proc(dev, map_rgb_color, gx_forward_map_rgb_color); |
54 | 0 | set_dev_proc(dev, map_color_rgb, gx_forward_map_color_rgb); |
55 | 0 | set_dev_proc(dev, fill_rectangle, rop_texture_fill_rectangle); |
56 | 0 | set_dev_proc(dev, copy_mono, rop_texture_copy_mono); |
57 | 0 | set_dev_proc(dev, copy_color, rop_texture_copy_color); |
58 | 0 | set_dev_proc(dev, get_params, gx_forward_get_params); |
59 | 0 | set_dev_proc(dev, put_params, gx_forward_put_params); |
60 | 0 | set_dev_proc(dev, map_cmyk_color, gx_forward_map_cmyk_color); |
61 | 0 | set_dev_proc(dev, get_page_device, gx_forward_get_page_device); |
62 | 0 | set_dev_proc(dev, copy_alpha, gx_no_copy_alpha); |
63 | 0 | set_dev_proc(dev, get_clipping_box, gx_forward_get_clipping_box); |
64 | 0 | set_dev_proc(dev, get_hardware_params, gx_forward_get_hardware_params); |
65 | 0 | set_dev_proc(dev, get_color_mapping_procs, gx_forward_get_color_mapping_procs); |
66 | 0 | set_dev_proc(dev, get_color_comp_index, gx_forward_get_color_comp_index); |
67 | 0 | set_dev_proc(dev, encode_color, gx_forward_encode_color); |
68 | 0 | set_dev_proc(dev, decode_color, gx_forward_decode_color); |
69 | 0 | set_dev_proc(dev, fill_rectangle_hl_color, gx_forward_fill_rectangle_hl_color); |
70 | 0 | set_dev_proc(dev, include_color_space, gx_forward_include_color_space); |
71 | 0 | set_dev_proc(dev, fill_linear_color_scanline, gx_forward_fill_linear_color_scanline); |
72 | 0 | set_dev_proc(dev, fill_linear_color_trapezoid, gx_forward_fill_linear_color_trapezoid); |
73 | 0 | set_dev_proc(dev, fill_linear_color_triangle, gx_forward_fill_linear_color_triangle); |
74 | 0 | set_dev_proc(dev, update_spot_equivalent_colors, gx_forward_update_spot_equivalent_colors); |
75 | 0 | set_dev_proc(dev, ret_devn_params, gx_forward_ret_devn_params); |
76 | 0 | set_dev_proc(dev, fillpage, gx_forward_fillpage); |
77 | 0 | set_dev_proc(dev, dev_spec_op, gx_forward_dev_spec_op); |
78 | 0 | set_dev_proc(dev, copy_planes, rop_texture_copy_planes); |
79 | 0 | set_dev_proc(dev, get_profile, gx_forward_get_profile); |
80 | 0 | set_dev_proc(dev, set_graphics_type_tag, gx_forward_set_graphics_type_tag); |
81 | 0 | } |
82 | | static const gx_device_rop_texture gs_rop_texture_device = { |
83 | | std_device_std_body(gx_device_rop_texture, |
84 | | rop_texture_initialize_device_procs, |
85 | | "rop source", |
86 | | 0, 0, 1, 1), |
87 | | { 0 }, |
88 | | 0, /* target */ |
89 | | lop_default /* log_op */ |
90 | | /* */ /* texture */ |
91 | | }; |
92 | | |
93 | | /* Create a RasterOp source device. */ |
94 | | int |
95 | | gx_alloc_rop_texture_device(gx_device_rop_texture ** prsdev, gs_memory_t * mem, |
96 | | client_name_t cname) |
97 | 0 | { |
98 | 0 | *prsdev = gs_alloc_struct(mem, gx_device_rop_texture, |
99 | 0 | &st_device_rop_texture, cname); |
100 | 0 | return (*prsdev == 0 ? gs_note_error(gs_error_VMerror) : 0); |
101 | 0 | } |
102 | | |
103 | | /* Initialize a RasterOp source device. */ |
104 | | /* 'target' device must not be NULL */ |
105 | | void |
106 | | gx_make_rop_texture_device(gx_device_rop_texture * dev, gx_device * target, |
107 | | gs_logical_operation_t log_op, const gx_device_color * texture) |
108 | 0 | { |
109 | | /* Can never fail */ |
110 | 0 | (void)gx_device_init((gx_device *) dev, |
111 | 0 | (const gx_device *)&gs_rop_texture_device, |
112 | 0 | target->memory, true); |
113 | 0 | gx_device_set_target((gx_device_forward *)dev, target); |
114 | | /* Drawing operations are defaulted, non-drawing are forwarded. */ |
115 | 0 | check_device_separable((gx_device *) dev); |
116 | 0 | gx_device_fill_in_procs((gx_device *) dev); |
117 | 0 | gx_device_copy_params((gx_device *)dev, target); |
118 | 0 | dev->graphics_type_tag = target->graphics_type_tag; /* Init from device */ |
119 | 0 | dev->log_op = log_op; |
120 | 0 | dev->texture = *texture; |
121 | 0 | } |
122 | | |
123 | | /* Fill a rectangle */ |
124 | | static int |
125 | | rop_texture_fill_rectangle(gx_device * dev, int x, int y, int w, int h, |
126 | | gx_color_index color) |
127 | 0 | { |
128 | 0 | gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev; |
129 | 0 | gx_rop_source_t source; |
130 | |
|
131 | 0 | source.sdata = NULL; |
132 | 0 | source.sourcex = 0; |
133 | 0 | source.sraster = 0; |
134 | 0 | source.id = gx_no_bitmap_id; |
135 | 0 | source.scolors[0] = source.scolors[1] = color; |
136 | 0 | source.planar_height = 0; |
137 | 0 | source.use_scolors = true; |
138 | 0 | return gx_device_color_fill_rectangle(&rtdev->texture, |
139 | 0 | x, y, w, h, rtdev->target, |
140 | 0 | rtdev->log_op, &source); |
141 | 0 | } |
142 | | |
143 | | /* Copy a monochrome rectangle */ |
144 | | static int |
145 | | rop_texture_copy_mono(gx_device * dev, |
146 | | const byte * data, int sourcex, int raster, gx_bitmap_id id, |
147 | | int x, int y, int w, int h, |
148 | | gx_color_index color0, gx_color_index color1) |
149 | 0 | { |
150 | 0 | gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev; |
151 | 0 | gx_rop_source_t source; |
152 | 0 | gs_logical_operation_t lop = rtdev->log_op; |
153 | |
|
154 | 0 | source.sdata = data; |
155 | 0 | source.sourcex = sourcex; |
156 | 0 | source.sraster = raster; |
157 | 0 | source.id = id; |
158 | 0 | source.scolors[0] = color0; |
159 | 0 | source.scolors[1] = color1; |
160 | 0 | source.planar_height = 0; |
161 | 0 | source.use_scolors = true; |
162 | | /* Adjust the logical operation per transparent colors. */ |
163 | 0 | if (color0 == gx_no_color_index) |
164 | 0 | lop = rop3_use_D_when_S_0(lop); |
165 | 0 | else if (color1 == gx_no_color_index) |
166 | 0 | lop = rop3_use_D_when_S_1(lop); |
167 | 0 | return gx_device_color_fill_rectangle(&rtdev->texture, |
168 | 0 | x, y, w, h, rtdev->target, |
169 | 0 | lop, &source); |
170 | 0 | } |
171 | | |
172 | | /* Copy a color rectangle */ |
173 | | static int |
174 | | rop_texture_copy_color(gx_device * dev, |
175 | | const byte * data, int sourcex, int raster, gx_bitmap_id id, |
176 | | int x, int y, int w, int h) |
177 | 0 | { |
178 | 0 | gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev; |
179 | 0 | gx_rop_source_t source; |
180 | |
|
181 | 0 | source.sdata = data; |
182 | 0 | source.sourcex = sourcex; |
183 | 0 | source.sraster = raster; |
184 | 0 | source.id = id; |
185 | 0 | source.scolors[0] = source.scolors[1] = gx_no_color_index; |
186 | 0 | source.planar_height = 0; |
187 | 0 | source.use_scolors = false; |
188 | 0 | return gx_device_color_fill_rectangle(&rtdev->texture, |
189 | 0 | x, y, w, h, rtdev->target, |
190 | 0 | rtdev->log_op, &source); |
191 | 0 | } |
192 | | |
193 | | /* Copy a color rectangle */ |
194 | | static int |
195 | | rop_texture_copy_planes(gx_device * dev, |
196 | | const byte * data, int sourcex, int raster, |
197 | | gx_bitmap_id id, int x, int y, int w, int h, |
198 | | int plane_height) |
199 | 0 | { |
200 | 0 | gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev; |
201 | 0 | gx_rop_source_t source; |
202 | |
|
203 | 0 | source.sdata = data; |
204 | 0 | source.sourcex = sourcex; |
205 | 0 | source.sraster = raster; |
206 | 0 | source.id = id; |
207 | 0 | source.scolors[0] = source.scolors[1] = gx_no_color_index; |
208 | 0 | source.planar_height = plane_height; |
209 | 0 | source.use_scolors = false; |
210 | 0 | return gx_device_color_fill_rectangle(&rtdev->texture, |
211 | 0 | x, y, w, h, rtdev->target, |
212 | 0 | rtdev->log_op, |
213 | 0 | &source); |
214 | 0 | } |