From f48f7832bccda869fa6389577045e71d18b42687 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sat, 7 Dec 2024 13:23:54 +0000 Subject: [PATCH] [ts-registry] Update jpegxl decoder - update to jxl-oxide 0.10.2 - use write_to_buffer:: and write_to_buffer:: where applicable --- Cargo.lock | 56 ++++++++++++------- transfer-syntax-registry/Cargo.toml | 2 +- .../src/adapters/jpegxl.rs | 55 ++++++++++++------ 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa30e13f..9eb40cf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1227,18 +1227,18 @@ dependencies = [ [[package]] name = "jxl-bitstream" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5855ff16398ffbcf81fee52c41ca65326499c8764b21bb9952c367ace98995fb" +checksum = "116184a8c915e99b08c7a4abca038b05863980bbf9e433dc2883363853c99afe" dependencies = [ "tracing", ] [[package]] name = "jxl-coding" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da5b5093904e940bc11ef50e872c7bdf7b6e88653f012b925f8479daf212b5c9" +checksum = "0dd7ffdab0c48e989f23a8bd6113d88bd243ae45c7871e90cfdcb6997eacbfb2" dependencies = [ "jxl-bitstream", "tracing", @@ -1246,28 +1246,30 @@ dependencies = [ [[package]] name = "jxl-color" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ec11695f2091e50531c970ad7eb4819989a20a2c89d68ae1b4f74f48454c10" +checksum = "4806c94be9e37c82e571684ad673af0a2e4049a74942c407034da6a087c4de7b" dependencies = [ "jxl-bitstream", "jxl-coding", "jxl-grid", + "jxl-oxide-common", "jxl-threadpool", "tracing", ] [[package]] name = "jxl-frame" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4719f285ebfff5e64f352d0ef149a5244aef4f8e6b5aa666ba6241e90b50632f" +checksum = "1649956cb002031108e1fa44e0e483a770e2e95f4544137788c32265db0b8c71" dependencies = [ "jxl-bitstream", "jxl-coding", "jxl-grid", "jxl-image", "jxl-modular", + "jxl-oxide-common", "jxl-threadpool", "jxl-vardct", "tracing", @@ -1275,59 +1277,71 @@ dependencies = [ [[package]] name = "jxl-grid" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13a28ba2734da33624db4b426b44750a7b1238e6cba65d27b7d84bf3cba7f507" +checksum = "80f25f406f215f07f0b994801bc2d6adbfcd5710fcdd8f12d662e80700469e6c" dependencies = [ "tracing", ] [[package]] name = "jxl-image" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3824c81613c05c19a9e4329d569145d3f460c0fcadb3965bd8418162d43f7f4" +checksum = "1de3283303bb66b1742538f1a6947313596242598d6ddf325f301c2fbf01abd3" dependencies = [ "jxl-bitstream", "jxl-color", "jxl-grid", + "jxl-oxide-common", "tracing", ] [[package]] name = "jxl-modular" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e10bbc6041d9ea64bcfc6931ed89f0192954ac0a02bdbad624aa43b345e613" +checksum = "b3f2fd5a3346deda8169f6b26aa6c955c32bd275377b527415ef2e5f362e00ad" dependencies = [ "jxl-bitstream", "jxl-coding", "jxl-grid", + "jxl-oxide-common", "jxl-threadpool", "tracing", ] [[package]] name = "jxl-oxide" -version = "0.9.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f3b9dbe4adefadac57b25a15bf7735202ba58c0e5500c6bfb2d63398bf21c2" +checksum = "67a42a404a09f4704e60ad102eb995ac074cad467df48631c1a1269b97eef3c5" dependencies = [ "jxl-bitstream", "jxl-color", "jxl-frame", "jxl-grid", "jxl-image", + "jxl-oxide-common", "jxl-render", "jxl-threadpool", "tracing", ] +[[package]] +name = "jxl-oxide-common" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4efb65a6ef812eae1083e5d2d1a4358bd74cf7e08d112f6e939a40003a6a9920" +dependencies = [ + "jxl-bitstream", +] + [[package]] name = "jxl-render" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4259446ca029587f2b7850d223d57b4f69665dd8628e83bcb0a6c2ab964f1ef" +checksum = "b9b7162076893570cdeaced01086893df132ff8b2eaf22d63ed3b066d9b88739" dependencies = [ "jxl-bitstream", "jxl-coding", @@ -1336,6 +1350,7 @@ dependencies = [ "jxl-grid", "jxl-image", "jxl-modular", + "jxl-oxide-common", "jxl-threadpool", "jxl-vardct", "tracing", @@ -1354,14 +1369,15 @@ dependencies = [ [[package]] name = "jxl-vardct" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15da4b49b832b3d8a67329f47e2a1732e0847667938bb9b4a37d99a4668775c2" +checksum = "737b4a65897907c644329c8a54e042cefdec2989e482698eea150d463e475fe5" dependencies = [ "jxl-bitstream", "jxl-coding", "jxl-grid", "jxl-modular", + "jxl-oxide-common", "jxl-threadpool", "tracing", ] diff --git a/transfer-syntax-registry/Cargo.toml b/transfer-syntax-registry/Cargo.toml index cf91f741..8b13e726 100644 --- a/transfer-syntax-registry/Cargo.toml +++ b/transfer-syntax-registry/Cargo.toml @@ -75,7 +75,7 @@ optional = true features = ["static"] [dependencies.jxl-oxide] -version = "0.9.1" +version = "0.10.2" optional = true [dependencies.zune-jpegxl] diff --git a/transfer-syntax-registry/src/adapters/jpegxl.rs b/transfer-syntax-registry/src/adapters/jpegxl.rs index bd20ea81..00c42b83 100644 --- a/transfer-syntax-registry/src/adapters/jpegxl.rs +++ b/transfer-syntax-registry/src/adapters/jpegxl.rs @@ -87,33 +87,56 @@ impl PixelDataReader for JpegXlAdapter { let mut stream = frame.stream(); - // write all f32 samples to a buffer - - let mut buffer = - vec![ - 0_f32; - stream.channels() as usize * stream.width() as usize * stream.height() as usize - ]; - - let count = stream.write_to_buffer(&mut buffer); - buffer.truncate(count); - - // convert samples to the destination buffer depending on bit depth + // write and convert samples to the destination buffer depending on bit depth match bits_allocated { 1 => { whatever!("Unsupported bit depth 1 by JPEG XL decoder"); } 8 => { - for &sample in &buffer { - dst.push((sample * 255.) as u8); - } + // write directly to dst as u8 samples + + let samples_per_frame = stream.channels() as usize * stream.width() as usize * stream.height() as usize; + + dst.try_reserve(samples_per_frame) + .whatever_context("Failed to reserve heap space for JPEG XL frame")?; + + let offset = dst.len(); + dst.resize(offset + samples_per_frame, 0); + + let count = stream.write_to_buffer(&mut dst[offset..]); + dst.truncate(offset + count); } 16 => { + // write all u16 samples to a buffer + + let mut buffer = + vec![ + 0_u16; + stream.channels() as usize * stream.width() as usize * stream.height() as usize + ]; + + let count = stream.write_to_buffer(&mut buffer); + buffer.truncate(count); + + // pass them as bytes in native endian + for &sample in &buffer { - dst.extend_from_slice(&((sample * 65535.) as u16).to_ne_bytes()); + dst.extend_from_slice(&sample.to_ne_bytes()); } } 24 => { + // write all f32 samples to a buffer + + let mut buffer = + vec![ + 0_f32; + stream.channels() as usize * stream.width() as usize * stream.height() as usize + ]; + + let count = stream.write_to_buffer(&mut buffer); + buffer.truncate(count); + + // then convert them to 24-bit integers for &sample in &buffer { let bytes = &((sample * 16777215.) as u32).to_ne_bytes(); dst.extend_from_slice(&bytes[..3]);