1 /* Copyright (C) 1995, 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: gdevrops.c,v 1.12 2004/06/24 05:03:36 dan Exp $ */
18 /* RasterOp source device */
19 #include "gx.h"
20 #include "gserrors.h"
21 #include "gxdcolor.h"
22 #include "gxdevice.h"
23 #include "gdevmrop.h"
24
25 /* GC procedures */
26 private_st_device_rop_texture();
ENUM_PTRS_BEGIN(device_rop_texture_enum_ptrs)27 private ENUM_PTRS_BEGIN(device_rop_texture_enum_ptrs) {
28 if (index < st_device_color_max_ptrs) {
29 gs_ptr_type_t ptype =
30 ENUM_SUPER_ELT(gx_device_rop_texture, st_device_color, texture, 0);
31
32 if (ptype)
33 return ptype;
34 return ENUM_OBJ(NULL); /* don't stop early */
35 }
36 ENUM_PREFIX(st_device_forward, st_device_color_max_ptrs);
37 } ENUM_PTRS_END
RELOC_PTRS_BEGIN(device_rop_texture_reloc_ptrs)38 private RELOC_PTRS_BEGIN(device_rop_texture_reloc_ptrs) {
39 RELOC_PREFIX(st_device_forward);
40 RELOC_SUPER(gx_device_rop_texture, st_device_color, texture);
41 } RELOC_PTRS_END
42
43 /* Device for providing source data for RasterOp. */
44 private dev_proc_fill_rectangle(rop_texture_fill_rectangle);
45 private dev_proc_copy_mono(rop_texture_copy_mono);
46 private dev_proc_copy_color(rop_texture_copy_color);
47
48 /* The device descriptor. */
49 private const gx_device_rop_texture gs_rop_texture_device = {
50 std_device_std_body(gx_device_rop_texture, 0, "rop source",
51 0, 0, 1, 1),
52 {NULL, /* open_device */
53 gx_forward_get_initial_matrix,
54 NULL, /* default_sync_output */
55 NULL, /* output_page */
56 NULL, /* close_device */
57 gx_forward_map_rgb_color,
58 gx_forward_map_color_rgb,
59 rop_texture_fill_rectangle,
60 NULL, /* tile_rectangle */
61 rop_texture_copy_mono,
62 rop_texture_copy_color,
63 NULL, /* draw_line */
64 NULL, /* get_bits */
65 gx_forward_get_params,
66 gx_forward_put_params,
67 gx_forward_map_cmyk_color,
68 gx_forward_get_xfont_procs,
69 gx_forward_get_xfont_device,
70 gx_forward_map_rgb_alpha_color,
71 gx_forward_get_page_device,
72 NULL, /* get_alpha_bits (no alpha) */
73 gx_no_copy_alpha, /* shouldn't be called */
74 gx_forward_get_band,
75 gx_no_copy_rop, /* shouldn't be called */
76 NULL, /* fill_path */
77 NULL, /* stroke_path */
78 NULL, /* fill_mask */
79 NULL, /* fill_trapezoid */
80 NULL, /* fill_parallelogram */
81 NULL, /* fill_triangle */
82 NULL, /* draw_thin_line */
83 NULL, /* begin_image */
84 NULL, /* image_data */
85 NULL, /* end_image */
86 NULL, /* strip_tile_rectangle */
87 NULL, /* strip_copy_rop */
88 gx_forward_get_clipping_box,
89 NULL, /* begin_typed_image */
90 NULL, /* get_bits_rectangle */
91 gx_forward_map_color_rgb_alpha,
92 NULL, /* create_compositor */
93 gx_forward_get_hardware_params,
94 NULL, /* text_begin */
95 NULL, /* finish_copydevice */
96 NULL, /* begin_transparency_group */
97 NULL, /* end_transparency_group */
98 NULL, /* begin_transparency_mask */
99 NULL, /* end_transparency_mask */
100 NULL, /* discard_transparency_layer */
101 gx_forward_get_color_mapping_procs,
102 gx_forward_get_color_comp_index,
103 gx_forward_encode_color,
104 gx_forward_decode_color,
105 gx_forward_pattern_manage,
106 gx_forward_fill_rectangle_hl_color,
107 gx_forward_include_color_space,
108 gx_forward_fill_linear_color_scanline,
109 gx_forward_fill_linear_color_trapezoid,
110 gx_forward_fill_linear_color_triangle,
111 gx_forward_update_spot_equivalent_colors
112 },
113 0, /* target */
114 lop_default /* log_op */
115 /* */ /* texture */
116 };
117
118 /* Create a RasterOp source device. */
119 int
gx_alloc_rop_texture_device(gx_device_rop_texture ** prsdev,gs_memory_t * mem,client_name_t cname)120 gx_alloc_rop_texture_device(gx_device_rop_texture ** prsdev, gs_memory_t * mem,
121 client_name_t cname)
122 {
123 *prsdev = gs_alloc_struct(mem, gx_device_rop_texture,
124 &st_device_rop_texture, cname);
125 return (*prsdev == 0 ? gs_note_error(gs_error_VMerror) : 0);
126 }
127
128 /* Initialize a RasterOp source device. */
129 void
gx_make_rop_texture_device(gx_device_rop_texture * dev,gx_device * target,gs_logical_operation_t log_op,const gx_device_color * texture)130 gx_make_rop_texture_device(gx_device_rop_texture * dev, gx_device * target,
131 gs_logical_operation_t log_op, const gx_device_color * texture)
132 {
133 gx_device_init((gx_device *) dev,
134 (const gx_device *)&gs_rop_texture_device,
135 NULL, true);
136 gx_device_set_target((gx_device_forward *)dev, target);
137 /* Drawing operations are defaulted, non-drawing are forwarded. */
138 check_device_separable((gx_device *) dev);
139 gx_device_fill_in_procs((gx_device *) dev);
140 gx_device_copy_params((gx_device *)dev, target);
141 dev->log_op = log_op;
142 dev->texture = *texture;
143 }
144
145 /* Fill a rectangle */
146 private int
rop_texture_fill_rectangle(gx_device * dev,int x,int y,int w,int h,gx_color_index color)147 rop_texture_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
148 gx_color_index color)
149 {
150 gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
151 gx_rop_source_t source;
152
153 source.sdata = NULL;
154 source.sourcex = 0;
155 source.sraster = 0;
156 source.id = gx_no_bitmap_id;
157 source.scolors[0] = source.scolors[1] = color;
158 source.use_scolors = true;
159 return gx_device_color_fill_rectangle(&rtdev->texture,
160 x, y, w, h, rtdev->target,
161 rtdev->log_op, &source);
162 }
163
164 /* Copy a monochrome rectangle */
165 private int
rop_texture_copy_mono(gx_device * dev,const byte * data,int sourcex,int raster,gx_bitmap_id id,int x,int y,int w,int h,gx_color_index color0,gx_color_index color1)166 rop_texture_copy_mono(gx_device * dev,
167 const byte * data, int sourcex, int raster, gx_bitmap_id id,
168 int x, int y, int w, int h,
169 gx_color_index color0, gx_color_index color1)
170 {
171 gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
172 gx_rop_source_t source;
173 gs_logical_operation_t lop = rtdev->log_op;
174
175 source.sdata = data;
176 source.sourcex = sourcex;
177 source.sraster = raster;
178 source.id = id;
179 source.scolors[0] = color0;
180 source.scolors[1] = color1;
181 source.use_scolors = true;
182 /* Adjust the logical operation per transparent colors. */
183 if (color0 == gx_no_color_index)
184 lop = rop3_use_D_when_S_0(lop);
185 else if (color1 == gx_no_color_index)
186 lop = rop3_use_D_when_S_1(lop);
187 return gx_device_color_fill_rectangle(&rtdev->texture,
188 x, y, w, h, rtdev->target,
189 lop, &source);
190 }
191
192 /* Copy a color rectangle */
193 private int
rop_texture_copy_color(gx_device * dev,const byte * data,int sourcex,int raster,gx_bitmap_id id,int x,int y,int w,int h)194 rop_texture_copy_color(gx_device * dev,
195 const byte * data, int sourcex, int raster, gx_bitmap_id id,
196 int x, int y, int w, int h)
197 {
198 gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
199 gx_rop_source_t source;
200
201 source.sdata = data;
202 source.sourcex = sourcex;
203 source.sraster = raster;
204 source.id = id;
205 source.scolors[0] = source.scolors[1] = gx_no_color_index;
206 source.use_scolors = false;
207 return gx_device_color_fill_rectangle(&rtdev->texture,
208 x, y, w, h, rtdev->target,
209 rtdev->log_op, &source);
210 }
211