mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
use getchannel where is possible
This commit is contained in:
parent
0002e18c74
commit
349e300d7b
|
@ -67,7 +67,7 @@ class Contrast(_Enhance):
|
|||
self.degenerate = Image.new("L", image.size, mean).convert(image.mode)
|
||||
|
||||
if 'A' in image.getbands():
|
||||
self.degenerate.putalpha(image.split()[-1])
|
||||
self.degenerate.putalpha(image.getchannel('A'))
|
||||
|
||||
|
||||
class Brightness(_Enhance):
|
||||
|
@ -82,7 +82,7 @@ class Brightness(_Enhance):
|
|||
self.degenerate = Image.new(image.mode, image.size, 0)
|
||||
|
||||
if 'A' in image.getbands():
|
||||
self.degenerate.putalpha(image.split()[-1])
|
||||
self.degenerate.putalpha(image.getchannel('A'))
|
||||
|
||||
|
||||
class Sharpness(_Enhance):
|
||||
|
@ -97,4 +97,4 @@ class Sharpness(_Enhance):
|
|||
self.degenerate = image.filter(ImageFilter.SMOOTH)
|
||||
|
||||
if 'A' in image.getbands():
|
||||
self.degenerate.putalpha(image.split()[-1])
|
||||
self.degenerate.putalpha(image.getchannel('A'))
|
||||
|
|
|
@ -200,7 +200,7 @@ class TestFilePng(PillowTestCase):
|
|||
self.assert_image(im, "RGBA", (162, 150))
|
||||
|
||||
# image has 124 unique alpha values
|
||||
self.assertEqual(len(im.split()[3].getcolors()), 124)
|
||||
self.assertEqual(len(im.getchannel('A').getcolors()), 124)
|
||||
|
||||
def test_load_transparent_rgb(self):
|
||||
test_file = "Tests/images/rgb_trns.png"
|
||||
|
@ -212,7 +212,7 @@ class TestFilePng(PillowTestCase):
|
|||
self.assert_image(im, "RGBA", (64, 64))
|
||||
|
||||
# image has 876 transparent pixels
|
||||
self.assertEqual(im.split()[3].getcolors()[0][0], 876)
|
||||
self.assertEqual(im.getchannel('A').getcolors()[0][0], 876)
|
||||
|
||||
def test_save_p_transparent_palette(self):
|
||||
in_file = "Tests/images/pil123p.png"
|
||||
|
@ -234,7 +234,7 @@ class TestFilePng(PillowTestCase):
|
|||
self.assert_image(im, "RGBA", (162, 150))
|
||||
|
||||
# image has 124 unique alpha values
|
||||
self.assertEqual(len(im.split()[3].getcolors()), 124)
|
||||
self.assertEqual(len(im.getchannel('A').getcolors()), 124)
|
||||
|
||||
def test_save_p_single_transparency(self):
|
||||
in_file = "Tests/images/p_trns_single.png"
|
||||
|
@ -258,7 +258,7 @@ class TestFilePng(PillowTestCase):
|
|||
self.assertEqual(im.getpixel((31, 31)), (0, 255, 52, 0))
|
||||
|
||||
# image has 876 transparent pixels
|
||||
self.assertEqual(im.split()[3].getcolors()[0][0], 876)
|
||||
self.assertEqual(im.getchannel('A').getcolors()[0][0], 876)
|
||||
|
||||
def test_save_p_transparent_black(self):
|
||||
# check if solid black image with full transparency
|
||||
|
@ -287,7 +287,7 @@ class TestFilePng(PillowTestCase):
|
|||
|
||||
# There are 559 transparent pixels.
|
||||
im = im.convert('RGBA')
|
||||
self.assertEqual(im.split()[3].getcolors()[0][0], 559)
|
||||
self.assertEqual(im.getchannel('A').getcolors()[0][0], 559)
|
||||
|
||||
def test_save_rgb_single_transparency(self):
|
||||
in_file = "Tests/images/caption_6_33_22.png"
|
||||
|
@ -550,7 +550,7 @@ class TestTruncatedPngPLeaks(PillowTestCase):
|
|||
# linux
|
||||
# man 2 getrusage
|
||||
# ru_maxrss (since Linux 2.6.32)
|
||||
# This is the maximum resident set size used (in kilobytes).
|
||||
# This is the maximum resident set size used (in kilobytes).
|
||||
return mem / 1024 # megs
|
||||
|
||||
def test_leak_load(self):
|
||||
|
|
|
@ -103,11 +103,11 @@ class TestFormatHSV(PillowTestCase):
|
|||
# im.split()[0].show()
|
||||
# comparable.split()[0].show()
|
||||
|
||||
self.assert_image_similar(im.split()[0], comparable.split()[0],
|
||||
self.assert_image_similar(im.getchannel(0), comparable.getchannel(0),
|
||||
1, "Hue conversion is wrong")
|
||||
self.assert_image_similar(im.split()[1], comparable.split()[1],
|
||||
self.assert_image_similar(im.getchannel(1), comparable.getchannel(1),
|
||||
1, "Saturation conversion is wrong")
|
||||
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
||||
self.assert_image_similar(im.getchannel(2), comparable.getchannel(2),
|
||||
1, "Value conversion is wrong")
|
||||
|
||||
# print(im.getpixel((192, 64)))
|
||||
|
@ -120,11 +120,11 @@ class TestFormatHSV(PillowTestCase):
|
|||
# print(im.getpixel((192, 64)))
|
||||
# print(comparable.getpixel((192, 64)))
|
||||
|
||||
self.assert_image_similar(im.split()[0], comparable.split()[0],
|
||||
self.assert_image_similar(im.getchannel(0), comparable.getchannel(0),
|
||||
3, "R conversion is wrong")
|
||||
self.assert_image_similar(im.split()[1], comparable.split()[1],
|
||||
self.assert_image_similar(im.getchannel(1), comparable.getchannel(1),
|
||||
3, "G conversion is wrong")
|
||||
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
||||
self.assert_image_similar(im.getchannel(2), comparable.getchannel(2),
|
||||
3, "B conversion is wrong")
|
||||
|
||||
def test_convert(self):
|
||||
|
@ -137,11 +137,11 @@ class TestFormatHSV(PillowTestCase):
|
|||
# print(im.split()[0].histogram())
|
||||
# print(comparable.split()[0].histogram())
|
||||
|
||||
self.assert_image_similar(im.split()[0], comparable.split()[0],
|
||||
self.assert_image_similar(im.getchannel(0), comparable.getchannel(0),
|
||||
1, "Hue conversion is wrong")
|
||||
self.assert_image_similar(im.split()[1], comparable.split()[1],
|
||||
self.assert_image_similar(im.getchannel(1), comparable.getchannel(1),
|
||||
1, "Saturation conversion is wrong")
|
||||
self.assert_image_similar(im.split()[2], comparable.split()[2],
|
||||
self.assert_image_similar(im.getchannel(2), comparable.getchannel(2),
|
||||
1, "Value conversion is wrong")
|
||||
|
||||
def test_hsv_to_rgb(self):
|
||||
|
@ -155,11 +155,14 @@ class TestFormatHSV(PillowTestCase):
|
|||
# print([ord(x) for x in target.split()[1].tobytes()[:80]])
|
||||
# print([ord(x) for x in converted.split()[1].tobytes()[:80]])
|
||||
|
||||
self.assert_image_similar(converted.split()[0], comparable.split()[0],
|
||||
self.assert_image_similar(converted.getchannel(0),
|
||||
comparable.getchannel(0),
|
||||
3, "R conversion is wrong")
|
||||
self.assert_image_similar(converted.split()[1], comparable.split()[1],
|
||||
self.assert_image_similar(converted.getchannel(1),
|
||||
comparable.getchannel(1),
|
||||
3, "G conversion is wrong")
|
||||
self.assert_image_similar(converted.split()[2], comparable.split()[2],
|
||||
self.assert_image_similar(converted.getchannel(2),
|
||||
comparable.getchannel(2),
|
||||
3, "B conversion is wrong")
|
||||
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ class TestImageConvert(PillowTestCase):
|
|||
alpha = hopper('L')
|
||||
im.putalpha(alpha)
|
||||
|
||||
comparable = im.convert('P').convert('LA').split()[1]
|
||||
comparable = im.convert('P').convert('LA').getchannel('A')
|
||||
|
||||
self.assert_image_similar(alpha, comparable, 5)
|
||||
|
||||
|
@ -185,7 +185,7 @@ class TestImageConvert(PillowTestCase):
|
|||
if converted_im.mode == 'RGB':
|
||||
self.assert_image_similar(converted_im, target, 3)
|
||||
else:
|
||||
self.assert_image_similar(converted_im, target.split()[0], 1)
|
||||
self.assert_image_similar(converted_im, target.getchannel(0), 1)
|
||||
|
||||
matrix_convert('RGB')
|
||||
matrix_convert('L')
|
||||
|
|
|
@ -360,8 +360,7 @@ class TestImageCms(PillowTestCase):
|
|||
return Image.merge(mode, chans)
|
||||
|
||||
source_image = create_test_image()
|
||||
preserved_channel_ndx = source_image.getbands().index(preserved_channel)
|
||||
source_image_aux = source_image.split()[preserved_channel_ndx]
|
||||
source_image_aux = source_image.getchannel(preserved_channel)
|
||||
|
||||
# create some transform, it doesn't matter which one
|
||||
source_profile = ImageCms.createProfile("sRGB")
|
||||
|
@ -374,7 +373,7 @@ class TestImageCms(PillowTestCase):
|
|||
result_image = source_image
|
||||
else:
|
||||
result_image = ImageCms.applyTransform(source_image, t, inPlace=False)
|
||||
result_image_aux = result_image.split()[preserved_channel_ndx]
|
||||
result_image_aux = result_image.getchannel(preserved_channel)
|
||||
|
||||
self.assert_image_equal(source_image_aux, result_image_aux)
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestImageEnhance(PillowTestCase):
|
|||
|
||||
def _check_alpha(self, im, original, op, amount):
|
||||
self.assertEqual(im.getbands(), original.getbands())
|
||||
self.assert_image_equal(im.split()[-1], original.split()[-1],
|
||||
self.assert_image_equal(im.getchannel('A'), original.getchannel('A'),
|
||||
"Diff on %s: %s" % (op, amount))
|
||||
|
||||
def test_alpha(self):
|
||||
|
|
|
@ -52,7 +52,7 @@ class TestNumpy(PillowTestCase):
|
|||
a = numpy.array([[x]*bands for x in data], dtype=dtype)
|
||||
a.shape = TEST_IMAGE_SIZE[0], TEST_IMAGE_SIZE[1], bands
|
||||
i = Image.fromarray(a)
|
||||
if list(i.split()[0].getdata()) != list(range(100)):
|
||||
if list(i.getchannel(0).getdata()) != list(range(100)):
|
||||
print("data mismatch for", dtype)
|
||||
# print(dtype, list(i.getdata()))
|
||||
return i
|
||||
|
|
Loading…
Reference in New Issue
Block a user