Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using pillow for png as well. #15193

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install:
# if conda-forge gets a new pyqt, it might be nice to install it as well to have more backends
# https://github.com/conda-forge/conda-forge.github.io/issues/157#issuecomment-223536381
- conda create -q -n test-environment python=%PYTHON_VERSION%
freetype=2.6 "libpng>=1.6.21,<1.7" zlib=1.2 tk=8.5
freetype=2.6 zlib=1.2 tk=8.5
pip setuptools numpy sphinx tornado
- activate test-environment
- echo %PYTHON_VERSION% %TARGET_ARCH%
Expand All @@ -81,11 +81,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
28 changes: 13 additions & 15 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 All @@ -121,7 +121,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 @@ -177,8 +176,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 @@ -195,8 +194,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 @@ -237,20 +236,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 @@ -274,7 +273,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 @@ -290,17 +289,16 @@ Wheel builds using conda packages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a wheel build, but we use conda packages to get all the requirements.
The binary requirements (png, FreeType,...) are statically linked and therefore
not needed during the wheel install.
FreeType is statically linked and therefore not needed during the wheel install.

Set up the conda environment. Note, if you want a qt backend, add ``pyqt`` to
the list of conda packages.

::

conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk libpng zlib freetype
conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk zlib freetype
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
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/development.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
Development changes
-------------------

Matplotlib now uses Pillow to save and read pngs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The builtin png encoder and decoder has been removed, and Pillow is now a
dependency. Note that when reading 16-bit RGB(A) images, Pillow truncates them
to 8-bit precision, whereas the old builtin decoder kept the full precision.

The deprecated wx backend (not wxagg!) now always uses wx's builtin jpeg and
tiff support rather than relying on Pillow for writing these formats; this
behavior is consistent with wx's png output.
2 changes: 1 addition & 1 deletion doc/devel/min_dep_policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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.
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/image_thumbnail_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
===============

You can use matplotlib to generate thumbnails from existing images.
matplotlib natively supports PNG files on the input side, and other
image types transparently if your have PIL installed

Matplotlib relies on Pillow_ for reading images, and thus supports all formats
supported by Pillow.

.. _Pillow: http://python-pillow.org/
"""

# build thumbnails of all images in a directory
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,6 @@ def cleanup(self):
class PillowWriter(MovieWriter):
@classmethod
def isAvailable(cls):
try:
import PIL
except ImportError:
return False
return True

def __init__(self, *args, **kwargs):
Expand Down
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