diff --git a/Tests/test_file_avif.py b/Tests/test_file_avif.py index 08b20047f0c..32dd694f580 100644 --- a/Tests/test_file_avif.py +++ b/Tests/test_file_avif.py @@ -327,6 +327,10 @@ def test_exif(self) -> None: exif = im.getexif() assert exif[274] == 1 + with Image.open("Tests/images/avif/xmp_tags_orientation.avif") as im: + exif = im.getexif() + assert exif[274] == 3 + def test_exif_save_default(self, tmp_path: Path) -> None: with Image.open("Tests/images/avif/exif.avif") as im: test_file = str(tmp_path / "temp.avif") @@ -549,22 +553,6 @@ def test_decoder_codec_available_cannot_decode(self) -> None: def test_decoder_codec_available_invalid(self) -> None: assert _avif.decoder_codec_available("foo") is False - @pytest.mark.parametrize("upsampling", ["fastest", "best", "nearest", "bilinear"]) - def test_decoder_upsampling( - self, monkeypatch: pytest.MonkeyPatch, upsampling: str - ) -> None: - monkeypatch.setattr(AvifImagePlugin, "CHROMA_UPSAMPLING", upsampling) - - with Image.open(TEST_AVIF_FILE): - pass - - def test_decoder_upsampling_invalid(self, monkeypatch: pytest.MonkeyPatch) -> None: - monkeypatch.setattr(AvifImagePlugin, "CHROMA_UPSAMPLING", "foo") - - with pytest.raises(ValueError): - with Image.open(TEST_AVIF_FILE): - pass - def test_p_mode_transparency(self) -> None: im = Image.new("P", size=(64, 64)) draw = ImageDraw.Draw(im) diff --git a/src/PIL/AvifImagePlugin.py b/src/PIL/AvifImagePlugin.py index e9749f36cc2..1c90f428a09 100644 --- a/src/PIL/AvifImagePlugin.py +++ b/src/PIL/AvifImagePlugin.py @@ -16,7 +16,6 @@ # Decoder options as module globals, until there is a way to pass parameters # to Image.open (see https://github.com/python-pillow/Pillow/issues/569) DECODE_CODEC_CHOICE = "auto" -CHROMA_UPSAMPLING = "auto" DEFAULT_MAX_THREADS = 0 _VALID_AVIF_MODES = {"RGB", "RGBA"} @@ -76,7 +75,6 @@ def _open(self) -> None: self._decoder = _avif.AvifDecoder( self.fp.read(), DECODE_CODEC_CHOICE, - CHROMA_UPSAMPLING, _get_default_max_threads(), ) @@ -238,22 +236,12 @@ def _save( for idx in range(nfr): ims.seek(idx) - ims.load() # Make sure image mode is supported frame = ims rawmode = ims.mode if ims.mode not in _VALID_AVIF_MODES: - alpha = ( - "A" in ims.mode - or "a" in ims.mode - or (ims.mode == "P" and "A" in ims.im.getpalettemode()) - or ( - ims.mode == "P" - and ims.info.get("transparency", None) is not None - ) - ) - rawmode = "RGBA" if alpha else "RGB" + rawmode = "RGBA" if ims.has_transparency_data else "RGB" frame = ims.convert(rawmode) # Update frame duration diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a49a38739f8..c00ab8a886d 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1548,8 +1548,8 @@ def getexif(self) -> Exif: # XMP tags if ExifTags.Base.Orientation not in self._exif: - xmp_tags = self.info.get("XML:com.adobe.xmp") or self.info.get("xmp") - if isinstance(xmp_tags, bytes): + xmp_tags = self.info.get("XML:com.adobe.xmp") + if not xmp_tags and (xmp_tags := self.info.get("xmp")): xmp_tags = xmp_tags.decode("utf-8") if xmp_tags: match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags) diff --git a/src/_avif.c b/src/_avif.c index 5e993e35447..d0bb81f4619 100644 --- a/src/_avif.c +++ b/src/_avif.c @@ -3,12 +3,6 @@ #include #include "avif/avif.h" -#if AVIF_VERSION < 80300 -#define AVIF_CHROMA_UPSAMPLING_AUTOMATIC AVIF_CHROMA_UPSAMPLING_BILINEAR -#define AVIF_CHROMA_UPSAMPLING_BEST_QUALITY AVIF_CHROMA_UPSAMPLING_BILINEAR -#define AVIF_CHROMA_UPSAMPLING_FASTEST AVIF_CHROMA_UPSAMPLING_NEAREST -#endif - typedef struct { avifPixelFormat subsampling; int qmin; @@ -671,32 +665,13 @@ AvifDecoderNew(PyObject *self_, PyObject *args) { PyObject *avif_bytes; AvifDecoderObject *self = NULL; - char *upsampling_str; char *codec_str; avifCodecChoice codec; - avifChromaUpsampling upsampling; int max_threads; avifResult result; - if (!PyArg_ParseTuple( - args, "Sssi", &avif_bytes, &codec_str, &upsampling_str, &max_threads - )) { - return NULL; - } - - if (!strcmp(upsampling_str, "auto")) { - upsampling = AVIF_CHROMA_UPSAMPLING_AUTOMATIC; - } else if (!strcmp(upsampling_str, "fastest")) { - upsampling = AVIF_CHROMA_UPSAMPLING_FASTEST; - } else if (!strcmp(upsampling_str, "best")) { - upsampling = AVIF_CHROMA_UPSAMPLING_BEST_QUALITY; - } else if (!strcmp(upsampling_str, "nearest")) { - upsampling = AVIF_CHROMA_UPSAMPLING_NEAREST; - } else if (!strcmp(upsampling_str, "bilinear")) { - upsampling = AVIF_CHROMA_UPSAMPLING_BILINEAR; - } else { - PyErr_Format(PyExc_ValueError, "Invalid upsampling option: %s", upsampling_str); + if (!PyArg_ParseTuple(args, "Ssi", &avif_bytes, &codec_str, &max_threads)) { return NULL; } diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index d19eb978fe9..8ee9cd90e54 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -402,8 +402,7 @@ def cmd_msbuild( }, "rav1e": { "url": ( - f"https://github.com/xiph/rav1e/releases/download/v{V['RAV1E']}/" - f"rav1e-{V['RAV1E']}-windows-msvc-generic.zip" + f"https://github.com/xiph/rav1e/releases/download/v{V['RAV1E']}/FILENAME" ), "filename": f"rav1e-{V['RAV1E']}-windows-msvc-generic.zip", "dir": "rav1e-windows-msvc-sdk",