diff --git a/PIL/Image.py b/PIL/Image.py index 333397701..c74971b1d 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -101,7 +101,7 @@ import collections import numbers # works everywhere, win for pypy, not cpython -USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info') +USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info') try: import cffi HAS_CFFI=True @@ -233,7 +233,7 @@ _MODE_CONV = { "CMYK": ('|u1', 4), "YCbCr": ('|u1', 3), "LAB": ('|u1', 3), # UNDONE - unsigned |u1i1i1 - # I;16 == I;16L, and I;32 == I;32L + # I;16 == I;16L, and I;32 == I;32L "I;16": ('u2', None), "I;16L": (' 8bit images. + # a gamma function point transform on > 8bit images. scale, offset = _getscaleoffset(lut) return self._new(self.im.point_transform(scale, offset)) # for other modes, convert the function to a table @@ -1420,8 +1429,8 @@ class Image: self._copy() self.pyaccess = None self.load() - - if self.pyaccess: + + if self.pyaccess: return self.pyaccess.putpixel(xy,value) return self.im.putpixel(xy, value) diff --git a/Tests/test_pickle.py b/Tests/test_pickle.py new file mode 100644 index 000000000..a40d26088 --- /dev/null +++ b/Tests/test_pickle.py @@ -0,0 +1,63 @@ +from tester import * + +from PIL import Image + + +def test_frombytes_tobytes(): + # Arrange + im = Image.open('Images/lena.jpg') + + # Act + data = im.tobytes() + new_im = Image.frombytes(im.mode, im.size, data) + + # Assert + assert_image_equal(im, new_im) + + +def helper_test_pickle_file(pickle, protocol=0): + im = Image.open('Images/lena.jpg') + filename = tempfile('temp.pkl') + + # Act + with open(filename, 'wb') as f: + pickle.dump(im, f, protocol) + with open(filename, 'rb') as f: + loaded_im = pickle.load(f) + + # Assert + assert_image_equal(im, loaded_im) + + +def helper_test_pickle_string(pickle, protocol=0): + im = Image.open('Images/lena.jpg') + + # Act + dumped_string = pickle.dumps(im, protocol) + loaded_im = pickle.loads(dumped_string) + + # Assert + assert_image_equal(im, loaded_im) + + +def test_pickle_image(): + # Arrange + import pickle + + # Act / Assert + for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1): + helper_test_pickle_string(pickle, protocol) + helper_test_pickle_file(pickle, protocol) + + +def test_cpickle_image(): + # Arrange + import cPickle + + # Act / Assert + for protocol in range(0, cPickle.HIGHEST_PROTOCOL + 1): + helper_test_pickle_string(cPickle, protocol) + helper_test_pickle_file(cPickle, protocol) + + +# End of file