Skip to content

Commit

Permalink
Merge pull request python-pillow#654 from wiredfool/cleanup
Browse files Browse the repository at this point in the history
Thanks.
  • Loading branch information
hugovk committed Jun 24, 2014
2 parents a8cfe52 + 1633ffa commit 0cd5241
Show file tree
Hide file tree
Showing 38 changed files with 82 additions and 75 deletions.
2 changes: 1 addition & 1 deletion PIL/ArgImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def __store(self):
im1 = im1.chop_add_modulo(im0.crop(bbox))
im0.paste(im1, bbox)

self.count = self.count - 1
self.count -= 1

if self.count == 0 and self.show:
self.im = self.images[self.id]
Expand Down
2 changes: 1 addition & 1 deletion PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ def __init__(self, fp):
if not c:
break
id, ch, (xy, dst, src), im = c
if ch >= 0 and ch < len(self.glyph):
if 0 <= ch < len(self.glyph):
self.glyph[ch] = xy, dst, src, im
4 changes: 2 additions & 2 deletions PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def Ghostscript(tile, size, fp, scale=1):
s = fp.read(min(lengthfile, 100*1024))
if not s:
break
lengthfile = lengthfile - len(s)
length -= len(s)
f.write(s)

# Build ghostscript command
Expand Down Expand Up @@ -161,7 +161,7 @@ def readbinary(self, count):
def tell(self):
pos = self.fp.tell()
if self.char:
pos = pos - 1
pos -= 1
return pos
def readline(self):
s = b""
Expand Down
7 changes: 2 additions & 5 deletions PIL/ExifTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@
0x0201: "JpegIFOffset",
0x0202: "JpegIFByteCount",
0x0211: "YCbCrCoefficients",
0x0211: "YCbCrCoefficients",
0x0212: "YCbCrSubSampling",
0x0213: "YCbCrPositioning",
0x0213: "YCbCrPositioning",
0x0214: "ReferenceBlackWhite",
0x0214: "ReferenceBlackWhite",
0x1000: "RelatedImageFileFormat",
0x1001: "RelatedImageLength",
0x1001: "RelatedImageWidth",
0x1001: "RelatedImageLength", # FIXME / Dictionary contains duplicate keys
0x1001: "RelatedImageWidth", # FIXME \ Dictionary contains duplicate keys
0x828d: "CFARepeatPatternDim",
0x828e: "CFAPattern",
0x828f: "BatteryLevel",
Expand Down
2 changes: 1 addition & 1 deletion PIL/FliImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _palette(self, palette, shift):
g = i8(s[n+1]) << shift
b = i8(s[n+2]) << shift
palette[i] = (r, g, b)
i = i + 1
i += 1

def seek(self, frame):

Expand Down
4 changes: 2 additions & 2 deletions PIL/FontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def puti16(fp, values):
# write network order (big-endian) 16-bit sequence
for v in values:
if v < 0:
v = v + 65536
v += 65536
fp.write(_binary.o16be(v))

##
Expand Down Expand Up @@ -63,7 +63,7 @@ def compile(self):
h = max(h, src[3] - src[1])
w = w + (src[2] - src[0])
if w > WIDTH:
lines = lines + 1
lines += 1
w = (src[2] - src[0])
maxwidth = max(maxwidth, w)

Expand Down
2 changes: 1 addition & 1 deletion PIL/FpxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _open_index(self, index = 1):
i = 1
while size > 64:
size = size / 2
i = i + 1
i += 1
self.maxid = i - 1

# mode. instead of using a single field for this, flashpix
Expand Down
2 changes: 1 addition & 1 deletion PIL/GimpGradientFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def getpalette(self, entries = 256):
x = i / float(entries-1)

while x1 < x:
ix = ix + 1
ix += 1
x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix]

w = x1 - x0
Expand Down
2 changes: 1 addition & 1 deletion PIL/GimpPaletteFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, fp):
if 0 <= i <= 255:
self.palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])

i = i + 1
i += 1

self.palette = b"".join(self.palette)

Expand Down
8 changes: 4 additions & 4 deletions PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def read_32(fobj, start_length, size):
else:
blocksize = byte + 1
data.append(fobj.read(blocksize))
bytesleft = bytesleft - blocksize
bytesleft -= blocksize
if bytesleft <= 0:
break
if bytesleft != 0:
Expand Down Expand Up @@ -179,11 +179,11 @@ def __init__(self, fobj):
i = HEADERSIZE
while i < filesize:
sig, blocksize = nextheader(fobj)
i = i + HEADERSIZE
blocksize = blocksize - HEADERSIZE
i += HEADERSIZE
blocksize -= HEADERSIZE
dct[sig] = (i, blocksize)
fobj.seek(blocksize, 1)
i = i + blocksize
i += blocksize

def itersizes(self):
sizes = []
Expand Down
2 changes: 1 addition & 1 deletion PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _open(self):
self.info[k] = v

if k in TAGS:
n = n + 1
n += 1

else:

Expand Down
3 changes: 1 addition & 2 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def _getscaleoffset(expr):
(a, b, c) = data # simplified syntax
if (a is stub and b == "__mul__" and isinstance(c, numbers.Number)):
return c, 0.0
if (a is stub and b == "__add__" and isinstance(c, numbers.Number)):
if a is stub and b == "__add__" and isinstance(c, numbers.Number):
return 1.0, c
except TypeError:
pass
Expand Down Expand Up @@ -2081,7 +2081,6 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
.. versionadded:: 1.1.4
"""
"Load image from bytes or buffer"

# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
Expand Down
2 changes: 1 addition & 1 deletion PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,5 @@ def _safe_read(fp, size):
if not block:
break
data.append(block)
size = size - len(block)
size -= len(block)
return b"".join(data)
1 change: 0 additions & 1 deletion PIL/ImageMath.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from PIL import Image
from PIL import _imagingmath
import sys

try:
import builtins
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def autocontrast(image, cutoff=0, ignore=None):
cut = cut - h[lo]
h[lo] = 0
else:
h[lo] = h[lo] - cut
h[lo] -= cut
cut = 0
if cut <= 0:
break
Expand All @@ -105,7 +105,7 @@ def autocontrast(image, cutoff=0, ignore=None):
cut = cut - h[hi]
h[hi] = 0
else:
h[hi] = h[hi] - cut
h[hi] -= cut
cut = 0
if cut <= 0:
break
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImageShow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from PIL import Image
import os, sys

if(sys.version_info >= (3, 3)):
if sys.version_info >= (3, 3):
from shlex import quote
else:
from pipes import quote
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_command_ex(self, file, title=None, **options):
# imagemagick's display command instead.
command = executable = "xv"
if title:
command = command + " -name %s" % quote(title)
command += " -name %s" % quote(title)
return command, executable

if which("xv"):
Expand Down
5 changes: 2 additions & 3 deletions PIL/ImageStat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# See the README file for information on usage and redistribution.
#

from PIL import Image
import operator, math
from functools import reduce

Expand Down Expand Up @@ -81,7 +80,7 @@ def _getsum(self):
for i in range(0, len(self.h), 256):
sum = 0.0
for j in range(256):
sum = sum + j * self.h[i+j]
sum += j * self.h[i + j]
v.append(sum)
return v

Expand All @@ -92,7 +91,7 @@ def _getsum2(self):
for i in range(0, len(self.h), 256):
sum2 = 0.0
for j in range(256):
sum2 = sum2 + (j ** 2) * float(self.h[i+j])
sum2 += (j ** 2) * float(self.h[i + j])
v.append(sum2)
return v

Expand Down
14 changes: 7 additions & 7 deletions PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _is_raw(self, offset, size):
break
if s != sz:
return 0
y = y + 1
y += 1
return y == size[1]

def _open(self):
Expand Down Expand Up @@ -187,7 +187,7 @@ def load(self):
if not s:
break
o.write(s)
size = size - len(s)
size -= len(s)
o.close()

try:
Expand Down Expand Up @@ -235,26 +235,26 @@ def getiptcinfo(im):
# parse the image resource block
offset = 0
while app[offset:offset+4] == "8BIM":
offset = offset + 4
offset += 4
# resource code
code = JpegImagePlugin.i16(app, offset)
offset = offset + 2
offset += 2
# resource name (usually empty)
name_len = i8(app[offset])
name = app[offset+1:offset+1+name_len]
offset = 1 + offset + name_len
if offset & 1:
offset = offset + 1
offset += 1
# resource data block
size = JpegImagePlugin.i32(app, offset)
offset = offset + 4
offset += 4
if code == 0x0404:
# 0x0404 contains IPTC/NAA data
data = app[offset:offset+size]
break
offset = offset + size
if offset & 1:
offset = offset + 1
offset += 1
except (AttributeError, KeyError):
pass

Expand Down
4 changes: 2 additions & 2 deletions PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _parse_codestream(fp):
elif csiz == 3:
mode = 'RGB'
elif csiz == 4:
mode == 'RGBA'
mode = 'RGBA'
else:
mode = None

Expand Down Expand Up @@ -124,7 +124,7 @@ def _parse_jp2_header(fp):
if nc == 3:
mode = 'RGB'
elif nc == 4:
mode == 'RGBA'
mode = 'RGBA'
break

return (size, mode)
Expand Down
4 changes: 2 additions & 2 deletions PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ def validate_qtables(qtables):
i = 1
for marker in markers:
size = struct.pack(">H", 2 + ICC_OVERHEAD_LEN + len(marker))
extra = extra + (b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) + o8(len(markers)) + marker)
i = i + 1
extra += b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) + o8(len(markers)) + marker
i += 1

# get keyword arguments
im.encoderconfig = (
Expand Down
4 changes: 2 additions & 2 deletions PIL/MpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def peek(self, bits):
self.bits = 0
continue
self.bitbuffer = (self.bitbuffer << 8) + c
self.bits = self.bits + 8
self.bits += 8
return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1

def skip(self, bits):
while self.bits < bits:
self.bitbuffer = (self.bitbuffer << 8) + i8(self.fp.read(1))
self.bits = self.bits + 8
self.bits += 8
self.bits = self.bits - bits

def read(self, bits):
Expand Down
8 changes: 4 additions & 4 deletions PIL/PalmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,21 @@ def _save(im, fp, filename, check=0):
cols = im.size[0]
rows = im.size[1]

rowbytes = ((cols + (16//bpp - 1)) / (16 // bpp)) * 2;
rowbytes = ((cols + (16//bpp - 1)) / (16 // bpp)) * 2
transparent_index = 0
compression_type = _COMPRESSION_TYPES["none"]

flags = 0;
flags = 0
if im.mode == "P" and "custom-colormap" in im.info:
flags = flags & _FLAGS["custom-colormap"]
colormapsize = 4 * 256 + 2;
colormapsize = 4 * 256 + 2
colormapmode = im.palette.mode
colormap = im.getdata().getpalette()
else:
colormapsize = 0

if "offset" in im.info:
offset = (rowbytes * rows + 16 + 3 + colormapsize) // 4;
offset = (rowbytes * rows + 16 + 3 + colormapsize) // 4
else:
offset = 0

Expand Down
2 changes: 1 addition & 1 deletion PIL/PcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _save(im, fp, filename, check=0):
# bytes per plane
stride = (im.size[0] * bits + 7) // 8
# stride should be even
stride = stride + (stride % 2)
stride += stride % 2
# Stride needs to be kept in sync with the PcxEncode.c version.
# Ideally it should be passed in in the state, but the bytes value
# gets overwritten.
Expand Down
4 changes: 2 additions & 2 deletions PIL/PdfImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def write(self, value):
r = i8(palette[i*3])
g = i8(palette[i*3+1])
b = i8(palette[i*3+2])
colorspace = colorspace + "%02x%02x%02x " % (r, g, b)
colorspace = colorspace + "> ]"
colorspace += "%02x%02x%02x " % (r, g, b)
colorspace += "> ]"
procset = "/ImageI" # indexed color
elif im.mode == "RGB":
filter = "/DCTDecode"
Expand Down
Loading

0 comments on commit 0cd5241

Please sign in to comment.