Skip to content

Commit

Permalink
fix: Opening HEIC images now throws UnidentifiedImageError
Browse files Browse the repository at this point in the history
This will allow pillow-avif-plugin to be interoperable with the HEIC
opener in pillow_heif. Fixes #19.
  • Loading branch information
fdintino committed Oct 28, 2022
1 parent 1dc3cab commit ed6dfbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ Changelog
``save()``).
* **Fixed**: ``tile_cols`` encoder setting (the ``save()`` method was using
the value passed to ``tile_rows`` instead)
* **Fixed**: Attempts to open non-AV1 images in HEIF containers (e.g. HEIC)
now raises UnidentifiedImageError, not ValueError. Fixes `#19`_.
* **CI**: manylinux2014 aarch64 wheels
* **CI**: bundle libyuv and libsharpyuv
* **CI**: Python 3.11 wheels
* **CI**: Update bundled libraries (see table below, changes from previous
release in bold)

.. _#19: https://github.com/fdintino/pillow-avif-plugin/issues/19

.. table::

=========== ==========
Expand Down
2 changes: 1 addition & 1 deletion src/pillow_avif/_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ normalize_tiles_log2(int value) {
static PyObject *
exc_type_for_avif_result(avifResult result) {
switch (result) {
case AVIF_RESULT_INVALID_FTYP:
case AVIF_RESULT_INVALID_EXIF_PAYLOAD:
case AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION:
return PyExc_ValueError;
case AVIF_RESULT_INVALID_FTYP:
case AVIF_RESULT_BMFF_PARSE_FAILED:
case AVIF_RESULT_TRUNCATED_DATA:
case AVIF_RESULT_NO_CONTENT:
Expand Down
Binary file added tests/images/rgba10.heif
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ def test_sequence_dimension_mismatch_check(self, tmp_path):
with pytest.raises(ValueError):
frame1.save(temp_file, save_all=True, append_images=[frame2], duration=100)

def test_heif_raises_unidentified_image_error(self):
with pytest.raises(UnidentifiedImageError or IOError):
with Image.open("tests/images/rgba10.heif"):
pass

@skip_unless_avif_version_gte((0, 9, 0))
@pytest.mark.parametrize("alpha_premultipled", [False, True])
def test_alpha_premultiplied_true(self, alpha_premultipled):
Expand Down

0 comments on commit ed6dfbf

Please sign in to comment.