← Back to Pull requests

cuslide2: raise an error instead of returning zeros when no JPEG 2000 decoder is loaded #1222

Closed
unknown closed this pull request without merging on Nov 23, 2026 20:49 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 18:26 UTC
Author

The issue fixed was discovered along with #1211 and described there, but was not the main focus of that issue.

This PR is on top of #1219 (https://github.com/rapidsai/cucim/pull/1219), which adds the
synthetic-image tests that this PR extends. Until #1219 is merged, this PR also shows its two
commits. The change here is the last commit.

Summary

If the nvJPEG2000 or nvTIFF library cannot be loaded, read_region on a JPEG 2000 TIFF (Aperio
compression 33003 and 33005, or TIFF compression 34712) returns an all-zero image without an
error
, on the CPU and on the GPU. nvImageCodec prints Failed to load nvjpeg2k library! or
Failed to load nvtiff library! once, and OpenCV prints
Compression scheme 33003 tile decoding is not implemented for each tile, but the call returns
normally. The caller cannot tell the image from a black one.

Cause: nvImageCodec has CPU-only fallback decoders for TIFF (libtiff and OpenCV extensions). They
accept a JPEG 2000 TIFF, fail on every tile, and report success. cuslide2 checks the processing
status of the decode, but the status is success.

#1219 adds the nvImageCodec extras to the pip requirements, which removes the usual cause for pip
installs. This PR makes the failure visible when the libraries are missing anyway (a pip install
without the extras, a conda environment without libnvjpeg2k or libnvtiff, or a system install).

Changes

  • NvImageCodecTiffParserManager::get_decoder_for(codec, compression_known) returns the default

  • decoder, except for JPEG 2000 IFDs, and for IFDs whose compression is not known because no TIFF
    tags were returned (nvTIFF is not loaded, so the compression cannot be ruled out). For those it
    returns a second decoder, created on first use, that allows only the GPU-only, hybrid CPU/GPU and
    hardware backends and not the CPU-only ones. If nvJPEG2000 or nvTIFF is missing, nvImageCodec then
    reports that the image cannot be decoded, and the existing error path raises.
  • The three decode functions (single ROI, batch, async batch) get their decoder from

  • get_decoder_for.
  • The "Failed to decode IFD" error now names the missing libraries and the pip and conda packages.

  • With no GPU (the CPU-only mode of the plugin) or when the restricted decoder cannot be created,

  • the default decoder is used as before.
  • Test: test_cuslide2_jpeg2000_is_decoded_or_an_error writes a JPEG 2000 TIFF with tifffile

  • (33003, 33005 and 34712). A read must either match the source image (mean absolute error of at
    most 1) or raise an error that mentions nvImageCodec, and must never return blank data. No sample
    data is downloaded.

    Behavior change

    Without nvTIFF, every compression now raises. Before, JPEG, Deflate and LZW TIFFs were decoded
    correctly by the CPU fallbacks, but with a wrong pyramid (extra levels for the macro, thumbnail and
    label images) and tile sizes of (0, 0), so the image was not usable as a slide anyway. A pip
    install with the extras from #1219 is not affected. Only a setup without nvTIFF is. If you prefer,
    this can be limited to IFDs that are known to be JPEG 2000 (the second case in get_decoder_for),
    which keeps the old behavior without nvTIFF but leaves the all-zero result in that setup.

    Testing

    I built the plugin from this branch against a source build of libcucim and ran the new test with
    three nvImageCodec layouts, with the old plugin (before this change) and the new one:

    | nvImageCodec layout | old plugin | new plugin |
    |---|---|---|
    | pip package, no extras | 3 failed: blank region | 3 passed: error raised |
    | pip package plus nvTIFF only | 3 failed: blank region | 3 passed: error raised |
    | all libraries | 3 passed | 3 passed |

    With all libraries, the 7 tests of test_cuslide2_plugin.py pass (the pyramids and pixels of
    Deflate, LZW, JPEG and JPEG 2000 TIFFs on the CPU and the GPU). With the pip layout without extras,
    the pyramid tests now fail with the new error instead of reading a wrong pyramid.

    The libnvimgcodec libraries in these layouts are not loaded the same way in every environment, so
    I did not add a test that removes them. The new test is a regression check that is useful when run
    where a library is missing, and it passes where all libraries are present, as in CI.

    Diff: 532 lines (+399 / -133) across 6 files Reviewer: gigony Review duration: 20303m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 532 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1222"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.9% · Safe to merge
    18.9%
    Repository