Re: PIL bug: Antialias.c bicubic filter error
David <[email protected]>
| Newsgroups | gmane.comp.python.image |
|---|---|
| Message-ID | <[email protected]> |
On May 9, 2010, at 4:03 AM, Xavier Ho wrote: > On Sun, May 9, 2010 at 11:47 AM, David <[email protected]> wrote: > return (((a * x) - 5*a) * x + 8*a) * x - 4*a; > > Hello David, > I just factored out from your patch, as a comment to your post. > > ((x - 5) * x + 8) * a * x - 4*a; > Yes, of course, thanks! Actually there seems to be another bug in that file, which becomes apparent when a is not 0: The support of the filter is set to 0.5 for every magnification, which degrades ANTIALIAS and BICUBIC resizing to something that looks close to BILINEAR. The attached patch attempts to fix both. till then, David. _______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig
bicubic.patch
(application/octet-stream, 923 B)
diff -r 8b7cf4e45de7 libImaging/Antialias.c
--- a/libImaging/Antialias.c Wed May 26 03:49:05 2010 +0200
+++ b/libImaging/Antialias.c Wed May 26 04:17:58 2010 +0200
@@ -64,16 +64,14 @@
static inline float bicubic_filter(float x)
{
- /* FIXME: double-check this algorithm */
- /* FIXME: for best results, "a" should be -0.5 to -1.0, but we'll
- set it to zero for now, to match the 1.1 magnifying filter */
-#define a 0.0
+ /* for best results, "a" should be -0.5 to -1.0 */
+#define a -0.5
if (x < 0.0)
x = -x;
if (x < 1.0)
return (((a + 2.0) * x) - (a + 3.0)) * x*x + 1;
if (x < 2.0)
- return (((a * x) - 5*a) * x + 8) * x - 4*a;
+ return (((x - 5) * x + 8) * x - 4) * a;
return 0.0;
#undef a
}
@@ -131,7 +129,6 @@
if (filterscale < 1.0) {
filterscale = 1.0;
- support = 0.5;
}
support = support * filterscale;