feat(libSceJxr): implement quantizer remapping, AC prediction mode and zigzag scan setup #14933

Merged
Noxy-HNR merged 3 commits from upstream-pr/14933 into main 2026-11-05 18:46:14 +00:00
Noxy-HNR commented 2026-11-02 01:36:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-02T01:36:48Z.


What

Four libSceJxr codec helpers currently throw: remapQP, formatQuantizer, getACPredMode and InitZigzagScan. They now call jxrlib's strPredQuant.c, strcodec.c and image.c, built from 3rdparty/jxrlib, through a C bridge (src/NativeQuant.c). No jxrlib logic is copied into core/.

  • remapQP / formatQuantizer fill the 20-byte CWMIQuantizer (QP, offset, reciprocal mantissa/exponent) from its index, copying channel 0 or 1 first for uniform/mixed modes.
  • getACPredMode picks horizontal, vertical or no AC prediction from a 1,160-byte CWMIMBInfo.
  • InitZigzagScan fills the three 4x4 scan tables of a 704-byte CCodingContext; null is ignored, as in jxrlib.

The bridge asserts these layouts (LP64, without WMP_OPT_QT). The C++ adapters in src/Quantizer.cpp throw on a null quantizer, quantizer table, used channel or macroblock, on more than 16 channels, and on a scaled shift that would push the QP outside 32 bits. Review fix 7c1b94d83e calculates the shift plus index exponent in 64-bit arithmetic before checking its range; the regression covers INT32_MIN and INT32_MAX for indices 3 and 255. That the console's module uses these prototypes and layouts is inferred from the export names; nothing is checked on a console, and the debt file records this. No title unblock is claimed.

Tested

Latest independent verification at 7c1b94d83e: Windows 11 x86-64, WinLibs GCC 15.2.0, Release. Rebuilt guest_jxr_quantizer_tests, guest_jxr_stream_tests and guest_jxr_tests; 3/3 passed.

Linux source-level sanitizer probe: Ubuntu 26.04, GCC 15.2.0, -fsanitize=undefined -fno-sanitize-recover=all, UBSAN_OPTIONS=halt_on_error=1, using the exact adapter, C bridge and pinned native remapQP. All four extreme-shift calls throw without changing the quantizer; valid lossless and scaled calls reach the native implementation and pass their controls. The same probe with the pre-fix adapter from 21a07dbca2 stops on signed overflow in the exponent calculation. This is a focused source probe, not a full Linux guest-runtime run.

The earlier hosted Windows job passed all ten JXR tests but timed out in check_compile_test_crlf_and_quoted_response_definitions_compile_without_changing_build_outputs and avplayer_http_transport. After the PR was closed and reopened, the fresh Windows job passed on the same head, 7c1b94d83e. The latest conventions and library-portability checks also pass. The earlier timeouts were not reproduced or attributed to a specific cause.

Earlier reported validation:

New guest_jxr_quantizer test, comparing the guest exports with jxrlib called directly:

  • remapQP for all 256 indices, shifts 0 to 2, with and without scaled arithmetic, plus known values (lossless index 0, index 4, index 255).

  • 2,000 random formatQuantizer tables (1 to 16 channels, every mode).

  • 20,000 random macroblocks for getACPredMode across the colour formats, plus no, horizontal, vertical and balanced energy.

  • InitZigzagScan over a randomised context, and null.

  • Every rejected argument.

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream 93dbd0f82a: ctest -R guest_jxr 10/10 passed.

  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: ctest -R guest_jxr 10/10 passed, including the _patched lookup tests.

  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (399 libraries, 26,813 exports): passed.

  • python tools/pr_overlap.py --branch claude/jxr-quantizer (1,867 open PRs): no shared exports or new files. #14425, #14631, #14905 and #14916 touch neighbouring lines of CMakeLists.txt, Export.cpp, include/Api.hpp and the debt file. Merge order is #14905, #14916, then this PR. These are integration prerequisites, with no runtime dependency between the features. Rebase and rerun the focused tests after they merge.

No console or retail-title test.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #14905, #14916
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113619457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14933). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-02T01:36:48Z. --- ### What Four libSceJxr codec helpers currently throw: `remapQP`, `formatQuantizer`, `getACPredMode` and `InitZigzagScan`. They now call jxrlib's [strPredQuant.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strPredQuant.c#L79-L192), [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L861-L874) and [image.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/image.c#L173-L183), built from `3rdparty/jxrlib`, through a C bridge (`src/NativeQuant.c`). No jxrlib logic is copied into `core/`. - `remapQP` / `formatQuantizer` fill the 20-byte `CWMIQuantizer` (QP, offset, reciprocal mantissa/exponent) from its index, copying channel 0 or 1 first for uniform/mixed modes. - `getACPredMode` picks horizontal, vertical or no AC prediction from a 1,160-byte `CWMIMBInfo`. - `InitZigzagScan` fills the three 4x4 scan tables of a 704-byte `CCodingContext`; null is ignored, as in jxrlib. The bridge asserts these layouts (LP64, without `WMP_OPT_QT`). The C++ adapters in `src/Quantizer.cpp` throw on a null quantizer, quantizer table, used channel or macroblock, on more than 16 channels, and on a scaled shift that would push the QP outside 32 bits. Review fix `7c1b94d83e` calculates the shift plus index exponent in 64-bit arithmetic before checking its range; the regression covers `INT32_MIN` and `INT32_MAX` for indices 3 and 255. That the console's module uses these prototypes and layouts is inferred from the export names; nothing is checked on a console, and the debt file records this. No title unblock is claimed. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Latest independent verification at `7c1b94d83e`: Windows 11 x86-64, WinLibs GCC 15.2.0, Release. Rebuilt `guest_jxr_quantizer_tests`, `guest_jxr_stream_tests` and `guest_jxr_tests`; **3/3 passed**. Linux source-level sanitizer probe: Ubuntu 26.04, GCC 15.2.0, `-fsanitize=undefined -fno-sanitize-recover=all`, `UBSAN_OPTIONS=halt_on_error=1`, using the exact adapter, C bridge and pinned native `remapQP`. All four extreme-shift calls throw without changing the quantizer; valid lossless and scaled calls reach the native implementation and pass their controls. The same probe with the pre-fix adapter from `21a07dbca2` stops on signed overflow in the exponent calculation. This is a focused source probe, not a full Linux guest-runtime run. The earlier [hosted Windows job](https://github.com/boykopovar/AnyPS5/actions/runs/41510076953/job/125499560710) passed all ten JXR tests but timed out in `check_compile_test_crlf_and_quoted_response_definitions_compile_without_changing_build_outputs` and `avplayer_http_transport`. After the PR was closed and reopened, the [fresh Windows job](https://github.com/boykopovar/AnyPS5/actions/runs/41519531781/job/125538919047) passed on the same head, `7c1b94d83e`. The latest conventions and library-portability checks also pass. The earlier timeouts were not reproduced or attributed to a specific cause. Earlier reported validation: New `guest_jxr_quantizer` test, comparing the guest exports with jxrlib called directly: - `remapQP` for all 256 indices, shifts 0 to 2, with and without scaled arithmetic, plus known values (lossless index 0, index 4, index 255). - 2,000 random `formatQuantizer` tables (1 to 16 channels, every mode). - 20,000 random macroblocks for `getACPredMode` across the colour formats, plus no, horizontal, vertical and balanced energy. - `InitZigzagScan` over a randomised context, and null. - Every rejected argument. - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream `93dbd0f82a`: `ctest -R guest_jxr` **10/10 passed**. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: `ctest -R guest_jxr` **10/10 passed**, including the `_patched` lookup tests. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (399 libraries, 26,813 exports): passed. - `python tools/pr_overlap.py --branch claude/jxr-quantizer` (1,867 open PRs): no shared exports or new files. #14425, #14631, #14905 and #14916 touch neighbouring lines of `CMakeLists.txt`, `Export.cpp`, `include/Api.hpp` and the debt file. Merge order is #14905, #14916, then this PR. These are integration prerequisites, with no runtime dependency between the features. Rebase and rerun the focused tests after they merge. No console or retail-title test. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #14905, #14916 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14933
No description provided.