mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Removed duplicate code
This commit is contained in:
parent
568fc2def8
commit
683768095b
|
@ -46,6 +46,13 @@ class TestFilePalm(PillowTestCase):
|
|||
self.skipKnownBadTest("Palm P image is wrong")
|
||||
self.roundtrip(mode)
|
||||
|
||||
def test_l_ioerror(self):
|
||||
# Arrange
|
||||
mode = "L"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(IOError, self.helper_save_as_palm, mode)
|
||||
|
||||
def test_rgb_ioerror(self):
|
||||
# Arrange
|
||||
mode = "RGB"
|
||||
|
|
|
@ -130,26 +130,23 @@ def _save(im, fp, filename):
|
|||
bpp = 8
|
||||
version = 1
|
||||
|
||||
elif im.mode == "L" and im.encoderinfo.get("bpp") in (1, 2, 4):
|
||||
elif im.mode == "L":
|
||||
if im.encoderinfo.get("bpp") in (1, 2, 4):
|
||||
# this is 8-bit grayscale, so we shift it to get the high-order bits,
|
||||
# and invert it because
|
||||
# Palm does greyscale from white (0) to black (1)
|
||||
bpp = im.encoderinfo["bpp"]
|
||||
im = im.point(
|
||||
lambda x, shift=8-bpp, maxval=(1 << bpp)-1: maxval - (x >> shift))
|
||||
elif im.info.get("bpp") in (1, 2, 4):
|
||||
# here we assume that even though the inherent mode is 8-bit grayscale,
|
||||
# only the lower bpp bits are significant.
|
||||
# We invert them to match the Palm.
|
||||
bpp = im.info["bpp"]
|
||||
im = im.point(lambda x, maxval=(1 << bpp)-1: maxval - (x & maxval))
|
||||
else:
|
||||
raise IOError("cannot write mode %s as Palm" % im.mode)
|
||||
|
||||
# this is 8-bit grayscale, so we shift it to get the high-order bits,
|
||||
# and invert it because
|
||||
# Palm does greyscale from white (0) to black (1)
|
||||
bpp = im.encoderinfo["bpp"]
|
||||
im = im.point(
|
||||
lambda x, shift=8-bpp, maxval=(1 << bpp)-1: maxval - (x >> shift))
|
||||
# we ignore the palette here
|
||||
im.mode = "P"
|
||||
rawmode = "P;" + str(bpp)
|
||||
version = 1
|
||||
|
||||
elif im.mode == "L" and im.info.get("bpp") in (1, 2, 4):
|
||||
|
||||
# here we assume that even though the inherent mode is 8-bit grayscale,
|
||||
# only the lower bpp bits are significant.
|
||||
# We invert them to match the Palm.
|
||||
bpp = im.info["bpp"]
|
||||
im = im.point(lambda x, maxval=(1 << bpp)-1: maxval - (x & maxval))
|
||||
# we ignore the palette here
|
||||
im.mode = "P"
|
||||
rawmode = "P;" + str(bpp)
|
||||
|
|
Loading…
Reference in New Issue
Block a user