From fe72e26f94cc40837e2bd15f5e782ae048ce3b5c Mon Sep 17 00:00:00 2001 From: Daniel Oelschlegel Date: Thu, 1 May 2014 23:01:50 +0200 Subject: [PATCH] new style class definition performance improvements through using of list comprehension --- PIL/BmpImagePlugin.py | 3 +-- PIL/Image.py | 6 +++--- PIL/ImageOps.py | 29 +++++++---------------------- PIL/ImagePalette.py | 21 ++++++--------------- PIL/ImagePath.py | 2 +- PIL/ImageQt.py | 6 ++---- PIL/ImageSequence.py | 2 +- PIL/ImageShow.py | 4 ++-- PIL/ImageStat.py | 2 +- PIL/ImageTk.py | 4 ++-- PIL/ImageWin.py | 8 ++++---- PIL/PcxImagePlugin.py | 3 +-- 12 files changed, 31 insertions(+), 59 deletions(-) diff --git a/PIL/BmpImagePlugin.py b/PIL/BmpImagePlugin.py index cd6dc49a2..386010e50 100644 --- a/PIL/BmpImagePlugin.py +++ b/PIL/BmpImagePlugin.py @@ -232,8 +232,7 @@ def _save(im, fp, filename, check=0): for i in (0, 255): fp.write(o8(i) * 4) elif im.mode == "L": - for i in range(256): - fp.write(o8(i) * 4) + fp.write("".join(o8(i) * 4 for i in range(256))) elif im.mode == "P": fp.write(im.im.getpalette("RGB", "BGRX")) diff --git a/PIL/Image.py b/PIL/Image.py index 8d278317e..45480a7ee 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -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": ('= (3, 3)): +if sys.version_info >= (3, 3): from shlex import quote else: from pipes import quote @@ -52,7 +52,7 @@ def show(image, title=None, **options): ## # Base class for viewers. -class Viewer: +class Viewer(object): # main api diff --git a/PIL/ImageStat.py b/PIL/ImageStat.py index ef63b7857..e5ba3070b 100644 --- a/PIL/ImageStat.py +++ b/PIL/ImageStat.py @@ -26,7 +26,7 @@ import operator, math from functools import reduce -class Stat: +class Stat(object): def __init__(self, image_or_list, mask = None): try: diff --git a/PIL/ImageTk.py b/PIL/ImageTk.py index 1e81d240e..22653c159 100644 --- a/PIL/ImageTk.py +++ b/PIL/ImageTk.py @@ -54,7 +54,7 @@ def _pilbitmap_check(): # -------------------------------------------------------------------- # PhotoImage -class PhotoImage: +class PhotoImage(object): """ A Tkinter-compatible photo image. This can be used everywhere Tkinter expects an image object. If the image is an RGBA @@ -192,7 +192,7 @@ class PhotoImage: # BitmapImage -class BitmapImage: +class BitmapImage(object): """ A Tkinter-compatible bitmap image. This can be used everywhere Tkinter diff --git a/PIL/ImageWin.py b/PIL/ImageWin.py index aa90b887b..caaca822f 100644 --- a/PIL/ImageWin.py +++ b/PIL/ImageWin.py @@ -21,7 +21,7 @@ import warnings from PIL import Image -class HDC: +class HDC(object): """ Wraps a HDC integer. The resulting object can be passed to the :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose` @@ -32,7 +32,7 @@ class HDC: def __int__(self): return self.dc -class HWND: +class HWND(object): """ Wraps a HWND integer. The resulting object can be passed to the :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose` @@ -44,7 +44,7 @@ class HWND: return self.wnd -class Dib: +class Dib(object): """ A Windows bitmap with the given mode and size. The mode can be one of "1", "L", "P", or "RGB". @@ -207,7 +207,7 @@ class Dib: ## # Create a Window with the given title size. -class Window: +class Window(object): def __init__(self, title="PIL", width=None, height=None): self.hwnd = Image.core.createwindow( diff --git a/PIL/PcxImagePlugin.py b/PIL/PcxImagePlugin.py index 2496af676..c7025fecc 100644 --- a/PIL/PcxImagePlugin.py +++ b/PIL/PcxImagePlugin.py @@ -173,8 +173,7 @@ def _save(im, fp, filename, check=0): elif im.mode == "L": # greyscale palette fp.write(o8(12)) - for i in range(256): - fp.write(o8(i)*3) + fp.write("".join(o8(i)*3 for i in range(256))) # -------------------------------------------------------------------- # registry