Coverage Report

Created: 2026-04-01 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/base/gdevrops.c
Line
Count
Source
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
274
{
52
274
    set_dev_proc(dev, get_initial_matrix,gx_forward_get_initial_matrix);
53
274
    set_dev_proc(dev, map_rgb_color, gx_forward_map_rgb_color);
54
274
    set_dev_proc(dev, map_color_rgb, gx_forward_map_color_rgb);
55
274
    set_dev_proc(dev, fill_rectangle, rop_texture_fill_rectangle);
56
274
    set_dev_proc(dev, copy_mono, rop_texture_copy_mono);
57
274
    set_dev_proc(dev, copy_color, rop_texture_copy_color);
58
274
    set_dev_proc(dev, get_params, gx_forward_get_params);
59
274
    set_dev_proc(dev, put_params, gx_forward_put_params);
60
274
    set_dev_proc(dev, map_cmyk_color, gx_forward_map_cmyk_color);
61
274
    set_dev_proc(dev, get_page_device, gx_forward_get_page_device);
62
274
    set_dev_proc(dev, copy_alpha, gx_no_copy_alpha);
63
274
    set_dev_proc(dev, get_clipping_box, gx_forward_get_clipping_box);
64
274
    set_dev_proc(dev, get_hardware_params, gx_forward_get_hardware_params);
65
274
    set_dev_proc(dev, get_color_mapping_procs, gx_forward_get_color_mapping_procs);
66
274
    set_dev_proc(dev, get_color_comp_index, gx_forward_get_color_comp_index);
67
274
    set_dev_proc(dev, encode_color, gx_forward_encode_color);
68
274
    set_dev_proc(dev, decode_color, gx_forward_decode_color);
69
274
    set_dev_proc(dev, fill_rectangle_hl_color, gx_forward_fill_rectangle_hl_color);
70
274
    set_dev_proc(dev, include_color_space, gx_forward_include_color_space);
71
274
    set_dev_proc(dev, fill_linear_color_scanline, gx_forward_fill_linear_color_scanline);
72
274
    set_dev_proc(dev, fill_linear_color_trapezoid, gx_forward_fill_linear_color_trapezoid);
73
274
    set_dev_proc(dev, fill_linear_color_triangle, gx_forward_fill_linear_color_triangle);
74
274
    set_dev_proc(dev, update_spot_equivalent_colors, gx_forward_update_spot_equivalent_colors);
75
274
    set_dev_proc(dev, ret_devn_params, gx_forward_ret_devn_params);
76
274
    set_dev_proc(dev, fillpage, gx_forward_fillpage);
77
274
    set_dev_proc(dev, dev_spec_op, gx_forward_dev_spec_op);
78
274
    set_dev_proc(dev, copy_planes, rop_texture_copy_planes);
79
274
    set_dev_proc(dev, get_profile, gx_forward_get_profile);
80
274
    set_dev_proc(dev, set_graphics_type_tag, gx_forward_set_graphics_type_tag);
81
274
}
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
274
{
98
274
    *prsdev = gs_alloc_struct(mem, gx_device_rop_texture,
99
274
                              &st_device_rop_texture, cname);
100
274
    return (*prsdev == 0 ? gs_note_error(gs_error_VMerror) : 0);
101
274
}
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
274
{
109
    /* Can never fail */
110
274
    (void)gx_device_init((gx_device *) dev,
111
274
                         (const gx_device *)&gs_rop_texture_device,
112
274
                         target->memory, true);
113
274
    gx_device_set_target((gx_device_forward *)dev, target);
114
    /* Drawing operations are defaulted, non-drawing are forwarded. */
115
274
    check_device_separable((gx_device *) dev);
116
274
    gx_device_fill_in_procs((gx_device *) dev);
117
274
    gx_device_copy_params((gx_device *)dev, target);
118
274
    dev->graphics_type_tag = target->graphics_type_tag; /* Init from device */
119
274
    dev->log_op = log_op;
120
274
    dev->texture = *texture;
121
274
}
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
29.5k
{
128
29.5k
    gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
129
29.5k
    gx_rop_source_t source;
130
131
29.5k
    source.sdata = NULL;
132
29.5k
    source.sourcex = 0;
133
29.5k
    source.sraster = 0;
134
29.5k
    source.id = gx_no_bitmap_id;
135
29.5k
    source.scolors[0] = source.scolors[1] = color;
136
29.5k
    source.planar_height = 0;
137
29.5k
    source.use_scolors = true;
138
29.5k
    return gx_device_color_fill_rectangle(&rtdev->texture,
139
29.5k
                                          x, y, w, h, rtdev->target,
140
29.5k
                                          rtdev->log_op, &source);
141
29.5k
}
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
36
{
150
36
    gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
151
36
    gx_rop_source_t source;
152
36
    gs_logical_operation_t lop = rtdev->log_op;
153
154
36
    source.sdata = data;
155
36
    source.sourcex = sourcex;
156
36
    source.sraster = raster;
157
36
    source.id = id;
158
36
    source.scolors[0] = color0;
159
36
    source.scolors[1] = color1;
160
36
    source.planar_height = 0;
161
36
    source.use_scolors = true;
162
    /* Adjust the logical operation per transparent colors. */
163
36
    if (color0 == gx_no_color_index)
164
0
        lop = rop3_use_D_when_S_0(lop);
165
36
    else if (color1 == gx_no_color_index)
166
0
        lop = rop3_use_D_when_S_1(lop);
167
36
    return gx_device_color_fill_rectangle(&rtdev->texture,
168
36
                                          x, y, w, h, rtdev->target,
169
36
                                          lop, &source);
170
36
}
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
}