Skip to content

Commit

Permalink
Merge 6821c49 into 8c052ba
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 24, 2015
2 parents 8c052ba + 6821c49 commit 2781d5b
Show file tree
Hide file tree
Showing 61 changed files with 234 additions and 245 deletions.
4 changes: 2 additions & 2 deletions PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _open(self):
# Note: The DSC spec says that BoundingBox
# fields should be integers, but some drivers
# put floating point values there anyway.
box = [int(float(s)) for s in v.split()]
box = [int(float(i)) for i in v.split()]
self.size = box[2] - box[0], box[3] - box[1]
self.tile = [("eps", (0, 0) + self.size, offset,
(length, box))]
Expand Down Expand Up @@ -288,7 +288,7 @@ def _open(self):

if s[:11] == "%ImageData:":
# Encoded bitmapped image.
[x, y, bi, mo, z3, z4, en, id] = s[11:].split(None, 7)
x, y, bi, mo = s[11:].split(None, 7)[:4]

if int(bi) != 8:
break
Expand Down
8 changes: 2 additions & 6 deletions PIL/FontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
import os
from PIL import Image, _binary

try:
import zlib
except ImportError:
zlib = None

WIDTH = 800


Expand Down Expand Up @@ -83,7 +78,8 @@ def compile(self):
glyph = self[i]
if glyph:
d, dst, src, im = glyph
xx, yy = src[2] - src[0], src[3] - src[1]
xx = src[2] - src[0]
# yy = src[3] - src[1]
x0, y0 = x, y
x = x + xx
if x > WIDTH:
Expand Down
4 changes: 2 additions & 2 deletions PIL/GbrImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def _open(self):

width = i32(self.fp.read(4))
height = i32(self.fp.read(4))
bytes = i32(self.fp.read(4))
if width <= 0 or height <= 0 or bytes != 1:
color_depth = i32(self.fp.read(4))
if width <= 0 or height <= 0 or color_depth != 1:
raise SyntaxError("not a GIMP brush")

comment = self.fp.read(header_size - 20)[:-1]
Expand Down
2 changes: 1 addition & 1 deletion PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def read_32(fobj, start_length, size):

def read_mk(fobj, start_length, size):
# Alpha masks seem to be uncompressed
(start, length) = start_length
start = start_length[0]
fobj.seek(start)
pixel_size = (size[0] * size[2], size[1] * size[2])
sizesq = pixel_size[0] * pixel_size[1]
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def tell(self):
def _save(im, fp, filename, check=0):

try:
type, rawmode = SAVE[im.mode]
image_type, rawmode = SAVE[im.mode]
except KeyError:
raise ValueError("Cannot save %s images as IM" % im.mode)

Expand All @@ -325,7 +325,7 @@ def _save(im, fp, filename, check=0):
if check:
return check

fp.write(("Image type: %s image\r\n" % type).encode('ascii'))
fp.write(("Image type: %s image\r\n" % image_type).encode('ascii'))
if filename:
fp.write(("Name: %s\r\n" % filename).encode('ascii'))
fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii'))
Expand Down
1 change: 1 addition & 0 deletions PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class Parser:
image = None
data = None
decoder = None
offset = 0
finished = 0

def reset(self):
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImageFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution.
#

from functools import reduce
import functools


class Filter(object):
Expand Down Expand Up @@ -43,7 +43,7 @@ class Kernel(Filter):
def __init__(self, size, kernel, scale=None, offset=0):
if scale is None:
# default scale is sum of kernel
scale = reduce(lambda a, b: a+b, kernel)
scale = functools.reduce(lambda a, b: a+b, kernel)
if size[0] * size[1] != len(kernel):
raise ValueError("not enough coefficients in kernel")
self.filterargs = size, scale, offset, kernel
Expand Down
5 changes: 2 additions & 3 deletions PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from PIL import Image
from PIL._util import isStringType
import operator
from functools import reduce
import functools


#
Expand Down Expand Up @@ -213,7 +213,7 @@ def equalize(image, mask=None):
if len(histo) <= 1:
lut.extend(list(range(256)))
else:
step = (reduce(operator.add, histo) - histo[-1]) // 255
step = (functools.reduce(operator.add, histo) - histo[-1]) // 255
if not step:
lut.extend(list(range(256)))
else:
Expand All @@ -233,7 +233,6 @@ def expand(image, border=0, fill=0):
:param fill: Pixel fill value (a color value). Default is 0 (black).
:return: An image.
"""
"Add border to image"
left, top, right, bottom = _border(border)
width = left + image.size[0] + right
height = top + image.size[1] + bottom
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImagePalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def load(filename):
p = PaletteFile.PaletteFile(fp)
lut = p.getpalette()
except (SyntaxError, ValueError):
import traceback
traceback.print_exc()
#import traceback
#traceback.print_exc()
pass

if not lut:
Expand Down
10 changes: 5 additions & 5 deletions PIL/ImageStat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import math
import operator
from functools import reduce
import functools


class Stat:
Expand Down Expand Up @@ -71,18 +71,18 @@ def _getcount(self):

v = []
for i in range(0, len(self.h), 256):
v.append(reduce(operator.add, self.h[i:i+256]))
v.append(functools.reduce(operator.add, self.h[i:i+256]))
return v

def _getsum(self):
"Get sum of all pixels in each layer"

v = []
for i in range(0, len(self.h), 256):
sum = 0.0
layerSum = 0.0
for j in range(256):
sum += j * self.h[i + j]
v.append(sum)
layerSum += j * self.h[i + j]
v.append(layerSum)
return v

def _getsum2(self):
Expand Down
2 changes: 1 addition & 1 deletion PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def getiptcinfo(im):
offset += 2
# resource name (usually empty)
name_len = i8(app[offset])
name = app[offset+1:offset+1+name_len]
# name = app[offset+1:offset+1+name_len]
offset = 1 + offset + name_len
if offset & 1:
offset += 1
Expand Down
6 changes: 3 additions & 3 deletions PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ def _getmp(self):
data = self.info["mp"]
except KeyError:
return None
file = io.BytesIO(data)
head = file.read(8)
file_contents = io.BytesIO(data)
head = file_contents.read(8)
endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<'
mp = {}
# process dictionary
info = TiffImagePlugin.ImageFileDirectory(head)
info.load(file)
info.load(file_contents)
for key, value in info.items():
mp[key] = _fixup(value)
# it's an error not to have a number of images
Expand Down
8 changes: 4 additions & 4 deletions PIL/MicImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


from PIL import Image, TiffImagePlugin
from PIL.OleFileIO import *
from PIL.OleFileIO import MAGIC, OleFileIO


#
Expand Down Expand Up @@ -54,9 +54,9 @@ def _open(self):
# best way to identify MIC files, but what the... ;-)

self.images = []
for file in self.ole.listdir():
if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image":
self.images.append(file)
for path in self.ole.listdir():
if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
self.images.append(path)

# if we didn't find any images, this is probably not
# an MIC file.
Expand Down
12 changes: 6 additions & 6 deletions PIL/MspImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def _open(self):
raise SyntaxError("not an MSP file")

# Header checksum
sum = 0
checksum = 0
for i in range(0, 32, 2):
sum = sum ^ i16(s[i:i+2])
if sum != 0:
checksum = checksum ^ i16(s[i:i+2])
if checksum != 0:
raise SyntaxError("bad MSP checksum")

self.mode = "1"
Expand Down Expand Up @@ -83,10 +83,10 @@ def _save(im, fp, filename):
header[6], header[7] = 1, 1
header[8], header[9] = im.size

sum = 0
checksum = 0
for h in header:
sum = sum ^ h
header[12] = sum # FIXME: is this the right field?
checksum = checksum ^ h
header[12] = checksum # FIXME: is this the right field?

# header
for h in header:
Expand Down
28 changes: 14 additions & 14 deletions PIL/OleFileIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ def set_debug_mode(debug_mode):
#TODO: check Excel, PPT, ...

#[PL]: Defect levels to classify parsing errors - see OleFileIO._raise_defect()
DEFECT_UNSURE = 10 # a case which looks weird, but not sure it's a defect
DEFECT_POTENTIAL = 20 # a potential defect
DEFECT_INCORRECT = 30 # an error according to specifications, but parsing
# can go on
DEFECT_FATAL = 40 # an error which cannot be ignored, parsing is
# impossible
DEFECT_UNSURE = 10 # a case which looks weird, but not sure it's a defect
DEFECT_POTENTIAL = 20 # a potential defect
DEFECT_INCORRECT = 30 # an error according to specifications, but parsing
# can go on
DEFECT_FATAL = 40 # an error which cannot be ignored, parsing is
# impossible

#[PL] add useful constants to __all__:
for key in list(vars().keys()):
Expand Down Expand Up @@ -468,14 +468,14 @@ def _unicode(s, errors='replace'):


def filetime2datetime(filetime):
"""
convert FILETIME (64 bits int) to Python datetime.datetime
"""
# TODO: manage exception when microseconds is too large
# inspired from http://code.activestate.com/recipes/511425-filetime-to-datetime/
_FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0)
#debug('timedelta days=%d' % (filetime//(10*1000000*3600*24)))
return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10)
"""
convert FILETIME (64 bits int) to Python datetime.datetime
"""
# TODO: manage exception when microseconds is too large
# inspired from http://code.activestate.com/recipes/511425-filetime-to-datetime/
_FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0)
#debug('timedelta days=%d' % (filetime//(10*1000000*3600*24)))
return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10)


#=== CLASSES ==================================================================
Expand Down
2 changes: 1 addition & 1 deletion PIL/PcfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _load_bitmaps(self, metrics):
for i in range(4):
bitmapSizes.append(i32(fp.read(4)))

byteorder = format & 4 # non-zero => MSB
# byteorder = format & 4 # non-zero => MSB
bitorder = format & 8 # non-zero => MSB
padindex = format & 3

Expand Down
2 changes: 1 addition & 1 deletion PIL/PyAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def set_pixel(self, x, y, color):
pixel = self.pixels[y][x]
try:
color = min(color, 65535)
except:
except TypeError:
color = min(color[0], 65535)

pixel.l = color & 0xFF
Expand Down
12 changes: 6 additions & 6 deletions PIL/SpiderImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def isInt(f):
return 1
else:
return 0
except:
except ValueError:
return 0

iforms = [1, 3, -11, -12, -21, -22]
Expand Down Expand Up @@ -173,11 +173,11 @@ def seek(self, frame):

# returns a byte image after rescaling to 0..255
def convert2byte(self, depth=255):
(min, max) = self.getextrema()
(minimum, maximum) = self.getextrema()
m = 1
if max != min:
m = depth / (max-min)
b = -m * min
if maximum != minimum:
m = depth / (maximum-minimum)
b = -m * minimum
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")

# returns a ImageTk.PhotoImage object, after rescaling to 0..255
Expand Down Expand Up @@ -271,7 +271,7 @@ def _save(im, fp, filename):

def _save_spider(im, fp, filename):
# get the filename extension and register it with Image
fn, ext = os.path.splitext(filename)
ext = os.path.splitext(filename)[1]
Image.register_extension("SPIDER", ext)
_save(im, fp, filename)

Expand Down
6 changes: 3 additions & 3 deletions PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ def _load_libtiff(self):

# (self._compression, (extents tuple),
# 0, (rawmode, self._compression, fp))
ignored, extents, ignored_2, args = self.tile[0]
args = args + (self.ifd.offset,)
extents = self.tile[0][1]
args = self.tile[0][3] + (self.ifd.offset,)
decoder = Image._getdecoder(self.mode, 'libtiff', args,
self.decoderconfig)
try:
Expand Down Expand Up @@ -978,7 +978,7 @@ def _setup(self):
# fixup palette descriptor

if self.mode == "P":
palette = [o8(a // 256) for a in self.tag[COLORMAP]]
palette = [o8(b // 256) for b in self.tag[COLORMAP]]
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
#
# --------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions Scripts/enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#

try:
from tkinter import *
from tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL
except ImportError:
from Tkinter import *
from Tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL

from PIL import Image, ImageTk, ImageEnhance
import sys
Expand Down
4 changes: 2 additions & 2 deletions Scripts/painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#

try:
from tkinter import *
from tkinter import Tk, Canvas, NW
except ImportError:
from Tkinter import *
from Tkinter import Tk, Canvas, NW

from PIL import Image, ImageTk
import sys
Expand Down

0 comments on commit 2781d5b

Please sign in to comment.