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 | */ |
---|
19 | |
---|
20 | #include "config.h" |
---|
21 | #include "art_uta_rect.h" |
---|
22 | |
---|
23 | #include "art_misc.h" |
---|
24 | #include "art_uta.h" |
---|
25 | #include "art_rect.h" |
---|
26 | |
---|
27 | /** |
---|
28 | * art_uta_from_irect: Generate uta covering a rectangle. |
---|
29 | * @bbox: The source rectangle. |
---|
30 | * |
---|
31 | * Generates a uta exactly covering @bbox. Please do not call this |
---|
32 | * function with a @bbox with zero height or width. |
---|
33 | * |
---|
34 | * Return value: the new uta. |
---|
35 | **/ |
---|
36 | ArtUta * |
---|
37 | art_uta_from_irect (ArtIRect *bbox) |
---|
38 | { |
---|
39 | ArtUta *uta; |
---|
40 | ArtUtaBbox *utiles; |
---|
41 | ArtUtaBbox bb; |
---|
42 | int width, height; |
---|
43 | int x, y; |
---|
44 | int xf0, yf0, xf1, yf1; |
---|
45 | int ix; |
---|
46 | |
---|
47 | uta = art_new (ArtUta, 1); |
---|
48 | uta->x0 = bbox->x0 >> ART_UTILE_SHIFT; |
---|
49 | uta->y0 = bbox->y0 >> ART_UTILE_SHIFT; |
---|
50 | width = ((bbox->x1 + ART_UTILE_SIZE - 1) >> ART_UTILE_SHIFT) - uta->x0; |
---|
51 | height = ((bbox->y1 + ART_UTILE_SIZE - 1) >> ART_UTILE_SHIFT) - uta->y0; |
---|
52 | utiles = art_new (ArtUtaBbox, width * height); |
---|
53 | |
---|
54 | uta->width = width; |
---|
55 | uta->height = height; |
---|
56 | uta->utiles = utiles; |
---|
57 | |
---|
58 | xf0 = bbox->x0 & (ART_UTILE_SIZE - 1); |
---|
59 | yf0 = bbox->y0 & (ART_UTILE_SIZE - 1); |
---|
60 | xf1 = ((bbox->x1 - 1) & (ART_UTILE_SIZE - 1)) + 1; |
---|
61 | yf1 = ((bbox->y1 - 1) & (ART_UTILE_SIZE - 1)) + 1; |
---|
62 | if (height == 1) |
---|
63 | { |
---|
64 | if (width == 1) |
---|
65 | utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, xf1, yf1); |
---|
66 | else |
---|
67 | { |
---|
68 | utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, ART_UTILE_SIZE, yf1); |
---|
69 | bb = ART_UTA_BBOX_CONS (0, yf0, ART_UTILE_SIZE, yf1); |
---|
70 | for (x = 1; x < width - 1; x++) |
---|
71 | utiles[x] = bb; |
---|
72 | utiles[x] = ART_UTA_BBOX_CONS (0, yf0, xf1, yf1); |
---|
73 | } |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | if (width == 1) |
---|
78 | { |
---|
79 | utiles[0] = ART_UTA_BBOX_CONS (xf0, yf0, xf1, ART_UTILE_SIZE); |
---|
80 | bb = ART_UTA_BBOX_CONS (xf0, 0, xf1, ART_UTILE_SIZE); |
---|
81 | for (y = 1; y < height - 1; y++) |
---|
82 | utiles[y] = bb; |
---|
83 | utiles[y] = ART_UTA_BBOX_CONS (xf0, 0, xf1, yf1); |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | utiles[0] = |
---|
88 | ART_UTA_BBOX_CONS (xf0, yf0, ART_UTILE_SIZE, ART_UTILE_SIZE); |
---|
89 | bb = ART_UTA_BBOX_CONS (0, yf0, ART_UTILE_SIZE, ART_UTILE_SIZE); |
---|
90 | for (x = 1; x < width - 1; x++) |
---|
91 | utiles[x] = bb; |
---|
92 | utiles[x] = ART_UTA_BBOX_CONS (0, yf0, xf1, ART_UTILE_SIZE); |
---|
93 | ix = width; |
---|
94 | for (y = 1; y < height - 1; y++) |
---|
95 | { |
---|
96 | utiles[ix++] = |
---|
97 | ART_UTA_BBOX_CONS (xf0, 0, ART_UTILE_SIZE, ART_UTILE_SIZE); |
---|
98 | bb = ART_UTA_BBOX_CONS (0, 0, ART_UTILE_SIZE, ART_UTILE_SIZE); |
---|
99 | for (x = 1; x < width - 1; x++) |
---|
100 | utiles[ix++] = bb; |
---|
101 | utiles[ix++] = ART_UTA_BBOX_CONS (0, 0, xf1, ART_UTILE_SIZE); |
---|
102 | } |
---|
103 | utiles[ix++] = ART_UTA_BBOX_CONS (xf0, 0, ART_UTILE_SIZE, yf1); |
---|
104 | bb = ART_UTA_BBOX_CONS (0, 0, ART_UTILE_SIZE, yf1); |
---|
105 | for (x = 1; x < width - 1; x++) |
---|
106 | utiles[ix++] = bb; |
---|
107 | utiles[ix++] = ART_UTA_BBOX_CONS (0, 0, xf1, yf1); |
---|
108 | } |
---|
109 | } |
---|
110 | return uta; |
---|
111 | } |
---|