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
|
/* Copyright (C) 2001-2006 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 that
license. Refer to licensing information at http://www.artifex.com/
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
/* $Id$ */
/* Functions for masked fill optimization. */
#include "gx.h"
#include "memory_.h"
#include "gserrors.h"
#include "gsptype2.h"
#include "gxdevice.h"
#include "gxdcolor.h"
#include "gxcpath.h"
#include "gximask.h"
#include "gzacpath.h"
#include "gzcpath.h"
/* Functions for masked fill optimization. */
/* Imagemask with a shading color would paint entire shading for each rectangle of the mask.
These functions convert the mask into a clipping path and then render entire shading
at once through it.
*/
int
gx_image_fill_masked_start(gx_device *dev, const gx_device_color *pdevc, const gx_clip_path *pcpath,
gs_memory_t *mem, gx_device **cdev)
{
if (gx_dc_is_pattern2_color(pdevc)) {
if (!dev_proc(dev, pattern_manage)(dev, gs_no_id, NULL, pattern_manage__can_accum)) {
extern_st(st_device_cpath_accum);
gx_device_cpath_accum *pcdev = gs_alloc_struct(mem,
gx_device_cpath_accum, &st_device_cpath_accum, "gx_image_fill_masked_start");
gs_fixed_rect cbox;
if (pcdev == NULL)
return_error(gs_error_VMerror);
gx_cpath_accum_begin(pcdev, mem);
gx_cpath_outer_box(pcpath, &cbox);
gx_cpath_accum_set_cbox(pcdev, &cbox);
pcdev->rc.memory = mem;
gx_device_retain((gx_device *)pcdev, true);
*cdev = (gx_device *)pcdev;
}
} else
*cdev = dev;
return 0;
}
int
gx_image_fill_masked_end(gx_device *dev, gx_device *tdev, const gx_device_color *pdevc)
{
gx_device_cpath_accum *pcdev = (gx_device_cpath_accum *)dev;
gx_clip_path cpath, cpath_with_shading_bbox;
const gx_clip_path *pcpath1 = &cpath;
gx_device_clip cdev;
int code, code1;
gx_cpath_init_local(&cpath, pcdev->memory);
code = gx_cpath_accum_end(pcdev, &cpath);
if (code >= 0)
code = gx_dc_pattern2_clip_with_bbox(pdevc, tdev, &cpath_with_shading_bbox, &pcpath1);
if (code >= 0) {
gx_make_clip_device_on_stack(&cdev, pcpath1, tdev);
code1 = gx_device_color_fill_rectangle(pdevc,
pcdev->bbox.p.x, pcdev->bbox.p.y,
pcdev->bbox.q.x - pcdev->bbox.p.x,
pcdev->bbox.q.y - pcdev->bbox.p.y,
(gx_device *)&cdev, lop_default, 0);
if (code == 0)
code = code1;
gx_device_retain((gx_device *)pcdev, false);
}
if (pcpath1 == &cpath_with_shading_bbox)
gx_cpath_free(&cpath_with_shading_bbox, "s_image_cleanup");
gx_cpath_free(&cpath, "s_image_cleanup");
return code;
}
int
gx_image_fill_masked(gx_device *dev,
const byte *data, int data_x, int raster, gx_bitmap_id id,
int x, int y, int width, int height,
const gx_device_color *pdc, int depth,
gs_logical_operation_t lop, const gx_clip_path *pcpath)
{
gx_device *cdev;
int code;
code = gx_image_fill_masked_start(dev, pdc, pcpath, dev->memory, &cdev);
if (code >= 0)
code = (*dev_proc(cdev, fill_mask))(cdev, data, data_x, raster, id,
x, y, width, height, pdc, depth, lop, pcpath);
if (code >= 0 && cdev != dev)
code = gx_image_fill_masked_end(cdev, dev, pdc);
return code;
}
|