mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Drop support for EOL Python 2.7
This commit is contained in:
parent
127b322194
commit
af770a6c55
|
@ -13,13 +13,7 @@ environment:
|
||||||
TEST_OPTIONS:
|
TEST_OPTIONS:
|
||||||
DEPLOY: YES
|
DEPLOY: YES
|
||||||
matrix:
|
matrix:
|
||||||
- PYTHON: C:/vp/pypy2
|
|
||||||
EXECUTABLE: bin/pypy.exe
|
|
||||||
PIP_DIR: bin
|
|
||||||
VENV: YES
|
|
||||||
- PYTHON: C:/Python27-x64
|
|
||||||
- PYTHON: C:/Python37
|
- PYTHON: C:/Python37
|
||||||
- PYTHON: C:/Python27
|
|
||||||
- PYTHON: C:/Python37-x64
|
- PYTHON: C:/Python37-x64
|
||||||
- PYTHON: C:/Python36
|
- PYTHON: C:/Python36
|
||||||
- PYTHON: C:/Python36-x64
|
- PYTHON: C:/Python36-x64
|
||||||
|
@ -44,11 +38,6 @@ install:
|
||||||
- xcopy c:\pillow-depends\*.tar.gz c:\pillow\winbuild\
|
- xcopy c:\pillow-depends\*.tar.gz c:\pillow\winbuild\
|
||||||
- xcopy /s c:\pillow-depends\test_images\* c:\pillow\tests\images
|
- xcopy /s c:\pillow-depends\test_images\* c:\pillow\tests\images
|
||||||
- cd c:\pillow\winbuild\
|
- cd c:\pillow\winbuild\
|
||||||
- ps: |
|
|
||||||
if ($env:PYTHON -eq "c:/vp/pypy2")
|
|
||||||
{
|
|
||||||
c:\pillow\winbuild\appveyor_install_pypy2.cmd
|
|
||||||
}
|
|
||||||
- ps: |
|
- ps: |
|
||||||
if ($env:PYTHON -eq "c:/vp/pypy3")
|
if ($env:PYTHON -eq "c:/vp/pypy3")
|
||||||
{
|
{
|
||||||
|
|
4
.github/CONTRIBUTING.md
vendored
4
.github/CONTRIBUTING.md
vendored
|
@ -9,14 +9,14 @@ Please send a pull request to the master branch. Please include [documentation](
|
||||||
- Fork the Pillow repository.
|
- Fork the Pillow repository.
|
||||||
- Create a branch from master.
|
- Create a branch from master.
|
||||||
- Develop bug fixes, features, tests, etc.
|
- Develop bug fixes, features, tests, etc.
|
||||||
- Run the test suite on Python 2.7 and 3.x. You can enable [Travis CI](https://travis-ci.org/profile/) and [AppVeyor](https://ci.appveyor.com/projects/new) on your repo to catch test failures prior to the pull request, and [Codecov](https://codecov.io/gh) to see if the changed code is covered by tests.
|
- Run the test suite. You can enable [Travis CI](https://travis-ci.org/profile/) and [AppVeyor](https://ci.appveyor.com/projects/new) on your repo to catch test failures prior to the pull request, and [Codecov](https://codecov.io/gh) to see if the changed code is covered by tests.
|
||||||
- Create a pull request to pull the changes from your branch to the Pillow master.
|
- Create a pull request to pull the changes from your branch to the Pillow master.
|
||||||
|
|
||||||
### Guidelines
|
### Guidelines
|
||||||
|
|
||||||
- Separate code commits from reformatting commits.
|
- Separate code commits from reformatting commits.
|
||||||
- Provide tests for any newly added code.
|
- Provide tests for any newly added code.
|
||||||
- Follow PEP8.
|
- Follow PEP 8.
|
||||||
- When committing only documentation changes please include [ci skip] in the commit message to avoid running tests on Travis-CI and AppVeyor.
|
- When committing only documentation changes please include [ci skip] in the commit message to avoid running tests on Travis-CI and AppVeyor.
|
||||||
|
|
||||||
## Reporting Issues
|
## Reporting Issues
|
||||||
|
|
|
@ -6,8 +6,8 @@ notifications:
|
||||||
irc: "chat.freenode.net#pil"
|
irc: "chat.freenode.net#pil"
|
||||||
|
|
||||||
# Run fast lint first to get fast feedback.
|
# Run fast lint first to get fast feedback.
|
||||||
# Run slow PyPy* next, to give them a headstart and reduce waiting time.
|
# Run slow PyPy next, to give it a headstart and reduce waiting time.
|
||||||
# Run latest 3.x and 2.x next, to get quick compatibility results.
|
# Run latest 3.x next, to get quick compatibility results.
|
||||||
# Then run the remainder, with fastest Docker jobs last.
|
# Then run the remainder, with fastest Docker jobs last.
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
@ -16,15 +16,11 @@ matrix:
|
||||||
- python: "3.6"
|
- python: "3.6"
|
||||||
name: "Lint"
|
name: "Lint"
|
||||||
env: LINT="true"
|
env: LINT="true"
|
||||||
- python: "pypy"
|
|
||||||
name: "PyPy2 Xenial"
|
|
||||||
- python: "pypy3"
|
- python: "pypy3"
|
||||||
name: "PyPy3 Xenial"
|
name: "PyPy3 Xenial"
|
||||||
- python: '3.7'
|
- python: '3.7'
|
||||||
name: "3.7 Xenial"
|
name: "3.7 Xenial"
|
||||||
services: xvfb
|
services: xvfb
|
||||||
- python: '2.7'
|
|
||||||
name: "2.7 Xenial"
|
|
||||||
- python: '3.6'
|
- python: '3.6'
|
||||||
name: "3.6 Xenial PYTHONOPTIMIZE=1"
|
name: "3.6 Xenial PYTHONOPTIMIZE=1"
|
||||||
env: PYTHONOPTIMIZE=1
|
env: PYTHONOPTIMIZE=1
|
||||||
|
|
|
@ -11,16 +11,12 @@ coveralls-lcov -v -n coverage.filtered.info > coverage.c.json
|
||||||
|
|
||||||
coverage report
|
coverage report
|
||||||
pip install codecov
|
pip install codecov
|
||||||
if [[ $TRAVIS_PYTHON_VERSION != "2.7_with_system_site_packages" ]]; then
|
pip install coveralls-merge
|
||||||
# Not working here. Just skip it, it's being removed soon.
|
coveralls-merge coverage.c.json
|
||||||
pip install coveralls-merge
|
|
||||||
coveralls-merge coverage.c.json
|
|
||||||
fi
|
|
||||||
codecov
|
codecov
|
||||||
|
|
||||||
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ] && [ "$DOCKER" == "" ]; then
|
if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ] && [ "$DOCKER" == "" ]; then
|
||||||
# Coverage and quality reports on just the latest diff.
|
# Coverage and quality reports on just the latest diff.
|
||||||
# (Installation is very slow on Py3, so just do it for Py2.)
|
|
||||||
depends/diffcover-install.sh
|
depends/diffcover-install.sh
|
||||||
depends/diffcover-run.sh
|
depends/diffcover-run.sh
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -20,8 +20,8 @@ if [[ $TRAVIS_PYTHON_VERSION == 3.* ]]; then
|
||||||
pip install pyqt5
|
pip install pyqt5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# docs only on Python 2.7
|
# docs only on Python 3.7
|
||||||
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip install -r requirements.txt ; fi
|
if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then pip install -r requirements.txt ; fi
|
||||||
|
|
||||||
# webp
|
# webp
|
||||||
pushd depends && ./install_webp.sh && popd
|
pushd depends && ./install_webp.sh && popd
|
||||||
|
|
|
@ -9,4 +9,4 @@ make install-coverage
|
||||||
python -m pytest -v -x --cov PIL --cov-report term Tests
|
python -m pytest -v -x --cov PIL --cov-report term Tests
|
||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then make doccheck; fi
|
if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then make doccheck; fi
|
||||||
|
|
36
Makefile
36
Makefile
|
@ -3,7 +3,7 @@
|
||||||
.DEFAULT_GOAL := release-test
|
.DEFAULT_GOAL := release-test
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
python setup.py clean
|
python3 setup.py clean
|
||||||
rm src/PIL/*.so || true
|
rm src/PIL/*.so || true
|
||||||
rm -r build || true
|
rm -r build || true
|
||||||
find . -name __pycache__ | xargs rm -r || true
|
find . -name __pycache__ | xargs rm -r || true
|
||||||
|
@ -15,8 +15,8 @@ co:
|
||||||
done
|
done
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
python selftest.py
|
python3 selftest.py
|
||||||
python setup.py test
|
python3 setup.py test
|
||||||
rm -r htmlcov || true
|
rm -r htmlcov || true
|
||||||
coverage report
|
coverage report
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ doccheck:
|
||||||
$(MAKE) -C docs linkcheck || true
|
$(MAKE) -C docs linkcheck || true
|
||||||
|
|
||||||
docserve:
|
docserve:
|
||||||
cd docs/_build/html && python -mSimpleHTTPServer 2> /dev/null&
|
cd docs/_build/html && python3 -mSimpleHTTPServer 2> /dev/null&
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo "Welcome to Pillow development. Please use \`make <target>\` where <target> is one of"
|
@echo "Welcome to Pillow development. Please use \`make <target>\` where <target> is one of"
|
||||||
|
@ -50,22 +50,22 @@ help:
|
||||||
@echo " upload-test build and upload sdists to test.pythonpackages.com"
|
@echo " upload-test build and upload sdists to test.pythonpackages.com"
|
||||||
|
|
||||||
inplace: clean
|
inplace: clean
|
||||||
python setup.py develop build_ext --inplace
|
python3 setup.py develop build_ext --inplace
|
||||||
|
|
||||||
install:
|
install:
|
||||||
python setup.py install
|
python3 setup.py install
|
||||||
python selftest.py
|
python3 selftest.py
|
||||||
|
|
||||||
install-coverage:
|
install-coverage:
|
||||||
CFLAGS="-coverage" python setup.py build_ext install
|
CFLAGS="-coverage" python3 setup.py build_ext install
|
||||||
python selftest.py
|
python3 selftest.py
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
# make a debug version if we don't have a -dbg python. Leaves in symbols
|
# make a debug version if we don't have a -dbg python. Leaves in symbols
|
||||||
# for our stuff, kills optimization, and redirects to dev null so we
|
# for our stuff, kills optimization, and redirects to dev null so we
|
||||||
# see any build failures.
|
# see any build failures.
|
||||||
make clean > /dev/null
|
make clean > /dev/null
|
||||||
CFLAGS='-g -O0' python setup.py build_ext install > /dev/null
|
CFLAGS='-g -O0' python3 setup.py build_ext install > /dev/null
|
||||||
|
|
||||||
install-req:
|
install-req:
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
@ -76,17 +76,17 @@ install-venv:
|
||||||
|
|
||||||
release-test:
|
release-test:
|
||||||
$(MAKE) install-req
|
$(MAKE) install-req
|
||||||
python setup.py develop
|
python3 setup.py develop
|
||||||
python selftest.py
|
python3 selftest.py
|
||||||
python -m pytest Tests
|
python3 -m pytest Tests
|
||||||
python setup.py install
|
python3 setup.py install
|
||||||
python -m pytest -qq
|
python3 -m pytest -qq
|
||||||
check-manifest
|
check-manifest
|
||||||
pyroma .
|
pyroma .
|
||||||
viewdoc
|
viewdoc
|
||||||
|
|
||||||
sdist:
|
sdist:
|
||||||
python setup.py sdist --format=gztar
|
python3 setup.py sdist --format=gztar
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pytest -qq
|
pytest -qq
|
||||||
|
@ -97,10 +97,10 @@ upload-test:
|
||||||
# username:
|
# username:
|
||||||
# password:
|
# password:
|
||||||
# repository = http://test.pythonpackages.com
|
# repository = http://test.pythonpackages.com
|
||||||
python setup.py sdist --format=gztar upload -r test
|
python3 setup.py sdist --format=gztar upload -r test
|
||||||
|
|
||||||
upload:
|
upload:
|
||||||
python setup.py sdist --format=gztar upload
|
python3 setup.py sdist --format=gztar upload
|
||||||
|
|
||||||
readme:
|
readme:
|
||||||
viewdoc
|
viewdoc
|
||||||
|
|
|
@ -10,7 +10,6 @@ import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from PIL import Image, ImageMath
|
from PIL import Image, ImageMath
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -277,11 +276,6 @@ class PillowLeakTestCase(PillowTestCase):
|
||||||
|
|
||||||
# helpers
|
# helpers
|
||||||
|
|
||||||
if not py3:
|
|
||||||
# Remove DeprecationWarning in Python 3
|
|
||||||
PillowTestCase.assertRaisesRegex = PillowTestCase.assertRaisesRegexp
|
|
||||||
PillowTestCase.assertRegex = PillowTestCase.assertRegexpMatches
|
|
||||||
|
|
||||||
|
|
||||||
def fromstring(data):
|
def fromstring(data):
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import sys
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
from PIL import Image, IptcImagePlugin
|
from PIL import Image, IptcImagePlugin
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper
|
from .helper import PillowTestCase, hopper
|
||||||
|
@ -52,12 +55,6 @@ class TestFileIptc(PillowTestCase):
|
||||||
# Arrange
|
# Arrange
|
||||||
c = b"abc"
|
c = b"abc"
|
||||||
# Temporarily redirect stdout
|
# Temporarily redirect stdout
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
import sys
|
|
||||||
|
|
||||||
old_stdout = sys.stdout
|
old_stdout = sys.stdout
|
||||||
sys.stdout = mystdout = StringIO()
|
sys.stdout = mystdout = StringIO()
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ from collections import namedtuple
|
||||||
from ctypes import c_float
|
from ctypes import c_float
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin, TiffTags, features
|
from PIL import Image, TiffImagePlugin, TiffTags, features
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper
|
from .helper import PillowTestCase, hopper
|
||||||
|
|
||||||
|
@ -361,12 +360,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
b = im.tobytes()
|
b = im.tobytes()
|
||||||
# Bytes are in image native order (little endian)
|
# Bytes are in image native order (little endian)
|
||||||
if py3:
|
self.assertEqual(b[0], ord(b"\xe0"))
|
||||||
self.assertEqual(b[0], ord(b"\xe0"))
|
self.assertEqual(b[1], ord(b"\x01"))
|
||||||
self.assertEqual(b[1], ord(b"\x01"))
|
|
||||||
else:
|
|
||||||
self.assertEqual(b[0], b"\xe0")
|
|
||||||
self.assertEqual(b[1], b"\x01")
|
|
||||||
|
|
||||||
out = self.tempfile("temp.tif")
|
out = self.tempfile("temp.tif")
|
||||||
# out = "temp.le.tif"
|
# out = "temp.le.tif"
|
||||||
|
@ -387,12 +382,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
b = im.tobytes()
|
b = im.tobytes()
|
||||||
|
|
||||||
# Bytes are in image native order (big endian)
|
# Bytes are in image native order (big endian)
|
||||||
if py3:
|
self.assertEqual(b[0], ord(b"\x01"))
|
||||||
self.assertEqual(b[0], ord(b"\x01"))
|
self.assertEqual(b[1], ord(b"\xe0"))
|
||||||
self.assertEqual(b[1], ord(b"\xe0"))
|
|
||||||
else:
|
|
||||||
self.assertEqual(b[0], b"\x01")
|
|
||||||
self.assertEqual(b[1], b"\xe0")
|
|
||||||
|
|
||||||
out = self.tempfile("temp.tif")
|
out = self.tempfile("temp.tif")
|
||||||
im.save(out)
|
im.save(out)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import zlib
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from PIL import Image, ImageFile, PngImagePlugin
|
from PIL import Image, ImageFile, PngImagePlugin
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowLeakTestCase, PillowTestCase, hopper, unittest
|
from .helper import PillowLeakTestCase, PillowTestCase, hopper, unittest
|
||||||
|
|
||||||
|
@ -460,12 +459,11 @@ class TestFilePng(PillowTestCase):
|
||||||
im = roundtrip(im, pnginfo=info)
|
im = roundtrip(im, pnginfo=info)
|
||||||
self.assertEqual(im.info, {"Text": value})
|
self.assertEqual(im.info, {"Text": value})
|
||||||
|
|
||||||
if py3:
|
rt_text(" Aa" + chr(0xA0) + chr(0xC4) + chr(0xFF)) # Latin1
|
||||||
rt_text(" Aa" + chr(0xA0) + chr(0xC4) + chr(0xFF)) # Latin1
|
rt_text(chr(0x400) + chr(0x472) + chr(0x4FF)) # Cyrillic
|
||||||
rt_text(chr(0x400) + chr(0x472) + chr(0x4FF)) # Cyrillic
|
# CJK:
|
||||||
# CJK:
|
rt_text(chr(0x4E00) + chr(0x66F0) + chr(0x9FBA) + chr(0x3042) + chr(0xAC00))
|
||||||
rt_text(chr(0x4E00) + chr(0x66F0) + chr(0x9FBA) + chr(0x3042) + chr(0xAC00))
|
rt_text("A" + chr(0xC4) + chr(0x472) + chr(0x3042)) # Combined
|
||||||
rt_text("A" + chr(0xC4) + chr(0x472) + chr(0x3042)) # Combined
|
|
||||||
|
|
||||||
def test_scary(self):
|
def test_scary(self):
|
||||||
# Check reading of evil PNG file. For information, see:
|
# Check reading of evil PNG file. For information, see:
|
||||||
|
|
|
@ -3,7 +3,6 @@ import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin
|
from PIL import Image, TiffImagePlugin
|
||||||
from PIL._util import py3
|
|
||||||
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
|
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper, unittest
|
from .helper import PillowTestCase, hopper, unittest
|
||||||
|
@ -176,12 +175,8 @@ class TestFileTiff(PillowTestCase):
|
||||||
|
|
||||||
b = im.tobytes()
|
b = im.tobytes()
|
||||||
# Bytes are in image native order (little endian)
|
# Bytes are in image native order (little endian)
|
||||||
if py3:
|
self.assertEqual(b[0], ord(b"\xe0"))
|
||||||
self.assertEqual(b[0], ord(b"\xe0"))
|
self.assertEqual(b[1], ord(b"\x01"))
|
||||||
self.assertEqual(b[1], ord(b"\x01"))
|
|
||||||
else:
|
|
||||||
self.assertEqual(b[0], b"\xe0")
|
|
||||||
self.assertEqual(b[1], b"\x01")
|
|
||||||
|
|
||||||
def test_big_endian(self):
|
def test_big_endian(self):
|
||||||
im = Image.open("Tests/images/16bit.MM.cropped.tif")
|
im = Image.open("Tests/images/16bit.MM.cropped.tif")
|
||||||
|
@ -191,12 +186,8 @@ class TestFileTiff(PillowTestCase):
|
||||||
b = im.tobytes()
|
b = im.tobytes()
|
||||||
|
|
||||||
# Bytes are in image native order (big endian)
|
# Bytes are in image native order (big endian)
|
||||||
if py3:
|
self.assertEqual(b[0], ord(b"\x01"))
|
||||||
self.assertEqual(b[0], ord(b"\x01"))
|
self.assertEqual(b[1], ord(b"\xe0"))
|
||||||
self.assertEqual(b[1], ord(b"\xe0"))
|
|
||||||
else:
|
|
||||||
self.assertEqual(b[0], b"\x01")
|
|
||||||
self.assertEqual(b[1], b"\xe0")
|
|
||||||
|
|
||||||
def test_16bit_s(self):
|
def test_16bit_s(self):
|
||||||
im = Image.open("Tests/images/16bit.s.tif")
|
im = Image.open("Tests/images/16bit.s.tif")
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from PIL import FontFile, Image, ImageDraw, ImageFont, PcfFontFile
|
from PIL import FontFile, Image, ImageDraw, ImageFont, PcfFontFile
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase
|
from .helper import PillowTestCase
|
||||||
|
|
||||||
|
@ -74,6 +73,5 @@ class TestFontPcf(PillowTestCase):
|
||||||
def test_high_characters(self):
|
def test_high_characters(self):
|
||||||
message = "".join(chr(i + 1) for i in range(140, 232))
|
message = "".join(chr(i + 1) for i in range(140, 232))
|
||||||
self._test_high_characters(message)
|
self._test_high_characters(message)
|
||||||
# accept bytes instances in Py3.
|
# accept bytes instances.
|
||||||
if py3:
|
self._test_high_characters(message.encode("latin1"))
|
||||||
self._test_high_characters(message.encode("latin1"))
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import colorsys
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper
|
from .helper import PillowTestCase, hopper
|
||||||
|
|
||||||
|
@ -49,27 +48,18 @@ class TestFormatHSV(PillowTestCase):
|
||||||
|
|
||||||
(r, g, b) = im.split()
|
(r, g, b) = im.split()
|
||||||
|
|
||||||
if py3:
|
conv_func = self.int_to_float
|
||||||
conv_func = self.int_to_float
|
|
||||||
else:
|
|
||||||
conv_func = self.str_to_float
|
|
||||||
|
|
||||||
if hasattr(itertools, "izip"):
|
|
||||||
iter_helper = itertools.izip
|
|
||||||
else:
|
|
||||||
iter_helper = itertools.zip_longest
|
|
||||||
|
|
||||||
converted = [
|
converted = [
|
||||||
self.tuple_to_ints(func(conv_func(_r), conv_func(_g), conv_func(_b)))
|
self.tuple_to_ints(func(conv_func(_r), conv_func(_g), conv_func(_b)))
|
||||||
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(), b.tobytes())
|
for (_r, _g, _b) in itertools.zip_longest(
|
||||||
|
r.tobytes(), g.tobytes(), b.tobytes()
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
if py3:
|
new_bytes = b"".join(
|
||||||
new_bytes = b"".join(
|
bytes(chr(h) + chr(s) + chr(v), "latin-1") for (h, s, v) in converted
|
||||||
bytes(chr(h) + chr(s) + chr(v), "latin-1") for (h, s, v) in converted
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
new_bytes = b"".join(chr(h) + chr(s) + chr(v) for (h, s, v) in converted)
|
|
||||||
|
|
||||||
hsv = Image.frombytes(mode, r.size, new_bytes)
|
hsv = Image.frombytes(mode, r.size, new_bytes)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper, unittest
|
from .helper import PillowTestCase, hopper, unittest
|
||||||
|
|
||||||
|
@ -80,20 +79,14 @@ class TestImage(PillowTestCase):
|
||||||
im.size = (3, 4)
|
im.size = (3, 4)
|
||||||
|
|
||||||
def test_invalid_image(self):
|
def test_invalid_image(self):
|
||||||
if py3:
|
import io
|
||||||
import io
|
|
||||||
|
|
||||||
im = io.BytesIO(b"")
|
im = io.BytesIO(b"")
|
||||||
else:
|
|
||||||
import StringIO
|
|
||||||
|
|
||||||
im = StringIO.StringIO("")
|
|
||||||
self.assertRaises(IOError, Image.open, im)
|
self.assertRaises(IOError, Image.open, im)
|
||||||
|
|
||||||
def test_bad_mode(self):
|
def test_bad_mode(self):
|
||||||
self.assertRaises(ValueError, Image.open, "filename", "bad mode")
|
self.assertRaises(ValueError, Image.open, "filename", "bad mode")
|
||||||
|
|
||||||
@unittest.skipUnless(Image.HAS_PATHLIB, "requires pathlib/pathlib2")
|
|
||||||
def test_pathlib(self):
|
def test_pathlib(self):
|
||||||
from PIL.Image import Path
|
from PIL.Image import Path
|
||||||
|
|
||||||
|
|
|
@ -349,12 +349,8 @@ class TestEmbeddable(unittest.TestCase):
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char *home = "%s";
|
char *home = "%s";
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
wchar_t *whome = Py_DecodeLocale(home, NULL);
|
wchar_t *whome = Py_DecodeLocale(home, NULL);
|
||||||
Py_SetPythonHome(whome);
|
Py_SetPythonHome(whome);
|
||||||
#else
|
|
||||||
Py_SetPythonHome(home);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Py_InitializeEx(0);
|
Py_InitializeEx(0);
|
||||||
Py_DECREF(PyImport_ImportModule("PIL.Image"));
|
Py_DECREF(PyImport_ImportModule("PIL.Image"));
|
||||||
|
@ -364,9 +360,7 @@ int main(int argc, char* argv[])
|
||||||
Py_DECREF(PyImport_ImportModule("PIL.Image"));
|
Py_DECREF(PyImport_ImportModule("PIL.Image"));
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
PyMem_RawFree(whome);
|
PyMem_RawFree(whome);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper
|
from .helper import PillowTestCase, hopper
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +6,5 @@ class TestImageGetIm(PillowTestCase):
|
||||||
im = hopper()
|
im = hopper()
|
||||||
type_repr = repr(type(im.getim()))
|
type_repr = repr(type(im.getim()))
|
||||||
|
|
||||||
if py3:
|
self.assertIn("PyCapsule", type_repr)
|
||||||
self.assertIn("PyCapsule", type_repr)
|
|
||||||
|
|
||||||
self.assertIsInstance(im.im.id, int)
|
self.assertIsInstance(im.im.id, int)
|
||||||
|
|
|
@ -2,7 +2,6 @@ import array
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from PIL import Image, ImagePath
|
from PIL import Image, ImagePath
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase
|
from .helper import PillowTestCase
|
||||||
|
|
||||||
|
@ -75,10 +74,7 @@ class TestImagePath(PillowTestCase):
|
||||||
# This fails due to the invalid malloc above,
|
# This fails due to the invalid malloc above,
|
||||||
# and segfaults
|
# and segfaults
|
||||||
for i in range(200000):
|
for i in range(200000):
|
||||||
if py3:
|
x[i] = b"0" * 16
|
||||||
x[i] = b"0" * 16
|
|
||||||
else:
|
|
||||||
x[i] = "0" * 16
|
|
||||||
|
|
||||||
|
|
||||||
class evil:
|
class evil:
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import py3
|
|
||||||
|
|
||||||
from .helper import PillowTestCase, hopper, unittest
|
from .helper import PillowTestCase, hopper, unittest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import ImageTk
|
from PIL import ImageTk
|
||||||
|
|
||||||
if py3:
|
import tkinter as tk
|
||||||
import tkinter as tk
|
|
||||||
else:
|
|
||||||
import Tkinter as tk
|
|
||||||
dir(ImageTk)
|
dir(ImageTk)
|
||||||
HAS_TK = True
|
HAS_TK = True
|
||||||
except (OSError, ImportError):
|
except (OSError, ImportError):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
from PIL import Image, PSDraw
|
from PIL import Image, PSDraw
|
||||||
|
|
||||||
|
@ -47,10 +48,6 @@ class TestPsDraw(PillowTestCase):
|
||||||
|
|
||||||
def test_stdout(self):
|
def test_stdout(self):
|
||||||
# Temporarily redirect stdout
|
# Temporarily redirect stdout
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
old_stdout = sys.stdout
|
old_stdout = sys.stdout
|
||||||
sys.stdout = mystdout = StringIO()
|
sys.stdout = mystdout = StringIO()
|
||||||
|
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
# A monkey patch of the base distutils.ccompiler to use parallel builds
|
|
||||||
# Tested on 2.7, looks to be identical to 3.3.
|
|
||||||
# Only applied on Python 2.7 because otherwise, it conflicts with Python's
|
|
||||||
# own newly-added support for parallel builds.
|
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from distutils.ccompiler import CCompiler
|
|
||||||
from multiprocessing import Pool, cpu_count
|
|
||||||
|
|
||||||
try:
|
|
||||||
MAX_PROCS = int(os.environ.get("MAX_CONCURRENCY", min(4, cpu_count())))
|
|
||||||
except NotImplementedError:
|
|
||||||
MAX_PROCS = None
|
|
||||||
|
|
||||||
|
|
||||||
# hideous monkeypatching. but. but. but.
|
|
||||||
def _mp_compile_one(tp):
|
|
||||||
(self, obj, build, cc_args, extra_postargs, pp_opts) = tp
|
|
||||||
try:
|
|
||||||
src, ext = build[obj]
|
|
||||||
except KeyError:
|
|
||||||
return
|
|
||||||
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _mp_compile(
|
|
||||||
self,
|
|
||||||
sources,
|
|
||||||
output_dir=None,
|
|
||||||
macros=None,
|
|
||||||
include_dirs=None,
|
|
||||||
debug=0,
|
|
||||||
extra_preargs=None,
|
|
||||||
extra_postargs=None,
|
|
||||||
depends=None,
|
|
||||||
):
|
|
||||||
"""Compile one or more source files.
|
|
||||||
|
|
||||||
see distutils.ccompiler.CCompiler.compile for comments.
|
|
||||||
"""
|
|
||||||
# A concrete compiler class can either override this method
|
|
||||||
# entirely or implement _compile().
|
|
||||||
|
|
||||||
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
|
|
||||||
output_dir, macros, include_dirs, sources, depends, extra_postargs
|
|
||||||
)
|
|
||||||
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
|
||||||
|
|
||||||
pool = Pool(MAX_PROCS)
|
|
||||||
try:
|
|
||||||
print("Building using %d processes" % pool._processes)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
arr = [(self, obj, build, cc_args, extra_postargs, pp_opts) for obj in objects]
|
|
||||||
pool.map_async(_mp_compile_one, arr)
|
|
||||||
pool.close()
|
|
||||||
pool.join()
|
|
||||||
# Return *all* object filenames, not just the ones we just built.
|
|
||||||
return objects
|
|
||||||
|
|
||||||
|
|
||||||
def install():
|
|
||||||
|
|
||||||
fl_win = sys.platform.startswith("win")
|
|
||||||
fl_cygwin = sys.platform.startswith("cygwin")
|
|
||||||
|
|
||||||
if fl_win or fl_cygwin:
|
|
||||||
# Windows barfs on multiprocessing installs
|
|
||||||
print("Single threaded build for Windows")
|
|
||||||
return
|
|
||||||
|
|
||||||
if MAX_PROCS != 1:
|
|
||||||
# explicitly don't enable if environment says 1 processor
|
|
||||||
try:
|
|
||||||
# bug, only enable if we can make a Pool. see issue #790 and
|
|
||||||
# https://stackoverflow.com/questions/6033599/oserror-38-errno-38-with-multiprocessing
|
|
||||||
Pool(2)
|
|
||||||
CCompiler.compile = _mp_compile
|
|
||||||
except Exception as msg:
|
|
||||||
print("Exception installing mp_compile, proceeding without: %s" % msg)
|
|
||||||
else:
|
|
||||||
print(
|
|
||||||
"Single threaded build, not installing mp_compile: %s processes" % MAX_PROCS
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# We monkeypatch Python 2.7
|
|
||||||
if sys.version_info.major < 3:
|
|
||||||
install()
|
|
15
setup.py
15
setup.py
|
@ -20,10 +20,6 @@ from distutils.command.build_ext import build_ext
|
||||||
|
|
||||||
from setuptools import Extension, setup
|
from setuptools import Extension, setup
|
||||||
|
|
||||||
# monkey patch import hook. Even though flake8 says it's not used, it is.
|
|
||||||
# comment this out to disable multi threaded builds.
|
|
||||||
import mp_compile
|
|
||||||
|
|
||||||
if sys.platform == "win32" and sys.version_info >= (3, 8):
|
if sys.platform == "win32" and sys.version_info >= (3, 8):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Pillow does not yet support Python {}.{} and does not yet provide "
|
"Pillow does not yet support Python {}.{} and does not yet provide "
|
||||||
|
@ -332,12 +328,6 @@ class pil_build_ext(build_ext):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
global DEBUG
|
global DEBUG
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
if sys.version_info.major >= 3 and not self.parallel:
|
|
||||||
# For Python 2.7, we monkeypatch distutils to have parallel
|
|
||||||
# builds. If --parallel (or -j) wasn't specified, we want to
|
|
||||||
# reproduce the same behavior as before, that is, auto-detect the
|
|
||||||
# number of jobs.
|
|
||||||
self.parallel = mp_compile.MAX_PROCS
|
|
||||||
for x in self.feature:
|
for x in self.feature:
|
||||||
if getattr(self, "disable_%s" % x):
|
if getattr(self, "disable_%s" % x):
|
||||||
setattr(self.feature, x, False)
|
setattr(self.feature, x, False)
|
||||||
|
@ -861,12 +851,11 @@ try:
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 6 - Mature",
|
"Development Status :: 6 - Mature",
|
||||||
"License :: OSI Approved :: Historical Permission Notice and Disclaimer (HPND)", # noqa: E501
|
"License :: OSI Approved :: Historical Permission Notice and Disclaimer (HPND)", # noqa: E501
|
||||||
"Programming Language :: Python :: 2",
|
|
||||||
"Programming Language :: Python :: 2.7",
|
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Programming Language :: Python :: 3.5",
|
"Programming Language :: Python :: 3.5",
|
||||||
"Programming Language :: Python :: 3.6",
|
"Programming Language :: Python :: 3.6",
|
||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
"Programming Language :: Python :: Implementation :: CPython",
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
"Programming Language :: Python :: Implementation :: PyPy",
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
"Topic :: Multimedia :: Graphics",
|
"Topic :: Multimedia :: Graphics",
|
||||||
|
@ -875,7 +864,7 @@ try:
|
||||||
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
||||||
"Topic :: Multimedia :: Graphics :: Viewers",
|
"Topic :: Multimedia :: Graphics :: Viewers",
|
||||||
],
|
],
|
||||||
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
|
python_requires=">=3.5",
|
||||||
cmdclass={"build_ext": pil_build_ext},
|
cmdclass={"build_ext": pil_build_ext},
|
||||||
ext_modules=[Extension("PIL._imaging", ["_imaging.c"])],
|
ext_modules=[Extension("PIL._imaging", ["_imaging.c"])],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
|
|
@ -42,15 +42,8 @@ gs_windows_binary = None
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
if hasattr(shutil, "which"):
|
|
||||||
which = shutil.which
|
|
||||||
else:
|
|
||||||
# Python 2
|
|
||||||
import distutils.spawn
|
|
||||||
|
|
||||||
which = distutils.spawn.find_executable
|
|
||||||
for binary in ("gswin32c", "gswin64c", "gs"):
|
for binary in ("gswin32c", "gswin64c", "gs"):
|
||||||
if which(binary) is not None:
|
if shutil.which(binary) is not None:
|
||||||
gs_windows_binary = binary
|
gs_windows_binary = binary
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -378,9 +371,8 @@ def _save(im, fp, filename, eps=1):
|
||||||
base_fp = fp
|
base_fp = fp
|
||||||
wrapped_fp = False
|
wrapped_fp = False
|
||||||
if fp != sys.stdout:
|
if fp != sys.stdout:
|
||||||
if sys.version_info.major > 2:
|
fp = io.TextIOWrapper(fp, encoding="latin-1")
|
||||||
fp = io.TextIOWrapper(fp, encoding="latin-1")
|
wrapped_fp = True
|
||||||
wrapped_fp = True
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if eps:
|
if eps:
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
|
import builtins
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
@ -33,29 +34,15 @@ import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
from collections.abc import Callable, MutableMapping
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# VERSION was removed in Pillow 6.0.0.
|
# VERSION was removed in Pillow 6.0.0.
|
||||||
# PILLOW_VERSION was removed in Pillow 7.0.0.
|
# PILLOW_VERSION was removed in Pillow 7.0.0.
|
||||||
# Use __version__ instead.
|
# Use __version__ instead.
|
||||||
from . import ImageMode, TiffTags, __version__, _plugins
|
from . import ImageMode, TiffTags, __version__, _plugins
|
||||||
from ._binary import i8, i32le
|
from ._binary import i8, i32le
|
||||||
from ._util import deferred_error, isPath, isStringType, py3
|
from ._util import deferred_error, isPath, isStringType
|
||||||
|
|
||||||
try:
|
|
||||||
import builtins
|
|
||||||
except ImportError:
|
|
||||||
import __builtin__
|
|
||||||
|
|
||||||
builtins = __builtin__
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Python 3
|
|
||||||
from collections.abc import Callable, MutableMapping
|
|
||||||
except ImportError:
|
|
||||||
# Python 2.7
|
|
||||||
from collections import Callable, MutableMapping
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -134,18 +121,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
cffi = None
|
cffi = None
|
||||||
|
|
||||||
try:
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
HAS_PATHLIB = True
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
from pathlib2 import Path
|
|
||||||
|
|
||||||
HAS_PATHLIB = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_PATHLIB = False
|
|
||||||
|
|
||||||
|
|
||||||
def isImageType(t):
|
def isImageType(t):
|
||||||
"""
|
"""
|
||||||
|
@ -621,10 +596,8 @@ class Image(object):
|
||||||
# object is gone.
|
# object is gone.
|
||||||
self.im = deferred_error(ValueError("Operation on closed image"))
|
self.im = deferred_error(ValueError("Operation on closed image"))
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
def __del__(self):
|
||||||
|
self.__exit__()
|
||||||
def __del__(self):
|
|
||||||
self.__exit__()
|
|
||||||
|
|
||||||
def _copy(self):
|
def _copy(self):
|
||||||
self.load()
|
self.load()
|
||||||
|
@ -1347,10 +1320,7 @@ class Image(object):
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
try:
|
try:
|
||||||
if py3:
|
return list(self.im.getpalette())
|
||||||
return list(self.im.getpalette())
|
|
||||||
else:
|
|
||||||
return [i8(c) for c in self.im.getpalette()]
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None # no palette
|
return None # no palette
|
||||||
|
|
||||||
|
@ -1701,10 +1671,7 @@ class Image(object):
|
||||||
palette = ImagePalette.raw(data.rawmode, data.palette)
|
palette = ImagePalette.raw(data.rawmode, data.palette)
|
||||||
else:
|
else:
|
||||||
if not isinstance(data, bytes):
|
if not isinstance(data, bytes):
|
||||||
if py3:
|
data = bytes(data)
|
||||||
data = bytes(data)
|
|
||||||
else:
|
|
||||||
data = "".join(chr(x) for x in data)
|
|
||||||
palette = ImagePalette.raw(rawmode, data)
|
palette = ImagePalette.raw(rawmode, data)
|
||||||
self.mode = "PA" if "A" in self.mode else "P"
|
self.mode = "PA" if "A" in self.mode else "P"
|
||||||
self.palette = palette
|
self.palette = palette
|
||||||
|
@ -2036,7 +2003,7 @@ class Image(object):
|
||||||
if isPath(fp):
|
if isPath(fp):
|
||||||
filename = fp
|
filename = fp
|
||||||
open_fp = True
|
open_fp = True
|
||||||
elif HAS_PATHLIB and isinstance(fp, Path):
|
elif isinstance(fp, Path):
|
||||||
filename = str(fp)
|
filename = str(fp)
|
||||||
open_fp = True
|
open_fp = True
|
||||||
if not filename and hasattr(fp, "name") and isPath(fp.name):
|
if not filename and hasattr(fp, "name") and isPath(fp.name):
|
||||||
|
@ -2747,7 +2714,7 @@ def open(fp, mode="r"):
|
||||||
|
|
||||||
exclusive_fp = False
|
exclusive_fp = False
|
||||||
filename = ""
|
filename = ""
|
||||||
if HAS_PATHLIB and isinstance(fp, Path):
|
if isinstance(fp, Path):
|
||||||
filename = str(fp.resolve())
|
filename = str(fp.resolve())
|
||||||
elif isPath(fp):
|
elif isPath(fp):
|
||||||
filename = fp
|
filename = fp
|
||||||
|
@ -3311,11 +3278,6 @@ class Exif(MutableMapping):
|
||||||
def __contains__(self, tag):
|
def __contains__(self, tag):
|
||||||
return tag in self._data or (self._info is not None and tag in self._info)
|
return tag in self._data or (self._info is not None and tag in self._info)
|
||||||
|
|
||||||
if not py3:
|
|
||||||
|
|
||||||
def has_key(self, tag):
|
|
||||||
return tag in self
|
|
||||||
|
|
||||||
def __setitem__(self, tag, value):
|
def __setitem__(self, tag, value):
|
||||||
if self._info is not None and tag in self._info:
|
if self._info is not None and tag in self._info:
|
||||||
del self._info[tag]
|
del self._info[tag]
|
||||||
|
|
|
@ -29,7 +29,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import isDirectory, isPath, py3
|
from ._util import isDirectory, isPath
|
||||||
|
|
||||||
LAYOUT_BASIC = 0
|
LAYOUT_BASIC = 0
|
||||||
LAYOUT_RAQM = 1
|
LAYOUT_RAQM = 1
|
||||||
|
@ -695,10 +695,7 @@ def load_path(filename):
|
||||||
for directory in sys.path:
|
for directory in sys.path:
|
||||||
if isDirectory(directory):
|
if isDirectory(directory):
|
||||||
if not isinstance(filename, str):
|
if not isinstance(filename, str):
|
||||||
if py3:
|
filename = filename.decode("utf-8")
|
||||||
filename = filename.decode("utf-8")
|
|
||||||
else:
|
|
||||||
filename = filename.encode("utf-8")
|
|
||||||
try:
|
try:
|
||||||
return load(os.path.join(directory, filename))
|
return load(os.path.join(directory, filename))
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
|
@ -15,15 +15,9 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import builtins
|
||||||
|
|
||||||
from . import Image, _imagingmath
|
from . import Image, _imagingmath
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
try:
|
|
||||||
import builtins
|
|
||||||
except ImportError:
|
|
||||||
import __builtin__
|
|
||||||
|
|
||||||
builtins = __builtin__
|
|
||||||
|
|
||||||
VERBOSE = 0
|
VERBOSE = 0
|
||||||
|
|
||||||
|
@ -101,11 +95,6 @@ class _Operand(object):
|
||||||
# an image is "true" if it contains at least one non-zero pixel
|
# an image is "true" if it contains at least one non-zero pixel
|
||||||
return self.im.getbbox() is not None
|
return self.im.getbbox() is not None
|
||||||
|
|
||||||
if not py3:
|
|
||||||
# Provide __nonzero__ for pre-Py3k
|
|
||||||
__nonzero__ = __bool__
|
|
||||||
del __bool__
|
|
||||||
|
|
||||||
def __abs__(self):
|
def __abs__(self):
|
||||||
return self.apply("abs", self)
|
return self.apply("abs", self)
|
||||||
|
|
||||||
|
@ -152,13 +141,6 @@ class _Operand(object):
|
||||||
def __rpow__(self, other):
|
def __rpow__(self, other):
|
||||||
return self.apply("pow", other, self)
|
return self.apply("pow", other, self)
|
||||||
|
|
||||||
if not py3:
|
|
||||||
# Provide __div__ and __rdiv__ for pre-Py3k
|
|
||||||
__div__ = __truediv__
|
|
||||||
__rdiv__ = __rtruediv__
|
|
||||||
del __truediv__
|
|
||||||
del __rtruediv__
|
|
||||||
|
|
||||||
# bitwise
|
# bitwise
|
||||||
def __invert__(self):
|
def __invert__(self):
|
||||||
return self.apply("invert", self)
|
return self.apply("invert", self)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import isPath, py3
|
from ._util import isPath
|
||||||
|
|
||||||
qt_versions = [["5", "PyQt5"], ["side2", "PySide2"]]
|
qt_versions = [["5", "PyQt5"], ["side2", "PySide2"]]
|
||||||
|
|
||||||
|
@ -125,10 +125,7 @@ def _toqclass_helper(im):
|
||||||
# handle filename, if given instead of image name
|
# handle filename, if given instead of image name
|
||||||
if hasattr(im, "toUtf8"):
|
if hasattr(im, "toUtf8"):
|
||||||
# FIXME - is this really the best way to do this?
|
# FIXME - is this really the best way to do this?
|
||||||
if py3:
|
im = str(im.toUtf8(), "utf-8")
|
||||||
im = str(im.toUtf8(), "utf-8")
|
|
||||||
else:
|
|
||||||
im = unicode(im.toUtf8(), "utf-8") # noqa: F821
|
|
||||||
if isPath(im):
|
if isPath(im):
|
||||||
im = Image.open(im)
|
im = Image.open(im)
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,10 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from shlex import quote
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
|
||||||
from shlex import quote
|
|
||||||
else:
|
|
||||||
from pipes import quote
|
|
||||||
|
|
||||||
_viewers = []
|
_viewers = []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,11 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import tkinter
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
|
||||||
if sys.version_info.major > 2:
|
|
||||||
import tkinter
|
|
||||||
else:
|
|
||||||
import Tkinter as tkinter
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Check for Tkinter interface hooks
|
# Check for Tkinter interface hooks
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import EpsImagePlugin
|
from . import EpsImagePlugin
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Simple Postscript graphics interface.
|
# Simple Postscript graphics interface.
|
||||||
|
@ -36,7 +35,7 @@ class PSDraw(object):
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
|
|
||||||
def _fp_write(self, to_write):
|
def _fp_write(self, to_write):
|
||||||
if not py3 or self.fp == sys.stdout:
|
if self.fp == sys.stdout:
|
||||||
self.fp.write(to_write)
|
self.fp.write(to_write)
|
||||||
else:
|
else:
|
||||||
self.fp.write(bytes(to_write, "UTF-8"))
|
self.fp.write(bytes(to_write, "UTF-8"))
|
||||||
|
|
|
@ -7,24 +7,14 @@ import re
|
||||||
import time
|
import time
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from UserDict import UserDict # Python 2.x
|
from UserDict import UserDict # Python 2.x
|
||||||
except ImportError:
|
except ImportError:
|
||||||
UserDict = collections.UserDict # Python 3.x
|
UserDict = collections.UserDict # Python 3.x
|
||||||
|
|
||||||
|
|
||||||
if py3: # Python 3.x
|
def make_bytes(s):
|
||||||
|
return s.encode("us-ascii")
|
||||||
def make_bytes(s):
|
|
||||||
return s.encode("us-ascii")
|
|
||||||
|
|
||||||
|
|
||||||
else: # Python 2.x
|
|
||||||
|
|
||||||
def make_bytes(s): # pragma: no cover
|
|
||||||
return s # pragma: no cover
|
|
||||||
|
|
||||||
|
|
||||||
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
|
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
|
||||||
|
@ -81,10 +71,8 @@ PDFDocEncoding = {
|
||||||
def decode_text(b):
|
def decode_text(b):
|
||||||
if b[: len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
|
if b[: len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
|
||||||
return b[len(codecs.BOM_UTF16_BE) :].decode("utf_16_be")
|
return b[len(codecs.BOM_UTF16_BE) :].decode("utf_16_be")
|
||||||
elif py3: # Python 3.x
|
else:
|
||||||
return "".join(PDFDocEncoding.get(byte, chr(byte)) for byte in b)
|
return "".join(PDFDocEncoding.get(byte, chr(byte)) for byte in b)
|
||||||
else: # Python 2.x
|
|
||||||
return u"".join(PDFDocEncoding.get(ord(byte), byte) for byte in b)
|
|
||||||
|
|
||||||
|
|
||||||
class PdfFormatError(RuntimeError):
|
class PdfFormatError(RuntimeError):
|
||||||
|
@ -252,16 +240,10 @@ class PdfName:
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
result = bytearray(b"/")
|
result = bytearray(b"/")
|
||||||
for b in self.name:
|
for b in self.name:
|
||||||
if py3: # Python 3.x
|
if b in self.allowed_chars:
|
||||||
if b in self.allowed_chars:
|
result.append(b)
|
||||||
result.append(b)
|
else:
|
||||||
else:
|
result.extend(make_bytes("#%02X" % b))
|
||||||
result.extend(make_bytes("#%02X" % b))
|
|
||||||
else: # Python 2.x
|
|
||||||
if ord(b) in self.allowed_chars:
|
|
||||||
result.append(b)
|
|
||||||
else:
|
|
||||||
result.extend(b"#%02X" % ord(b))
|
|
||||||
return bytes(result)
|
return bytes(result)
|
||||||
|
|
||||||
__str__ = __bytes__
|
__str__ = __bytes__
|
||||||
|
@ -324,23 +306,13 @@ class PdfDict(UserDict):
|
||||||
out.extend(b"\n>>")
|
out.extend(b"\n>>")
|
||||||
return bytes(out)
|
return bytes(out)
|
||||||
|
|
||||||
if not py3:
|
|
||||||
__str__ = __bytes__
|
|
||||||
|
|
||||||
|
|
||||||
class PdfBinary:
|
class PdfBinary:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
if py3: # Python 3.x
|
def __bytes__(self):
|
||||||
|
return make_bytes("<%s>" % "".join("%02X" % b for b in self.data))
|
||||||
def __bytes__(self):
|
|
||||||
return make_bytes("<%s>" % "".join("%02X" % b for b in self.data))
|
|
||||||
|
|
||||||
else: # Python 2.x
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "<%s>" % "".join("%02X" % ord(b) for b in self.data)
|
|
||||||
|
|
||||||
|
|
||||||
class PdfStream:
|
class PdfStream:
|
||||||
|
@ -382,9 +354,7 @@ def pdf_repr(x):
|
||||||
return bytes(PdfDict(x))
|
return bytes(PdfDict(x))
|
||||||
elif isinstance(x, list):
|
elif isinstance(x, list):
|
||||||
return bytes(PdfArray(x))
|
return bytes(PdfArray(x))
|
||||||
elif (py3 and isinstance(x, str)) or (
|
elif isinstance(x, str):
|
||||||
not py3 and isinstance(x, unicode) # noqa: F821
|
|
||||||
):
|
|
||||||
return pdf_repr(encode_text(x))
|
return pdf_repr(encode_text(x))
|
||||||
elif isinstance(x, bytes):
|
elif isinstance(x, bytes):
|
||||||
# XXX escape more chars? handle binary garbage
|
# XXX escape more chars? handle binary garbage
|
||||||
|
|
|
@ -38,7 +38,6 @@ import zlib
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette
|
from . import Image, ImageFile, ImagePalette
|
||||||
from ._binary import i8, i16be as i16, i32be as i32, o16be as o16, o32be as o32
|
from ._binary import i8, i16be as i16, i32be as i32, o16be as o16, o32be as o32
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
# __version__ is deprecated and will be removed in a future version. Use
|
# __version__ is deprecated and will be removed in a future version. Use
|
||||||
# PIL.__version__ instead.
|
# PIL.__version__ instead.
|
||||||
|
@ -450,9 +449,8 @@ class PngStream(ChunkStream):
|
||||||
k = s
|
k = s
|
||||||
v = b""
|
v = b""
|
||||||
if k:
|
if k:
|
||||||
if py3:
|
k = k.decode("latin-1", "strict")
|
||||||
k = k.decode("latin-1", "strict")
|
v = v.decode("latin-1", "replace")
|
||||||
v = v.decode("latin-1", "replace")
|
|
||||||
|
|
||||||
self.im_info[k] = self.im_text[k] = v
|
self.im_info[k] = self.im_text[k] = v
|
||||||
self.check_text_memory(len(v))
|
self.check_text_memory(len(v))
|
||||||
|
@ -487,9 +485,8 @@ class PngStream(ChunkStream):
|
||||||
v = b""
|
v = b""
|
||||||
|
|
||||||
if k:
|
if k:
|
||||||
if py3:
|
k = k.decode("latin-1", "strict")
|
||||||
k = k.decode("latin-1", "strict")
|
v = v.decode("latin-1", "replace")
|
||||||
v = v.decode("latin-1", "replace")
|
|
||||||
|
|
||||||
self.im_info[k] = self.im_text[k] = v
|
self.im_info[k] = self.im_text[k] = v
|
||||||
self.check_text_memory(len(v))
|
self.check_text_memory(len(v))
|
||||||
|
@ -524,14 +521,13 @@ class PngStream(ChunkStream):
|
||||||
return s
|
return s
|
||||||
else:
|
else:
|
||||||
return s
|
return s
|
||||||
if py3:
|
try:
|
||||||
try:
|
k = k.decode("latin-1", "strict")
|
||||||
k = k.decode("latin-1", "strict")
|
lang = lang.decode("utf-8", "strict")
|
||||||
lang = lang.decode("utf-8", "strict")
|
tk = tk.decode("utf-8", "strict")
|
||||||
tk = tk.decode("utf-8", "strict")
|
v = v.decode("utf-8", "strict")
|
||||||
v = v.decode("utf-8", "strict")
|
except UnicodeError:
|
||||||
except UnicodeError:
|
return s
|
||||||
return s
|
|
||||||
|
|
||||||
self.im_info[k] = self.im_text[k] = iTXt(v, lang, tk)
|
self.im_info[k] = self.im_text[k] = iTXt(v, lang, tk)
|
||||||
self.check_text_memory(len(v))
|
self.check_text_memory(len(v))
|
||||||
|
|
|
@ -27,7 +27,6 @@ import struct
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i8, i16be as i16, o8
|
from ._binary import i8, i16be as i16, o8
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
# __version__ is deprecated and will be removed in a future version. Use
|
# __version__ is deprecated and will be removed in a future version. Use
|
||||||
# PIL.__version__ instead.
|
# PIL.__version__ instead.
|
||||||
|
@ -173,8 +172,7 @@ def _save(im, fp, filename):
|
||||||
pinmax = 255
|
pinmax = 255
|
||||||
# Image name (79 characters max, truncated below in write)
|
# Image name (79 characters max, truncated below in write)
|
||||||
imgName = os.path.splitext(os.path.basename(filename))[0]
|
imgName = os.path.splitext(os.path.basename(filename))[0]
|
||||||
if py3:
|
imgName = imgName.encode("ascii", "ignore")
|
||||||
imgName = imgName.encode("ascii", "ignore")
|
|
||||||
# Standard representation of pixel in the file
|
# Standard representation of pixel in the file
|
||||||
colormap = 0
|
colormap = 0
|
||||||
fp.write(struct.pack(">h", magicNumber))
|
fp.write(struct.pack(">h", magicNumber))
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import sys
|
|
||||||
|
|
||||||
from . import ContainerIO
|
from . import ContainerIO
|
||||||
|
|
||||||
|
@ -64,10 +63,8 @@ class TarIO(ContainerIO.ContainerIO):
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
def __del__(self):
|
||||||
|
self.close()
|
||||||
def __del__(self):
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.fh.close()
|
self.fh.close()
|
||||||
|
|
|
@ -46,24 +46,15 @@ import io
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
|
||||||
import warnings
|
import warnings
|
||||||
|
from collections.abc import MutableMapping
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
from numbers import Number, Rational
|
from numbers import Number, Rational
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette, TiffTags
|
from . import Image, ImageFile, ImagePalette, TiffTags
|
||||||
from ._binary import i8, o8
|
from ._binary import i8, o8
|
||||||
from ._util import py3
|
|
||||||
from .TiffTags import TYPES
|
from .TiffTags import TYPES
|
||||||
|
|
||||||
try:
|
|
||||||
# Python 3
|
|
||||||
from collections.abc import MutableMapping
|
|
||||||
except ImportError:
|
|
||||||
# Python 2.7
|
|
||||||
from collections import MutableMapping
|
|
||||||
|
|
||||||
|
|
||||||
# __version__ is deprecated and will be removed in a future version. Use
|
# __version__ is deprecated and will be removed in a future version. Use
|
||||||
# PIL.__version__ instead.
|
# PIL.__version__ instead.
|
||||||
__version__ = "1.3.5"
|
__version__ = "1.3.5"
|
||||||
|
@ -531,18 +522,11 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
def __contains__(self, tag):
|
def __contains__(self, tag):
|
||||||
return tag in self._tags_v2 or tag in self._tagdata
|
return tag in self._tags_v2 or tag in self._tagdata
|
||||||
|
|
||||||
if not py3:
|
|
||||||
|
|
||||||
def has_key(self, tag):
|
|
||||||
return tag in self
|
|
||||||
|
|
||||||
def __setitem__(self, tag, value):
|
def __setitem__(self, tag, value):
|
||||||
self._setitem(tag, value, self.legacy_api)
|
self._setitem(tag, value, self.legacy_api)
|
||||||
|
|
||||||
def _setitem(self, tag, value, legacy_api):
|
def _setitem(self, tag, value, legacy_api):
|
||||||
basetypes = (Number, bytes, str)
|
basetypes = (Number, bytes, str)
|
||||||
if not py3:
|
|
||||||
basetypes += (unicode,) # noqa: F821
|
|
||||||
|
|
||||||
info = TiffTags.lookup(tag)
|
info = TiffTags.lookup(tag)
|
||||||
values = [value] if isinstance(value, basetypes) else value
|
values = [value] if isinstance(value, basetypes) else value
|
||||||
|
@ -562,14 +546,10 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
elif all(isinstance(v, float) for v in values):
|
elif all(isinstance(v, float) for v in values):
|
||||||
self.tagtype[tag] = TiffTags.DOUBLE
|
self.tagtype[tag] = TiffTags.DOUBLE
|
||||||
else:
|
else:
|
||||||
if py3:
|
if all(isinstance(v, str) for v in values):
|
||||||
if all(isinstance(v, str) for v in values):
|
|
||||||
self.tagtype[tag] = TiffTags.ASCII
|
|
||||||
else:
|
|
||||||
# Never treat data as binary by default on Python 2.
|
|
||||||
self.tagtype[tag] = TiffTags.ASCII
|
self.tagtype[tag] = TiffTags.ASCII
|
||||||
|
|
||||||
if self.tagtype[tag] == TiffTags.UNDEFINED and py3:
|
if self.tagtype[tag] == TiffTags.UNDEFINED:
|
||||||
values = [
|
values = [
|
||||||
value.encode("ascii", "replace") if isinstance(value, str) else value
|
value.encode("ascii", "replace") if isinstance(value, str) else value
|
||||||
]
|
]
|
||||||
|
@ -689,8 +669,6 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
@_register_writer(2)
|
@_register_writer(2)
|
||||||
def write_string(self, value):
|
def write_string(self, value):
|
||||||
# remerge of https://github.com/python-pillow/Pillow/pull/1416
|
# remerge of https://github.com/python-pillow/Pillow/pull/1416
|
||||||
if sys.version_info.major == 2:
|
|
||||||
value = value.decode("ascii", "replace")
|
|
||||||
return b"" + value.encode("ascii", "replace") + b"\0"
|
return b"" + value.encode("ascii", "replace") + b"\0"
|
||||||
|
|
||||||
@_register_loader(5, 8)
|
@_register_loader(5, 8)
|
||||||
|
@ -1132,7 +1110,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
fp = hasattr(self.fp, "fileno") and os.dup(self.fp.fileno())
|
fp = hasattr(self.fp, "fileno") and os.dup(self.fp.fileno())
|
||||||
# flush the file descriptor, prevents error on pypy 2.4+
|
# flush the file descriptor, prevents error on pypy 2.4+
|
||||||
# should also eliminate the need for fp.tell for py3
|
# should also eliminate the need for fp.tell
|
||||||
# in _seek
|
# in _seek
|
||||||
if hasattr(self.fp, "flush"):
|
if hasattr(self.fp, "flush"):
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
|
@ -1602,13 +1580,10 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
if tag in ifd.tagtype:
|
if tag in ifd.tagtype:
|
||||||
types[tag] = ifd.tagtype[tag]
|
types[tag] = ifd.tagtype[tag]
|
||||||
elif not (
|
elif not (isinstance(value, (int, float, str, bytes))):
|
||||||
isinstance(value, (int, float, str, bytes))
|
|
||||||
or (not py3 and isinstance(value, unicode)) # noqa: F821
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
if tag not in atts and tag not in blocklist:
|
if tag not in atts and tag not in blocklist:
|
||||||
if isinstance(value, str if py3 else unicode): # noqa: F821
|
if isinstance(value, str):
|
||||||
atts[tag] = value.encode("ascii", "replace") + b"\0"
|
atts[tag] = value.encode("ascii", "replace") + b"\0"
|
||||||
elif isinstance(value, IFDRational):
|
elif isinstance(value, IFDRational):
|
||||||
atts[tag] = float(value)
|
atts[tag] = float(value)
|
||||||
|
|
|
@ -21,16 +21,11 @@
|
||||||
# https://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml
|
# https://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml
|
||||||
# and has been tested with a few sample files found using google.
|
# and has been tested with a few sample files found using google.
|
||||||
|
|
||||||
|
import builtins
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._binary import i32le as i32
|
from ._binary import i32le as i32
|
||||||
|
|
||||||
try:
|
|
||||||
import builtins
|
|
||||||
except ImportError:
|
|
||||||
import __builtin__
|
|
||||||
|
|
||||||
builtins = __builtin__
|
|
||||||
|
|
||||||
|
|
||||||
def open(filename):
|
def open(filename):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -23,7 +23,6 @@ from __future__ import print_function
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16le as word, i32le as dword, si16le as short, si32le as _long
|
from ._binary import i16le as word, i32le as dword, si16le as short, si32le as _long
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
# __version__ is deprecated and will be removed in a future version. Use
|
# __version__ is deprecated and will be removed in a future version. Use
|
||||||
# PIL.__version__ instead.
|
# PIL.__version__ instead.
|
||||||
|
@ -31,9 +30,6 @@ __version__ = "0.2"
|
||||||
|
|
||||||
_handler = None
|
_handler = None
|
||||||
|
|
||||||
if py3:
|
|
||||||
long = int
|
|
||||||
|
|
||||||
|
|
||||||
def register_handler(handler):
|
def register_handler(handler):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -13,24 +13,13 @@
|
||||||
|
|
||||||
from struct import pack, unpack_from
|
from struct import pack, unpack_from
|
||||||
|
|
||||||
from ._util import py3
|
|
||||||
|
|
||||||
if py3:
|
def i8(c):
|
||||||
|
return c if c.__class__ is int else c[0]
|
||||||
def i8(c):
|
|
||||||
return c if c.__class__ is int else c[0]
|
|
||||||
|
|
||||||
def o8(i):
|
|
||||||
return bytes((i & 255,))
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
def o8(i):
|
||||||
|
return bytes((i & 255,))
|
||||||
def i8(c):
|
|
||||||
return ord(c)
|
|
||||||
|
|
||||||
def o8(i):
|
|
||||||
return chr(i & 255)
|
|
||||||
|
|
||||||
|
|
||||||
# Input, le = little endian, be = big endian
|
# Input, le = little endian, be = big endian
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
""" Find compiled module linking to Tcl / Tk libraries
|
""" Find compiled module linking to Tcl / Tk libraries
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
from tkinter import _tkinter as tk
|
||||||
if sys.version_info.major > 2:
|
|
||||||
from tkinter import _tkinter as tk
|
|
||||||
else:
|
|
||||||
from Tkinter import tkinter as tk
|
|
||||||
|
|
||||||
if hasattr(sys, "pypy_find_executable"):
|
if hasattr(sys, "pypy_find_executable"):
|
||||||
# Tested with packages at https://bitbucket.org/pypy/pypy/downloads.
|
# Tested with packages at https://bitbucket.org/pypy/pypy/downloads.
|
||||||
|
|
|
@ -1,33 +1,24 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
py3 = sys.version_info.major >= 3
|
|
||||||
py36 = sys.version_info[0:2] >= (3, 6)
|
py36 = sys.version_info[0:2] >= (3, 6)
|
||||||
|
|
||||||
if py3:
|
|
||||||
|
|
||||||
def isStringType(t):
|
def isStringType(t):
|
||||||
return isinstance(t, str)
|
return isinstance(t, str)
|
||||||
|
|
||||||
if py36:
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
def isPath(f):
|
if py36:
|
||||||
return isinstance(f, (bytes, str, Path))
|
from pathlib import Path
|
||||||
|
|
||||||
else:
|
def isPath(f):
|
||||||
|
return isinstance(f, (bytes, str, Path))
|
||||||
def isPath(f):
|
|
||||||
return isinstance(f, (bytes, str))
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def isStringType(t):
|
|
||||||
return isinstance(t, basestring) # noqa: F821
|
|
||||||
|
|
||||||
def isPath(f):
|
def isPath(f):
|
||||||
return isinstance(f, basestring) # noqa: F821
|
return isinstance(f, (bytes, str))
|
||||||
|
|
||||||
|
|
||||||
# Checks if an object is a string, and that it points to a directory.
|
# Checks if an object is a string, and that it points to a directory.
|
||||||
|
|
|
@ -225,11 +225,7 @@ TkImaging_Init(Tcl_Interp* interp)
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
/* Must be linked with 'psapi' library */
|
/* Must be linked with 'psapi' library */
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
#define TKINTER_PKG "tkinter"
|
#define TKINTER_PKG "tkinter"
|
||||||
#else
|
|
||||||
#define TKINTER_PKG "Tkinter"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FARPROC _dfunc(HMODULE lib_handle, const char *func_name)
|
FARPROC _dfunc(HMODULE lib_handle, const char *func_name)
|
||||||
{
|
{
|
||||||
|
@ -354,7 +350,6 @@ int load_tkinter_funcs(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* From module __file__ attribute to char *string for dlopen. */
|
/* From module __file__ attribute to char *string for dlopen. */
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
char *fname2char(PyObject *fname)
|
char *fname2char(PyObject *fname)
|
||||||
{
|
{
|
||||||
PyObject* bytes;
|
PyObject* bytes;
|
||||||
|
@ -364,9 +359,6 @@ char *fname2char(PyObject *fname)
|
||||||
}
|
}
|
||||||
return PyBytes_AsString(bytes);
|
return PyBytes_AsString(bytes);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#define fname2char(s) (PyString_AsString(s))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
105
src/_imaging.c
105
src/_imaging.c
|
@ -84,8 +84,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
#define _USE_MATH_DEFINES
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -237,45 +235,13 @@ void ImagingSectionLeave(ImagingSectionCookie* cookie)
|
||||||
|
|
||||||
int PyImaging_CheckBuffer(PyObject* buffer)
|
int PyImaging_CheckBuffer(PyObject* buffer)
|
||||||
{
|
{
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
return PyObject_CheckBuffer(buffer);
|
return PyObject_CheckBuffer(buffer);
|
||||||
#else
|
|
||||||
return PyObject_CheckBuffer(buffer) || PyObject_CheckReadBuffer(buffer);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view)
|
int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view)
|
||||||
{
|
{
|
||||||
/* must call check_buffer first! */
|
/* must call check_buffer first! */
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
return PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE);
|
return PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE);
|
||||||
#else
|
|
||||||
/* Use new buffer protocol if available
|
|
||||||
(mmap doesn't support this in 2.7, go figure) */
|
|
||||||
if (PyObject_CheckBuffer(buffer)) {
|
|
||||||
int success = PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE);
|
|
||||||
if (!success) { return success; }
|
|
||||||
PyErr_Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pretend we support the new protocol; PyBuffer_Release happily ignores
|
|
||||||
calling bf_releasebuffer on objects that don't support it */
|
|
||||||
view->buf = NULL;
|
|
||||||
view->len = 0;
|
|
||||||
view->readonly = 1;
|
|
||||||
view->format = NULL;
|
|
||||||
view->ndim = 0;
|
|
||||||
view->shape = NULL;
|
|
||||||
view->strides = NULL;
|
|
||||||
view->suboffsets = NULL;
|
|
||||||
view->itemsize = 0;
|
|
||||||
view->internal = NULL;
|
|
||||||
|
|
||||||
Py_INCREF(buffer);
|
|
||||||
view->obj = buffer;
|
|
||||||
|
|
||||||
return PyObject_AsReadBuffer(buffer, (void *) &view->buf, &view->len);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -416,11 +382,11 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
||||||
// on this switch. And 3 fewer loops to copy/paste.
|
// on this switch. And 3 fewer loops to copy/paste.
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TYPE_UINT8:
|
case TYPE_UINT8:
|
||||||
itemp = PyInt_AsLong(op);
|
itemp = PyLong_AsLong(op);
|
||||||
list[i] = CLIP8(itemp);
|
list[i] = CLIP8(itemp);
|
||||||
break;
|
break;
|
||||||
case TYPE_INT32:
|
case TYPE_INT32:
|
||||||
itemp = PyInt_AsLong(op);
|
itemp = PyLong_AsLong(op);
|
||||||
memcpy(list + i * sizeof(INT32), &itemp, sizeof(itemp));
|
memcpy(list + i * sizeof(INT32), &itemp, sizeof(itemp));
|
||||||
break;
|
break;
|
||||||
case TYPE_FLOAT32:
|
case TYPE_FLOAT32:
|
||||||
|
@ -499,7 +465,7 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
|
||||||
case IMAGING_TYPE_UINT8:
|
case IMAGING_TYPE_UINT8:
|
||||||
switch (im->bands) {
|
switch (im->bands) {
|
||||||
case 1:
|
case 1:
|
||||||
return PyInt_FromLong(pixel.b[0]);
|
return PyLong_FromLong(pixel.b[0]);
|
||||||
case 2:
|
case 2:
|
||||||
return Py_BuildValue("BB", pixel.b[0], pixel.b[1]);
|
return Py_BuildValue("BB", pixel.b[0], pixel.b[1]);
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -509,12 +475,12 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IMAGING_TYPE_INT32:
|
case IMAGING_TYPE_INT32:
|
||||||
return PyInt_FromLong(pixel.i);
|
return PyLong_FromLong(pixel.i);
|
||||||
case IMAGING_TYPE_FLOAT32:
|
case IMAGING_TYPE_FLOAT32:
|
||||||
return PyFloat_FromDouble(pixel.f);
|
return PyFloat_FromDouble(pixel.f);
|
||||||
case IMAGING_TYPE_SPECIAL:
|
case IMAGING_TYPE_SPECIAL:
|
||||||
if (strncmp(im->mode, "I;16", 4) == 0)
|
if (strncmp(im->mode, "I;16", 4) == 0)
|
||||||
return PyInt_FromLong(pixel.h);
|
return PyLong_FromLong(pixel.h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,16 +509,8 @@ getink(PyObject* color, Imaging im, char* ink)
|
||||||
if (im->type == IMAGING_TYPE_UINT8 ||
|
if (im->type == IMAGING_TYPE_UINT8 ||
|
||||||
im->type == IMAGING_TYPE_INT32 ||
|
im->type == IMAGING_TYPE_INT32 ||
|
||||||
im->type == IMAGING_TYPE_SPECIAL) {
|
im->type == IMAGING_TYPE_SPECIAL) {
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (PyLong_Check(color)) {
|
if (PyLong_Check(color)) {
|
||||||
r = PyLong_AsLongLong(color);
|
r = PyLong_AsLongLong(color);
|
||||||
#else
|
|
||||||
if (PyInt_Check(color) || PyLong_Check(color)) {
|
|
||||||
if (PyInt_Check(color))
|
|
||||||
r = PyInt_AS_LONG(color);
|
|
||||||
else
|
|
||||||
r = PyLong_AsLongLong(color);
|
|
||||||
#endif
|
|
||||||
rIsInt = 1;
|
rIsInt = 1;
|
||||||
}
|
}
|
||||||
if (r == -1 && PyErr_Occurred()) {
|
if (r == -1 && PyErr_Occurred()) {
|
||||||
|
@ -1129,16 +1087,16 @@ _getxy(PyObject* xy, int* x, int *y)
|
||||||
goto badarg;
|
goto badarg;
|
||||||
|
|
||||||
value = PyTuple_GET_ITEM(xy, 0);
|
value = PyTuple_GET_ITEM(xy, 0);
|
||||||
if (PyInt_Check(value))
|
if (PyLong_Check(value))
|
||||||
*x = PyInt_AS_LONG(value);
|
*x = PyLong_AS_LONG(value);
|
||||||
else if (PyFloat_Check(value))
|
else if (PyFloat_Check(value))
|
||||||
*x = (int) PyFloat_AS_DOUBLE(value);
|
*x = (int) PyFloat_AS_DOUBLE(value);
|
||||||
else
|
else
|
||||||
goto badval;
|
goto badval;
|
||||||
|
|
||||||
value = PyTuple_GET_ITEM(xy, 1);
|
value = PyTuple_GET_ITEM(xy, 1);
|
||||||
if (PyInt_Check(value))
|
if (PyLong_Check(value))
|
||||||
*y = PyInt_AS_LONG(value);
|
*y = PyLong_AS_LONG(value);
|
||||||
else if (PyFloat_Check(value))
|
else if (PyFloat_Check(value))
|
||||||
*y = (int) PyFloat_AS_DOUBLE(value);
|
*y = (int) PyFloat_AS_DOUBLE(value);
|
||||||
else
|
else
|
||||||
|
@ -1255,7 +1213,7 @@ _histogram(ImagingObject* self, PyObject* args)
|
||||||
list = PyList_New(h->bands * 256);
|
list = PyList_New(h->bands * 256);
|
||||||
for (i = 0; i < h->bands * 256; i++) {
|
for (i = 0; i < h->bands * 256; i++) {
|
||||||
PyObject* item;
|
PyObject* item;
|
||||||
item = PyInt_FromLong(h->histogram[i]);
|
item = PyLong_FromLong(h->histogram[i]);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
Py_DECREF(list);
|
Py_DECREF(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
@ -1524,7 +1482,7 @@ _putdata(ImagingObject* self, PyObject* args)
|
||||||
/* Clipped data */
|
/* Clipped data */
|
||||||
for (i = x = y = 0; i < n; i++) {
|
for (i = x = y = 0; i < n; i++) {
|
||||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
image->image8[y][x] = (UINT8) CLIP8(PyInt_AsLong(op));
|
image->image8[y][x] = (UINT8) CLIP8(PyLong_AsLong(op));
|
||||||
if (++x >= (int) image->xsize){
|
if (++x >= (int) image->xsize){
|
||||||
x = 0, y++;
|
x = 0, y++;
|
||||||
}
|
}
|
||||||
|
@ -1635,7 +1593,7 @@ _putpalette(ImagingObject* self, PyObject* args)
|
||||||
char* rawmode;
|
char* rawmode;
|
||||||
UINT8* palette;
|
UINT8* palette;
|
||||||
Py_ssize_t palettesize;
|
Py_ssize_t palettesize;
|
||||||
if (!PyArg_ParseTuple(args, "s"PY_ARG_BYTES_LENGTH, &rawmode, &palette, &palettesize))
|
if (!PyArg_ParseTuple(args, "sy#", &rawmode, &palette, &palettesize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (strcmp(self->image->mode, "L") && strcmp(self->image->mode, "LA") &&
|
if (strcmp(self->image->mode, "L") && strcmp(self->image->mode, "LA") &&
|
||||||
|
@ -1698,7 +1656,7 @@ _putpalettealphas(ImagingObject* self, PyObject* args)
|
||||||
int i;
|
int i;
|
||||||
UINT8 *values;
|
UINT8 *values;
|
||||||
Py_ssize_t length;
|
Py_ssize_t length;
|
||||||
if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH, &values, &length))
|
if (!PyArg_ParseTuple(args, "y#", &values, &length))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!self->image->palette) {
|
if (!self->image->palette) {
|
||||||
|
@ -2136,7 +2094,7 @@ _getprojection(ImagingObject* self, PyObject* args)
|
||||||
|
|
||||||
ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
|
ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
|
||||||
|
|
||||||
result = Py_BuildValue(PY_ARG_BYTES_LENGTH PY_ARG_BYTES_LENGTH,
|
result = Py_BuildValue("y#y#",
|
||||||
xprofile, (Py_ssize_t)self->image->xsize,
|
xprofile, (Py_ssize_t)self->image->xsize,
|
||||||
yprofile, (Py_ssize_t)self->image->ysize);
|
yprofile, (Py_ssize_t)self->image->ysize);
|
||||||
|
|
||||||
|
@ -2414,7 +2372,7 @@ _font_new(PyObject* self_, PyObject* args)
|
||||||
ImagingObject* imagep;
|
ImagingObject* imagep;
|
||||||
unsigned char* glyphdata;
|
unsigned char* glyphdata;
|
||||||
Py_ssize_t glyphdata_length;
|
Py_ssize_t glyphdata_length;
|
||||||
if (!PyArg_ParseTuple(args, "O!"PY_ARG_BYTES_LENGTH,
|
if (!PyArg_ParseTuple(args, "O!y#",
|
||||||
&Imaging_Type, &imagep,
|
&Imaging_Type, &imagep,
|
||||||
&glyphdata, &glyphdata_length))
|
&glyphdata, &glyphdata_length))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2648,7 +2606,7 @@ _draw_ink(ImagingDrawObject* self, PyObject* args)
|
||||||
if (!getink(color, self->image->image, (char*) &ink))
|
if (!getink(color, self->image->image, (char*) &ink))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyInt_FromLong((int) ink);
|
return PyLong_FromLong((int) ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -3356,13 +3314,13 @@ _getattr_size(ImagingObject* self, void* closure)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_getattr_bands(ImagingObject* self, void* closure)
|
_getattr_bands(ImagingObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->image->bands);
|
return PyLong_FromLong(self->image->bands);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_getattr_id(ImagingObject* self, void* closure)
|
_getattr_id(ImagingObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromSsize_t((Py_ssize_t) self->image);
|
return PyLong_FromSsize_t((Py_ssize_t) self->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -3575,17 +3533,17 @@ _get_stats(PyObject* self, PyObject* args)
|
||||||
if ( ! d)
|
if ( ! d)
|
||||||
return NULL;
|
return NULL;
|
||||||
PyDict_SetItemString(d, "new_count",
|
PyDict_SetItemString(d, "new_count",
|
||||||
PyInt_FromLong(arena->stats_new_count));
|
PyLong_FromLong(arena->stats_new_count));
|
||||||
PyDict_SetItemString(d, "allocated_blocks",
|
PyDict_SetItemString(d, "allocated_blocks",
|
||||||
PyInt_FromLong(arena->stats_allocated_blocks));
|
PyLong_FromLong(arena->stats_allocated_blocks));
|
||||||
PyDict_SetItemString(d, "reused_blocks",
|
PyDict_SetItemString(d, "reused_blocks",
|
||||||
PyInt_FromLong(arena->stats_reused_blocks));
|
PyLong_FromLong(arena->stats_reused_blocks));
|
||||||
PyDict_SetItemString(d, "reallocated_blocks",
|
PyDict_SetItemString(d, "reallocated_blocks",
|
||||||
PyInt_FromLong(arena->stats_reallocated_blocks));
|
PyLong_FromLong(arena->stats_reallocated_blocks));
|
||||||
PyDict_SetItemString(d, "freed_blocks",
|
PyDict_SetItemString(d, "freed_blocks",
|
||||||
PyInt_FromLong(arena->stats_freed_blocks));
|
PyLong_FromLong(arena->stats_freed_blocks));
|
||||||
PyDict_SetItemString(d, "blocks_cached",
|
PyDict_SetItemString(d, "blocks_cached",
|
||||||
PyInt_FromLong(arena->blocks_cached));
|
PyLong_FromLong(arena->blocks_cached));
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3613,7 +3571,7 @@ _get_alignment(PyObject* self, PyObject* args)
|
||||||
if (!PyArg_ParseTuple(args, ":get_alignment"))
|
if (!PyArg_ParseTuple(args, ":get_alignment"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyInt_FromLong(ImagingDefaultArena.alignment);
|
return PyLong_FromLong(ImagingDefaultArena.alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -3622,7 +3580,7 @@ _get_block_size(PyObject* self, PyObject* args)
|
||||||
if (!PyArg_ParseTuple(args, ":get_block_size"))
|
if (!PyArg_ParseTuple(args, ":get_block_size"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyInt_FromLong(ImagingDefaultArena.block_size);
|
return PyLong_FromLong(ImagingDefaultArena.block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -3631,7 +3589,7 @@ _get_blocks_max(PyObject* self, PyObject* args)
|
||||||
if (!PyArg_ParseTuple(args, ":get_blocks_max"))
|
if (!PyArg_ParseTuple(args, ":get_blocks_max"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyInt_FromLong(ImagingDefaultArena.blocks_max);
|
return PyLong_FromLong(ImagingDefaultArena.blocks_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -3959,7 +3917,6 @@ setup_module(PyObject* m) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imaging(void) {
|
PyInit__imaging(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -3979,11 +3936,3 @@ PyInit__imaging(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imaging(void)
|
|
||||||
{
|
|
||||||
PyObject* m = Py_InitModule("_imaging", functions);
|
|
||||||
setup_module(m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ http://www.cazabon.com\n\
|
||||||
|
|
||||||
#include "lcms2.h"
|
#include "lcms2.h"
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#define PYCMSVERSION "1.0.0 pil"
|
#define PYCMSVERSION "1.0.0 pil"
|
||||||
|
|
||||||
|
@ -122,13 +121,8 @@ cms_profile_fromstring(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
char* pProfile;
|
char* pProfile;
|
||||||
Py_ssize_t nProfile;
|
Py_ssize_t nProfile;
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile))
|
if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile))
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
|
||||||
if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
|
hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
|
||||||
if (!hProfile) {
|
if (!hProfile) {
|
||||||
|
@ -172,11 +166,7 @@ cms_profile_tobytes(PyObject* self, PyObject* args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
ret = PyBytes_FromStringAndSize(pProfile, (Py_ssize_t)nProfile);
|
ret = PyBytes_FromStringAndSize(pProfile, (Py_ssize_t)nProfile);
|
||||||
#else
|
|
||||||
ret = PyString_FromStringAndSize(pProfile, (Py_ssize_t)nProfile);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
free(pProfile);
|
free(pProfile);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -592,7 +582,7 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args)
|
||||||
|
|
||||||
/* printf("cmsIsIntentSupported(%p, %d, %d) => %d\n", self->profile, intent, direction, result); */
|
/* printf("cmsIsIntentSupported(%p, %d, %d) => %d\n", self->profile, intent, direction, result); */
|
||||||
|
|
||||||
return PyInt_FromLong(result != 0);
|
return PyLong_FromLong(result != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -691,11 +681,7 @@ _profile_read_int_as_string(cmsUInt32Number nr)
|
||||||
buf[3] = (char) (nr & 0xff);
|
buf[3] = (char) (nr & 0xff);
|
||||||
buf[4] = 0;
|
buf[4] = 0;
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
ret = PyUnicode_DecodeASCII(buf, 4, NULL);
|
ret = PyUnicode_DecodeASCII(buf, 4, NULL);
|
||||||
#else
|
|
||||||
ret = PyString_FromStringAndSize(buf, 4);
|
|
||||||
#endif
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,7 +884,7 @@ _is_intent_supported(CmsProfileObject* self, int clut)
|
||||||
|| intent == INTENT_SATURATION || intent == INTENT_ABSOLUTE_COLORIMETRIC))
|
|| intent == INTENT_SATURATION || intent == INTENT_ABSOLUTE_COLORIMETRIC))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
id = PyInt_FromLong((long) intent);
|
id = PyLong_FromLong((long) intent);
|
||||||
entry = Py_BuildValue("(OOO)",
|
entry = Py_BuildValue("(OOO)",
|
||||||
_check_intent(clut, self->profile, intent, LCMS_USED_AS_INPUT) ? Py_True : Py_False,
|
_check_intent(clut, self->profile, intent, LCMS_USED_AS_INPUT) ? Py_True : Py_False,
|
||||||
_check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True : Py_False,
|
_check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True : Py_False,
|
||||||
|
@ -1010,7 +996,7 @@ cms_profile_getattr_product_copyright(CmsProfileObject* self, void* closure)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
|
cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(cmsGetHeaderRenderingIntent(self->profile));
|
return PyLong_FromLong(cmsGetHeaderRenderingIntent(self->profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -1098,7 +1084,7 @@ cms_profile_getattr_version(CmsProfileObject* self, void* closure)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
cms_profile_getattr_icc_version(CmsProfileObject* self, void* closure)
|
cms_profile_getattr_icc_version(CmsProfileObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong((long) cmsGetEncodedICCversion(self->profile));
|
return PyLong_FromLong((long) cmsGetEncodedICCversion(self->profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -1115,7 +1101,7 @@ static PyObject*
|
||||||
cms_profile_getattr_header_flags(CmsProfileObject* self, void* closure)
|
cms_profile_getattr_header_flags(CmsProfileObject* self, void* closure)
|
||||||
{
|
{
|
||||||
cmsUInt32Number flags = cmsGetHeaderFlags(self->profile);
|
cmsUInt32Number flags = cmsGetHeaderFlags(self->profile);
|
||||||
return PyInt_FromLong(flags);
|
return PyLong_FromLong(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
@ -1611,7 +1597,6 @@ setup_module(PyObject* m) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imagingcms(void) {
|
PyInit__imagingcms(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -1633,12 +1618,3 @@ PyInit__imagingcms(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imagingcms(void)
|
|
||||||
{
|
|
||||||
PyObject *m = Py_InitModule("_imagingcms", pyCMSdll_methods);
|
|
||||||
setup_module(m);
|
|
||||||
PyDateTime_IMPORT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
103
src/_imagingft.c
103
src/_imagingft.c
|
@ -30,7 +30,6 @@
|
||||||
#include FT_SFNT_NAMES_H
|
#include FT_SFNT_NAMES_H
|
||||||
|
|
||||||
#define KEEP_PY_UNICODE
|
#define KEEP_PY_UNICODE
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
@ -266,8 +265,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "etn|ns"PY_ARG_BYTES_LENGTH"n",
|
if (!PyArg_ParseTupleAndKeywords(args, kw, "etn|nsy#n", kwlist,
|
||||||
kwlist,
|
|
||||||
Py_FileSystemDefaultEncoding, &filename,
|
Py_FileSystemDefaultEncoding, &filename,
|
||||||
&size, &index, &encoding, &font_bytes,
|
&size, &index, &encoding, &font_bytes,
|
||||||
&font_bytes_size, &layout_engine)) {
|
&font_bytes_size, &layout_engine)) {
|
||||||
|
@ -328,7 +326,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
|
||||||
static int
|
static int
|
||||||
font_getchar(PyObject* string, int index, FT_ULong* char_out)
|
font_getchar(PyObject* string, int index, FT_ULong* char_out)
|
||||||
{
|
{
|
||||||
#if (PY_VERSION_HEX < 0x03030000) || (defined(PYPY_VERSION_NUM))
|
#if (defined(PYPY_VERSION_NUM))
|
||||||
if (PyUnicode_Check(string)) {
|
if (PyUnicode_Check(string)) {
|
||||||
Py_UNICODE* p = PyUnicode_AS_UNICODE(string);
|
Py_UNICODE* p = PyUnicode_AS_UNICODE(string);
|
||||||
int size = PyUnicode_GET_SIZE(string);
|
int size = PyUnicode_GET_SIZE(string);
|
||||||
|
@ -337,16 +335,6 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out)
|
||||||
*char_out = p[index];
|
*char_out = p[index];
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX < 0x03000000
|
|
||||||
if (PyString_Check(string)) {
|
|
||||||
unsigned char* p = (unsigned char*) PyString_AS_STRING(string);
|
|
||||||
int size = PyString_GET_SIZE(string);
|
|
||||||
if (index >= size)
|
|
||||||
return 0;
|
|
||||||
*char_out = (unsigned char) p[index];
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
if (PyUnicode_Check(string)) {
|
if (PyUnicode_Check(string)) {
|
||||||
if (index >= PyUnicode_GET_LENGTH(string))
|
if (index >= PyUnicode_GET_LENGTH(string))
|
||||||
|
@ -375,7 +363,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (PY_VERSION_HEX < 0x03030000) || (defined(PYPY_VERSION_NUM))
|
#if (defined(PYPY_VERSION_NUM))
|
||||||
if (PyUnicode_Check(string)) {
|
if (PyUnicode_Check(string)) {
|
||||||
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
|
Py_UNICODE *text = PyUnicode_AS_UNICODE(string);
|
||||||
Py_ssize_t size = PyUnicode_GET_SIZE(string);
|
Py_ssize_t size = PyUnicode_GET_SIZE(string);
|
||||||
|
@ -395,25 +383,6 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX < 0x03000000
|
|
||||||
else if (PyString_Check(string)) {
|
|
||||||
char *text = PyString_AS_STRING(string);
|
|
||||||
int size = PyString_GET_SIZE(string);
|
|
||||||
if (! size) {
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
if (!(*p_raqm.set_text_utf8)(rq, text, size)) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "raqm_set_text_utf8() failed");
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
if (lang) {
|
|
||||||
if (!(*p_raqm.set_language)(rq, lang, start, size)) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "raqm_set_language() failed");
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
if (PyUnicode_Check(string)) {
|
if (PyUnicode_Check(string)) {
|
||||||
Py_UCS4 *text = PyUnicode_AsUCS4Copy(string);
|
Py_UCS4 *text = PyUnicode_AsUCS4Copy(string);
|
||||||
|
@ -479,11 +448,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
|
||||||
Py_ssize_t size = 0;
|
Py_ssize_t size = 0;
|
||||||
PyObject *bytes;
|
PyObject *bytes;
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (!PyUnicode_Check(item)) {
|
if (!PyUnicode_Check(item)) {
|
||||||
#else
|
|
||||||
if (!PyUnicode_Check(item) && !PyString_Check(item)) {
|
|
||||||
#endif
|
|
||||||
PyErr_SetString(PyExc_TypeError, "expected a string");
|
PyErr_SetString(PyExc_TypeError, "expected a string");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
@ -495,12 +460,6 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
|
||||||
feature = PyBytes_AS_STRING(bytes);
|
feature = PyBytes_AS_STRING(bytes);
|
||||||
size = PyBytes_GET_SIZE(bytes);
|
size = PyBytes_GET_SIZE(bytes);
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX < 0x03000000
|
|
||||||
else {
|
|
||||||
feature = PyString_AsString(item);
|
|
||||||
size = PyString_GET_SIZE(item);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (!(*p_raqm.add_font_feature)(rq, feature, size)) {
|
if (!(*p_raqm.add_font_feature)(rq, feature, size)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "raqm_add_font_feature() failed");
|
PyErr_SetString(PyExc_ValueError, "raqm_add_font_feature() failed");
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -581,11 +540,7 @@ text_layout_fallback(PyObject* string, FontObject* self, const char* dir, PyObje
|
||||||
if (features != Py_None || dir != NULL || lang != NULL) {
|
if (features != Py_None || dir != NULL || lang != NULL) {
|
||||||
PyErr_SetString(PyExc_KeyError, "setting text direction, language or font features is not supported without libraqm");
|
PyErr_SetString(PyExc_KeyError, "setting text direction, language or font features is not supported without libraqm");
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (!PyUnicode_Check(string)) {
|
if (!PyUnicode_Check(string)) {
|
||||||
#else
|
|
||||||
if (!PyUnicode_Check(string) && !PyString_Check(string)) {
|
|
||||||
#endif
|
|
||||||
PyErr_SetString(PyExc_TypeError, "expected string");
|
PyErr_SetString(PyExc_TypeError, "expected string");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -990,8 +945,7 @@ font_render(FontObject* self, PyObject* args)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (master->namedstyle[j].strid == name.name_id) {
|
if (master->namedstyle[j].strid == name.name_id) {
|
||||||
list_name = Py_BuildValue(PY_ARG_BYTES_LENGTH,
|
list_name = Py_BuildValue("y#", name.string, name.string_len);
|
||||||
name.string, name.string_len);
|
|
||||||
PyList_SetItem(list_names, j, list_name);
|
PyList_SetItem(list_names, j, list_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1025,11 +979,11 @@ font_render(FontObject* self, PyObject* args)
|
||||||
|
|
||||||
list_axis = PyDict_New();
|
list_axis = PyDict_New();
|
||||||
PyDict_SetItemString(list_axis, "minimum",
|
PyDict_SetItemString(list_axis, "minimum",
|
||||||
PyInt_FromLong(axis.minimum / 65536));
|
PyLong_FromLong(axis.minimum / 65536));
|
||||||
PyDict_SetItemString(list_axis, "default",
|
PyDict_SetItemString(list_axis, "default",
|
||||||
PyInt_FromLong(axis.def / 65536));
|
PyLong_FromLong(axis.def / 65536));
|
||||||
PyDict_SetItemString(list_axis, "maximum",
|
PyDict_SetItemString(list_axis, "maximum",
|
||||||
PyInt_FromLong(axis.maximum / 65536));
|
PyLong_FromLong(axis.maximum / 65536));
|
||||||
|
|
||||||
for (j = 0; j < name_count; j++) {
|
for (j = 0; j < name_count; j++) {
|
||||||
error = FT_Get_Sfnt_Name(self->face, j, &name);
|
error = FT_Get_Sfnt_Name(self->face, j, &name);
|
||||||
|
@ -1037,8 +991,7 @@ font_render(FontObject* self, PyObject* args)
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
|
|
||||||
if (name.name_id == axis.strid) {
|
if (name.name_id == axis.strid) {
|
||||||
axis_name = Py_BuildValue(PY_ARG_BYTES_LENGTH,
|
axis_name = Py_BuildValue("y#", name.string, name.string_len);
|
||||||
name.string, name.string_len);
|
|
||||||
PyDict_SetItemString(list_axis, "name", axis_name);
|
PyDict_SetItemString(list_axis, "name", axis_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1095,8 +1048,8 @@ font_render(FontObject* self, PyObject* args)
|
||||||
item = PyList_GET_ITEM(axes, i);
|
item = PyList_GET_ITEM(axes, i);
|
||||||
if (PyFloat_Check(item))
|
if (PyFloat_Check(item))
|
||||||
coord = PyFloat_AS_DOUBLE(item);
|
coord = PyFloat_AS_DOUBLE(item);
|
||||||
else if (PyInt_Check(item))
|
else if (PyLong_Check(item))
|
||||||
coord = (float) PyInt_AS_LONG(item);
|
coord = (float) PyLong_AS_LONG(item);
|
||||||
else if (PyNumber_Check(item))
|
else if (PyNumber_Check(item))
|
||||||
coord = PyFloat_AsDouble(item);
|
coord = PyFloat_AsDouble(item);
|
||||||
else {
|
else {
|
||||||
|
@ -1146,64 +1099,54 @@ static PyMethodDef font_methods[] = {
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_family(FontObject* self, void* closure)
|
font_getattr_family(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (self->face->family_name)
|
if (self->face->family_name)
|
||||||
return PyUnicode_FromString(self->face->family_name);
|
return PyUnicode_FromString(self->face->family_name);
|
||||||
#else
|
|
||||||
if (self->face->family_name)
|
|
||||||
return PyString_FromString(self->face->family_name);
|
|
||||||
#endif
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_style(FontObject* self, void* closure)
|
font_getattr_style(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (self->face->style_name)
|
if (self->face->style_name)
|
||||||
return PyUnicode_FromString(self->face->style_name);
|
return PyUnicode_FromString(self->face->style_name);
|
||||||
#else
|
|
||||||
if (self->face->style_name)
|
|
||||||
return PyString_FromString(self->face->style_name);
|
|
||||||
#endif
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_ascent(FontObject* self, void* closure)
|
font_getattr_ascent(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(PIXEL(self->face->size->metrics.ascender));
|
return PyLong_FromLong(PIXEL(self->face->size->metrics.ascender));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_descent(FontObject* self, void* closure)
|
font_getattr_descent(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(-PIXEL(self->face->size->metrics.descender));
|
return PyLong_FromLong(-PIXEL(self->face->size->metrics.descender));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_height(FontObject* self, void* closure)
|
font_getattr_height(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(PIXEL(self->face->size->metrics.height));
|
return PyLong_FromLong(PIXEL(self->face->size->metrics.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_x_ppem(FontObject* self, void* closure)
|
font_getattr_x_ppem(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->face->size->metrics.x_ppem);
|
return PyLong_FromLong(self->face->size->metrics.x_ppem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_y_ppem(FontObject* self, void* closure)
|
font_getattr_y_ppem(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->face->size->metrics.y_ppem);
|
return PyLong_FromLong(self->face->size->metrics.y_ppem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
font_getattr_glyphs(FontObject* self, void* closure)
|
font_getattr_glyphs(FontObject* self, void* closure)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->face->num_glyphs);
|
return PyLong_FromLong(self->face->num_glyphs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct PyGetSetDef font_getsetters[] = {
|
static struct PyGetSetDef font_getsetters[] = {
|
||||||
|
@ -1271,11 +1214,7 @@ setup_module(PyObject* m) {
|
||||||
|
|
||||||
FT_Library_Version(library, &major, &minor, &patch);
|
FT_Library_Version(library, &major, &minor, &patch);
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
|
v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
|
||||||
#else
|
|
||||||
v = PyString_FromFormat("%d.%d.%d", major, minor, patch);
|
|
||||||
#endif
|
|
||||||
PyDict_SetItemString(d, "freetype2_version", v);
|
PyDict_SetItemString(d, "freetype2_version", v);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1286,7 +1225,6 @@ setup_module(PyObject* m) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imagingft(void) {
|
PyInit__imagingft(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -1306,12 +1244,3 @@ PyInit__imagingft(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imagingft(void)
|
|
||||||
{
|
|
||||||
PyObject* m = Py_InitModule("_imagingft", _functions);
|
|
||||||
setup_module(m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "float.h"
|
#include "float.h"
|
||||||
|
@ -215,7 +214,7 @@ static PyMethodDef _functions[] = {
|
||||||
static void
|
static void
|
||||||
install(PyObject *d, char* name, void* value)
|
install(PyObject *d, char* name, void* value)
|
||||||
{
|
{
|
||||||
PyObject *v = PyInt_FromSsize_t((Py_ssize_t) value);
|
PyObject *v = PyLong_FromSsize_t((Py_ssize_t) value);
|
||||||
if (!v || PyDict_SetItemString(d, name, v))
|
if (!v || PyDict_SetItemString(d, name, v))
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
|
@ -273,7 +272,6 @@ setup_module(PyObject* m) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imagingmath(void) {
|
PyInit__imagingmath(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -293,12 +291,3 @@ PyInit__imagingmath(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imagingmath(void)
|
|
||||||
{
|
|
||||||
PyObject* m = Py_InitModule("_imagingmath", _functions);
|
|
||||||
setup_module(m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#define LUT_SIZE (1<<9)
|
#define LUT_SIZE (1<<9)
|
||||||
|
|
||||||
|
@ -273,7 +272,6 @@ static PyMethodDef functions[] = {
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imagingmorph(void) {
|
PyInit__imagingmorph(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -293,12 +291,3 @@ PyInit__imagingmorph(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imagingmorph(void)
|
|
||||||
{
|
|
||||||
PyObject* m = Py_InitModule("_imagingmorph", functions);
|
|
||||||
setup_module(m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ static PyMethodDef functions[] = {
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__imagingtk(void) {
|
PyInit__imagingtk(void) {
|
||||||
static PyModuleDef module_def = {
|
static PyModuleDef module_def = {
|
||||||
|
@ -78,12 +77,3 @@ PyInit__imagingtk(void) {
|
||||||
m = PyModule_Create(&module_def);
|
m = PyModule_Create(&module_def);
|
||||||
return (load_tkinter_funcs() == 0) ? m : NULL;
|
return (load_tkinter_funcs() == 0) ? m : NULL;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_imagingtk(void)
|
|
||||||
{
|
|
||||||
Py_InitModule("_imagingtk", functions);
|
|
||||||
load_tkinter_funcs();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
16
src/_webp.c
16
src/_webp.c
|
@ -1,7 +1,6 @@
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
#include <webp/encode.h>
|
#include <webp/encode.h>
|
||||||
#include <webp/decode.h>
|
#include <webp/decode.h>
|
||||||
#include <webp/types.h>
|
#include <webp/types.h>
|
||||||
|
@ -557,7 +556,7 @@ PyObject* WebPEncode_wrapper(PyObject* self, PyObject* args)
|
||||||
Py_ssize_t xmp_size;
|
Py_ssize_t xmp_size;
|
||||||
size_t ret_size;
|
size_t ret_size;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH"iiifss#s#s#",
|
if (!PyArg_ParseTuple(args, "y#iiifss#s#s#",
|
||||||
(char**)&rgb, &size, &width, &height, &lossless, &quality_factor, &mode,
|
(char**)&rgb, &size, &width, &height, &lossless, &quality_factor, &mode,
|
||||||
&icc_bytes, &icc_size, &exif_bytes, &exif_size, &xmp_bytes, &xmp_size)) {
|
&icc_bytes, &icc_size, &exif_bytes, &exif_size, &xmp_bytes, &xmp_size)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -754,11 +753,7 @@ PyObject* WebPDecode_wrapper(PyObject* self, PyObject* args)
|
||||||
config.output.u.YUVA.y_size);
|
config.output.u.YUVA.y_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
pymode = PyUnicode_FromString(mode);
|
pymode = PyUnicode_FromString(mode);
|
||||||
#else
|
|
||||||
pymode = PyString_FromString(mode);
|
|
||||||
#endif
|
|
||||||
ret = Py_BuildValue("SiiSSS", bytes, config.output.width,
|
ret = Py_BuildValue("SiiSSS", bytes, config.output.width,
|
||||||
config.output.height, pymode,
|
config.output.height, pymode,
|
||||||
NULL == icc_profile ? Py_None : icc_profile,
|
NULL == icc_profile ? Py_None : icc_profile,
|
||||||
|
@ -848,7 +843,6 @@ static int setup_module(PyObject* m) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit__webp(void) {
|
PyInit__webp(void) {
|
||||||
PyObject* m;
|
PyObject* m;
|
||||||
|
@ -867,11 +861,3 @@ PyInit__webp(void) {
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
init_webp(void)
|
|
||||||
{
|
|
||||||
PyObject* m = Py_InitModule("_webp", webpMethods);
|
|
||||||
setup_module(m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
#include "Gif.h"
|
#include "Gif.h"
|
||||||
#include "Raw.h"
|
#include "Raw.h"
|
||||||
|
@ -122,7 +121,7 @@ _decode(ImagingDecoderObject* decoder, PyObject* args)
|
||||||
int status;
|
int status;
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH, &buffer, &bufsize))
|
if (!PyArg_ParseTuple(args, "y#", &buffer, &bufsize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!decoder->pulls_fd) {
|
if (!decoder->pulls_fd) {
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* Windows DIB support */
|
/* Windows DIB support */
|
||||||
|
@ -187,13 +186,8 @@ _frombytes(ImagingDisplayObject* display, PyObject* args)
|
||||||
char* ptr;
|
char* ptr;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes))
|
if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes))
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
|
||||||
if (!PyArg_ParseTuple(args, "s#:fromstring", &ptr, &bytes))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (display->dib->ysize * display->dib->linesize != bytes) {
|
if (display->dib->ysize * display->dib->linesize != bytes) {
|
||||||
PyErr_SetString(PyExc_ValueError, "wrong size");
|
PyErr_SetString(PyExc_ValueError, "wrong size");
|
||||||
|
@ -209,13 +203,8 @@ _frombytes(ImagingDisplayObject* display, PyObject* args)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
_tobytes(ImagingDisplayObject* display, PyObject* args)
|
_tobytes(ImagingDisplayObject* display, PyObject* args)
|
||||||
{
|
{
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
if (!PyArg_ParseTuple(args, ":tobytes"))
|
if (!PyArg_ParseTuple(args, ":tobytes"))
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
|
||||||
if (!PyArg_ParseTuple(args, ":tostring"))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return PyBytes_FromStringAndSize(
|
return PyBytes_FromStringAndSize(
|
||||||
display->dib->bits, display->dib->ysize * display->dib->linesize
|
display->dib->bits, display->dib->ysize * display->dib->linesize
|
||||||
|
@ -741,7 +730,7 @@ PyImaging_DrawWmf(PyObject* self, PyObject* args)
|
||||||
int datasize;
|
int datasize;
|
||||||
int width, height;
|
int width, height;
|
||||||
int x0, y0, x1, y1;
|
int x0, y0, x1, y1;
|
||||||
if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH"(ii)(iiii):_load", &data, &datasize,
|
if (!PyArg_ParseTuple(args, "y#(ii)(iiii):_load", &data, &datasize,
|
||||||
&width, &height, &x0, &x1, &y0, &y1))
|
&width, &height, &x0, &x1, &y0, &y1))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
43
src/encode.c
43
src/encode.c
|
@ -26,7 +26,6 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "py3.h"
|
|
||||||
#include "Gif.h"
|
#include "Gif.h"
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
|
@ -567,7 +566,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
||||||
Py_ssize_t compress_type = -1;
|
Py_ssize_t compress_type = -1;
|
||||||
char* dictionary = NULL;
|
char* dictionary = NULL;
|
||||||
Py_ssize_t dictionary_size = 0;
|
Py_ssize_t dictionary_size = 0;
|
||||||
if (!PyArg_ParseTuple(args, "ss|nnn"PY_ARG_BYTES_LENGTH, &mode, &rawmode,
|
if (!PyArg_ParseTuple(args, "ss|nnny#", &mode, &rawmode,
|
||||||
&optimize,
|
&optimize,
|
||||||
&compress_level, &compress_type,
|
&compress_level, &compress_type,
|
||||||
&dictionary, &dictionary_size))
|
&dictionary, &dictionary_size))
|
||||||
|
@ -693,7 +692,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
item = PyList_GetItem(tags, pos);
|
item = PyList_GetItem(tags, pos);
|
||||||
// We already checked that tags is a 2-tuple list.
|
// We already checked that tags is a 2-tuple list.
|
||||||
key = PyTuple_GetItem(item, 0);
|
key = PyTuple_GetItem(item, 0);
|
||||||
key_int = (int)PyInt_AsLong(key);
|
key_int = (int)PyLong_AsLong(key);
|
||||||
value = PyTuple_GetItem(item, 1);
|
value = PyTuple_GetItem(item, 1);
|
||||||
status = 0;
|
status = 0;
|
||||||
is_core_tag = 0;
|
is_core_tag = 0;
|
||||||
|
@ -710,7 +709,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (!is_core_tag) {
|
if (!is_core_tag) {
|
||||||
PyObject *tag_type = PyDict_GetItem(types, key);
|
PyObject *tag_type = PyDict_GetItem(types, key);
|
||||||
if (tag_type) {
|
if (tag_type) {
|
||||||
int type_int = PyInt_AsLong(tag_type);
|
int type_int = PyLong_AsLong(tag_type);
|
||||||
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
|
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
|
||||||
type = (TIFFDataType)type_int;
|
type = (TIFFDataType)type_int;
|
||||||
}
|
}
|
||||||
|
@ -721,7 +720,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (type == TIFF_NOTYPE) {
|
if (type == TIFF_NOTYPE) {
|
||||||
// Autodetect type. Types should not be changed for backwards
|
// Autodetect type. Types should not be changed for backwards
|
||||||
// compatibility.
|
// compatibility.
|
||||||
if (PyInt_Check(value)) {
|
if (PyLong_Check(value)) {
|
||||||
type = TIFF_LONG;
|
type = TIFF_LONG;
|
||||||
} else if (PyFloat_Check(value)) {
|
} else if (PyFloat_Check(value)) {
|
||||||
type = TIFF_DOUBLE;
|
type = TIFF_DOUBLE;
|
||||||
|
@ -749,7 +748,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (type == TIFF_NOTYPE) {
|
if (type == TIFF_NOTYPE) {
|
||||||
// Autodetect type based on first item. Types should not be
|
// Autodetect type based on first item. Types should not be
|
||||||
// changed for backwards compatibility.
|
// changed for backwards compatibility.
|
||||||
if (PyInt_Check(PyTuple_GetItem(value,0))) {
|
if (PyLong_Check(PyTuple_GetItem(value,0))) {
|
||||||
type = TIFF_LONG;
|
type = TIFF_LONG;
|
||||||
} else if (PyFloat_Check(PyTuple_GetItem(value,0))) {
|
} else if (PyFloat_Check(PyTuple_GetItem(value,0))) {
|
||||||
type = TIFF_FLOAT;
|
type = TIFF_FLOAT;
|
||||||
|
@ -775,7 +774,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(UINT8));
|
av = calloc(len, sizeof(UINT8));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (UINT8)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (UINT8)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -786,7 +785,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(UINT16));
|
av = calloc(len, sizeof(UINT16));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (UINT16)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (UINT16)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -797,7 +796,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(UINT32));
|
av = calloc(len, sizeof(UINT32));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (UINT32)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (UINT32)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -808,7 +807,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(INT8));
|
av = calloc(len, sizeof(INT8));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (INT8)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (INT8)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -819,7 +818,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(INT16));
|
av = calloc(len, sizeof(INT16));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (INT16)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (INT16)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -830,7 +829,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
av = calloc(len, sizeof(INT32));
|
av = calloc(len, sizeof(INT32));
|
||||||
if (av) {
|
if (av) {
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
av[i] = (INT32)PyInt_AsLong(PyTuple_GetItem(value,i));
|
av[i] = (INT32)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
}
|
}
|
||||||
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int, len, av);
|
||||||
free(av);
|
free(av);
|
||||||
|
@ -862,19 +861,19 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (type == TIFF_SHORT) {
|
if (type == TIFF_SHORT) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(UINT16)PyInt_AsLong(value));
|
(UINT16)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_LONG) {
|
} else if (type == TIFF_LONG) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(UINT32)PyInt_AsLong(value));
|
(UINT32)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_SSHORT) {
|
} else if (type == TIFF_SSHORT) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(INT16)PyInt_AsLong(value));
|
(INT16)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_SLONG) {
|
} else if (type == TIFF_SLONG) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(INT32)PyInt_AsLong(value));
|
(INT32)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_FLOAT) {
|
} else if (type == TIFF_FLOAT) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
|
@ -886,11 +885,11 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
} else if (type == TIFF_BYTE) {
|
} else if (type == TIFF_BYTE) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(UINT8)PyInt_AsLong(value));
|
(UINT8)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_SBYTE) {
|
} else if (type == TIFF_SBYTE) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
(INT8)PyInt_AsLong(value));
|
(INT8)PyLong_AsLong(value));
|
||||||
} else if (type == TIFF_ASCII) {
|
} else if (type == TIFF_ASCII) {
|
||||||
status = ImagingLibTiffSetField(&encoder->state,
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
(ttag_t) key_int,
|
(ttag_t) key_int,
|
||||||
|
@ -984,7 +983,7 @@ static unsigned int* get_qtables_arrays(PyObject* qtables, int* qtablesLen) {
|
||||||
}
|
}
|
||||||
table_data = PySequence_Fast(table, "expected a sequence");
|
table_data = PySequence_Fast(table, "expected a sequence");
|
||||||
for (j = 0; j < DCTSIZE2; j++) {
|
for (j = 0; j < DCTSIZE2; j++) {
|
||||||
qarrays[i * DCTSIZE2 + j] = PyInt_AS_LONG(PySequence_Fast_GET_ITEM(table_data, j));
|
qarrays[i * DCTSIZE2 + j] = PyLong_AS_LONG(PySequence_Fast_GET_ITEM(table_data, j));
|
||||||
}
|
}
|
||||||
Py_DECREF(table_data);
|
Py_DECREF(table_data);
|
||||||
}
|
}
|
||||||
|
@ -1024,7 +1023,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
char* rawExif = NULL;
|
char* rawExif = NULL;
|
||||||
Py_ssize_t rawExifLen = 0;
|
Py_ssize_t rawExifLen = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ss|nnnnnnnnO"PY_ARG_BYTES_LENGTH""PY_ARG_BYTES_LENGTH,
|
if (!PyArg_ParseTuple(args, "ss|nnnnnnnnOy#y#",
|
||||||
&mode, &rawmode, &quality,
|
&mode, &rawmode, &quality,
|
||||||
&progressive, &smooth, &optimize, &streamtype,
|
&progressive, &smooth, &optimize, &streamtype,
|
||||||
&xdpi, &ydpi, &subsampling, &qtables, &extra, &extra_size,
|
&xdpi, &ydpi, &subsampling, &qtables, &extra, &extra_size,
|
||||||
|
@ -1109,8 +1108,8 @@ j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y)
|
||||||
*x = *y = 0;
|
*x = *y = 0;
|
||||||
|
|
||||||
if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) {
|
if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) {
|
||||||
*x = (int)PyInt_AsLong(PyTuple_GET_ITEM(tuple, 0));
|
*x = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 0));
|
||||||
*y = (int)PyInt_AsLong(PyTuple_GET_ITEM(tuple, 1));
|
*y = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 1));
|
||||||
|
|
||||||
if (*x < 0)
|
if (*x < 0)
|
||||||
*x = 0;
|
*x = 0;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include "../py3.h"
|
|
||||||
|
|
||||||
|
|
||||||
Py_ssize_t
|
Py_ssize_t
|
||||||
|
@ -72,7 +71,7 @@ _imaging_tell_pyFd(PyObject *fd)
|
||||||
Py_ssize_t location;
|
Py_ssize_t location;
|
||||||
|
|
||||||
result = PyObject_CallMethod(fd, "tell", NULL);
|
result = PyObject_CallMethod(fd, "tell", NULL);
|
||||||
location = PyInt_AsSsize_t(result);
|
location = PyLong_AsSsize_t(result);
|
||||||
|
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return location;
|
return location;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
/* compatibility wrappers (defined in _imaging.c) */
|
/* compatibility wrappers (defined in _imaging.c) */
|
||||||
extern int PyImaging_CheckBuffer(PyObject* buffer);
|
extern int PyImaging_CheckBuffer(PyObject* buffer);
|
||||||
extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view);
|
extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view);
|
||||||
|
|
19
src/path.c
19
src/path.c
|
@ -31,8 +31,6 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "py3.h"
|
|
||||||
|
|
||||||
/* compatibility wrappers (defined in _imaging.c) */
|
/* compatibility wrappers (defined in _imaging.c) */
|
||||||
extern int PyImaging_CheckBuffer(PyObject* buffer);
|
extern int PyImaging_CheckBuffer(PyObject* buffer);
|
||||||
extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view);
|
extern int PyImaging_GetBuffer(PyObject* buffer, Py_buffer *view);
|
||||||
|
@ -170,8 +168,8 @@ PyPath_Flatten(PyObject* data, double **pxy)
|
||||||
PyObject *op = PyList_GET_ITEM(data, i);
|
PyObject *op = PyList_GET_ITEM(data, i);
|
||||||
if (PyFloat_Check(op))
|
if (PyFloat_Check(op))
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
xy[j++] = PyFloat_AS_DOUBLE(op);
|
||||||
else if (PyInt_Check(op))
|
else if (PyLong_Check(op))
|
||||||
xy[j++] = (float) PyInt_AS_LONG(op);
|
xy[j++] = (float) PyLong_AS_LONG(op);
|
||||||
else if (PyNumber_Check(op))
|
else if (PyNumber_Check(op))
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
xy[j++] = PyFloat_AsDouble(op);
|
||||||
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
||||||
|
@ -188,8 +186,8 @@ PyPath_Flatten(PyObject* data, double **pxy)
|
||||||
PyObject *op = PyTuple_GET_ITEM(data, i);
|
PyObject *op = PyTuple_GET_ITEM(data, i);
|
||||||
if (PyFloat_Check(op))
|
if (PyFloat_Check(op))
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
xy[j++] = PyFloat_AS_DOUBLE(op);
|
||||||
else if (PyInt_Check(op))
|
else if (PyLong_Check(op))
|
||||||
xy[j++] = (float) PyInt_AS_LONG(op);
|
xy[j++] = (float) PyLong_AS_LONG(op);
|
||||||
else if (PyNumber_Check(op))
|
else if (PyNumber_Check(op))
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
xy[j++] = PyFloat_AsDouble(op);
|
||||||
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
||||||
|
@ -217,8 +215,8 @@ PyPath_Flatten(PyObject* data, double **pxy)
|
||||||
}
|
}
|
||||||
if (PyFloat_Check(op))
|
if (PyFloat_Check(op))
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
xy[j++] = PyFloat_AS_DOUBLE(op);
|
||||||
else if (PyInt_Check(op))
|
else if (PyLong_Check(op))
|
||||||
xy[j++] = (float) PyInt_AS_LONG(op);
|
xy[j++] = (float) PyLong_AS_LONG(op);
|
||||||
else if (PyNumber_Check(op))
|
else if (PyNumber_Check(op))
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
xy[j++] = PyFloat_AsDouble(op);
|
||||||
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
||||||
|
@ -552,13 +550,8 @@ path_subscript(PyPathObject* self, PyObject* item) {
|
||||||
int len = 4;
|
int len = 4;
|
||||||
Py_ssize_t start, stop, step, slicelength;
|
Py_ssize_t start, stop, step, slicelength;
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03020000
|
|
||||||
if (PySlice_GetIndicesEx(item, len, &start, &stop, &step, &slicelength) < 0)
|
if (PySlice_GetIndicesEx(item, len, &start, &stop, &step, &slicelength) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
|
||||||
if (PySlice_GetIndicesEx((PySliceObject*)item, len, &start, &stop, &step, &slicelength) < 0)
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (slicelength <= 0) {
|
if (slicelength <= 0) {
|
||||||
double *xy = alloc_array(0);
|
double *xy = alloc_array(0);
|
||||||
|
|
56
src/py3.h
56
src/py3.h
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
Python3 definition file to consistently map the code to Python 2 or
|
|
||||||
Python 3.
|
|
||||||
|
|
||||||
PyInt and PyLong were merged into PyLong in Python 3, so all PyInt functions
|
|
||||||
are mapped to PyLong.
|
|
||||||
|
|
||||||
PyString, on the other hand, was split into PyBytes and PyUnicode. We map
|
|
||||||
both back onto PyString, so use PyBytes or PyUnicode where appropriate. The
|
|
||||||
only exception to this is _imagingft.c, where PyUnicode is left alone.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
|
||||||
#define PY_ARG_BYTES_LENGTH "y#"
|
|
||||||
|
|
||||||
/* Map PyInt -> PyLong */
|
|
||||||
#define PyInt_AsLong PyLong_AsLong
|
|
||||||
#define PyInt_Check PyLong_Check
|
|
||||||
#define PyInt_FromLong PyLong_FromLong
|
|
||||||
#define PyInt_AS_LONG PyLong_AS_LONG
|
|
||||||
#define PyInt_FromSsize_t PyLong_FromSsize_t
|
|
||||||
#define PyInt_AsSsize_t PyLong_AsSsize_t
|
|
||||||
|
|
||||||
#else /* PY_VERSION_HEX < 0x03000000 */
|
|
||||||
#define PY_ARG_BYTES_LENGTH "s#"
|
|
||||||
|
|
||||||
#if !defined(KEEP_PY_UNICODE)
|
|
||||||
/* Map PyUnicode -> PyString */
|
|
||||||
#undef PyUnicode_AsString
|
|
||||||
#undef PyUnicode_AS_STRING
|
|
||||||
#undef PyUnicode_Check
|
|
||||||
#undef PyUnicode_FromStringAndSize
|
|
||||||
#undef PyUnicode_FromString
|
|
||||||
#undef PyUnicode_FromFormat
|
|
||||||
#undef PyUnicode_DecodeFSDefault
|
|
||||||
|
|
||||||
#define PyUnicode_AsString PyString_AsString
|
|
||||||
#define PyUnicode_AS_STRING PyString_AS_STRING
|
|
||||||
#define PyUnicode_Check PyString_Check
|
|
||||||
#define PyUnicode_FromStringAndSize PyString_FromStringAndSize
|
|
||||||
#define PyUnicode_FromString PyString_FromString
|
|
||||||
#define PyUnicode_FromFormat PyString_FromFormat
|
|
||||||
#define PyUnicode_DecodeFSDefault PyString_FromString
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Map PyBytes -> PyString */
|
|
||||||
#define PyBytesObject PyStringObject
|
|
||||||
#define PyBytes_AsString PyString_AsString
|
|
||||||
#define PyBytes_AS_STRING PyString_AS_STRING
|
|
||||||
#define PyBytes_Check PyString_Check
|
|
||||||
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
|
|
||||||
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
|
||||||
#define PyBytes_FromString PyString_FromString
|
|
||||||
#define _PyBytes_Resize _PyString_Resize
|
|
||||||
|
|
||||||
#endif /* PY_VERSION_HEX < 0x03000000 */
|
|
2
tox.ini
2
tox.ini
|
@ -6,7 +6,7 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist =
|
envlist =
|
||||||
lint
|
lint
|
||||||
py{27,35,36,37}
|
py{35,36,37}
|
||||||
minversion = 1.9
|
minversion = 1.9
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
|
|
@ -2,15 +2,11 @@
|
||||||
|
|
||||||
mkdir /var/cache/pacman/pkg
|
mkdir /var/cache/pacman/pkg
|
||||||
pacman -S --noconfirm mingw32/mingw-w64-i686-python3-pip \
|
pacman -S --noconfirm mingw32/mingw-w64-i686-python3-pip \
|
||||||
mingw32/mingw-w64-i686-python3-setuptools \
|
mingw32/mingw-w64-i686-python3-setuptools \
|
||||||
mingw32/mingw-w64-i686-python3-pytest \
|
mingw32/mingw-w64-i686-python3-pytest \
|
||||||
mingw32/mingw-w64-i686-python3-pytest-cov \
|
mingw32/mingw-w64-i686-python3-pytest-cov \
|
||||||
mingw32/mingw-w64-i686-python2-pip \
|
mingw-w64-i686-libjpeg-turbo \
|
||||||
mingw32/mingw-w64-i686-python2-setuptools \
|
mingw-w64-i686-libimagequant
|
||||||
mingw32/mingw-w64-i686-python2-pytest \
|
|
||||||
mingw32/mingw-w64-i686-python2-pytest-cov \
|
|
||||||
mingw-w64-i686-libjpeg-turbo \
|
|
||||||
mingw-w64-i686-libimagequant
|
|
||||||
|
|
||||||
C:/msys64/mingw32/bin/python3 -m pip install --upgrade pip
|
C:/msys64/mingw32/bin/python3 -m pip install --upgrade pip
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
curl -fsSL -o pypy2.zip https://bitbucket.org/pypy/pypy/downloads/pypy2.7-v7.1.1-win32.zip
|
|
||||||
7z x pypy2.zip -oc:\
|
|
||||||
c:\Python37\Scripts\virtualenv.exe -p c:\pypy2.7-v7.1.1-win32\pypy.exe c:\vp\pypy2
|
|
|
@ -105,10 +105,7 @@ def build_one(py_ver, compiler, bit):
|
||||||
args["executable"] = "%EXECUTABLE%"
|
args["executable"] = "%EXECUTABLE%"
|
||||||
|
|
||||||
args["py_ver"] = py_ver
|
args["py_ver"] = py_ver
|
||||||
if "27" in py_ver:
|
args["tcl_ver"] = "86"
|
||||||
args["tcl_ver"] = "85"
|
|
||||||
else:
|
|
||||||
args["tcl_ver"] = "86"
|
|
||||||
|
|
||||||
if compiler["vc_version"] == "2015":
|
if compiler["vc_version"] == "2015":
|
||||||
args["imaging_libs"] = " build_ext --add-imaging-libs=msvcrt"
|
args["imaging_libs"] = " build_ext --add-imaging-libs=msvcrt"
|
||||||
|
|
|
@ -4,8 +4,6 @@ SF_MIRROR = "http://iweb.dl.sourceforge.net"
|
||||||
PILLOW_DEPENDS_DIR = "C:\\pillow-depends\\"
|
PILLOW_DEPENDS_DIR = "C:\\pillow-depends\\"
|
||||||
|
|
||||||
pythons = {
|
pythons = {
|
||||||
"27": {"compiler": 7, "vc": 2010},
|
|
||||||
"pypy2": {"compiler": 7, "vc": 2010},
|
|
||||||
"35": {"compiler": 7.1, "vc": 2015},
|
"35": {"compiler": 7.1, "vc": 2015},
|
||||||
"36": {"compiler": 7.1, "vc": 2015},
|
"36": {"compiler": 7.1, "vc": 2015},
|
||||||
"pypy3": {"compiler": 7.1, "vc": 2015},
|
"pypy3": {"compiler": 7.1, "vc": 2015},
|
||||||
|
@ -131,7 +129,7 @@ compilers = {
|
||||||
def pyversion_from_env():
|
def pyversion_from_env():
|
||||||
py = os.environ["PYTHON"]
|
py = os.environ["PYTHON"]
|
||||||
|
|
||||||
py_version = "27"
|
py_version = "35"
|
||||||
for k in pythons:
|
for k in pythons:
|
||||||
if k in py:
|
if k in py:
|
||||||
py_version = k
|
py_version = k
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
from fetch import fetch
|
from fetch import fetch
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for version in ["2.7.15", "3.4.4"]:
|
for version in ["3.4.4"]:
|
||||||
for platform in ["", ".amd64"]:
|
for platform in ["", ".amd64"]:
|
||||||
for extension in ["", ".asc"]:
|
for extension in ["", ".asc"]:
|
||||||
fetch(
|
fetch(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user