~ml-launchpad/ubuntu/natty/gcompris/fix-for-777349

« back to all changes in this revision

Viewing changes to src/libart_lgpl/art_uta_ops.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Libart_LGPL - library of basic graphic primitives
2
 
 * Copyright (C) 1998-2000 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 3 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, see <http://www.gnu.org/licenses/>.
16
 
 * Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
#include "art_uta_ops.h"
21
 
 
22
 
#include <string.h>
23
 
#include "art_misc.h"
24
 
#include "art_uta.h"
25
 
 
26
 
#ifndef MIN
27
 
#define MIN(a,b) ((a) < (b) ? (a) : (b))
28
 
#endif
29
 
 
30
 
#ifndef MAX
31
 
#define MAX(a,b) ((a) > (b) ? (a) : (b))
32
 
#endif
33
 
 
34
 
/**
35
 
 * art_uta_union: Compute union of two uta's.
36
 
 * @uta1: One uta.
37
 
 * @uta2: The other uta.
38
 
 *
39
 
 * Computes the union of @uta1 and @uta2. The union is approximate,
40
 
 * but coverage is guaranteed over all pixels included in either of
41
 
 * the arguments, ie more pixels may be covered than the "exact"
42
 
 * union.
43
 
 *
44
 
 * Note: this routine is used in the Gnome Canvas to accumulate the
45
 
 * region that needs to be repainted. However, since it copies over
46
 
 * the entire uta (which might be largish) even when the update may be
47
 
 * small, it can be a performance bottleneck. There are two approaches
48
 
 * to this problem, both of which are probably worthwhile. First, the
49
 
 * generated uta's should always be limited to the visible window,
50
 
 * thus guaranteeing that uta's never become large. Second, there
51
 
 * should be a new, destructive union operation that only touches a
52
 
 * small part of the uta when the update is small.
53
 
 *
54
 
 * Return value: The new union uta.
55
 
 **/
56
 
ArtUta *
57
 
art_uta_union (ArtUta *uta1, ArtUta *uta2)
58
 
{
59
 
  ArtUta *uta;
60
 
  int x0, y0, x1, y1;
61
 
  int x, y;
62
 
  int ix, ix1, ix2;
63
 
  ArtUtaBbox bb, bb1, bb2;
64
 
 
65
 
  x0 = MIN(uta1->x0, uta2->x0);
66
 
  y0 = MIN(uta1->y0, uta2->y0);
67
 
  x1 = MAX(uta1->x0 + uta1->width, uta2->x0 + uta2->width);
68
 
  y1 = MAX(uta1->y0 + uta1->height, uta2->y0 + uta2->height);
69
 
  uta = art_uta_new (x0, y0, x1, y1);
70
 
 
71
 
  /* could move the first two if/else statements out of the loop */
72
 
  ix = 0;
73
 
  for (y = y0; y < y1; y++)
74
 
    {
75
 
      ix1 = (y - uta1->y0) * uta1->width + x0 - uta1->x0;
76
 
      ix2 = (y - uta2->y0) * uta2->width + x0 - uta2->x0;
77
 
      for (x = x0; x < x1; x++)
78
 
        {
79
 
          if (x < uta1->x0 || y < uta1->y0 ||
80
 
              x >= uta1->x0 + uta1->width || y >= uta1->y0 + uta1->height)
81
 
            bb1 = 0;
82
 
          else
83
 
            bb1 = uta1->utiles[ix1];
84
 
 
85
 
          if (x < uta2->x0 || y < uta2->y0 ||
86
 
              x >= uta2->x0 + uta2->width || y >= uta2->y0 + uta2->height)
87
 
            bb2 = 0;
88
 
          else
89
 
            bb2 = uta2->utiles[ix2];
90
 
 
91
 
          if (bb1 == 0)
92
 
            bb = bb2;
93
 
          else if (bb2 == 0)
94
 
            bb = bb1;
95
 
          else
96
 
            bb = ART_UTA_BBOX_CONS(MIN(ART_UTA_BBOX_X0(bb1),
97
 
                                       ART_UTA_BBOX_X0(bb2)),
98
 
                                   MIN(ART_UTA_BBOX_Y0(bb1),
99
 
                                       ART_UTA_BBOX_Y0(bb2)),
100
 
                                   MAX(ART_UTA_BBOX_X1(bb1),
101
 
                                       ART_UTA_BBOX_X1(bb2)),
102
 
                                   MAX(ART_UTA_BBOX_Y1(bb1),
103
 
                                       ART_UTA_BBOX_Y1(bb2)));
104
 
          uta->utiles[ix] = bb;
105
 
          ix++;
106
 
          ix1++;
107
 
          ix2++;
108
 
        }
109
 
    }
110
 
  return uta;
111
 
}