Skip to content

Commit

Permalink
Merge branch 'master' into rm-deprecated-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Jun 13, 2017
2 parents c70eb8a + ae431bc commit c3e041e
Show file tree
Hide file tree
Showing 71 changed files with 533 additions and 289 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ htmlcov/
nosetests.xml
coverage.xml

# Test files
test_images

# Translations
*.mo

Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ notifications:
matrix:
fast_finish: true
include:
- python: "pypy"
- python: "pypy3"
- python: "pypy-5.7.1"
- python: "pypy3.3-5.2-alpha1"
- python: '3.6'
- python: '2.7'
- python: "2.7_with_system_site_packages" # For PyQt4
Expand Down
8 changes: 3 additions & 5 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
set -e

sudo apt-get update
sudo apt-get -qq install libfreetype6-dev liblcms2-dev\
sudo apt-get -qq install libfreetype6-dev liblcms2-dev python-tk \
python-qt4 ghostscript libffi-dev libjpeg-turbo-progs cmake imagemagick
pip install cffi
pip install nose
pip install check-manifest
pip install olefile
# Pyroma tests sometimes hang on PyPy; skip
if [ "$TRAVIS_PYTHON_VERSION" != "pypy" ]; then pip install pyroma; fi

pip install pyroma
pip install coverage

# docs only on python 2.7
# docs only on Python 2.7
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip install -r requirements.txt ; fi

# clean checkout for manifest
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Changelog (Pillow)
4.2.0 (unreleased)
------------------

- Update Feature Detection
[wiredfool]

- CI: Update pypy on TravisCI
[hugovk]

- ImageMorph: Fix wrong expected size of MRLs read from disk #2561
[dov]

- Docs: Update install docs for FreeBSD #2546
[wiredfool]

Expand Down
4 changes: 2 additions & 2 deletions PIL/IcoImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def frame(self, idx):
# figure out where AND mask image starts
mode = a[0]
bpp = 8
for k in BmpImagePlugin.BIT2MODE.keys():
if mode == BmpImagePlugin.BIT2MODE[k][1]:
for k, v in BmpImagePlugin.BIT2MODE.items():
if mode == v[1]:
bpp = k
break

Expand Down
2 changes: 1 addition & 1 deletion PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def _conv_type_shape(im):
return shape+(extra,), typ


MODES = sorted(_MODEINFO.keys())
MODES = sorted(_MODEINFO)

# raw modes that may be memory mapped. NOTE: if you change this, you
# may have to modify the stride calculation in map.c too!
Expand Down
1 change: 1 addition & 0 deletions PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def Draw(im, mode=None):
except AttributeError:
return ImageDraw(im, mode)


# experimental access to the outline API
try:
Outline = Image.core.outline
Expand Down
8 changes: 4 additions & 4 deletions PIL/ImageMorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _pattern_permute(self, basic_pattern, options, basic_result):
.replace('0', 'Z')
.replace('1', '0')
.replace('Z', '1'))
res = '%d' % (1-int(res))
res = 1-int(res)
patterns.append((pattern, res))

return patterns
Expand Down Expand Up @@ -152,8 +152,8 @@ def build_lut(self):
patterns += self._pattern_permute(pattern, options, result)

# # Debugging
# for p,r in patterns:
# print(p,r)
# for p, r in patterns:
# print(p, r)
# print('--')

# compile the patterns into regular expressions for speed
Expand Down Expand Up @@ -234,7 +234,7 @@ def load_lut(self, filename):
with open(filename, 'rb') as f:
self.lut = bytearray(f.read())

if len(self.lut) != 8192:
if len(self.lut) != LUT_SIZE:
self.lut = None
raise Exception('Wrong size operator file!')

Expand Down
2 changes: 1 addition & 1 deletion PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _open(self):
tagdata = self.fp.read(size)
else:
tagdata = None
if tag in list(self.info.keys()):
if tag in self.info:
if isinstance(self.info[tag], list):
self.info[tag].append(tagdata)
else:
Expand Down
1 change: 1 addition & 0 deletions PIL/McIdasImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _open(self):

self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))]


# --------------------------------------------------------------------
# registry

Expand Down
195 changes: 104 additions & 91 deletions PIL/PdfImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Image plugin for PDF images (output only).
##

from . import Image, ImageFile
from . import Image, ImageFile, ImageSequence
from ._binary import i8
import io

Expand Down Expand Up @@ -133,13 +133,24 @@ def write(self, value):

#
# pages
numberOfPages = 1
ims = [im]
if save_all:
try:
numberOfPages = im.n_frames
except AttributeError:
# Image format does not have n_frames. It is a single frame image
pass
append_images = im.encoderinfo.get("append_images", [])
for append_im in append_images:
if append_im.mode != im.mode:
append_im = append_im.convert(im.mode)
append_im.encoderinfo = im.encoderinfo.copy()
ims.append(append_im)
numberOfPages = 0
for im in ims:
im_numberOfPages = 1
if save_all:
try:
im_numberOfPages = im.n_frames
except AttributeError:
# Image format does not have n_frames. It is a single frame image
pass
numberOfPages += im_numberOfPages
pages = [str(pageNumber*3+4)+" 0 R"
for pageNumber in range(0, numberOfPages)]

Expand All @@ -151,90 +162,92 @@ def write(self, value):
Kids="["+"\n".join(pages)+"]")
_endobj(fp)

for pageNumber in range(0, numberOfPages):
im.seek(pageNumber)

#
# image

op = io.BytesIO()

if filter == "/ASCIIHexDecode":
if bits == 1:
# FIXME: the hex encoder doesn't support packed 1-bit
# images; do things the hard way...
data = im.tobytes("raw", "1")
im = Image.new("L", (len(data), 1), None)
im.putdata(data)
ImageFile._save(im, op, [("hex", (0, 0)+im.size, 0, im.mode)])
elif filter == "/DCTDecode":
Image.SAVE["JPEG"](im, op, filename)
elif filter == "/FlateDecode":
ImageFile._save(im, op, [("zip", (0, 0)+im.size, 0, im.mode)])
elif filter == "/RunLengthDecode":
ImageFile._save(im, op, [("packbits", (0, 0)+im.size, 0, im.mode)])
else:
raise ValueError("unsupported PDF filter (%s)" % filter)

#
# Get image characteristics

width, height = im.size

xref.append(fp.tell())
_obj(
fp, pageNumber*3+3,
Type="/XObject",
Subtype="/Image",
Width=width, # * 72.0 / resolution,
Height=height, # * 72.0 / resolution,
Length=len(op.getvalue()),
Filter=filter,
BitsPerComponent=bits,
DecodeParams=params,
ColorSpace=colorspace)

fp.write("stream\n")
fp.fp.write(op.getvalue())
fp.write("\nendstream\n")

_endobj(fp)

#
# page

xref.append(fp.tell())
_obj(fp, pageNumber*3+4)
fp.write(
"<<\n/Type /Page\n/Parent 2 0 R\n"
"/Resources <<\n/ProcSet [ /PDF %s ]\n"
"/XObject << /image %d 0 R >>\n>>\n"
"/MediaBox [ 0 0 %d %d ]\n/Contents %d 0 R\n>>\n" % (
procset,
pageNumber*3+3,
int(width * 72.0 / resolution),
int(height * 72.0 / resolution),
pageNumber*3+5))
_endobj(fp)

#
# page contents

op = TextWriter(io.BytesIO())

op.write(
"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
int(width * 72.0 / resolution),
int(height * 72.0 / resolution)))

xref.append(fp.tell())
_obj(fp, pageNumber*3+5, Length=len(op.fp.getvalue()))

fp.write("stream\n")
fp.fp.write(op.fp.getvalue())
fp.write("\nendstream\n")

_endobj(fp)
pageNumber = 0
for imSequence in ims:
for im in ImageSequence.Iterator(imSequence):
#
# image

op = io.BytesIO()

if filter == "/ASCIIHexDecode":
if bits == 1:
# FIXME: the hex encoder doesn't support packed 1-bit
# images; do things the hard way...
data = im.tobytes("raw", "1")
im = Image.new("L", (len(data), 1), None)
im.putdata(data)
ImageFile._save(im, op, [("hex", (0, 0)+im.size, 0, im.mode)])
elif filter == "/DCTDecode":
Image.SAVE["JPEG"](im, op, filename)
elif filter == "/FlateDecode":
ImageFile._save(im, op, [("zip", (0, 0)+im.size, 0, im.mode)])
elif filter == "/RunLengthDecode":
ImageFile._save(im, op, [("packbits", (0, 0)+im.size, 0, im.mode)])
else:
raise ValueError("unsupported PDF filter (%s)" % filter)

#
# Get image characteristics

width, height = im.size

xref.append(fp.tell())
_obj(
fp, pageNumber*3+3,
Type="/XObject",
Subtype="/Image",
Width=width, # * 72.0 / resolution,
Height=height, # * 72.0 / resolution,
Length=len(op.getvalue()),
Filter=filter,
BitsPerComponent=bits,
DecodeParams=params,
ColorSpace=colorspace)

fp.write("stream\n")
fp.fp.write(op.getvalue())
fp.write("\nendstream\n")

_endobj(fp)

#
# page

xref.append(fp.tell())
_obj(fp, pageNumber*3+4)
fp.write(
"<<\n/Type /Page\n/Parent 2 0 R\n"
"/Resources <<\n/ProcSet [ /PDF %s ]\n"
"/XObject << /image %d 0 R >>\n>>\n"
"/MediaBox [ 0 0 %d %d ]\n/Contents %d 0 R\n>>\n" % (
procset,
pageNumber*3+3,
int(width * 72.0 / resolution),
int(height * 72.0 / resolution),
pageNumber*3+5))
_endobj(fp)

#
# page contents

op = TextWriter(io.BytesIO())

op.write(
"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
int(width * 72.0 / resolution),
int(height * 72.0 / resolution)))

xref.append(fp.tell())
_obj(fp, pageNumber*3+5, Length=len(op.fp.getvalue()))

fp.write("stream\n")
fp.fp.write(op.fp.getvalue())
fp.write("\nendstream\n")

_endobj(fp)

pageNumber += 1

#
# trailer
Expand Down
Loading

0 comments on commit c3e041e

Please sign in to comment.