Skip to content

Commit

Permalink
Removed unused upsampling setting
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 12, 2024
1 parent ff80dcb commit 06cb099
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 44 deletions.
16 changes: 0 additions & 16 deletions Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,22 +549,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)
Expand Down
2 changes: 0 additions & 2 deletions src/PIL/AvifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -76,7 +75,6 @@ def _open(self) -> None:
self._decoder = _avif.AvifDecoder(
self.fp.read(),
DECODE_CODEC_CHOICE,
CHROMA_UPSAMPLING,
_get_default_max_threads(),
)

Expand Down
27 changes: 1 addition & 26 deletions src/_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 06cb099

Please sign in to comment.