diff --git a/PIL/MicImagePlugin.py b/PIL/MicImagePlugin.py index 0c5d09455..1b7972061 100644 --- a/PIL/MicImagePlugin.py +++ b/PIL/MicImagePlugin.py @@ -97,6 +97,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile): return self.frame + # # -------------------------------------------------------------------- diff --git a/Tests/images/hopper.mic b/Tests/images/hopper.mic new file mode 100644 index 000000000..fe6792f29 Binary files /dev/null and b/Tests/images/hopper.mic differ diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index ad4e8bc3f..0530f6146 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -2,7 +2,6 @@ from helper import unittest, PillowTestCase from PIL import Image, FliImagePlugin -# sample ppm stream # created as an export of a palette image from Gimp2.6 # save as...-> hopper.fli, default options. test_file = "Tests/images/hopper.fli" diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 3904340f3..4eb9435bd 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -3,7 +3,6 @@ from helper import unittest, PillowTestCase, hopper import io from PIL import Image, IcoImagePlugin -# sample ppm stream TEST_ICO_FILE = "Tests/images/hopper.ico" diff --git a/Tests/test_file_mic.py b/Tests/test_file_mic.py index 044248f3a..8724a2983 100644 --- a/Tests/test_file_mic.py +++ b/Tests/test_file_mic.py @@ -1,10 +1,50 @@ -from helper import unittest, PillowTestCase +from helper import unittest, PillowTestCase, hopper -from PIL import MicImagePlugin +from PIL import Image, ImagePalette, MicImagePlugin + +TEST_FILE = "Tests/images/hopper.mic" class TestFileMic(PillowTestCase): + def test_sanity(self): + im = Image.open(TEST_FILE) + im.load() + self.assertEqual(im.mode, "RGBA") + self.assertEqual(im.size, (128, 128)) + self.assertEqual(im.format, "MIC") + + # Adjust for the gamma of 2.2 encoded into the file + lut = ImagePalette.make_gamma_lut(1/2.2) + im = Image.merge('RGBA', [chan.point(lut) for chan in im.split()]) + + im2 = hopper("RGBA") + self.assert_image_similar(im, im2, 10) + + def test_n_frames(self): + im = Image.open(TEST_FILE) + + self.assertEqual(im.n_frames, 1) + + def test_is_animated(self): + im = Image.open(TEST_FILE) + + self.assertFalse(im.is_animated) + + def test_tell(self): + im = Image.open(TEST_FILE) + + self.assertEqual(im.tell(), 0) + + def test_seek(self): + im = Image.open(TEST_FILE) + + im.seek(0) + self.assertEqual(im.tell(), 0) + + self.assertRaises(EOFError, lambda: im.seek(99)) + self.assertEqual(im.tell(), 0) + def test_invalid_file(self): # Test an invalid OLE file invalid_file = "Tests/images/flower.jpg" diff --git a/Tests/test_file_pixar.py b/Tests/test_file_pixar.py index 3078b438b..b6b3f934d 100644 --- a/Tests/test_file_pixar.py +++ b/Tests/test_file_pixar.py @@ -2,11 +2,10 @@ from helper import hopper, unittest, PillowTestCase from PIL import Image, PixarImagePlugin -# sample ppm stream TEST_FILE = "Tests/images/hopper.pxr" -class TestImagePsd(PillowTestCase): +class TestFilePixar(PillowTestCase): def test_sanity(self): im = Image.open(TEST_FILE) diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index ddd2507bc..e2a9419b8 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -2,7 +2,6 @@ from helper import hopper, unittest, PillowTestCase from PIL import Image, PsdImagePlugin -# sample ppm stream test_file = "Tests/images/hopper.psd" diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 5940620ba..d8cc4fa3a 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -2,7 +2,6 @@ from helper import unittest, PillowTestCase, hopper from PIL import Image, XpmImagePlugin -# sample ppm stream TEST_FILE = "Tests/images/hopper.xpm" diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index 760c6019d..a0f638e84 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -124,7 +124,7 @@ are available:: eliminating unused colors. This is only useful if the palette can be compressed to the next smaller power of 2 elements. -**palette** +**palette** Use the specified palette for the saved image. The palette should be a bytes or bytearray object containing the palette entries in RGBRGB... form. It should be no more than 768 bytes. Alternately, @@ -789,6 +789,8 @@ PIL identifies and reads Microsoft Image Composer (MIC) files. When opened, the first sprite in the file is loaded. You can use :py:meth:`~file.seek` and :py:meth:`~file.tell` to read other sprites from the file. +Note that there may be an embedded gamma of 2.2 in MIC files. + MPO ^^^