Skip to content

Commit

Permalink
Update to use newest pylibjpeg-libjpeg release (#2036)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Mar 29, 2024
1 parent 98c240f commit cf472d3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 61 deletions.
12 changes: 6 additions & 6 deletions src/pydicom/pixels/decoders/pylibjpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@


DECODER_DEPENDENCIES = {
uid.JPEGBaseline8Bit: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGExtended12Bit: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGLosslessSV1: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGLSLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGLSNearLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.0.2"),
uid.JPEGBaseline8Bit: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEGExtended12Bit: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEGLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEGLosslessSV1: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEGLSLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEGLSNearLossless: ("pylibjpeg>=2.0", "pylibjpeg-libjpeg>=2.1"),
uid.JPEG2000Lossless: ("pylibjpeg>=2.0", "pylibjpeg-openjpeg>=2.0"),
uid.JPEG2000: ("pylibjpeg>=2.0", "pylibjpeg-openjpeg>=2.0"),
uid.HTJ2KLossless: ("pylibjpeg>=2.0", "pylibjpeg-openjpeg>=2.0"),
Expand Down
88 changes: 58 additions & 30 deletions tests/pixels/pixels_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,21 +1346,35 @@ def test(ref, arr, **kwargs):
# JPGB, (8, 8), (1, 256, 256, 3), OB, RGB, 0
# JPEG baseline in RGB colourspace with APP14 Adobe v101 marker
def test(ref, arr, **kwargs):
# Works with pillow and GDCM
# pylibjpeg: decoding error due to unknown Adobe marker version
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 190, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[210, 207, 225],
]
plugin = kwargs.get("plugin", None)
if plugin in ("pillow", "gdcm"):
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 190, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[210, 207, 225],
]
elif plugin == "pylibjpeg":
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 191, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[211, 207, 225],
]


JPGB_08_08_3_0_1F_RGB_APP14 = PixelReference(
Expand All @@ -1371,21 +1385,35 @@ def test(ref, arr, **kwargs):
# JPGB, (8, 8), (1, 256, 256, 3), OB, RGB, 0
# JPEG baseline in RGB colourspace with APP14 Adobe v101 marker
def test(ref, arr, **kwargs):
# Works with pillow and GDCM
# pylibjpeg: decoding error due to unknown Adobe marker version
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 190, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[210, 207, 225],
]
plugin = kwargs.get("plugin", None)
if plugin in ("pillow", "gdcm"):
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 190, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[210, 207, 225],
]
elif plugin == "pylibjpeg":
assert arr[99:104, 172].tolist() == [
[243, 244, 246],
[229, 224, 235],
[204, 191, 213],
[194, 176, 203],
[204, 188, 211],
]
assert arr[84, 239:243].tolist() == [
[229, 225, 234],
[174, 174, 202],
[187, 185, 203],
[211, 207, 225],
]


JPGB_08_08_3_0_1F_RGB_DCMD_APP14 = PixelReference(
Expand Down
25 changes: 0 additions & 25 deletions tests/pixels/test_decoder_pylibjpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
PIXEL_REFERENCE,
JPGE_BAD,
J2KR_16_13_1_1_1F_M2_MISMATCH,
JPGB_08_08_3_0_1F_RGB_APP14, # fails to decode
JPGB_08_08_3_0_1F_RGB_DCMD_APP14, # fails to decode
JLSN_08_01_1_0_1F,
)

Expand Down Expand Up @@ -64,10 +62,6 @@ class TestLibJpegDecoder:
@pytest.mark.parametrize("reference", PIXEL_REFERENCE[JPEGBaseline8Bit], ids=name)
def test_jpg_baseline(self, reference):
"""Test the decoder with JPEGBaseline8Bit."""
# Decoding failures due to unknown APP14 version
if reference in (JPGB_08_08_3_0_1F_RGB_APP14, JPGB_08_08_3_0_1F_RGB_DCMD_APP14):
return

decoder = get_decoder(JPEGBaseline8Bit)
arr = decoder.as_array(reference.ds, raw=True, decoding_plugin="pylibjpeg")
reference.test(arr, plugin="pylibjpeg")
Expand Down Expand Up @@ -141,25 +135,6 @@ def test_jpg_extended_invalid_se_raises(self):
with pytest.raises(RuntimeError, match=msg):
decoder.as_array(JPGE_BAD.ds, decoding_plugin="pylibjpeg")

def test_decode_failures(self):
"""Test decoding failures."""
decoder = get_decoder(JPEGBaseline8Bit)
msg = (
"Unable to decode as exceptions were raised by all available "
"plugins:\n pylibjpeg: libjpeg error code '-1038' returned "
r"from Decode\(\): A misplaced marker segment was found - Adobe "
"marker version unrecognized"
)
with pytest.raises(RuntimeError, match=msg):
decoder.as_array(
JPGB_08_08_3_0_1F_RGB_APP14.ds, decoding_plugin="pylibjpeg"
)

with pytest.raises(RuntimeError, match=msg):
decoder.as_array(
JPGB_08_08_3_0_1F_RGB_DCMD_APP14.ds, decoding_plugin="pylibjpeg"
)

def test_bits_allocated_mismatch(self):
"""Test the result when bits stored <= 8 and bits allocated 16"""
# The JPEG-LS codestream uses a precision of 8, so it will return
Expand Down

0 comments on commit cf472d3

Please sign in to comment.