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_rgb_affine_private.h"
25 #include "art_point.h"
26 #include "art_affine.h"
28 /* Private functions for the rgb affine image compositors - primarily,
29 the determination of runs, eliminating the need for source image
30 bbox calculation in the inner loop. */
32 /* Determine a "run", such that the inverse affine of all pixels from
33 (x0, y) inclusive to (x1, y) exclusive fit within the bounds
36 Initial values of x0, x1, and result values stored in first two
43 art_rgb_affine_run (int *p_x0, int *p_x1, int y,
44 int src_width, int src_height,
45 const double affine[6])
55 /* do left and right edges */
56 if (affine[0] > EPSILON)
58 z = affine[2] * (y + 0.5) + affine[4];
59 x_intercept = -z / affine[0];
60 xi = ceil (x_intercept + EPSILON - 0.5);
63 x_intercept = (-z + src_width) / affine[0];
64 xi = ceil (x_intercept - EPSILON - 0.5);
68 else if (affine[0] < -EPSILON)
70 z = affine[2] * (y + 0.5) + affine[4];
71 x_intercept = (-z + src_width) / affine[0];
72 xi = ceil (x_intercept + EPSILON - 0.5);
75 x_intercept = -z / affine[0];
76 xi = ceil (x_intercept - EPSILON - 0.5);
82 z = affine[2] * (y + 0.5) + affine[4];
83 if (z < 0 || z >= src_width)
90 /* do top and bottom edges */
91 if (affine[1] > EPSILON)
93 z = affine[3] * (y + 0.5) + affine[5];
94 x_intercept = -z / affine[1];
95 xi = ceil (x_intercept + EPSILON - 0.5);
98 x_intercept = (-z + src_height) / affine[1];
99 xi = ceil (x_intercept - EPSILON - 0.5);
103 else if (affine[1] < -EPSILON)
105 z = affine[3] * (y + 0.5) + affine[5];
106 x_intercept = (-z + src_height) / affine[1];
107 xi = ceil (x_intercept + EPSILON - 0.5);
110 x_intercept = -z / affine[1];
111 xi = ceil (x_intercept - EPSILON - 0.5);
117 z = affine[3] * (y + 0.5) + affine[5];
118 if (z < 0 || z >= src_height)