From a34adc1bd0f04bdf30cba4916c9d21e35438375f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 24 Mar 2017 20:39:48 +1100 Subject: [PATCH 1/3] Removed unnecessary brackets --- docs/example/DdsImagePlugin.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/example/DdsImagePlugin.py b/docs/example/DdsImagePlugin.py index dd048a32f..00eb10edb 100644 --- a/docs/example/DdsImagePlugin.py +++ b/docs/example/DdsImagePlugin.py @@ -144,7 +144,7 @@ def _dxt1(data, width, height): else: r, g, b = 0, 0, 0 - idx = 4 * ((y + j) * width + (x + i)) + idx = 4 * ((y + j) * width + x + i) ret[idx:idx+4] = struct.pack('4B', r, g, b, 255) return bytes(ret) @@ -201,7 +201,7 @@ def _dxt5(data, width, height): elif cc == 3: r, g, b = _c3(r0, r1), _c3(g0, g1), _c3(b0, b1) - idx = 4 * ((y + j) * width + (x + i)) + idx = 4 * ((y + j) * width + x + i) ret[idx:idx+4] = struct.pack('4B', r, g, b, alpha) return bytes(ret) @@ -241,8 +241,7 @@ class DdsImageFile(ImageFile.ImageFile): self.decoder = "DXT5" codec = _dxt5 else: - raise NotImplementedError("Unimplemented pixel format %r" % - (fourcc)) + raise NotImplementedError("Unimplemented pixel format %r" % fourcc) self.tile = [ (self.decoder, (0, 0) + self.size, 0, (self.mode, 0, 1)) From 17a111cba7b5ea1d626361061fd0312548860610 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 24 Mar 2017 20:43:03 +1100 Subject: [PATCH 2/3] Removed unused variable --- mp_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mp_compile.py b/mp_compile.py index 7448c8a09..31833dee3 100644 --- a/mp_compile.py +++ b/mp_compile.py @@ -73,7 +73,7 @@ def install(): try: # bug, only enable if we can make a Pool. see issue #790 and # https://stackoverflow.com/questions/6033599/oserror-38-errno-38-with-multiprocessing - pool = Pool(2) + Pool(2) CCompiler.compile = _mp_compile except Exception as msg: print("Exception installing mp_compile, proceeding without:" From 37b293f5937655169c2f59e80d272eefb65cbbc7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 20 Apr 2017 21:14:23 +1000 Subject: [PATCH 3/3] Flake8 fixes --- PIL/BmpImagePlugin.py | 2 +- PIL/GifImagePlugin.py | 48 ++++++++++++++++++++------------- PIL/Image.py | 16 +++++------ PIL/ImageCms.py | 1 - PIL/ImageFile.py | 22 +++++++-------- PIL/MspImagePlugin.py | 20 +++++++------- PIL/SgiImagePlugin.py | 10 +++---- PIL/SunImagePlugin.py | 5 ++-- PIL/TiffImagePlugin.py | 16 ++++++----- PIL/WmfImagePlugin.py | 2 +- PIL/_binary.py | 2 ++ Tests/helper.py | 2 ++ Tests/test_file_gif.py | 34 +++++++++++------------ Tests/test_file_libtiff.py | 3 ++- Tests/test_file_msp.py | 8 +++--- Tests/test_file_ppm.py | 1 - Tests/test_file_sgi.py | 3 +-- Tests/test_file_sun.py | 16 +++++------ Tests/test_file_wmf.py | 1 + Tests/test_image.py | 5 +++- Tests/test_image_access.py | 1 - Tests/test_image_convert.py | 1 - Tests/test_image_copy.py | 2 +- Tests/test_image_crop.py | 11 ++++---- Tests/test_image_fromqpixmap.py | 3 ++- Tests/test_image_paste.py | 6 ++--- Tests/test_image_resample.py | 14 +++++----- Tests/test_image_resize.py | 4 +-- Tests/test_image_rotate.py | 20 +++++++------- Tests/test_image_toqimage.py | 8 +++--- Tests/test_image_toqpixmap.py | 2 +- Tests/test_imagecms.py | 2 +- Tests/test_imagedraw.py | 1 - Tests/test_imagefile.py | 5 +++- Tests/test_imagepalette.py | 6 ++--- Tests/test_imagesequence.py | 1 - Tests/test_imagetk.py | 35 +++++++++++------------- docs/example/DdsImagePlugin.py | 8 +++--- 38 files changed, 177 insertions(+), 170 deletions(-) diff --git a/PIL/BmpImagePlugin.py b/PIL/BmpImagePlugin.py index 1afe303ab..cf18eab66 100644 --- a/PIL/BmpImagePlugin.py +++ b/PIL/BmpImagePlugin.py @@ -131,7 +131,7 @@ class BmpImageFile(ImageFile.ImageFile): # ----------------- Process BMP with Bitfields compression (not palette) if file_info['compression'] == self.BITFIELDS: SUPPORTED = { - 32: [(0xff0000, 0xff00, 0xff, 0x0), (0xff0000, 0xff00, 0xff, 0xff000000), (0x0, 0x0, 0x0, 0x0), (0xff000000, 0xff0000, 0xff00, 0x0) ], + 32: [(0xff0000, 0xff00, 0xff, 0x0), (0xff0000, 0xff00, 0xff, 0xff000000), (0x0, 0x0, 0x0, 0x0), (0xff000000, 0xff0000, 0xff00, 0x0)], 24: [(0xff0000, 0xff00, 0xff)], 16: [(0xf800, 0x7e0, 0x1f), (0x7c00, 0x3e0, 0x1f)] } diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 83161c320..b20fdd452 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -307,7 +307,7 @@ def _normalize_mode(im, initial_call=False): UNDONE: What is the point of mucking with the initial call palette, for an image that shouldn't have a palette, or it would be a mode 'P' and get returned in the RAWMODE clause. - + :param im: Image object :param initial_call: Default false, set to true for a single frame. :returns: Image object @@ -325,6 +325,7 @@ def _normalize_mode(im, initial_call=False): return im.convert("P") return im.convert("L") + def _normalize_palette(im, palette, info): """ Normalizes the palette for image. @@ -334,7 +335,7 @@ def _normalize_palette(im, palette, info): :param im: Image object :param palette: bytes object containing the source palette, or .... - :param info: encoderinfo + :param info: encoderinfo :returns: Image object """ source_palette = None @@ -347,7 +348,7 @@ def _normalize_palette(im, palette, info): zip(palette.palette[:256], palette.palette[256:512], palette.palette[512:768]))) - + if im.mode == "P": if not source_palette: source_palette = im.im.getpalette("RGB")[:768] @@ -364,6 +365,7 @@ def _normalize_palette(im, palette, info): im.palette.palette = source_palette return im + def _write_single_frame(im, fp, palette): im_out = _normalize_mode(im, True) im_out = _normalize_palette(im_out, palette, im.encoderinfo) @@ -383,6 +385,7 @@ def _write_single_frame(im, fp, palette): fp.write(b"\0") # end of image data + def _write_multiple_frames(im, fp, palette): duration = im.encoderinfo.get("duration", None) @@ -418,9 +421,9 @@ def _write_multiple_frames(im, fp, palette): else: bbox = None im_frames.append({ - 'im':im_frame, - 'bbox':bbox, - 'encoderinfo':encoderinfo + 'im': im_frame, + 'bbox': bbox, + 'encoderinfo': encoderinfo }) if len(im_frames) > 1: @@ -441,6 +444,7 @@ def _write_multiple_frames(im, fp, palette): _write_frame_data(fp, im_frame, offset, frame_data['encoderinfo']) return True + def _save_all(im, fp, filename): _save(im, fp, filename, save_all=True) @@ -593,6 +597,7 @@ def _save_netpbm(im, fp, filename): # cases where it took lots of memory and time previously. _FORCE_OPTIMIZE = False + def _get_optimize(im, info): """ Palette optimization is a potentially expensive operation. @@ -624,9 +629,10 @@ def _get_optimize(im, info): used_palette_colors.append(i) if optimise or (len(used_palette_colors) <= 128 and - max(used_palette_colors) > len(used_palette_colors)): + max(used_palette_colors) > len(used_palette_colors)): return used_palette_colors + def _get_color_table_size(palette_bytes): # calculate the palette size for the header import math @@ -635,6 +641,7 @@ def _get_color_table_size(palette_bytes): color_table_size = 0 return color_table_size + def _get_header_palette(palette_bytes): """ Returns the palette, null padded to the next power of 2 (*3) bytes @@ -652,14 +659,16 @@ def _get_header_palette(palette_bytes): palette_bytes += o8(0) * 3 * actual_target_size_diff return palette_bytes -def _get_palette_bytes(im): - """ - Gets the palette for inclusion in the gif header - :param im: Image object - :returns: Bytes, len<=768 suitable for inclusion in gif header - """ - return im.palette.palette +def _get_palette_bytes(im): + """ + Gets the palette for inclusion in the gif header + + :param im: Image object + :returns: Bytes, len<=768 suitable for inclusion in gif header + """ + return im.palette.palette + def _get_global_header(im, info): """Return a list of strings representing a GIF header""" @@ -671,7 +680,7 @@ def _get_global_header(im, info): for extensionKey in ["transparency", "duration", "loop", "comment"]: if info and extensionKey in info: if ((extensionKey == "duration" and info[extensionKey] == 0) or - (extensionKey == "comment" and not (1 <= len(info[extensionKey]) <= 255))): + (extensionKey == "comment" and not (1 <= len(info[extensionKey]) <= 255))): continue version = b"89a" break @@ -693,12 +702,13 @@ def _get_global_header(im, info): # size of global color table + global color table flag o8(color_table_size + 128), # packed fields # background + reserved/aspect - o8(background) + o8(0), + o8(background) + o8(0), # Global Color Table _get_header_palette(palette_bytes) ] + def _write_frame_data(fp, im_frame, offset, params): try: im_frame.encoderinfo = params @@ -716,6 +726,7 @@ def _write_frame_data(fp, im_frame, offset, params): # -------------------------------------------------------------------- # Legacy GIF utilities + def getheader(im, palette=None, info=None): """ Legacy Method to get Gif data from image. @@ -724,7 +735,7 @@ def getheader(im, palette=None, info=None): :param im: Image object :param palette: bytes object containing the source palette, or .... - :param info: encoderinfo + :param info: encoderinfo :returns: tuple of(list of header items, optimized palette) """ @@ -733,7 +744,7 @@ def getheader(im, palette=None, info=None): if info is None: info = {} - if not "background" in info and "background" in im.info: + if "background" not in info and "background" in im.info: info["background"] = im.info["background"] im_mod = _normalize_palette(im, palette, info) @@ -743,6 +754,7 @@ def getheader(im, palette=None, info=None): return header, used_palette_colors + # To specify duration, add the time in milliseconds to getdata(), # e.g. getdata(im_frame, duration=1000) def getdata(im, offset=(0, 0), **params): diff --git a/PIL/Image.py b/PIL/Image.py index ec995c8f4..c11c4cb3f 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -558,16 +558,16 @@ class Image(object): if getattr(self, 'map', None): self.map = None - + # Instead of simply setting to None, we're setting up a # deferred error that will better explain that the core image # object is gone. self.im = deferred_error(ValueError("Operation on closed image")) - if sys.version_info >= (3,4,0): + if sys.version_info >= (3, 4, 0): def __del__(self): - if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') - and self.fp and self._exclusive_fp): + if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') + and self.fp and self._exclusive_fp): self.fp.close() self.fp = None @@ -1554,7 +1554,6 @@ class Image(object): else: # L-mode source_palette = bytearray(i//3 for i in range(768)) - palette_bytes = b"" new_positions = [0]*256 @@ -1589,8 +1588,8 @@ class Image(object): m_im.palette = ImagePalette.ImagePalette("RGB", palette=mapping_palette*3, size=768) - #possibly set palette dirty, then - #m_im.putpalette(mapping_palette, 'L') # converts to 'P' + # possibly set palette dirty, then + # m_im.putpalette(mapping_palette, 'L') # converts to 'P' # or just force it. # UNDONE -- this is part of the general issue with palettes m_im.im.putpalette(*m_im.palette.getdata()) @@ -1607,8 +1606,6 @@ class Image(object): return m_im - - def resize(self, size, resample=NEAREST): """ Returns a resized copy of this image. @@ -2627,6 +2624,7 @@ def registered_extensions(): init() return EXTENSION + def register_decoder(name, decoder): """ Registers an image decoder. This function should not be diff --git a/PIL/ImageCms.py b/PIL/ImageCms.py index 267afa4c6..40fb1ad0a 100644 --- a/PIL/ImageCms.py +++ b/PIL/ImageCms.py @@ -166,7 +166,6 @@ class ImageCmsProfile(object): self._set(profile) else: raise TypeError("Invalid type for Profile") - def _set(self, profile, filename=None): self.profile = profile diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index b28aa798e..124a3a347 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -160,7 +160,7 @@ class ImageFile(Image.Image): # try memory mapping decoder_name, extents, offset, args = self.tile[0] if decoder_name == "raw" and len(args) >= 3 and args[0] == self.mode \ - and args[0] in Image._MAPMODES: + and args[0] in Image._MAPMODES: try: if hasattr(Image.core, "map"): # use built-in mapper WIN32 only @@ -199,7 +199,7 @@ class ImageFile(Image.Image): for decoder_name, extents, offset, args in self.tile: decoder = Image._getdecoder(self.mode, decoder_name, - args, self.decoderconfig) + args, self.decoderconfig) seek(offset) decoder.setimage(self.im, extents) if decoder.pulls_fd: @@ -540,6 +540,7 @@ class PyCodecState(object): return (self.xoff, self.yoff, self.xoff+self.xsize, self.yoff+self.ysize) + class PyDecoder(object): """ Python implementation of a format decoder. Override this class and @@ -565,7 +566,7 @@ class PyDecoder(object): :returns: None """ self.args = args - + @property def pulls_fd(self): return self._pulls_fd @@ -597,7 +598,7 @@ class PyDecoder(object): :returns: None """ self.fd = fd - + def setimage(self, im, extents=None): """ Called from ImageFile to set the core output image for the decoder @@ -607,7 +608,7 @@ class PyDecoder(object): for this tile :returns: None """ - + # following c code self.im = im @@ -616,7 +617,6 @@ class PyDecoder(object): else: (x0, y0, x1, y1) = (0, 0, 0, 0) - if x0 == 0 and x1 == 0: self.state.xsize, self.state.ysize = self.im.size else: @@ -627,11 +627,11 @@ class PyDecoder(object): if self.state.xsize <= 0 or self.state.ysize <= 0: raise ValueError("Size cannot be negative") - + if (self.state.xsize + self.state.xoff > self.im.size[0] or - self.state.ysize + self.state.yoff > self.im.size[1]): + self.state.ysize + self.state.yoff > self.im.size[1]): raise ValueError("Tile cannot extend outside image") - + def set_as_raw(self, data, rawmode=None): """ Convenience method to set the internal image from a stream of raw data @@ -641,13 +641,13 @@ class PyDecoder(object): it will default to the mode of the image :returns: None """ - + if not rawmode: rawmode = self.mode d = Image._getdecoder(self.mode, 'raw', (rawmode)) d.setimage(self.im, self.state.extents()) s = d.decode(data) - + if s[0] >= 0: raise ValueError("not enough image data") if s[1] != 0: diff --git a/PIL/MspImagePlugin.py b/PIL/MspImagePlugin.py index 11e983a3a..5ea3c1c49 100644 --- a/PIL/MspImagePlugin.py +++ b/PIL/MspImagePlugin.py @@ -25,7 +25,8 @@ from . import Image, ImageFile from ._binary import i16le as i16, o16le as o16, i8 -import struct, io +import struct +import io __version__ = "0.1" @@ -97,7 +98,7 @@ class MspDecoder(ImageFile.PyDecoder): # If the RunType value is non-zero # Use this value as the RunCount # Read and write the next RunCount bytes literally - # + # # e.g.: # 0x00 03 ff 05 00 01 02 03 04 # would yield the bytes: @@ -105,11 +106,10 @@ class MspDecoder(ImageFile.PyDecoder): # # which are then interpreted as a bit packed mode '1' image - _pulls_fd = True def decode(self, buffer): - + img = io.BytesIO() blank_line = bytearray((0xff,)*((self.state.xsize+7)//8)) try: @@ -140,17 +140,17 @@ class MspDecoder(ImageFile.PyDecoder): runcount = runtype img.write(row[idx:idx+runcount]) idx += runcount - + except struct.error: - raise IOError("Corrupted MSP file in row %d" %x) - + raise IOError("Corrupted MSP file in row %d" % x) + self.set_as_raw(img.getvalue(), ("1", 0, 1)) - - return 0,0 + + return 0, 0 Image.register_decoder('MSP', MspDecoder) - + # # write MSP files (uncompressed only) diff --git a/PIL/SgiImagePlugin.py b/PIL/SgiImagePlugin.py index 973c68567..bca7eb13f 100644 --- a/PIL/SgiImagePlugin.py +++ b/PIL/SgiImagePlugin.py @@ -124,14 +124,14 @@ def _save(im, fp, filename): fp.write(struct.pack('>l', pinmin)) fp.write(struct.pack('>l', pinmax)) - fp.write(struct.pack('4s', b'')) # dummy - fp.write(struct.pack('79s', imgName)) # truncates to 79 chars - fp.write(struct.pack('s', b'')) # force null byte after imgname + fp.write(struct.pack('4s', b'')) # dummy + fp.write(struct.pack('79s', imgName)) # truncates to 79 chars + fp.write(struct.pack('s', b'')) # force null byte after imgname fp.write(struct.pack('>l', colormap)) - fp.write(struct.pack('404s', b'')) # dummy + fp.write(struct.pack('404s', b'')) # dummy - #assert we've got the right number of bands. + # assert we've got the right number of bands. if len(im.getbands()) != z: raise ValueError("incorrect number of bands in SGI write: %s vs %s" % (z, len(im.getbands()))) diff --git a/PIL/SunImagePlugin.py b/PIL/SunImagePlugin.py index b57883df6..536aa134a 100644 --- a/PIL/SunImagePlugin.py +++ b/PIL/SunImagePlugin.py @@ -52,7 +52,6 @@ class SunImageFile(ImageFile.ImageFile): # DWORD ColorMapLength; /* Size of the color map in bytes */ # } SUNRASTER; - # HEAD s = self.fp.read(32) if i32(s) != 0x59a66a95: @@ -63,9 +62,9 @@ class SunImageFile(ImageFile.ImageFile): self.size = i32(s[4:8]), i32(s[8:12]) depth = i32(s[12:16]) - data_length = i32(s[16:20]) # unreliable, ignore. + data_length = i32(s[16:20]) # unreliable, ignore. file_type = i32(s[20:24]) - palette_type = i32(s[24:28]) # 0: None, 1: RGB, 2: Raw/arbitrary + palette_type = i32(s[24:28]) # 0: None, 1: RGB, 2: Raw/arbitrary palette_length = i32(s[28:32]) if depth == 1: diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index e80fc12ad..f9709e83b 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -616,7 +616,8 @@ class ImageFileDirectory_v2(collections.MutableMapping): @_register_loader(5, 8) def load_rational(self, data, legacy_api=True): vals = self._unpack("{}L".format(len(data) // 4), data) - combine = lambda a, b: (a, b) if legacy_api else IFDRational(a, b) + + def combine(a, b): return (a, b) if legacy_api else IFDRational(a, b) return tuple(combine(num, denom) for num, denom in zip(vals[::2], vals[1::2])) @@ -636,7 +637,8 @@ class ImageFileDirectory_v2(collections.MutableMapping): @_register_loader(10, 8) def load_signed_rational(self, data, legacy_api=True): vals = self._unpack("{}l".format(len(data) // 4), data) - combine = lambda a, b: (a, b) if legacy_api else IFDRational(a, b) + + def combine(a, b): return (a, b) if legacy_api else IFDRational(a, b) return tuple(combine(num, denom) for num, denom in zip(vals[::2], vals[1::2])) @@ -1136,7 +1138,7 @@ class TiffImageFile(ImageFile.ImageFile): sampleFormat = self.tag_v2.get(SAMPLEFORMAT, (1,)) if (len(sampleFormat) > 1 - and max(sampleFormat) == min(sampleFormat) == 1): + and max(sampleFormat) == min(sampleFormat) == 1): # SAMPLEFORMAT is properly per band, so an RGB image will # be (1,1,1). But, we don't support per band pixel types, # and anything more than one band is a uint8. So, just @@ -1174,7 +1176,7 @@ class TiffImageFile(ImageFile.ImageFile): self.info["dpi"] = xres, yres elif resunit == 3: # dots per centimeter. convert to dpi self.info["dpi"] = xres * 2.54, yres * 2.54 - elif resunit is None: # used to default to 1, but now 2) + elif resunit is None: # used to default to 1, but now 2) self.info["dpi"] = xres, yres # For backward compatibility, we also preserve the old behavior. self.info["resolution"] = xres, yres @@ -1492,6 +1494,7 @@ def _save(im, fp, filename): # just to access o32 and o16 (using correct byte order) im._debug_multipage = ifd + class AppendingTiffWriter: fieldSizes = [ 0, # None @@ -1679,12 +1682,12 @@ class AppendingTiffWriter: def fixIFD(self): numTags = self.readShort() - #trace("fixing IFD at %X; number of tags: %u (0x%X)", self.f.tell()-2, + # trace("fixing IFD at %X; number of tags: %u (0x%X)", self.f.tell()-2, # numTags, numTags) for i in range(numTags): tag, fieldType, count = struct.unpack(self.tagFormat, self.f.read(8)) - #trace(" at %X: tag %u (0x%X), type %u, count %u", self.f.tell()-8, + # trace(" at %X: tag %u (0x%X), type %u, count %u", self.f.tell()-8, # tag, tag, fieldType, count) fieldSize = self.fieldSizes[fieldType] @@ -1737,6 +1740,7 @@ class AppendingTiffWriter: else: self.rewriteLastLong(offset) + def _save_all(im, fp, filename): if not hasattr(im, "n_frames"): return _save(im, fp, filename) diff --git a/PIL/WmfImagePlugin.py b/PIL/WmfImagePlugin.py index f7076c0d9..584523fc7 100644 --- a/PIL/WmfImagePlugin.py +++ b/PIL/WmfImagePlugin.py @@ -25,7 +25,6 @@ from . import Image, ImageFile from ._binary import i16le as word, si16le as short, i32le as dword, si32le as _long - __version__ = "0.2" _handler = None @@ -66,6 +65,7 @@ if hasattr(Image.core, "drawwmf"): # -------------------------------------------------------------------- # Read WMF file + def _accept(prefix): return ( prefix[:6] == b"\xd7\xcd\xc6\x9a\x00\x00" or diff --git a/PIL/_binary.py b/PIL/_binary.py index 17ee67b11..b15f796c0 100644 --- a/PIL/_binary.py +++ b/PIL/_binary.py @@ -37,6 +37,7 @@ def i16le(c, o=0): """ return unpack(">> im = Image.open('Tests/images/hopper.ppm') - # >>> im = im.rotate(45, resample=Image.BICUBIC, expand=True) + # >>> im = im.rotate(45, resample=Image.BICUBIC, expand=True) # >>> im.save('Tests/images/hopper_45.png') target = Image.open('Tests/images/hopper_45.png') @@ -52,7 +52,7 @@ class TestImageRotate(PillowTestCase): target_origin = target.size[1]/2 target = target.crop((0, target_origin, 128, target_origin + 128)) - im = im.rotate(45, center=(0,0), resample=Image.BICUBIC) + im = im.rotate(45, center=(0, 0), resample=Image.BICUBIC) self.assert_image_similar(im, target, 15) @@ -62,7 +62,7 @@ class TestImageRotate(PillowTestCase): target_origin = target.size[1] / 2 - 14 target = target.crop((6, target_origin, 128 + 6, target_origin + 128)) - im = im.rotate(45, center=(14,14), resample=Image.BICUBIC) + im = im.rotate(45, center=(14, 14), resample=Image.BICUBIC) self.assert_image_similar(im, target, 10) @@ -73,7 +73,7 @@ class TestImageRotate(PillowTestCase): target = target.crop((target_origin, target_origin, target_origin + 128, target_origin + 128)) - im = im.rotate(45, translate=(5,5), resample=Image.BICUBIC) + im = im.rotate(45, translate=(5, 5), resample=Image.BICUBIC) self.assert_image_similar(im, target, 1) @@ -81,14 +81,14 @@ class TestImageRotate(PillowTestCase): # if the center is -1,-1 and we rotate by 90<=x<=270 the # resulting image should be black for angle in (90, 180, 270): - im = hopper().rotate(angle, center=(-1,-1)) + im = hopper().rotate(angle, center=(-1, -1)) self.assert_image_equal(im, Image.new('RGB', im.size, 'black')) def test_fastpath_translate(self): # if we post-translate by -128 # resulting image should be black for angle in (0, 90, 180, 270): - im = hopper().rotate(angle, translate=(-128,-128)) + im = hopper().rotate(angle, translate=(-128, -128)) self.assert_image_equal(im, Image.new('RGB', im.size, 'black')) def test_center(self): @@ -97,8 +97,6 @@ class TestImageRotate(PillowTestCase): self.rotate(im, im.mode, 45, translate=(im.size[0]/2, 0)) self.rotate(im, im.mode, 45, center=(0, 0), translate=(im.size[0]/2, 0)) - - if __name__ == '__main__': unittest.main() diff --git a/Tests/test_image_toqimage.py b/Tests/test_image_toqimage.py index 435a07765..6d7715c80 100644 --- a/Tests/test_image_toqimage.py +++ b/Tests/test_image_toqimage.py @@ -20,7 +20,8 @@ if ImageQt.qt_is_installed: from PySide import QtGui from PySide.QtGui import QWidget, QHBoxLayout, QLabel, QApplication QT_VERSION = 4 - + + class TestToQImage(PillowQtTestCase, PillowTestCase): def test_sanity(self): @@ -45,12 +46,12 @@ class TestToQImage(PillowQtTestCase, PillowTestCase): # libpng warning: Invalid color type/bit depth combination in IHDR # libpng error: Invalid IHDR data continue - + # Test saving the file tempfile = self.tempfile('temp_{}.png'.format(mode)) data.save(tempfile) - # Check that it actually worked. + # Check that it actually worked. reloaded = Image.open(tempfile) # Gray images appear to come back in palette mode. # They're roughly equivalent @@ -58,7 +59,6 @@ class TestToQImage(PillowQtTestCase, PillowTestCase): src = src.convert('P') self.assert_image_equal(reloaded, src) - def test_segfault(self): PillowQtTestCase.setUp(self) diff --git a/Tests/test_image_toqpixmap.py b/Tests/test_image_toqpixmap.py index 137a875fe..c6555d7ff 100644 --- a/Tests/test_image_toqpixmap.py +++ b/Tests/test_image_toqpixmap.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, hopper, distro +from helper import unittest, PillowTestCase, hopper from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase from PIL import ImageQt diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index d0168b141..21493e8d5 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -344,7 +344,7 @@ class TestImageCms(PillowTestCase): chans = [] bands = ImageMode.getmode(mode).bands for band_ndx in range(len(bands)): - channel_type = 'L' # 8-bit unorm + channel_type = 'L' # 8-bit unorm channel_pattern = hopper(channel_type) # paste pattern with varying offsets to avoid correlation diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index b0a4f2f1e..441a34a88 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -310,7 +310,6 @@ class TestImageDraw(PillowTestCase): self.assert_image_equal(im, im_floodfill) del draw - @unittest.skipIf(hasattr(sys, 'pypy_version_info'), "Causes fatal RPython error on PyPy") def test_floodfill_border(self): diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index d9ae74579..d44f5b2e6 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -138,10 +138,12 @@ class TestImageFile(PillowTestCase): class MockPyDecoder(ImageFile.PyDecoder): def decode(self, buffer): - #eof + # eof return (-1, 0) xoff, yoff, xsize, ysize = 10, 20, 100, 100 + + class MockImageFile(ImageFile.ImageFile): def _open(self): self.rawmode = 'RGBA' @@ -149,6 +151,7 @@ class MockImageFile(ImageFile.ImageFile): self.size = (200, 200) self.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize), 32, None)] + class TestPyDecoder(PillowTestCase): def get_decoder(self): diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index f80fa34c8..248138377 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -128,16 +128,16 @@ class TestImagePalette(PillowTestCase): def test_2bit_palette(self): # issue #2258, 2 bit palettes are corrupted. outfile = self.tempfile('temp.png') - + rgb = b'\x00' * 2 + b'\x01' * 2 + b'\x02' * 2 img = Image.frombytes('P', (6, 1), rgb) - img.putpalette(b'\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF') # RGB + img.putpalette(b'\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF') # RGB img.save(outfile, format='PNG') reloaded = Image.open(outfile) self.assert_image_equal(img, reloaded) - + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index c2d62f38c..e50b13924 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -62,7 +62,6 @@ class TestImageSequence(PillowTestCase): self.assert_image_equal(frame, firstFrame) break - def test_palette_mmap(self): # Using mmap in ImageFile can require to reload the palette. im = Image.open('Tests/images/multipage-mmap.tiff') diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index 1d5a281a6..8c8723927 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -10,9 +10,10 @@ try: except (OSError, ImportError) as v: # Skipped via setUp() HAS_TK = False - + TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA') + class TestImageTk(PillowTestCase): def setUp(self): @@ -21,7 +22,7 @@ class TestImageTk(PillowTestCase): try: # setup tk app = tk.Frame() - #root = tk.Tk() + # root = tk.Tk() except (tk.TclError) as v: self.skipTest("TCL Error: %s" % v) @@ -46,12 +47,11 @@ class TestImageTk(PillowTestCase): im = ImageTk._get_image_from_kw(kw) self.assertEqual(im, None) - def test_photoimage(self): for mode in TK_MODES: # test as image: im = hopper(mode) - + # this should not crash im_tk = ImageTk.PhotoImage(im) @@ -59,35 +59,32 @@ class TestImageTk(PillowTestCase): self.assertEqual(im_tk.height(), im.height) # _tkinter.TclError: this function is not yet supported - #reloaded = ImageTk.getimage(im_tk) - #self.assert_image_equal(reloaded, im) - - + # reloaded = ImageTk.getimage(im_tk) + # self.assert_image_equal(reloaded, im) def test_photoimage_blank(self): # test a image using mode/size: for mode in TK_MODES: - im_tk = ImageTk.PhotoImage(mode, (100,100)) - + im_tk = ImageTk.PhotoImage(mode, (100, 100)) + self.assertEqual(im_tk.width(), 100) self.assertEqual(im_tk.height(), 100) - - #reloaded = ImageTk.getimage(im_tk) - #self.assert_image_equal(reloaded, im) + + # reloaded = ImageTk.getimage(im_tk) + # self.assert_image_equal(reloaded, im) def test_bitmapimage(self): im = hopper('1') # this should not crash im_tk = ImageTk.BitmapImage(im) - + self.assertEqual(im_tk.width(), im.width) self.assertEqual(im_tk.height(), im.height) - - #reloaded = ImageTk.getimage(im_tk) - #self.assert_image_equal(reloaded, im) - - + # reloaded = ImageTk.getimage(im_tk) + # self.assert_image_equal(reloaded, im) + + if __name__ == '__main__': unittest.main() diff --git a/docs/example/DdsImagePlugin.py b/docs/example/DdsImagePlugin.py index 00eb10edb..29e13b920 100644 --- a/docs/example/DdsImagePlugin.py +++ b/docs/example/DdsImagePlugin.py @@ -233,7 +233,6 @@ class DdsImageFile(ImageFile.ImageFile): bitcount, rmask, gmask, bmask, amask = struct.unpack("<5I", header.read(20)) - if fourcc == b"DXT1": self.decoder = "DXT1" codec = _dxt1 @@ -247,7 +246,6 @@ class DdsImageFile(ImageFile.ImageFile): (self.decoder, (0, 0) + self.size, 0, (self.mode, 0, 1)) ] - def load_seek(self, pos): pass @@ -260,8 +258,8 @@ class DXT1Decoder(ImageFile.PyDecoder): self.set_as_raw(_dxt1(self.fd, self.state.xsize, self.state.ysize)) except struct.error: raise IOError("Truncated DDS file") - - return 0,0 + return 0, 0 + class DXT5Decoder(ImageFile.PyDecoder): _pulls_fd = True @@ -271,7 +269,7 @@ class DXT5Decoder(ImageFile.PyDecoder): self.set_as_raw(_dxt5(self.fd, self.state.xsize, self.state.ysize)) except struct.error: raise IOError("Truncated DDS file") - return 0,0 + return 0, 0 Image.register_decoder('DXT1', DXT1Decoder) Image.register_decoder('DXT5', DXT5Decoder)