~ubuntu-branches/ubuntu/hardy/cairo/hardy-updates

« back to all changes in this revision

Viewing changes to src/cairo-region.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-01-17 13:00:59 UTC
  • Revision ID: james.westby@ubuntu.com-20080117130059-3gbudaudr2w8bl4w
Tags: upstream-1.5.6
Import upstream version 1.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 
2
/* cairo - a vector graphics library with display and print output
 
3
 *
 
4
 * Copyright © 2005 Red Hat, Inc.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it either under the terms of the GNU Lesser General Public
 
8
 * License version 2.1 as published by the Free Software Foundation
 
9
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 
10
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 
11
 * notice, a recipient may use your version of this file under either
 
12
 * the MPL or the LGPL.
 
13
 *
 
14
 * You should have received a copy of the LGPL along with this library
 
15
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
17
 * You should have received a copy of the MPL along with this library
 
18
 * in the file COPYING-MPL-1.1
 
19
 *
 
20
 * The contents of this file are subject to the Mozilla Public License
 
21
 * Version 1.1 (the "License"); you may not use this file except in
 
22
 * compliance with the License. You may obtain a copy of the License at
 
23
 * http://www.mozilla.org/MPL/
 
24
 *
 
25
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 
26
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 
27
 * the specific language governing rights and limitations.
 
28
 *
 
29
 * The Original Code is the cairo graphics library.
 
30
 *
 
31
 * The Initial Developer of the Original Code is Red Hat, Inc.
 
32
 *
 
33
 * Contributor(s):
 
34
 *      Owen Taylor <otaylor@redhat.com>
 
35
 *      Vladimir Vukicevic <vladimir@pobox.com>
 
36
 */
 
37
 
 
38
#include "cairoint.h"
 
39
 
 
40
void
 
41
_cairo_region_init (cairo_region_t *region)
 
42
{
 
43
    pixman_region_init (&region->rgn);
 
44
}
 
45
 
 
46
void
 
47
_cairo_region_init_rect (cairo_region_t *region,
 
48
                         cairo_rectangle_int_t *rect)
 
49
{
 
50
    pixman_region_init_rect (&region->rgn,
 
51
                             rect->x, rect->y,
 
52
                             rect->width, rect->height);
 
53
}
 
54
 
 
55
cairo_int_status_t
 
56
_cairo_region_init_boxes (cairo_region_t *region,
 
57
                          cairo_box_int_t *boxes,
 
58
                          int count)
 
59
{
 
60
    pixman_box16_t stack_pboxes[CAIRO_STACK_ARRAY_LENGTH (pixman_box16_t)];
 
61
    pixman_box16_t *pboxes = stack_pboxes;
 
62
    cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
 
63
    int i;
 
64
 
 
65
    if (count > ARRAY_LENGTH(stack_pboxes)) {
 
66
        pboxes = _cairo_malloc_ab (count, sizeof(pixman_box16_t));
 
67
        if (pboxes == NULL)
 
68
            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
69
    }
 
70
 
 
71
    for (i = 0; i < count; i++) {
 
72
        pboxes[i].x1 = boxes[i].p1.x;
 
73
        pboxes[i].y1 = boxes[i].p1.y;
 
74
        pboxes[i].x2 = boxes[i].p2.x;
 
75
        pboxes[i].y2 = boxes[i].p2.y;
 
76
    }
 
77
 
 
78
    if (!pixman_region_init_rects (&region->rgn, pboxes, count))
 
79
        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
80
 
 
81
    if (pboxes != stack_pboxes)
 
82
        free (pboxes);
 
83
 
 
84
    return status;
 
85
}
 
86
 
 
87
void
 
88
_cairo_region_fini (cairo_region_t *region)
 
89
{
 
90
    pixman_region_fini (&region->rgn);
 
91
}
 
92
 
 
93
cairo_int_status_t
 
94
_cairo_region_copy (cairo_region_t *dst, cairo_region_t *src)
 
95
{
 
96
    if (!pixman_region_copy (&dst->rgn, &src->rgn))
 
97
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
98
 
 
99
    return CAIRO_STATUS_SUCCESS;
 
100
}
 
101
 
 
102
int
 
103
_cairo_region_num_boxes (cairo_region_t *region)
 
104
{
 
105
    return pixman_region_n_rects (&region->rgn);
 
106
}
 
107
 
 
108
cairo_int_status_t
 
109
_cairo_region_get_boxes (cairo_region_t *region, int *num_boxes, cairo_box_int_t **boxes)
 
110
{
 
111
    int nboxes;
 
112
    pixman_box16_t *pboxes;
 
113
    cairo_box_int_t *cboxes;
 
114
    int i;
 
115
 
 
116
    pboxes = pixman_region_rectangles (&region->rgn, &nboxes);
 
117
 
 
118
    if (nboxes == 0) {
 
119
        *num_boxes = 0;
 
120
        *boxes = NULL;
 
121
        return CAIRO_STATUS_SUCCESS;
 
122
    }
 
123
 
 
124
    cboxes = _cairo_malloc_ab (nboxes, sizeof(cairo_box_int_t));
 
125
    if (cboxes == NULL)
 
126
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
127
 
 
128
    for (i = 0; i < nboxes; i++) {
 
129
        cboxes[i].p1.x = pboxes[i].x1;
 
130
        cboxes[i].p1.y = pboxes[i].y1;
 
131
        cboxes[i].p2.x = pboxes[i].x2;
 
132
        cboxes[i].p2.y = pboxes[i].y2;
 
133
    }
 
134
 
 
135
    *num_boxes = nboxes;
 
136
    *boxes = cboxes;
 
137
 
 
138
    return CAIRO_STATUS_SUCCESS;
 
139
}
 
140
 
 
141
void
 
142
_cairo_region_boxes_fini (cairo_region_t *region, cairo_box_int_t *boxes)
 
143
{
 
144
    free (boxes);
 
145
}
 
146
 
 
147
/**
 
148
 * _cairo_region_get_extents:
 
149
 * @region: a #cairo_region_t
 
150
 * @rect: rectangle into which to store the extents
 
151
 *
 
152
 * Gets the bounding box of a region as a cairo_rectangle_int_t
 
153
 **/
 
154
void
 
155
_cairo_region_get_extents (cairo_region_t *region, cairo_rectangle_int_t *extents)
 
156
{
 
157
    pixman_box16_t *pextents = pixman_region_extents (&region->rgn);
 
158
 
 
159
    extents->x = pextents->x1;
 
160
    extents->y = pextents->y1;
 
161
    extents->width = pextents->x2 - pextents->x1;
 
162
    extents->height = pextents->y2 - pextents->y1;
 
163
}
 
164
 
 
165
cairo_int_status_t
 
166
_cairo_region_subtract (cairo_region_t *dst, cairo_region_t *a, cairo_region_t *b)
 
167
{
 
168
    if (!pixman_region_subtract (&dst->rgn, &a->rgn, &b->rgn))
 
169
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
170
 
 
171
    return CAIRO_STATUS_SUCCESS;
 
172
}
 
173
 
 
174
cairo_int_status_t
 
175
_cairo_region_intersect (cairo_region_t *dst, cairo_region_t *a, cairo_region_t *b)
 
176
{
 
177
    if (!pixman_region_intersect (&dst->rgn, &a->rgn, &b->rgn))
 
178
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
179
 
 
180
    return CAIRO_STATUS_SUCCESS;
 
181
}
 
182
 
 
183
cairo_int_status_t
 
184
_cairo_region_union_rect (cairo_region_t *dst,
 
185
                          cairo_region_t *src,
 
186
                          cairo_rectangle_int_t *rect)
 
187
{
 
188
    if (!pixman_region_union_rect (&dst->rgn, &src->rgn,
 
189
                                   rect->x, rect->y,
 
190
                                   rect->width, rect->height))
 
191
        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
192
 
 
193
    return CAIRO_STATUS_SUCCESS;
 
194
}
 
195
 
 
196
cairo_bool_t
 
197
_cairo_region_not_empty (cairo_region_t *region)
 
198
{
 
199
    return (cairo_bool_t) pixman_region_not_empty (&region->rgn);
 
200
}
 
201
 
 
202
void
 
203
_cairo_region_translate (cairo_region_t *region,
 
204
                         int x, int y)
 
205
{
 
206
    pixman_region_translate (&region->rgn, x, y);
 
207
}
 
208
 
 
209
pixman_region_overlap_t
 
210
_cairo_region_contains_rectangle (cairo_region_t *region, cairo_rectangle_int_t *rect)
 
211
{
 
212
    pixman_box16_t pbox;
 
213
 
 
214
    pbox.x1 = rect->x;
 
215
    pbox.y1 = rect->y;
 
216
    pbox.x2 = rect->x + rect->width;
 
217
    pbox.y2 = rect->y + rect->height;
 
218
 
 
219
    return pixman_region_contains_rectangle (&region->rgn, &pbox);
 
220
}