Skip to content

Commit

Permalink
WIP: switch to using pillow for png as well.
Browse files Browse the repository at this point in the history
The version check in _has_pil (pillow>=3.4) was dropped as the oldest
Pillow that supports Py3.6 (the oldest Python supported by Matplotlib)
is 4.0 anyways.

- PIL returns uint16 images as int32
  (python-pillow/Pillow#3041); we could adopt
  imageio's dtype correcting code if desired.
  • Loading branch information
anntzer committed Sep 4, 2019
1 parent 0ac415f commit 9098297
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 1,018 deletions.
6 changes: 2 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ install:
# https://github.com/conda-forge/conda-forge.github.io/issues/157#issuecomment-223536381
#
- conda create -q -n test-environment python=%PYTHON_VERSION%
msinttypes freetype=2.6 "libpng>=1.6.21,<1.7" zlib=1.2 tk=8.5
msinttypes freetype=2.6 zlib=1.2 tk=8.5
pip setuptools numpy sphinx tornado
- activate test-environment
- echo %PYTHON_VERSION% %TARGET_ARCH%
Expand All @@ -85,11 +85,9 @@ test_script:
# Now build the thing..
- set LINK=/LIBPATH:%cd%\lib
- pip install -ve .
# these should show no z, png, or freetype dll...
# these should show no z or freetype dll...
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr z.*.dll && exit /b 1 || exit /b 0'
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr png.*.dll && exit /b 1 || exit /b 0'

# this are optional dependencies so that we don't skip so many tests...
- if x%TEST_ALL% == xyes conda install -q ffmpeg inkscape miktex pillow
Expand Down
25 changes: 12 additions & 13 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ toolchain is prefixed. This may be used for cross compiling. ::
export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config

Once you have satisfied the requirements detailed below (mainly
Python, NumPy, libpng and FreeType), you can build Matplotlib.
Python, NumPy, and FreeType), you can build Matplotlib.
::

cd matplotlib
Expand Down Expand Up @@ -128,7 +128,6 @@ Matplotlib requires the following dependencies:

* `Python <https://www.python.org/downloads/>`_ (>= 3.6)
* `FreeType <https://www.freetype.org/>`_ (>= 2.3)
* `libpng <http://www.libpng.org>`_ (>= 1.2)
* `NumPy <http://www.numpy.org>`_ (>= 1.11)
* `setuptools <https://setuptools.readthedocs.io/en/latest/>`_
* `cycler <http://matplotlib.org/cycler/>`_ (>= 0.10.0)
Expand Down Expand Up @@ -184,8 +183,8 @@ etc., you can install the following:
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/

If not using pkg-config (in particular on Windows), you may need to set the
include path (to the FreeType, libpng, and zlib headers) and link path (to
the FreeType, libpng, and zlib libraries) explicitly, if they are not in
include path (to the FreeType and zlib headers) and link path (to
the FreeType and zlib libraries) explicitly, if they are not in
standard locations. This can be done using standard environment variables
-- on Linux and OSX:

Expand All @@ -202,8 +201,8 @@ etc., you can install the following:
set LINK=/LIBPATH:C:\directory\containing\freetype.lib ...
where ``...`` means "also give, in the same format, the directories
containing ``png.h`` and ``zlib.h`` for the include path, and for
``libpng.so``/``png.lib`` and ``libz.so``/``z.lib`` for the link path."
containing ``zlib.h`` for the include path, and for
``libz.so``/``z.lib`` for the link path."

.. note::

Expand Down Expand Up @@ -244,20 +243,20 @@ Building on macOS
-----------------

The build situation on macOS is complicated by the various places one
can get the libpng and FreeType requirements (MacPorts, Fink,
can get FreeType (MacPorts, Fink,
/usr/X11R6), the different architectures (e.g., x86, ppc, universal), and
the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build
the way we do for the macOS release: get the source from the tarball or the
git repository and install the required dependencies through a third-party
package manager. Two widely used package managers are Homebrew, and MacPorts.
The following example illustrates how to install libpng and FreeType using
The following example illustrates how to install FreeType using
``brew``::

brew install libpng freetype pkg-config
brew install freetype pkg-config

If you are using MacPorts, execute the following instead::

port install libpng freetype pkgconfig
port install freetype pkgconfig

After installing the above requirements, install Matplotlib from source by
executing::
Expand All @@ -281,7 +280,7 @@ https://packaging.python.org/guides/packaging-binary-extensions/#setting-up-a-bu
for how to set up a build environment.

Since there is no canonical Windows package manager, the methods for building
FreeType, zlib, and libpng from source code are documented as a build script
FreeType and zlib from source code are documented as a build script
at `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_.

There are a few possibilities to build Matplotlib on Windows:
Expand All @@ -305,9 +304,9 @@ the list of conda packages.

::

conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk libpng zlib freetype msinttypes
conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk zlib freetype msinttypes
conda activate matplotlib_build
# force the build against static libpng and zlib libraries
# force the build against static zlib libraries
set MPLSTATICBUILD=True
python setup.py bdist_wheel

Expand Down
4 changes: 0 additions & 4 deletions ci/azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ steps:
displayName: 'Use latest available Nuget'

- script: |
nuget install libpng-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
nuget install zlib-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
echo ##vso[task.prependpath]$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\bin_release
echo ##vso[task.prependpath]$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\bin_release
echo ##vso[task.setvariable variable=CL]/I$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\include /I$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\include
echo ##vso[task.setvariable variable=LINK]/LIBPATH:$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\lib_release /LIBPATH:$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\lib_release
displayName: 'Install dependencies with nuget'
Expand Down
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2019-09-04-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Matplotlib now uses Pillow to save and read pngs
````````````````````````````````````````````````

The builtin png encoder and decoder has been removed, and Pillow is now a
dependency.
2 changes: 1 addition & 1 deletion doc/devel/min_dep_policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ minimum Python and numpy.
System and C-dependencies
=========================

For system or c-dependencies (libpng, freetype, GUI frameworks, latex,
For system or c-dependencies (freetype, GUI frameworks, latex,
gs, ffmpeg) support as old as practical. These can be difficult to
install for end-users and we want to be usable on as many systems as
possible. We will bump these on a case-by-case basis.
38 changes: 11 additions & 27 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,37 @@
from matplotlib.transforms import Affine2D
from matplotlib.path import Path

try:
from PIL import PILLOW_VERSION
from distutils.version import LooseVersion
if LooseVersion(PILLOW_VERSION) >= "3.4":
_has_pil = True
else:
_has_pil = False
del PILLOW_VERSION
except ImportError:
_has_pil = False

_log = logging.getLogger(__name__)

_default_filetypes = {
'ps': 'Postscript',
'eps': 'Encapsulated Postscript',
'jpg': 'Joint Photographic Experts Group',
'jpeg': 'Joint Photographic Experts Group',
'pdf': 'Portable Document Format',
'pgf': 'PGF code for LaTeX',
'png': 'Portable Network Graphics',
'ps': 'Postscript',
'raw': 'Raw RGBA bitmap',
'rgba': 'Raw RGBA bitmap',
'svg': 'Scalable Vector Graphics',
'svgz': 'Scalable Vector Graphics'
'svgz': 'Scalable Vector Graphics',
'tif': 'Tagged Image File Format',
'tiff': 'Tagged Image File Format',
}


_default_backends = {
'ps': 'matplotlib.backends.backend_ps',
'eps': 'matplotlib.backends.backend_ps',
'jpg': 'matplotlib.backends.backend_agg',
'jpeg': 'matplotlib.backends.backend_agg',
'pdf': 'matplotlib.backends.backend_pdf',
'pgf': 'matplotlib.backends.backend_pgf',
'png': 'matplotlib.backends.backend_agg',
'ps': 'matplotlib.backends.backend_ps',
'raw': 'matplotlib.backends.backend_agg',
'rgba': 'matplotlib.backends.backend_agg',
'svg': 'matplotlib.backends.backend_svg',
'svgz': 'matplotlib.backends.backend_svg',
'tif': 'matplotlib.backends.backend_agg',
'tiff': 'matplotlib.backends.backend_agg',
}


Expand Down Expand Up @@ -1604,17 +1599,6 @@ class FigureCanvasBase:
fixed_dpi = None

filetypes = _default_filetypes
if _has_pil:
# JPEG support
register_backend('jpg', 'matplotlib.backends.backend_agg',
'Joint Photographic Experts Group')
register_backend('jpeg', 'matplotlib.backends.backend_agg',
'Joint Photographic Experts Group')
# TIFF support
register_backend('tif', 'matplotlib.backends.backend_agg',
'Tagged Image File Format')
register_backend('tiff', 'matplotlib.backends.backend_agg',
'Tagged Image File Format')

@cbook._classproperty
def supports_blit(cls):
Expand Down
Loading

0 comments on commit 9098297

Please sign in to comment.