mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-25 00:34:14 +03:00
Merge pull request #3055 from uploadcare/imagemorph-type-check
Fix incorrect image type checking in _imagingmorph module
This commit is contained in:
commit
dddeecc945
|
@ -1,8 +1,7 @@
|
||||||
# Test the ImageMorphology functionality
|
# Test the ImageMorphology functionality
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image, ImageMorph, _imagingmorph
|
||||||
from PIL import ImageMorph
|
|
||||||
|
|
||||||
|
|
||||||
class MorphTests(PillowTestCase):
|
class MorphTests(PillowTestCase):
|
||||||
|
@ -284,6 +283,23 @@ class MorphTests(PillowTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(mop.lut, lut)
|
self.assertEqual(mop.lut, lut)
|
||||||
|
|
||||||
|
def test_wrong_mode(self):
|
||||||
|
lut = ImageMorph.LutBuilder(op_name='corner').build_lut()
|
||||||
|
imrgb = Image.new('RGB', (10, 10))
|
||||||
|
iml = Image.new('L', (10, 10))
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
_imagingmorph.apply(bytes(lut), imrgb.im.id, iml.im.id)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
_imagingmorph.apply(bytes(lut), iml.im.id, imrgb.im.id)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
_imagingmorph.match(bytes(lut), imrgb.im.id)
|
||||||
|
|
||||||
|
# Should not raise
|
||||||
|
_imagingmorph.match(bytes(lut), iml.im.id)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -64,14 +64,14 @@ apply(PyObject *self, PyObject* args)
|
||||||
width = imgin->xsize;
|
width = imgin->xsize;
|
||||||
height = imgin->ysize;
|
height = imgin->ysize;
|
||||||
|
|
||||||
if (imgin->type != IMAGING_TYPE_UINT8 &&
|
if (imgin->type != IMAGING_TYPE_UINT8 ||
|
||||||
imgin->bands != 1) {
|
imgin->bands != 1) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
|
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (imgout->type != IMAGING_TYPE_UINT8 &&
|
if (imgout->type != IMAGING_TYPE_UINT8 ||
|
||||||
imgout->bands != 1) {
|
imgout->bands != 1) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
|
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,9 +167,9 @@ match(PyObject *self, PyObject* args)
|
||||||
lut = PyBytes_AsString(py_lut);
|
lut = PyBytes_AsString(py_lut);
|
||||||
imgin = (Imaging) i0;
|
imgin = (Imaging) i0;
|
||||||
|
|
||||||
if (imgin->type != IMAGING_TYPE_UINT8 &&
|
if (imgin->type != IMAGING_TYPE_UINT8 ||
|
||||||
imgin->bands != 1) {
|
imgin->bands != 1) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
|
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user