mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-03 11:23:05 +03:00
Add tests. Rise for "P" and "1".
This commit is contained in:
parent
acdcdd487f
commit
36cbb16bf6
40
Tests/test_imaging_stretch.py
Normal file
40
Tests/test_imaging_stretch.py
Normal file
|
@ -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))
|
|
@ -95,6 +95,9 @@ ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
||||||
if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0)
|
if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
|
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
|
||||||
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
/* check filter */
|
/* check filter */
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case IMAGING_TRANSFORM_NEAREST:
|
case IMAGING_TRANSFORM_NEAREST:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user