1 /* Libart_LGPL - library of basic graphic primitives
2 * Copyright (C) 1998 Raph Levien
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.
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.
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.
21 #include "art_rect_uta.h"
23 /* Functions to decompose a microtile array into a list of rectangles. */
26 * art_rect_list_from_uta: Decompose uta into list of rectangles.
27 * @uta: The source uta.
28 * @max_width: The maximum width of the resulting rectangles.
29 * @max_height: The maximum height of the resulting rectangles.
30 * @p_nrects: Where to store the number of returned rectangles.
32 * Allocates a new list of rectangles, sets *@p_nrects to the number
33 * in the list. This list should be freed with art_free().
35 * Each rectangle bounded in size by (@max_width, @max_height).
36 * However, these bounds must be at least the size of one tile.
38 * This routine provides a precise implementation, i.e. the rectangles
39 * cover exactly the same area as the uta. It is thus appropriate in
40 * cases where the overhead per rectangle is small compared with the
41 * cost of filling in extra pixels.
43 * Return value: An array containing the resulting rectangles.
46 art_rect_list_from_uta (ArtUta
*uta
, int max_width
, int max_height
,
50 int n_rects
, n_rects_max
;
63 rects
= art_new (ArtIRect
, n_rects_max
);
69 glom
= art_new (int, width
* height
);
70 for (ix
= 0; ix
< width
* height
; ix
++)
74 for (y
= 0; y
< height
; y
++)
75 for (x
= 0; x
< width
; x
++)
80 x0
= ((uta
->x0
+ x
) << ART_UTILE_SHIFT
) + ART_UTA_BBOX_X0(bb
);
81 y0
= ((uta
->y0
+ y
) << ART_UTILE_SHIFT
) + ART_UTA_BBOX_Y0(bb
);
82 y1
= ((uta
->y0
+ y
) << ART_UTILE_SHIFT
) + ART_UTA_BBOX_Y1(bb
);
85 /* now try to extend to the right */
86 while (x
!= width
- 1 &&
87 ART_UTA_BBOX_X1(bb
) == ART_UTILE_SIZE
&&
88 (((bb
& 0xffffff) ^ utiles
[ix
+ 1]) & 0xffff00ff) == 0 &&
89 (((uta
->x0
+ x
+ 1) << ART_UTILE_SHIFT
) +
90 ART_UTA_BBOX_X1(utiles
[ix
+ 1]) -
97 x1
= ((uta
->x0
+ x
) << ART_UTILE_SHIFT
) + ART_UTA_BBOX_X1(bb
);
100 /* if rectangle nonempty */
101 if ((x1
^ x0
) | (y1
^ y0
))
103 /* try to glom onto an existing rectangle */
104 glom_rect
= glom
[left_ix
];
105 if (glom_rect
!= -1 &&
106 x0
== rects
[glom_rect
].x0
&&
107 x1
== rects
[glom_rect
].x1
&&
108 y0
== rects
[glom_rect
].y1
&&
109 y1
- rects
[glom_rect
].y0
<= max_height
)
111 rects
[glom_rect
].y1
= y1
;
115 if (n_rects
== n_rects_max
)
116 art_expand (rects
, ArtIRect
, n_rects_max
);
117 rects
[n_rects
].x0
= x0
;
118 rects
[n_rects
].y0
= y0
;
119 rects
[n_rects
].x1
= x1
;
120 rects
[n_rects
].y1
= y1
;
125 glom
[left_ix
+ width
] = glom_rect
;