Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ def test_prog_res_rt(card: ImageFile.ImageFile) -> None:
assert_image_equal(im, card)


def test_unknown_progression(tmp_path: Path) -> None:
outfile = tmp_path / "temp.jp2"

im = Image.new("1", (1, 1))
with pytest.raises(ValueError, match="unknown progression"):
im.save(outfile, progression="invalid")


def test_unknown_cinema_mode(tmp_path: Path) -> None:
outfile = tmp_path / "temp.jp2"

im = Image.new("1", (1, 1))
with pytest.raises(ValueError, match="unknown cinema mode"):
im.save(outfile, cinema_mode="invalid")


@pytest.mark.parametrize("num_resolutions", range(2, 6))
def test_default_num_resolutions(
card: ImageFile.ImageFile, num_resolutions: int
Expand Down
1 change: 1 addition & 0 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) {
} else if (strcmp(format, "jp2") == 0) {
codec_format = OPJ_CODEC_JP2;
} else {
PyErr_SetString(PyExc_ValueError, "unknown codec format");
return NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,10 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {

if (strcmp(format, "j2k") == 0) {
codec_format = OPJ_CODEC_J2K;
} else if (strcmp(format, "jpt") == 0) {
codec_format = OPJ_CODEC_JPT;
} else if (strcmp(format, "jp2") == 0) {
codec_format = OPJ_CODEC_JP2;
} else {
PyErr_SetString(PyExc_ValueError, "unknown codec format");
return NULL;
}

Expand All @@ -1362,6 +1361,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
} else if (strcmp(progression, "CPRL") == 0) {
prog_order = OPJ_CPRL;
} else {
PyErr_SetString(PyExc_ValueError, "unknown progression");
return NULL;
}

Expand All @@ -1374,6 +1374,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
} else if (strcmp(cinema_mode, "cinema4k-24") == 0) {
cine_mode = OPJ_CINEMA4K_24;
} else {
PyErr_SetString(PyExc_ValueError, "unknown cinema mode");
return NULL;
}

Expand Down
Loading