mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-06 14:40:51 +03:00
Removed unused upsampling setting (#5)
* Use filename placeholder in URL * Removed unused upsampling setting * Use has_transparency_data * Removed unnecessary load() * Test getexif() change --------- Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
This commit is contained in:
parent
50b993a0cb
commit
671e3c8b57
|
@ -327,6 +327,10 @@ class TestFileAvif:
|
|||
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 @@ class TestFileAvif:
|
|||
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)
|
||||
|
|
|
@ -16,7 +16,6 @@ except ImportError:
|
|||
# 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 @@ class AvifImageFile(ImageFile.ImageFile):
|
|||
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
|
||||
|
|
|
@ -1548,8 +1548,8 @@ class Image:
|
|||
|
||||
# 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)
|
||||
|
|
27
src/_avif.c
27
src/_avif.c
|
@ -3,12 +3,6 @@
|
|||
#include <Python.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -402,8 +402,7 @@ DEPS: dict[str, dict[str, Any]] = {
|
|||
},
|
||||
"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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user