From 36cbb16bf6c986df58407acba66d8907299cff4d Mon Sep 17 00:00:00 2001 From: homm Date: Sat, 25 Oct 2014 14:23:07 +0400 Subject: [PATCH] Add tests. Rise for "P" and "1". --- Tests/test_imaging_stretch.py | 40 +++++++++++++++++++++++++++++++++++ libImaging/Antialias.c | 3 +++ 2 files changed, 43 insertions(+) create mode 100644 Tests/test_imaging_stretch.py diff --git a/Tests/test_imaging_stretch.py b/Tests/test_imaging_stretch.py new file mode 100644 index 000000000..d2fbe1c79 --- /dev/null +++ b/Tests/test_imaging_stretch.py @@ -0,0 +1,40 @@ +""" +Tests for ImagingCore.stretch functionality. +""" + +from helper import unittest, PillowTestCase + +from PIL import Image + + +im = Image.open("Tests/images/hopper.ppm").copy() + + +class TestImagingStretch(PillowTestCase): + + def test_modes(self): + self.assertRaises(ValueError, im.convert("1").im.stretch, + (15, 12), Image.ANTIALIAS) + self.assertRaises(ValueError, im.convert("P").im.stretch, + (15, 12), Image.ANTIALIAS) + for mode in ["L", "I", "F", "RGB", "RGBA", "CMYK", "YCbCr"]: + s = im.convert(mode).im + r = s.stretch((15, 12), Image.ANTIALIAS) + self.assertEqual(r.mode, mode) + self.assertEqual(r.size, (15, 12)) + self.assertEqual(r.bands, s.bands) + + def test_reduce_filters(self): + # There is no Image.NEAREST because im.stretch implementation + # is not NEAREST for reduction. It should be removed + # or renamed to supersampling. + for f in [Image.BILINEAR, Image.BICUBIC, Image.ANTIALIAS]: + r = im.im.stretch((15, 12), f) + self.assertEqual(r.mode, "RGB") + self.assertEqual(r.size, (15, 12)) + + def test_enlarge_filters(self): + for f in [Image.BILINEAR, Image.BICUBIC, Image.ANTIALIAS]: + r = im.im.stretch((764, 414), f) + self.assertEqual(r.mode, "RGB") + self.assertEqual(r.size, (764, 414)) diff --git a/libImaging/Antialias.c b/libImaging/Antialias.c index 0c9c265ba..be49bc827 100644 --- a/libImaging/Antialias.c +++ b/libImaging/Antialias.c @@ -95,6 +95,9 @@ ImagingStretch(Imaging imOut, Imaging imIn, int filter) if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); + if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0) + return (Imaging) ImagingError_ModeError(); + /* check filter */ switch (filter) { case IMAGING_TRANSFORM_NEAREST: