Imaging extension: add optional pure-Rust JPEG 2000 backend #109
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Objective
Add a complete optional pure-Rust JPEG 2000 backend behind a Cargo feature named
rust-j2k. Use the pure-Rustj2kcrate from the current compatible 0.8 release line as the codec engine. The backend must implement the same LibreMetaverse/CoreJ2K behavior and the same bounded imaging contract as the existing OpenJPEG backend; it must not be a stub, decode-only fallback, or 8-bit convenience wrapper.The existing C# source and translated/golden tests are the behavioral reference. Do not run or depend on .NET code.
Current architecture
libremetaverse-imaging/jpeg2000enables the optional project-ownedlibremetaverse-openjpegadapter.crates/libremetaverse-imaging/src/jpeg2000.rscurrently ownsJ2kCodec,J2kFormat,J2kCompression,J2kDecodeOptions,J2kEncodeOptions, component conversion, bounds enforcement, and OpenJPEG adaptation.libremetaverse/jpeg2000feature forwards to that backend.j2kversion compatible with that floor and record the exact audited version inCargo.lock.Feature and API design
j2kand featurerust-j2k = ["dep:j2k"]tolibremetaverse-imaging.rust-j2k = ["libremetaverse-imaging/rust-j2k"]to the umbrellalibremetaversecrate.rust-j2kfeature must not enable, link, or transitively requirelibremetaverse-openjpeg, OpenJPEG, CMake, pkg-config, vcpkg, or another native codec.jpeg2000feature andJ2kCodecbehavior without a breaking rename. Expose the Rust backend explicitly, for example asRustJ2kCodec, implementingITextureCodecand the same byte/interleaved encode/decode operations.jpeg2000andrust-j2ktogether must compile and expose both backends.--all-featuresmust remain valid. Do not use feature ordering or a conditional type alias that silently changes which backendJ2kCodecmeans.Required behavior
Decode
ManagedImage.discard_levels,quality_layers, and strict/truncated-input behavior. Zero quality layers means all layers. Do not accept and ignore an option: if the upstream facade lacks a required control, add a real bounded adapter or contribute the missing capability upstream before completing this issue.Errorvariants without panic.Encode
J2kFormat.max_encoded_bytesand return a typed failure rather than truncating output.Resource safety
j2kAPIs where available. Decoder-controlled dimensions must never cause allocation beforemax_pixelsandDEFAULT_MAX_PIXELSare enforced.Tests
Refactor the codec contract tests so the same assertions run independently against OpenJPEG and
RustJ2kCodec, while retaining backend-specific tests where needed. Add at least:Tests must be deterministic, offline, and must not generate fixtures by invoking C#, OpenJPEG command-line programs, or network services at test time. Small audited fixtures may be checked in with provenance.
Validation gates
The implementation is complete only when all of the following pass:
Also verify the pure-Rust feature dependency tree contains neither
libremetaverse-openjpegnor a native OpenJPEG binding, and add CI coverage for Rust 1.96 plus current stable on Linux, Windows, and macOS.Documentation and audit
rust-j2kbuild and test commands and explain how it differs fromjpeg2000.docs/imaging-meshing.mdand relevant crate documentation with backend selection, supported formats/options, feature coexistence, MSRV, limits, and deployment implications.j2kversion, license, repository, safety posture, and relevant transitive dependencies in the dependency/license audit.rust-j2kis only planned once the feature is actually usable.Definition of done
A user can build MetaCrate with
--no-default-features --features rust-j2k, encode and decode compatible J2K and JP2 textures entirely in Rust, and pass the existing C#-derived imaging requirements without installing OpenJPEG or any other native JPEG 2000 library. Existing default and OpenJPEG builds remain unchanged, and every feature combination above is tested in isolation.Implemented the optional pure-Rust JPEG 2000 backend and verified it end to end.
Implementation:
Verification:
Primary implementation commit:
0bab5b4. Protected-main follow-up commits refresh deterministic audit evidence and serialize ARM64 Cargo work to avoid all-features clippy OOM; final verified tip:e1744f4.