1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
4 * This library is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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.
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 Lesser General Public
15 * License along with this library. If not, see
16 * <https://www.gnu.org/licenses/>.
21 #include <glib-object.h>
23 #include "libgimpmath/gimpmath.h"
25 #include "gimpcolortypes.h"
27 #include "gimpbilinear.h"
31 * SECTION: gimpbilinear
32 * @title: GimpBilinear
33 * @short_description: Utility functions for bilinear interpolation.
35 * Utility functions for bilinear interpolation.
40 gimp_bilinear (gdouble x
,
46 g_return_val_if_fail (values
!= NULL
, 0.0);
56 m0
= (1.0 - x
) * values
[0] + x
* values
[1];
57 m1
= (1.0 - x
) * values
[2] + x
* values
[3];
59 return (1.0 - y
) * m0
+ y
* m1
;
63 gimp_bilinear_8 (gdouble x
,
69 g_return_val_if_fail (values
!= NULL
, 0);
79 m0
= (1.0 - x
) * values
[0] + x
* values
[1];
80 m1
= (1.0 - x
) * values
[2] + x
* values
[3];
82 return (guchar
) ((1.0 - y
) * m0
+ y
* m1
);
86 gimp_bilinear_16 (gdouble x
,
92 g_return_val_if_fail (values
!= NULL
, 0);
102 m0
= (1.0 - x
) * values
[0] + x
* values
[1];
103 m1
= (1.0 - x
) * values
[2] + x
* values
[3];
105 return (guint16
) ((1.0 - y
) * m0
+ y
* m1
);
109 gimp_bilinear_32 (gdouble x
,
115 g_return_val_if_fail (values
!= NULL
, 0);
125 m0
= (1.0 - x
) * values
[0] + x
* values
[1];
126 m1
= (1.0 - x
) * values
[2] + x
* values
[3];
128 return (guint32
) ((1.0 - y
) * m0
+ y
* m1
);
132 gimp_bilinear_rgb (gdouble x
,
140 g_return_val_if_fail (values
!= NULL
, v
);
155 m0
= ix
* values
[0].r
+ x
* values
[1].r
;
156 m1
= ix
* values
[2].r
+ x
* values
[3].r
;
158 v
.r
= iy
* m0
+ y
* m1
;
162 m0
= ix
* values
[0].g
+ x
* values
[1].g
;
163 m1
= ix
* values
[2].g
+ x
* values
[3].g
;
165 v
.g
= iy
* m0
+ y
* m1
;
169 m0
= ix
* values
[0].b
+ x
* values
[1].b
;
170 m1
= ix
* values
[2].b
+ x
* values
[3].b
;
172 v
.b
= iy
* m0
+ y
* m1
;
178 gimp_bilinear_rgba (gdouble x
,
184 gdouble a0
, a1
, a2
, a3
, alpha
;
187 g_return_val_if_fail (values
!= NULL
, v
);
207 m0
= ix
* a0
+ x
* a1
;
208 m1
= ix
* a2
+ x
* a3
;
210 alpha
= v
.a
= iy
* m0
+ y
* m1
;
216 m0
= ix
* a0
* values
[0].r
+ x
* a1
* values
[1].r
;
217 m1
= ix
* a2
* values
[2].r
+ x
* a3
* values
[3].r
;
219 v
.r
= (iy
* m0
+ y
* m1
)/alpha
;
223 m0
= ix
* a0
* values
[0].g
+ x
* a1
* values
[1].g
;
224 m1
= ix
* a2
* values
[2].g
+ x
* a3
* values
[3].g
;
226 v
.g
= (iy
* m0
+ y
* m1
)/alpha
;
230 m0
= ix
* a0
* values
[0].b
+ x
* a1
* values
[1].b
;
231 m1
= ix
* a2
* values
[2].b
+ x
* a3
* values
[3].b
;
233 v
.b
= (iy
* m0
+ y
* m1
)/alpha
;