fix crashes reported by Debian Cylab Mayhem Team
[swftools.git] / lib / art / art_uta.c
blob10bd6ee3bd73fe4eaaec7971ab63262d39a064be
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.
20 #include "config.h"
21 #include "art_uta.h"
23 #include <string.h>
24 #include "art_misc.h"
26 /**
27 * art_uta_new: Allocate a new uta.
28 * @x0: Left coordinate of uta.
29 * @y0: Top coordinate of uta.
30 * @x1: Right coordinate of uta.
31 * @y1: Bottom coordinate of uta.
33 * Allocates a new microtile array. The arguments are in units of
34 * tiles, not pixels.
36 * Returns: the newly allocated #ArtUta.
37 **/
38 ArtUta *
39 art_uta_new (int x0, int y0, int x1, int y1)
41 ArtUta *uta;
43 uta = art_new (ArtUta, 1);
44 uta->x0 = x0;
45 uta->y0 = y0;
46 uta->width = x1 - x0;
47 uta->height = y1 - y0;
49 uta->utiles = art_new (ArtUtaBbox, uta->width * uta->height);
51 memset (uta->utiles, 0, uta->width * uta->height * sizeof(ArtUtaBbox));
52 return uta;
55 /**
56 * art_uta_new_coords: Allocate a new uta, based on pixel coordinates.
57 * @x0: Left coordinate of uta.
58 * @y0: Top coordinate of uta.
59 * @x1: Right coordinate of uta.
60 * @y1: Bottom coordinate of uta.
62 * Allocates a new microtile array. The arguments are in pixels
64 * Returns: the newly allocated #ArtUta.
65 **/
66 ArtUta *
67 art_uta_new_coords (int x0, int y0, int x1, int y1)
69 return art_uta_new (x0 >> ART_UTILE_SHIFT, y0 >> ART_UTILE_SHIFT,
70 1 + (x1 >> ART_UTILE_SHIFT),
71 1 + (y1 >> ART_UTILE_SHIFT));
74 /**
75 * art_uta_free: Free a uta.
76 * @uta: The uta to free.
78 * Frees the microtile array structure, including the actual microtile
79 * data.
80 **/
81 void
82 art_uta_free (ArtUta *uta)
84 art_free (uta->utiles);
85 art_free (uta);
88 /* User to Aardvark! */