Skip to content

feat(libSceJxr): implement the pixel format hash, image IID lookups, aligned allocation and IDPEmpty - #14905

Merged
oneandonlydean merged 6 commits into
boykopovar:mainfrom
Noxy-HNR:claude/jxr-glue-helpers
Nov 5, 2026
Merged

oneandonlydean merged 6 commits into
boykopovar:mainfrom
Noxy-HNR:claude/jxr-glue-helpers

Conversation

@Noxy-HNR

@Noxy-HNR Noxy-HNR commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Six named libSceJxr exports currently throw: GetPixelFormatFromHash, GetImageEncodeIID, GetImageDecodeIID, PKAllocAligned, PKFreeAligned and IDPEmpty. Implement them from Microsoft's jxrlib at the pinned submodule commit, JXRGlue.c and strcodec.c:

  • GetPixelFormatFromHash calls the pinned jxrlib through a C bridge, like PixelFormatLookup, and returns its read-only GUID for the hash (the GUID's last byte), or null.
  • GetImageEncodeIID / GetImageDecodeIID match .jxr, .wdp and .hdp as case-insensitive prefixes and store the exported IID_PKImageWmpEncode (101) / IID_PKImageWmpDecode (201). .wdp and .hdp encoding store a private IID_PKImageUnsupported (100), which the module does not export. Unknown extensions return WMP_errUnsupportedFormat (-106) without writing the output.
  • PKAllocAligned takes size + 8 + alignment - 1 bytes from the guest calloc, stores the original pointer just below the aligned block and returns WMP_errOutOfMemory (-101) when calloc fails. PKFreeAligned releases that original pointer through the guest free.
  • IDPEmpty returns ICERR_OK (0).

The third-party algorithms stay in the unmodified, source-built 3rdparty/jxrlib dependency, with its license notices retained. NativeGlue.c bridges to JXRGlue.c and strcodec.c; GlueHelpers.cpp supplies the guest ABI, argument checks and IID-object mapping. A dedicated JXRGlue.c build routes calloc and free through the guest heap. Null outputs, alignments below 8 and overflowing block sizes throw before entering jxrlib. That the console's module is jxrlib with these prototypes is inferred from the export names; nothing is checked on a console. These limits are recorded in the library's debt file. No title unblock is claimed.

Merge order: this PR follows #14425 and #14631. Both merge cleanly with current main individually, but their combination with this branch conflicts in the shared JXR files. There is no runtime dependency on either implementation; the dependency line records integration order. Rebase and rerun guest_jxr after those PRs merge. The current pairwise preview with #7645 is clean.

Tested

Latest follow-up verification at c7a34875b0: rebuilt guest_jxr_glue_tests, guest_jxr_stream_tests and guest_jxr_tests on Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release. ctest -R '^guest_jxr(_glue|_stream)?$': 3/3 passed. This directly checks the new native glue, the guest allocator routing and existing stream helpers. Conventions and whitespace checks passed. The hosted Windows, conventions and library-portability checks also pass at this head. The earlier 10-test runs below are retained as prior verification; Linux and patched lookup tests were not rerun in this follow-up.

New guest_jxr_glue test: all 256 hashes against the pinned jxrlib's GetPixelFormatFromHash (null-ness and GUID bytes), the IID lookups for each extension, case, prefix and unknown extension with and without an output, aligned allocation for alignments 8, 16, 24, 64 and 4096 and sizes 0, 1 and 100 through a recording application allocator (calloc arguments, alignment, zero fill, stored original pointer, release), calloc failure, null and too-small alignments and size overflow.

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream 0580e5c951: 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 against the patched libSceJxr.prx.
  • python tools/check_conventions.py --base origin/main, git diff --check and python core/libs/tests/test_public_headers.py --audit-only (399 libraries, 26,743 exports): passed.
  • python tools/pr_overlap.py --branch claude/jxr-glue-helpers (1,849 open PRs): feat(libSceJxr): implement PKAlloc #14425 (PKAlloc) and feat(libSceJxr): implement WMPAlloc, WMPFree and the memory stream #14631 (WMPAlloc, WMPFree, memory stream) touch neighbouring lines of CMakeLists.txt, Export.cpp, include/Api.hpp and the debt file; neither shares an export or new file. Whichever lands second needs a small rebase. fix(tests): stage linked .prx runtime files next to test executables on Windows #7645 also edits libSceJxr/CMakeLists.txt (Windows DLL staging for guest_jxr_lookup_tests); if it lands first, guest_jxr_glue_tests may need the same treatment.

No console or retail-title test.

Checklist

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Progress report (151a2cb → 642d95d)

📈 System libraries: 27.08% (+0.01%, +6 implemented functions)

✅ 6 implemented
Library Name
libSceJxr GetImageDecodeIID_nid_postfix
libSceJxr GetImageEncodeIID_nid_postfix
libSceJxr GetPixelFormatFromHash_nid_postfix
libSceJxr IDPEmpty_nid_postfix
libSceJxr PKAllocAligned_nid_postfix
libSceJxr PKFreeAligned_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceJxr 17/136 (12.50%) 23/136 (16.91%) +4.41%

@Noxy-HNR
Noxy-HNR marked this pull request as ready for review November 2, 2026 00:31
@Noxy-HNR

Noxy-HNR commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@AlexWhitehouse @ahmadmuj I checked this branch against #14425 and #14631. All three merge cleanly with main individually, but the combined branches conflict in the shared JXR declarations/debt; #14425 also conflicts in the build file and placeholder removals.

I've recorded Depends on: #14425, #14631 so this PR defers to both older changes. This records merge order, with no runtime dependency on either implementation. After they merge, this branch will need a rebase and the guest_jxr tests rerun. Please let me know if that order conflicts with your plans.

The current pairwise preview with #7645 is clean. The latest Windows, conventions and library-portability checks pass. This PR is ready for review; console behavior remains unverified as documented.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for this. At e89a05b55b7660c4d2717e4725c618a40684881d, could you resolve the adapted jxrlib implementation's placement under CONTRIBUTING.md:17 before landing?

core/libs/prx/libSceJxr/src/GlueHelpers.cpp:30 and :38 adapt the reference prefix lookup and IID table, while :73 and :95 adapt the reference aligned allocation/free algorithm. They are compiled directly from core/ at core/libs/prx/libSceJxr/CMakeLists.txt:5, although cmake/Jxr.cmake:37 already builds the pinned JXRGlue.c through 3rdparty/jxrlib. Please keep third-party implementation in the source-built dependency, with the guest ABI, argument checks and allocator routing in thin adapters. Preserve the dependency's license notices in any adapted source arrangement.

core/libs/prx/libSceJxr/src/NativeHash.c:4 already uses the thin-bridge pattern for the hash lookup. I found no separate functional defect in the IID mappings, original-pointer allocation/free pairing or IDPEmpty; this request concerns the placement of adapted reference implementation, not the constant return of the reference's empty hook.

Address review: the pixel-format hash, image IID lookups, aligned
allocation and IDPEmpty now call jxrlib's JXRGlue.c and strcodec.c from
3rdparty/jxrlib through a C bridge instead of adapted copies in core/.
A dedicated build of JXRGlue.c routes its calloc and free to the guest
heap; the C++ adapters keep only the guest ABI, argument checks and IID
object mapping. Alignments below 8 are now rejected up front, since
jxrlib would write the original pointer before the block.
@Noxy-HNR

Noxy-HNR commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, done in 1c522615fe (plus c7a34875b0, which drops the explanatory comments per CONVENTIONS).

The jxrlib logic is no longer adapted in core/. GetImageEncodeIID, GetImageDecodeIID, PKAllocAligned, PKFreeAligned, GetPixelFormatFromHash and IDPEmpty now call the pinned JXRGlue.c and strcodec.c from 3rdparty/jxrlib through the C bridge src/NativeGlue.c (which replaces NativeHash.c), so the license notices stay with the unmodified sources.

To route jxrlib's allocator to the guest heap without copying it, a new jxr_glue_guest target builds JXRGlue.c with a forced include of src/GuestHeap.h, which maps its calloc and free to the guest calloc and free. That archive is linked ahead of jxr, so it is the only JXRGlue.c in the module.

GlueHelpers.cpp is now only the thin adapter: the guest ABI, argument checks, and mapping jxrlib's IID values to the module's exported IID objects. One behavior change: alignments below 8 are now rejected before allocating, because jxrlib can then store the original pointer before the block, and an adapter can't intercept that halfway through. The debt entries are updated to match.

guest_jxr* passes 10/10 on Linux and on Windows (WinLibs GCC 15.2.0), with each JXRGlue symbol defined once in the module. The glue test still checks the allocations go through the hooked guest calloc/free.

BunnyFl added a commit to BunnyFl/AnyPS5 that referenced this pull request Nov 3, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 5, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @Noxy-HNR, I merged main (151a2cb6e2, merge 642d95d3b3) into this branch so it can land, after the quantizer work landed in libSceJxr. In CMakeLists.txt I kept your glue library and tests together with main's src/Quantizer.cpp and quantizer tests; in include/Api.hpp both sets of declarations are kept, and the placeholder block in Export.cpp is gone because each side implemented the entries the other still stubbed. The debt doc keeps both entries, with the count set to 113 (the stubs left in the merged Export.cpp). libSceJxr and the guest_jxr tests build and pass locally. No other changes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@oneandonlydean
oneandonlydean merged commit 55064c8 into boykopovar:main Nov 5, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants