1 /* Libart_LGPL - library of basic graphic primitives
2 * Copyright (C) 1998 Raph Levien
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
20 #include "art_misc.h"
21 #include "art_uta.h"
22 #include "art_rect.h"
23 #include "art_uta_rect.h"
25 /**
26 * art_uta_from_irect: Generate uta covering a rectangle.
27 * @bbox: The source rectangle.
28 *
29 * Generates a uta exactly covering @bbox. Please do not call this
30 * function with a @bbox with zero height or width.
31 *
32 * Return value: the new uta.
33 **/
34 ArtUta *
35 art_uta_from_irect (ArtIRect *bbox)
36 {
37 ArtUta *uta;
38 ArtUtaBbox *utiles;
39 ArtUtaBbox bb;
40 int width, height;
41 int x, y;
42 int xf0, yf0, xf1, yf1;
43 int ix;
45 uta = art_new (ArtUta, 1);
46 uta->x0 = bbox->x0 >> ART_UTILE_SHIFT;
47 uta->y0 = bbox->y0 >> ART_UTILE_SHIFT;
48 width = ((bbox->x1 + ART_UTILE_SIZE - 1) >> ART_UTILE_SHIFT) - uta->x0;
49 height = ((bbox->y1 + ART_UTILE_SIZE - 1) >> ART_UTILE_SHIFT) - uta->y0;
50 utiles = art_new (ArtUtaBbox, width * height);
52 uta->width = width;
53 uta->height = height;
54 uta->utiles = utiles;
56 xf0 = bbox->x0 & (ART_UTILE_SIZE - 1);
57 yf0 = bbox->y0 & (ART_UTILE_SIZE - 1);
58 xf1 = ((bbox->x1 - 1) & (ART_UTILE_SIZE - 1)) + 1;
59 yf1 = ((bbox->y1 - 1) & (ART_UTILE_SIZE - 1)) + 1;
60 if (height == 1)
61 {
62 if (width == 1)
63 utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, xf1, yf1);
64 else
65 {
66 utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, ART_UTILE_SIZE, yf1);
67 bb = ART_UTA_BBOX_CONS (0, yf0, ART_UTILE_SIZE, yf1);
68 for (x = 1; x < width - 1; x++)
69 utiles[x] = bb;
70 utiles[x] = ART_UTA_BBOX_CONS (0, yf0, xf1, yf1);
71 }
72 }
73 else
74 {
75 if (width == 1)
76 {
77 utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, xf1, ART_UTILE_SIZE);
78 bb = ART_UTA_BBOX_CONS (xf0, 0, xf1, ART_UTILE_SIZE);
79 for (y = 1; y < height - 1; y++)
80 utiles[y] = bb;
81 utiles[y] = ART_UTA_BBOX_CONS (xf0, 0, xf1, yf1);
82 }
83 else
84 {
85 utiles[0] =
86 ART_UTA_BBOX_CONS (xf0, yf0, ART_UTILE_SIZE, ART_UTILE_SIZE);
87 bb = ART_UTA_BBOX_CONS (0, yf0, ART_UTILE_SIZE, ART_UTILE_SIZE);
88 for (x = 1; x < width - 1; x++)
89 utiles[x] = bb;
90 utiles[x] = ART_UTA_BBOX_CONS (0, yf0, xf1, ART_UTILE_SIZE);
91 ix = width;
92 for (y = 1; y < height - 1; y++)
93 {
94 utiles[ix++] =
95 ART_UTA_BBOX_CONS (xf0, 0, ART_UTILE_SIZE, ART_UTILE_SIZE);
96 bb = ART_UTA_BBOX_CONS (0, 0, ART_UTILE_SIZE, ART_UTILE_SIZE);
97 for (x = 1; x < width - 1; x++)
98 utiles[ix++] = bb;
99 utiles[ix++] = ART_UTA_BBOX_CONS (0, 0, xf1, ART_UTILE_SIZE);
100 }
101 utiles[ix++] = ART_UTA_BBOX_CONS (xf0, 0, ART_UTILE_SIZE, yf1);
102 bb = ART_UTA_BBOX_CONS (0, 0, ART_UTILE_SIZE, yf1);
103 for (x = 1; x < width - 1; x++)
104 utiles[ix++] = bb;
105 utiles[ix++] = ART_UTA_BBOX_CONS (0, 0, xf1, yf1);
106 }
107 }
108 return uta;
109 }