File: gximask.c

package info (click to toggle)
ghostscript 9.06~dfsg-2%2Bdeb8u7
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 62,484 kB
  • sloc: ansic: 440,074; python: 4,915; cpp: 3,565; sh: 2,520; tcl: 1,482; perl: 1,374; makefile: 421; lisp: 407; awk: 66; yacc: 18
file content (112 lines) | stat: -rw-r--r-- 4,128 bytes parent folder | download | duplicates (2)
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
/* Copyright (C) 2001-2012 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.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
   CA  94903, U.S.A., +1(415)492-9861, for further information.
*/


/* Functions for masked fill optimization. */
#include "gx.h"
#include "memory_.h"
#include "gserrors.h"
#include "gsptype1.h"
#include "gsptype2.h"
#include "gxdevice.h"
#include "gxdcolor.h"
#include "gxcpath.h"
#include "gximask.h"
#include "gzacpath.h"
#include "gzcpath.h"
#include "gxdevsop.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) || gx_dc_is_pattern1_color_clist_based(pdevc)) {
        if (!dev_proc(dev, dev_spec_op)(dev, gxdso_pattern_can_accum, NULL, gs_no_id)) {
            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;
            pcdev->width = dev->width;   /* For gx_default_copy_mono. */
            pcdev->height = dev->height; /* For gx_default_copy_mono. */
            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;
    gx_clip_path 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);
    gx_make_clip_device_on_stack(&cdev, pcpath1, tdev);
    if (code >= 0 && pcdev->bbox.p.x < pcdev->bbox.q.x) {
        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;
    }
    if (pcpath1 == &cpath_with_shading_bbox)
        gx_cpath_free(&cpath_with_shading_bbox, "s_image_cleanup");
    gx_device_retain((gx_device *)pcdev, false);
    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;
}