1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* Copyright (C) 2001-2021 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
Refer to licensing information at http://www.artifex.com or contact
Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
CA 94945, U.S.A., +1(415)492-9861, for further information.
*/
/* RasterOp implementation for 2- and 4-bit memory devices */
#include "memory_.h"
#include "gx.h"
#include "gsbittab.h"
#include "gserrors.h"
#include "gsropt.h"
#include "gxcindex.h"
#include "gxdcolor.h"
#include "gxdevice.h"
#include "gxdevmem.h"
#include "gdevmem.h"
#include "gdevmrop.h"
/* Calculate the X offset for a given Y value, */
/* taking shift into account if necessary. */
#define x_offset(px, ty, textures)\
((textures)->shift == 0 ? (px) :\
(px) + (ty) / (textures)->rep_height * (textures)->rep_shift)
/* ---------------- Fake RasterOp for 2- and 4-bit devices ---------------- */
/*
* Define patched versions of the driver procedures that may be called
* by mem_mono_strip_copy_rop (see below). Currently we just punt to
* the slow, general case; we could do a lot better.
*/
static int
mem_gray_rop_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
gx_color_index color)
{
return -1;
}
static int
mem_gray_rop_copy_mono(gx_device * dev, const byte * data,
int dx, int raster, gx_bitmap_id id,
int x, int y, int w, int h,
gx_color_index zero, gx_color_index one)
{
return -1;
}
static int
mem_gray_rop_strip_tile_rectangle(gx_device * dev,
const gx_strip_bitmap * tiles,
int x, int y, int w, int h,
gx_color_index color0, gx_color_index color1,
int px, int py)
{
return -1;
}
int
mem_gray_strip_copy_rop2(gx_device * dev,
const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
const gx_color_index * scolors,
const gx_strip_bitmap * textures, const gx_color_index * tcolors,
int x, int y, int width, int height,
int phase_x, int phase_y, gs_logical_operation_t lop,
uint planar_height)
{
gx_color_index scolors2[2];
const gx_color_index *real_scolors = scolors;
gx_color_index tcolors2[2];
const gx_color_index *real_tcolors = tcolors;
gx_strip_bitmap texture2;
const gx_strip_bitmap *real_texture = textures;
long tdata;
int depth = dev->color_info.depth;
int log2_depth = depth >> 1; /* works for 2, 4 */
gx_color_index max_pixel = ((gx_color_index)1 << depth) - 1;
int code;
/* assert(planar_height == 0); */
#ifdef DEBUG
if (gs_debug_c('b'))
trace_copy_rop("mem_gray_strip_copy_rop",
dev, sdata, sourcex, sraster,
id, scolors, textures, tcolors,
x, y, width, height, phase_x, phase_y, lop);
#endif
lop = lop_sanitize(lop);
if (gx_device_has_color(dev) ||
(scolors && /* must be (0,0) or (max,max) */
((scolors[0] | scolors[1]) != 0) &&
((scolors[0] & scolors[1]) != max_pixel)) ||
(tcolors && (tcolors[0] != tcolors[1]))
) {
/* We can't fake it: do it the slow, painful way. */
return mem_default_strip_copy_rop2(dev, sdata, sourcex, sraster, id,
scolors, textures, tcolors,
x, y, width, height,
phase_x, phase_y, lop, 0);
}
if (scolors) { /* Must be a solid color: see above. */
scolors2[0] = scolors2[1] = scolors[0] & 1;
real_scolors = scolors2;
}
if (textures) {
texture2 = *textures;
texture2.size.x <<= log2_depth;
texture2.rep_width <<= log2_depth;
texture2.shift <<= log2_depth;
texture2.rep_shift <<= log2_depth;
texture2.num_planes = 1;
real_texture = &texture2;
}
if (tcolors) {
/* For polybit textures with colors other than */
/* all 0s or all 1s, fabricate the data. */
if (tcolors[0] != 0 && tcolors[0] != max_pixel) {
real_tcolors = 0;
*(byte *) & tdata = (byte) tcolors[0] << (8 - depth);
texture2.data = (byte *) & tdata;
texture2.raster = align_bitmap_mod;
texture2.size.x = texture2.rep_width = depth;
texture2.size.y = texture2.rep_height = 1;
texture2.id = gx_no_bitmap_id;
texture2.shift = texture2.rep_shift = 0;
real_texture = &texture2;
} else {
tcolors2[0] = tcolors2[1] = tcolors[0] & 1;
real_tcolors = tcolors2;
}
}
/*
* mem_mono_strip_copy_rop may call fill_rectangle, copy_mono, or
* strip_tile_rectangle for special cases. Patch those procedures
* temporarily so they will either do the right thing or return
* an error.
*/
{
dev_proc_fill_rectangle((*fill_rectangle)) =
dev_proc(dev, fill_rectangle);
dev_proc_copy_mono((*copy_mono)) =
dev_proc(dev, copy_mono);
dev_proc_strip_tile_rectangle((*strip_tile_rectangle)) =
dev_proc(dev, strip_tile_rectangle);
set_dev_proc(dev, fill_rectangle, mem_gray_rop_fill_rectangle);
set_dev_proc(dev, copy_mono, mem_gray_rop_copy_mono);
set_dev_proc(dev, strip_tile_rectangle,
mem_gray_rop_strip_tile_rectangle);
dev->width <<= log2_depth;
code = mem_mono_strip_copy_rop2(dev, sdata,
(real_scolors == NULL ?
sourcex << log2_depth : sourcex),
sraster, id, real_scolors,
real_texture, real_tcolors,
x << log2_depth, y,
width << log2_depth, height,
phase_x << log2_depth, phase_y,
lop, 0);
set_dev_proc(dev, fill_rectangle, fill_rectangle);
set_dev_proc(dev, copy_mono, copy_mono);
set_dev_proc(dev, strip_tile_rectangle, strip_tile_rectangle);
dev->width >>= log2_depth;
}
/* If we punted, use the general procedure. */
if (code < 0)
return mem_default_strip_copy_rop2(dev, sdata, sourcex, sraster, id,
scolors, textures, tcolors,
x, y, width, height,
phase_x, phase_y, lop, 0);
return code;
}
|