Skip to content

Commit

Permalink
Merge e1e11b9 into 72c7073
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 24, 2014
2 parents 72c7073 + e1e11b9 commit c6c29d7
Show file tree
Hide file tree
Showing 93 changed files with 899 additions and 633 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ after_success:
- travis_retry pip install pep8 pyflakes
- pep8 --statistics --count PIL/*.py
- pep8 --statistics --count Tests/*.py
- pyflakes *.py | tee >(wc -l)
- pyflakes PIL/*.py | tee >(wc -l)
- pyflakes Tests/*.py | tee >(wc -l)

Expand Down
21 changes: 11 additions & 10 deletions PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
# --------------------------------------------------------------------

bdf_slant = {
"R": "Roman",
"I": "Italic",
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other"
"R": "Roman",
"I": "Italic",
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other"
}

bdf_spacing = {
Expand All @@ -40,8 +40,8 @@
"C": "Cell"
}

def bdf_char(f):

def bdf_char(f):
# skip to STARTCHAR
while True:
s = f.readline()
Expand Down Expand Up @@ -82,6 +82,7 @@ def bdf_char(f):

return id, int(props["ENCODING"]), bbox, im


##
# Font file plugin for the X11 BDF format.

Expand Down Expand Up @@ -113,10 +114,10 @@ def __init__(self, fp):
font[4] = bdf_slant[font[4].upper()]
font[11] = bdf_spacing[font[11].upper()]

ascent = int(props["FONT_ASCENT"])
descent = int(props["FONT_DESCENT"])
# ascent = int(props["FONT_ASCENT"])
# descent = int(props["FONT_DESCENT"])

fontname = ";".join(font[1:])
# fontname = ";".join(font[1:])

# print "#", fontname
# for i in comments:
Expand Down
26 changes: 15 additions & 11 deletions PIL/BmpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
32: ("RGB", "BGRX")
}


def _accept(prefix):
return prefix[:2] == b"BM"


##
# Image plugin for the Windows BMP format.

Expand All @@ -62,8 +64,7 @@ class BmpImageFile(ImageFile.ImageFile):
format = "BMP"
format_description = "Windows Bitmap"

def _bitmap(self, header = 0, offset = 0):

def _bitmap(self, header=0, offset=0):
if header:
self.fp.seek(header)

Expand Down Expand Up @@ -97,8 +98,9 @@ def _bitmap(self, header = 0, offset = 0):
# upside-down storage
self.size = self.size[0], 2**32 - self.size[1]
direction = 0

self.info["dpi"] = tuple(map(lambda x: math.ceil(x / 39.3701), pxperm))

self.info["dpi"] = tuple(map(lambda x: math.ceil(x / 39.3701),
pxperm))

else:
raise IOError("Unsupported BMP header type (%d)" % len(s))
Expand Down Expand Up @@ -137,7 +139,7 @@ def _bitmap(self, header = 0, offset = 0):
greyscale = 1
if colors == 2:
indices = (0, 255)
elif colors > 2**16 or colors <=0: #We're reading a i32.
elif colors > 2**16 or colors <= 0: # We're reading a i32.
raise IOError("Unsupported BMP Palette size (%d)" % colors)
else:
indices = list(range(colors))
Expand All @@ -163,7 +165,8 @@ def _bitmap(self, header = 0, offset = 0):
self.tile = [("raw",
(0, 0) + self.size,
offset,
(rawmode, ((self.size[0]*bits+31)>>3)&(~3), direction))]
(rawmode, ((self.size[0]*bits+31) >> 3) & (~3),
direction))]

self.info["compression"] = compression

Expand Down Expand Up @@ -197,8 +200,8 @@ def _open(self):
"RGB": ("BGR", 24, 0),
}

def _save(im, fp, filename, check=0):

def _save(im, fp, filename, check=0):
try:
rawmode, bits, colors = SAVE[im.mode]
except KeyError:
Expand All @@ -214,10 +217,10 @@ def _save(im, fp, filename, check=0):
# 1 meter == 39.3701 inches
ppm = tuple(map(lambda x: int(x * 39.3701), dpi))

stride = ((im.size[0]*bits+7)//8+3)&(~3)
header = 40 # or 64 for OS/2 version 2
stride = ((im.size[0]*bits+7)//8+3) & (~3)
header = 40 # or 64 for OS/2 version 2
offset = 14 + header + colors * 4
image = stride * im.size[1]
image = stride * im.size[1]

# bitmap header
fp.write(b"BM" + # file type (magic)
Expand Down Expand Up @@ -248,7 +251,8 @@ def _save(im, fp, filename, check=0):
elif im.mode == "P":
fp.write(im.im.getpalette("RGB", "BGRX"))

ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, stride, -1))])
ImageFile._save(im, fp, [("raw", (0, 0)+im.size, 0,
(rawmode, stride, -1))])

#
# --------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions PIL/BufrStubImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

_handler = None


##
# Install application-specific BUFR image handler.
#
Expand All @@ -22,12 +23,14 @@ def register_handler(handler):
global _handler
_handler = handler


# --------------------------------------------------------------------
# Image adapter

def _accept(prefix):
return prefix[:4] == b"BUFR" or prefix[:4] == b"ZCZC"


class BufrStubImageFile(ImageFile.StubImageFile):

format = "BUFR"
Expand All @@ -53,6 +56,7 @@ def _open(self):
def _load(self):
return _handler


def _save(im, fp, filename):
if _handler is None or not hasattr("_handler", "save"):
raise IOError("BUFR save handler not installed")
Expand Down
7 changes: 4 additions & 3 deletions PIL/ContainerIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# A file object that provides read access to a part of an existing
# file (for example a TAR file).


class ContainerIO:

##
Expand Down Expand Up @@ -48,7 +49,7 @@ def isatty(self):
# for current offset, and 2 for end of region. You cannot move
# the pointer outside the defined region.

def seek(self, offset, mode = 0):
def seek(self, offset, mode=0):
if mode == 1:
self.pos = self.pos + offset
elif mode == 2:
Expand All @@ -75,12 +76,12 @@ def tell(self):
# read until end of region.
# @return An 8-bit string.

def read(self, n = 0):
def read(self, n=0):
if n:
n = min(n, self.length - self.pos)
else:
n = self.length - self.pos
if not n: # EOF
if not n: # EOF
return ""
self.pos = self.pos + n
return self.fh.read(n)
Expand Down

0 comments on commit c6c29d7

Please sign in to comment.