Skip to content

Commit

Permalink
Documented using PyEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 19, 2022
1 parent fb7f2eb commit 86ce449
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/handbook/appendices.rst
Expand Up @@ -8,4 +8,4 @@ Appendices

image-file-formats
text-anchors
writing-your-own-file-decoder
writing-your-own-image-plugin
Expand Up @@ -4,10 +4,9 @@ Writing Your Own Image Plugin
=============================

Pillow uses a plugin model which allows you to add your own
decoders to the library, without any changes to the library
itself. Such plugins usually have names like
:file:`XxxImagePlugin.py`, where ``Xxx`` is a unique format name
(usually an abbreviation).
decoders and encoders to the library, without any changes to the library
itself. Such plugins usually have names like :file:`XxxImagePlugin.py`,
where ``Xxx`` is a unique format name (usually an abbreviation).

.. warning:: Pillow >= 2.1.0 no longer automatically imports any file
in the Python path with a name ending in
Expand Down Expand Up @@ -413,23 +412,24 @@ value, or if there is a read error from the file. This function should
free any allocated memory and release any resources from external
libraries.

.. _file-decoders-py:
.. _file-codecs-py:

Writing Your Own File Decoder in Python
=======================================
Writing Your Own File Codec in Python
=====================================

Python file decoders should derive from
:py:class:`PIL.ImageFile.PyDecoder` and should at least override the
decode method. File decoders should be registered using
:py:meth:`PIL.Image.register_decoder`. As in the C implementation of
the file decoders, there are three stages in the lifetime of a
Python-based file decoder:
Python file decoders and encoders should derive from
:py:class:`PIL.ImageFile.PyDecoder` and :py:class:`PIL.ImageFile.PyEncoder`
respectively, and should at least override the decode or encode method.
They should be registered using :py:meth:`PIL.Image.register_decoder` and
:py:meth:`PIL.Image.register_encoder`. As in the C implementation of
the file codecs, there are three stages in the lifetime of a
Python-based file codec:

1. Setup: Pillow looks for the decoder in the registry, then
instantiates the class.

2. Decoding: The decoder instance's ``decode`` method is repeatedly
called with a buffer of data to be interpreted.

3. Cleanup: The decoder instance's ``cleanup`` method is called.
2. Transforming: The instance's ``decode`` method is repeatedly called with
a buffer of data to be interpreted, or the ``encode`` method is repeatedly
called with the size of data to be output.

3. Cleanup: The instance's ``cleanup`` method is called.
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Expand Up @@ -656,7 +656,7 @@ class PyDecoder(PyCodec):
Python implementation of a format decoder. Override this class and
add the decoding logic in the :meth:`decode` method.
See :ref:`Writing Your Own File Decoder in Python<file-decoders-py>`
See :ref:`Writing Your Own File Codec in Python<file-codecs-py>`
"""

_pulls_fd = False
Expand Down

0 comments on commit 86ce449

Please sign in to comment.