diff --git a/.gitmodules b/.gitmodules
index 6df9925..049bbb8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "libjxl"]
path = jpegxl-src/libjxl
url = https://github.com/libjxl/libjxl
- branch = tags/v0.8.2
+ branch = tags/v0.9.1
diff --git a/jpegxl-rs/Cargo.toml b/jpegxl-rs/Cargo.toml
index b147c72..b4572fe 100644
--- a/jpegxl-rs/Cargo.toml
+++ b/jpegxl-rs/Cargo.toml
@@ -8,7 +8,7 @@ license = "GPL-3.0-or-later"
name = "jpegxl-rs"
readme = "README.md"
repository = "https://github.com/inflation/jpegxl-rs"
-version = "0.8.3+libjxl-0.8.2"
+version = "0.9.0+libjxl-0.9.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -29,12 +29,12 @@ bench = []
[dependencies]
derive_builder = "0.12.0"
image = { version = "0.24.7", optional = true, default-features = false }
-thiserror = "1.0.50"
+thiserror = "1.0.51"
half = "2.3.1"
byteorder = "1.5.0"
[dependencies.jpegxl-sys]
-version = "0.8.2"
+version = "0.9.0"
path = "../jpegxl-sys"
[dev-dependencies]
@@ -42,7 +42,7 @@ image = { version = "0.24.7", default-features = false, features = [
"jpeg",
"png",
] }
-lcms2 = "6.0.0"
+lcms2 = "6.0.3"
testresult = "0.3.0"
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
diff --git a/jpegxl-rs/src/common.rs b/jpegxl-rs/src/common.rs
index 2813815..cb3c19f 100644
--- a/jpegxl-rs/src/common.rs
+++ b/jpegxl-rs/src/common.rs
@@ -19,10 +19,11 @@ along with jpegxl-rs. If not, see .
use byteorder::{ByteOrder, NativeEndian, BE, LE};
use half::f16;
-use jpegxl_sys::{JxlDataType, JxlPixelFormat};
+
+use jpegxl_sys::types::{JxlDataType, JxlPixelFormat};
/// Endianness of the pixels
-pub type Endianness = jpegxl_sys::JxlEndianness;
+pub type Endianness = jpegxl_sys::types::JxlEndianness;
mod private {
pub trait Sealed {}
diff --git a/jpegxl-rs/src/decode.rs b/jpegxl-rs/src/decode.rs
index 54f21d8..cf43ede 100644
--- a/jpegxl-rs/src/decode.rs
+++ b/jpegxl-rs/src/decode.rs
@@ -20,7 +20,11 @@ along with jpegxl-rs. If not, see .
use std::{mem::MaybeUninit, ptr::null};
#[allow(clippy::wildcard_imports)]
-use jpegxl_sys::*;
+use jpegxl_sys::{
+ codestream_header::{JxlBasicInfo, JxlOrientation},
+ decode::*,
+ types::{JxlDataType, JxlPixelFormat},
+};
use crate::{
common::{Endianness, PixelType},
@@ -84,7 +88,7 @@ impl Default for PixelFormat {
pub struct JxlDecoder<'pr, 'mm> {
/// Opaque pointer to the underlying decoder
#[builder(setter(skip))]
- dec: *mut jpegxl_sys::JxlDecoder,
+ dec: *mut jpegxl_sys::decode::JxlDecoder,
/// Override desired pixel format
pub pixel_format: Option,
@@ -298,7 +302,6 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
}
s::NeedPreviewOutBuffer => todo!(),
s::BoxNeedMoreOutput => todo!(),
- s::Extensions => todo!(),
s::PreviewImage => todo!(),
s::Frame => todo!(),
s::Box => todo!(),
@@ -351,19 +354,13 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
fn get_icc_profile(&self, icc_profile: &mut Vec) -> Result<(), DecodeError> {
let mut icc_size = 0;
check_dec_status(unsafe {
- JxlDecoderGetICCProfileSize(
- self.dec,
- null(),
- JxlColorProfileTarget::Data,
- &mut icc_size,
- )
+ JxlDecoderGetICCProfileSize(self.dec, JxlColorProfileTarget::Data, &mut icc_size)
})?;
icc_profile.resize(icc_size, 0);
check_dec_status(unsafe {
JxlDecoderGetColorAsICCProfile(
self.dec,
- null(),
JxlColorProfileTarget::Data,
icc_profile.as_mut_ptr(),
icc_size,
diff --git a/jpegxl-rs/src/decode/result.rs b/jpegxl-rs/src/decode/result.rs
index ec51515..408f536 100644
--- a/jpegxl-rs/src/decode/result.rs
+++ b/jpegxl-rs/src/decode/result.rs
@@ -16,7 +16,7 @@ along with jpegxl-rs. If not, see .
*/
use half::f16;
-use jpegxl_sys::{JxlDataType, JxlPixelFormat};
+use jpegxl_sys::types::{JxlDataType, JxlPixelFormat};
use super::Orientation;
use crate::common::PixelType;
diff --git a/jpegxl-rs/src/encode.rs b/jpegxl-rs/src/encode.rs
index 84f8919..467e7e6 100644
--- a/jpegxl-rs/src/encode.rs
+++ b/jpegxl-rs/src/encode.rs
@@ -17,10 +17,15 @@ along with jpegxl-rs. If not, see .
//! Encoder of JPEG XL format
-#[allow(clippy::wildcard_imports)]
-use jpegxl_sys::*;
use std::{marker::PhantomData, mem::MaybeUninit, ops::Deref, ptr::null};
+#[allow(clippy::wildcard_imports)]
+use jpegxl_sys::{
+ color_encoding::JxlColorEncoding,
+ encode::*,
+ types::{JxlEndianness, JxlPixelFormat},
+};
+
use crate::{
common::PixelType, errors::EncodeError, memory::MemoryManager, parallel::JxlParallelRunner,
};
@@ -165,7 +170,7 @@ impl Deref for EncoderResult {
pub struct JxlEncoder<'prl, 'mm> {
/// Opaque pointer to the underlying encoder
#[builder(setter(skip))]
- enc: *mut jpegxl_sys::JxlEncoder,
+ enc: *mut jpegxl_sys::encode::JxlEncoder,
/// Opaque pointer to the encoder options
#[builder(setter(skip))]
options_ptr: *mut JxlEncoderFrameSettings,
@@ -289,8 +294,6 @@ impl JxlEncoder<'_, '_> {
JxlEncoderError::NotSupported => Err(EncodeError::NotSupported),
JxlEncoderError::ApiUsage => Err(EncodeError::ApiUsage),
},
- #[allow(deprecated)]
- JxlEncoderStatus::NotSupported => Err(EncodeError::NotSupported),
JxlEncoderStatus::NeedMoreOutput => Err(EncodeError::NeedMoreOutput),
}
}
diff --git a/jpegxl-rs/src/errors.rs b/jpegxl-rs/src/errors.rs
index 25cac11..0b32e44 100644
--- a/jpegxl-rs/src/errors.rs
+++ b/jpegxl-rs/src/errors.rs
@@ -17,10 +17,10 @@ along with jpegxl-rs. If not, see .
//! Decoder and encoder errors
-#[allow(clippy::wildcard_imports)]
-use jpegxl_sys::*;
use thiserror::Error;
+use jpegxl_sys::{decode::JxlDecoderStatus, encode::JxlEncoderError};
+
/// Errors derived from [`JxlDecoderStatus`]
#[derive(Error, Debug)]
#[non_exhaustive]
diff --git a/jpegxl-rs/src/image.rs b/jpegxl-rs/src/image.rs
index eb400c3..6050111 100644
--- a/jpegxl-rs/src/image.rs
+++ b/jpegxl-rs/src/image.rs
@@ -22,7 +22,7 @@ along with jpegxl-rs. If not, see .
use std::mem::MaybeUninit;
use image::{DynamicImage, ImageBuffer};
-use jpegxl_sys::{JxlDataType, JxlPixelFormat};
+use jpegxl_sys::types::{JxlDataType, JxlPixelFormat};
use crate::{
common::PixelType,
diff --git a/jpegxl-rs/src/tests/encode.rs b/jpegxl-rs/src/tests/encode.rs
index 01e25f9..b5f44ab 100644
--- a/jpegxl-rs/src/tests/encode.rs
+++ b/jpegxl-rs/src/tests/encode.rs
@@ -178,7 +178,7 @@ fn gray() -> TestResult {
)?;
_ = decoder.decode(&result)?;
- encoder.set_frame_option(jpegxl_sys::FrameSetting::BrotliEffort, 1)?;
+ encoder.set_frame_option(jpegxl_sys::encode::FrameSetting::BrotliEffort, 1)?;
Ok(())
}
diff --git a/jpegxl-rs/src/utils.rs b/jpegxl-rs/src/utils.rs
index 7afaabc..ef4c2f0 100644
--- a/jpegxl-rs/src/utils.rs
+++ b/jpegxl-rs/src/utils.rs
@@ -17,7 +17,7 @@ along with jpegxl-rs. If not, see .
//! Utils functions when a decoder or encoder is not needed
-use jpegxl_sys::{JxlSignature, JxlSignatureCheck};
+use jpegxl_sys::decode::{JxlSignature, JxlSignatureCheck};
/// Check if the signature of the input is valid.
/// Return `None` if it needs more data.
diff --git a/jpegxl-src/Cargo.toml b/jpegxl-src/Cargo.toml
index ac0247e..04f1024 100644
--- a/jpegxl-src/Cargo.toml
+++ b/jpegxl-src/Cargo.toml
@@ -6,7 +6,7 @@ license = "BSD-3-Clause"
name = "jpegxl-src"
readme = "README.md"
repository = "https://github.com/inflation/jpegxl-rs"
-version = "0.8.2"
+version = "0.9.1"
exclude = [
"libjxl/third_party/libpng",
"libjxl/third_party/sjpeg",
@@ -33,3 +33,5 @@ exclude = [
[dependencies]
cmake = "0.1.50"
+
+[features]
diff --git a/jpegxl-src/libjxl b/jpegxl-src/libjxl
index 954b460..b8ceae3 160000
--- a/jpegxl-src/libjxl
+++ b/jpegxl-src/libjxl
@@ -1 +1 @@
-Subproject commit 954b460768c08a147abf47689ad69b0e7beff65e
+Subproject commit b8ceae3a6e9d0ffd9efebcbdd04322fcfc502eed
diff --git a/jpegxl-src/src/lib.rs b/jpegxl-src/src/lib.rs
index a231b1e..12ad3cd 100644
--- a/jpegxl-src/src/lib.rs
+++ b/jpegxl-src/src/lib.rs
@@ -2,7 +2,6 @@
use std::{
env,
- num::NonZeroUsize,
path::{Path, PathBuf},
};
@@ -17,15 +16,9 @@ fn source_dir() -> PathBuf {
pub fn build() {
let source = source_dir();
- env::set_var(
- "CMAKE_BUILD_PARALLEL_LEVEL",
- format!(
- "{}",
- std::thread::available_parallelism()
- .map(NonZeroUsize::get)
- .unwrap_or(1)
- ),
- );
+ if let Ok(p) = std::thread::available_parallelism() {
+ env::set_var("CMAKE_BUILD_PARALLEL_LEVEL", format!("{}", p))
+ }
let mut config = cmake::Config::new(source);
config
@@ -41,23 +34,17 @@ pub fn build() {
.define("JPEGXL_ENABLE_OPENEXR", "OFF");
let mut prefix = config.build();
- println!("cargo:rustc-link-lib=static=jxl");
- println!("cargo:rustc-link-lib=static=jxl_threads");
-
- println!("cargo:rustc-link-lib=static=hwy");
prefix.push("lib");
println!("cargo:rustc-link-search=native={}", prefix.display());
- prefix.pop();
- prefix.push("build");
- prefix.push("third_party");
- println!("cargo:rustc-link-search=native={}", prefix.display());
+ println!("cargo:rustc-link-lib=static=jxl");
+ println!("cargo:rustc-link-lib=static=jxl_cms");
+ println!("cargo:rustc-link-lib=static=jxl_threads");
- println!("cargo:rustc-link-lib=static=brotlicommon-static");
- println!("cargo:rustc-link-lib=static=brotlidec-static");
- println!("cargo:rustc-link-lib=static=brotlienc-static");
- prefix.push("brotli");
- println!("cargo:rustc-link-search=native={}", prefix.display());
+ println!("cargo:rustc-link-lib=static=hwy");
+ println!("cargo:rustc-link-lib=static=brotlicommon");
+ println!("cargo:rustc-link-lib=static=brotlidec");
+ println!("cargo:rustc-link-lib=static=brotlienc");
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
println!("cargo:rustc-link-lib=c++");
diff --git a/jpegxl-sys/Cargo.toml b/jpegxl-sys/Cargo.toml
index d012c7f..a802f15 100644
--- a/jpegxl-sys/Cargo.toml
+++ b/jpegxl-sys/Cargo.toml
@@ -9,7 +9,7 @@ links = "jxl"
name = "jpegxl-sys"
readme = "README.md"
repository = "https://github.com/inflation/jpegxl-rs"
-version = "0.8.2+libjxl-0.8.2"
+version = "0.9.0+libjxl-0.9.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -21,10 +21,10 @@ module_name_repetitions = "allow"
features = ["docs"]
[build-dependencies]
-pkg-config = "0.3.27"
+pkg-config = "0.3.28"
[build-dependencies.jpegxl-src]
-version = "0.8.2"
+version = "0.9.0"
path = "../jpegxl-src"
optional = true
diff --git a/jpegxl-sys/src/butteraugli.rs b/jpegxl-sys/src/butteraugli.rs
deleted file mode 100644
index 616acfc..0000000
--- a/jpegxl-sys/src/butteraugli.rs
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-This file is part of jpegxl-sys.
-
-jpegxl-sys is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-jpegxl-sys is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with jpegxl-sys. If not, see .
-*/
-
-use std::ffi::c_void;
-
-use crate::{
- common::JxlPixelFormat, memory_manager::JxlMemoryManager, parallel_runner::JxlParallelRunner,
-};
-
-// Opaque type
-#[repr(C)]
-pub struct JxlButteraugliApi {
- _unused: [u8; 0],
-}
-
-// Opaque type
-#[repr(C)]
-pub struct JxlButteraugliResult {
- _unused: [u8; 0],
-}
-
-extern "C" {
- pub fn JxlButteraugliResultDestroy(result: *mut JxlButteraugliResult);
-
- pub fn JxlButteraugliApiCreate(
- memory_manager: *const JxlMemoryManager,
- ) -> *mut JxlButteraugliApi;
-
- pub fn JxlButteraugliApiSetParallelRunner(
- api: *mut JxlButteraugliApi,
- parallel_runner: JxlParallelRunner,
- parallel_runner_opaque: *mut c_void,
- );
-
- pub fn JxlButteraugliApiSetHFAsymmetry(api: *mut JxlButteraugliApi, v: f32);
-
- pub fn JxlButteraugliApiSetIntensityTarget(api: *mut JxlButteraugliApi, v: f32);
-
- pub fn JxlButteraugliApiDestroy(api: *mut JxlButteraugliApi);
-
- pub fn JxlButteraugliCompute(
- api: *const JxlButteraugliApi,
- xsize: u32,
- ysize: u32,
- pixel_format_orig: *const JxlPixelFormat,
- buffer_orig: *const c_void,
- size_orig: usize,
- pixel_format_dist: *const JxlPixelFormat,
- buffer_dist: *const c_void,
- size_dist: usize,
- ) -> *mut JxlButteraugliResult;
-
- pub fn JxlButteraugliResultGetMaxDistance(result: *const JxlButteraugliResult) -> f32;
-
- pub fn JxlButteraugliResultGetDistance(result: *const JxlButteraugliResult, pnorm: f32) -> f32;
-
- pub fn JxlButteraugliResultGetDistmap(
- result: *const JxlButteraugliResult,
- buffer: *const *const f32,
- row_stride: *mut u32,
- );
-}
diff --git a/jpegxl-sys/src/cms.rs b/jpegxl-sys/src/cms.rs
index ce575e7..0a967f5 100644
--- a/jpegxl-sys/src/cms.rs
+++ b/jpegxl-sys/src/cms.rs
@@ -17,13 +17,25 @@ along with jpegxl-sys. If not, see .
use std::ffi::c_void;
-use crate::{JxlBool, JxlColorEncoding};
+use crate::{color_encoding::JxlColorEncoding, types::JxlBool};
+
+extern "C" {
+ pub fn JxlGetDefaultCms() -> *const JxlCmsInterface;
+}
+
+pub type JpegXlCmsSetFieldsFromIccFunc = extern "C" fn(
+ user_data: *mut c_void,
+ icc_data: *const u8,
+ icc_size: usize,
+ c: *mut JxlColorEncoding,
+ cmyk: *mut JxlBool,
+) -> JxlBool;
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlColorProfileIcc {
- pub data: *const u8,
- pub size: usize,
+ data: *const u8,
+ size: usize,
}
#[repr(C)]
@@ -58,6 +70,8 @@ pub type JpegXlCmsDestroyFun = extern "C" fn(user_data: *mut c_void);
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlCmsInterface {
+ pub set_fields_data: *mut c_void,
+ pub set_fields_from_icc: JpegXlCmsSetFieldsFromIccFunc,
pub init_data: *mut c_void,
pub init: JpegXlCmsInitFunc,
pub get_src_buf: JpegXlCmsGetBufferFunc,
diff --git a/jpegxl-sys/src/codestream_header.rs b/jpegxl-sys/src/codestream_header.rs
index 0a8071a..29eeec3 100644
--- a/jpegxl-sys/src/codestream_header.rs
+++ b/jpegxl-sys/src/codestream_header.rs
@@ -1,4 +1,4 @@
-use crate::JxlBool;
+use crate::types::JxlBool;
#[repr(C)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
diff --git a/jpegxl-sys/src/color_encoding.rs b/jpegxl-sys/src/color_encoding.rs
new file mode 100644
index 0000000..67cb005
--- /dev/null
+++ b/jpegxl-sys/src/color_encoding.rs
@@ -0,0 +1,63 @@
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlColorSpace {
+ Rgb = 0,
+ Gray,
+ Xyb,
+ Unknown,
+}
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlWhitePoint {
+ D65 = 1,
+ Custom = 2,
+ E = 10,
+ Dci = 11,
+}
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlPrimaries {
+ SRgb = 1,
+ Custom = 2,
+ Rec2100 = 9,
+ P3 = 11,
+}
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlTransferFunction {
+ Rec709 = 1,
+ Unknown = 2,
+ Linear = 8,
+ SRgb = 13,
+ Pq = 16,
+ Dci = 17,
+ Hlg = 18,
+ Gamma = 65535,
+}
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlRenderingIntent {
+ Perceptual = 0,
+ Relative,
+ Saturation,
+ Absolute,
+}
+
+#[repr(C)]
+#[derive(Clone, Debug)]
+pub struct JxlColorEncoding {
+ pub color_space: JxlColorSpace,
+ pub white_point: JxlWhitePoint,
+ pub white_point_xy: [f64; 2usize],
+ pub primaries: JxlPrimaries,
+ pub primaries_red_xy: [f64; 2usize],
+ pub primaries_green_xy: [f64; 2usize],
+ pub primaries_blue_xy: [f64; 2usize],
+ pub transfer_function: JxlTransferFunction,
+ pub gamma: f64,
+ pub rendering_intent: JxlRenderingIntent,
+}
diff --git a/jpegxl-sys/src/decoder.rs b/jpegxl-sys/src/decode.rs
similarity index 92%
rename from jpegxl-sys/src/decoder.rs
rename to jpegxl-sys/src/decode.rs
index fe8af17..6b9da46 100644
--- a/jpegxl-sys/src/decoder.rs
+++ b/jpegxl-sys/src/decode.rs
@@ -21,10 +21,12 @@ use std::{
};
use crate::{
- cms::JxlCmsInterface, memory_manager::JxlMemoryManager, parallel_runner::JxlParallelRunner,
- JxlBasicInfo, JxlBitDepth, JxlBlendInfo, JxlBool, JxlBoxType, JxlColorEncoding,
- JxlColorProfileTarget, JxlExtraChannelInfo, JxlFrameHeader, JxlPixelFormat,
- JxlProgressiveDetail,
+ cms::JxlCmsInterface,
+ codestream_header::{JxlBasicInfo, JxlBlendInfo, JxlExtraChannelInfo, JxlFrameHeader},
+ color_encoding::JxlColorEncoding,
+ memory_manager::JxlMemoryManager,
+ parallel_runner::JxlParallelRunner,
+ types::{JxlBitDepth, JxlBool, JxlBoxType, JxlPixelFormat},
};
#[repr(C)]
@@ -53,7 +55,6 @@ pub enum JxlDecoderStatus {
JpegNeedMoreOutput = 6,
BoxNeedMoreOutput = 7,
BasicInfo = 0x40,
- Extensions = 0x80,
ColorEncoding = 0x100,
PreviewImage = 0x200,
Frame = 0x400,
@@ -63,6 +64,25 @@ pub enum JxlDecoderStatus {
FrameProgression = 0x8000,
}
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlProgressiveDetail {
+ Frames = 0,
+ DC = 1,
+ LastPasses = 2,
+ Passes = 3,
+ DCProgressive = 4,
+ DCGroups = 5,
+ Groups = 6,
+}
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum JxlColorProfileTarget {
+ Original = 0,
+ Data = 1,
+}
+
pub type JxlImageOutCallback = extern "C" fn(
opaque: *mut c_void,
x: usize,
@@ -99,12 +119,6 @@ extern "C" {
pub fn JxlDecoderSkipCurrentFrame(dec: *mut JxlDecoder) -> JxlDecoderStatus;
- #[deprecated(since = "0.7.0")]
- pub fn JxlDecoderDefaultPixelFormat(
- dec: *const JxlDecoder,
- format: *mut JxlPixelFormat,
- ) -> JxlDecoderStatus;
-
pub fn JxlDecoderSetParallelRunner(
dec: *mut JxlDecoder,
parallel_runner: JxlParallelRunner,
@@ -167,21 +181,18 @@ extern "C" {
pub fn JxlDecoderGetColorAsEncodedProfile(
dec: *const JxlDecoder,
- unused_format: *const JxlPixelFormat,
target: JxlColorProfileTarget,
color_encoding: *mut JxlColorEncoding,
) -> JxlDecoderStatus;
pub fn JxlDecoderGetICCProfileSize(
dec: *const JxlDecoder,
- unused_format: *const JxlPixelFormat,
target: JxlColorProfileTarget,
size: *mut usize,
) -> JxlDecoderStatus;
pub fn JxlDecoderGetColorAsICCProfile(
dec: *const JxlDecoder,
- unused_format: *const JxlPixelFormat,
target: JxlColorProfileTarget,
icc_profile: *mut u8,
size: usize,
@@ -204,7 +215,7 @@ extern "C" {
icc_size: usize,
) -> JxlDecoderStatus;
- pub fn JxlDecoderSetCms(dec: *mut JxlDecoder, cms: JxlCmsInterface);
+ pub fn JxlDecoderSetCms(dec: *mut JxlDecoder, cms: JxlCmsInterface) -> JxlDecoderStatus;
pub fn JxlDecoderPreviewOutBufferSize(
dec: *const JxlDecoder,
diff --git a/jpegxl-sys/src/encoder.rs b/jpegxl-sys/src/encode.rs
similarity index 70%
rename from jpegxl-sys/src/encoder.rs
rename to jpegxl-sys/src/encode.rs
index 55cbcb9..9b9a7ef 100644
--- a/jpegxl-sys/src/encoder.rs
+++ b/jpegxl-sys/src/encode.rs
@@ -15,12 +15,18 @@ You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
-use std::ffi::c_void;
+use std::ffi::{c_char, c_void};
use crate::{
- cms::JxlCmsInterface, memory_manager::JxlMemoryManager, parallel_runner::JxlParallelRunner,
- JxlBasicInfo, JxlBitDepth, JxlBlendInfo, JxlBool, JxlBoxType, JxlColorEncoding,
- JxlExtraChannelInfo, JxlExtraChannelType, JxlFrameHeader, JxlPixelFormat,
+ cms::JxlCmsInterface,
+ codestream_header::{
+ JxlBasicInfo, JxlBlendInfo, JxlExtraChannelInfo, JxlExtraChannelType, JxlFrameHeader,
+ },
+ color_encoding::JxlColorEncoding,
+ memory_manager::JxlMemoryManager,
+ parallel_runner::JxlParallelRunner,
+ stats::JxlEncoderStats,
+ types::{JxlBitDepth, JxlBool, JxlBoxType, JxlPixelFormat},
};
// Opaque type
@@ -29,13 +35,6 @@ pub struct JxlEncoder {
_unused: [u8; 0],
}
-#[deprecated(since = "0.7.0", note = "Use `JxlEncoderFrameSettings` instead")]
-// Opaque type
-#[repr(C)]
-pub struct JxlEncoderOptions {
- _unused: [u8; 0],
-}
-
#[repr(C)]
pub struct JxlEncoderFrameSettings {
_unused: [u8; 0],
@@ -47,11 +46,6 @@ pub enum JxlEncoderStatus {
Success = 0,
Error = 1,
NeedMoreOutput = 2,
- #[deprecated(
- since = "0.7.0",
- note = "JxlEncoderStatus::Error is returned with JxlEncoderError::NotSupported instead"
- )]
- NotSupported = 3,
}
#[repr(C)]
@@ -103,10 +97,68 @@ pub enum FrameSetting {
IndexBox = 31,
BrotliEffort = 32,
JpegCompressBoxes = 33,
+ Buffering = 34,
+ JpegKeepExif = 35,
+ JpegKeepXmp = 36,
+ JpegKeepJumbf = 37,
FillEnum = 65535,
}
-#[allow(deprecated)]
+#[repr(C)]
+#[derive(Debug, Clone)]
+pub struct JxlEncoderOutputProcessor {
+ opaque: *mut c_void,
+ get_buffer: extern "C" fn(opaque: *mut c_void, size: *mut usize) -> *mut c_void,
+ release_buffer: extern "C" fn(opaque: *mut c_void, written_bytes: usize),
+ seek: Option,
+ set_finalized_position: extern "C" fn(opaque: *mut c_void, finalized_position: u64),
+}
+
+/**
+ * This struct provides callback functions to pass pixel data in a streaming
+ * manner instead of requiring the entire frame data in memory at once.
+ */
+#[repr(C)]
+#[derive(Debug, Clone)]
+pub struct JxlChunkedFrameInputSource {
+ opaque: *mut c_void,
+
+ get_color_channels_pixel_format:
+ extern "C" fn(opaque: *mut c_void, pixel_format: *mut JxlPixelFormat),
+
+ get_color_channels_data: extern "C" fn(
+ opaque: *mut c_void,
+ xpos: usize,
+ ypos: usize,
+ xsize: usize,
+ ysize: usize,
+ row_offset: *mut usize,
+ ) -> *const c_void,
+
+ get_extra_channel_pixel_format:
+ extern "C" fn(opaque: *mut c_void, ec_index: usize, pixel_format: *mut JxlPixelFormat),
+
+ get_extra_channel_data_at: extern "C" fn(
+ opaque: *mut c_void,
+ ec_index: usize,
+ xpos: usize,
+ ypos: usize,
+ xsize: usize,
+ ysize: usize,
+ row_offset: *mut usize,
+ ) -> *const c_void,
+ release_buffer: extern "C" fn(opaque: *mut c_void, buf: *const c_void),
+}
+
+pub type JxlDebugImageCallback = extern "C" fn(
+ opaque: *mut c_void,
+ label: *const c_char,
+ xsize: usize,
+ ysize: usize,
+ color: *const JxlColorEncoding,
+ pixels: *const u16,
+);
+
extern "C" {
pub fn JxlEncoderVersion() -> u32;
@@ -166,6 +218,19 @@ extern "C" {
size: usize,
) -> JxlEncoderStatus;
+ pub fn JxlEncoderSetOutputProcessor(
+ enc: *mut JxlEncoder,
+ output_processor: JxlEncoderOutputProcessor,
+ ) -> JxlEncoderStatus;
+
+ pub fn JxlEncoderFlushInput(enc: *mut JxlEncoder) -> JxlEncoderStatus;
+
+ pub fn JxlEncoderAddChunkedFrame(
+ frame_settings: *const JxlEncoderFrameSettings,
+ is_last_frame: JxlBool,
+ chunked_frame_input: JxlChunkedFrameInputSource,
+ ) -> JxlEncoderStatus;
+
pub fn JxlEncoderSetExtraChannelBuffer(
frame_settings: *const JxlEncoderFrameSettings,
pixel_format: *const JxlPixelFormat,
@@ -212,6 +277,12 @@ extern "C" {
info: *const JxlBasicInfo,
) -> JxlEncoderStatus;
+ pub fn JxlEncoderSetUpsamplingMode(
+ enc: *mut JxlEncoder,
+ factor: i64,
+ mode: i64,
+ ) -> JxlEncoderStatus;
+
pub fn JxlEncoderInitExtraChannelInfo(
channel_type: JxlExtraChannelType,
info: *mut JxlExtraChannelInfo,
@@ -258,48 +329,20 @@ extern "C" {
lossless: bool,
) -> JxlEncoderStatus;
- #[deprecated(since = "0.7.0", note = "Use `JxlEncoderSetFrameLossless` instead")]
- pub fn JxlEncoderOptionsSetLossless(
- options: *mut JxlEncoderOptions,
- lossless: bool,
- ) -> JxlEncoderStatus;
-
- #[deprecated(
- since = "0.7.0",
- note = "Use `JxlEncoderFrameSettingsSetOption(frame_settings, FrameSetting::Effort, effort)` instead."
- )]
- pub fn JxlEncoderOptionsSetEffort(
- options: *mut JxlEncoderOptions,
- effort: i32,
- ) -> JxlEncoderStatus;
-
- #[deprecated(
- since = "0.7.0",
- note = "Use `JxlEncoderFrameSettingsSetOption(frame_settings, FrameSetting::DecodingSpeed, effort)` instead."
- )]
- pub fn JxlEncoderOptionsSetDecodingSpeed(
- options: *mut JxlEncoderOptions,
- tier: i32,
- ) -> JxlEncoderStatus;
-
pub fn JxlEncoderSetFrameDistance(
options: *mut JxlEncoderFrameSettings,
distance: f32,
) -> JxlEncoderStatus;
- #[deprecated(since = "0.7.0", note = "Use `JxlEncoderSetFrameDistance` instead")]
- pub fn JxlEncoderOptionsSetDistance(
- options: *mut JxlEncoderOptions,
+ pub fn JxlEncoderSetExtraChannelDistance(
+ frame_settings: *mut JxlEncoderFrameSettings,
+ index: usize,
distance: f32,
) -> JxlEncoderStatus;
- pub fn JxlEncoderFrameSettingsCreate(
- enc: *mut JxlEncoder,
- source: *const JxlEncoderFrameSettings,
- ) -> *mut JxlEncoderFrameSettings;
+ pub fn JxlEncoderDistanceFromQuality(quality: f32) -> f32;
- #[deprecated(since = "0.7.0", note = "Use `JxlEncoderFrameSettingsCreate` instead")]
- pub fn JxlEncoderOptionsCreate(
+ pub fn JxlEncoderFrameSettingsCreate(
enc: *mut JxlEncoder,
source: *const JxlEncoderFrameSettings,
) -> *mut JxlEncoderFrameSettings;
@@ -309,4 +352,15 @@ extern "C" {
pub fn JxlColorEncodingSetToLinearSRGB(color_encoding: *mut JxlColorEncoding, is_gray: bool);
pub fn JxlEncoderAllowExpertOptions(enc: *mut JxlEncoder);
+
+ pub fn JxlEncoderSetDebugImageCallback(
+ frame_settings: *mut JxlEncoderFrameSettings,
+ callback: JxlDebugImageCallback,
+ opaque: *mut c_void,
+ );
+
+ pub fn JxlEncoderCollectStats(
+ frame_settings: *mut JxlEncoderFrameSettings,
+ stats: *mut JxlEncoderStats,
+ );
}
diff --git a/jpegxl-sys/src/lib.rs b/jpegxl-sys/src/lib.rs
index b1acc77..ea4c4a4 100644
--- a/jpegxl-sys/src/lib.rs
+++ b/jpegxl-sys/src/lib.rs
@@ -17,16 +17,15 @@ along with jpegxl-sys. If not, see .
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
-pub mod butteraugli;
pub mod cms;
pub mod codestream_header;
-pub mod common;
-pub mod decoder;
-pub mod encoder;
+pub mod color_encoding;
+pub mod decode;
+pub mod encode;
pub mod memory_manager;
pub mod parallel_runner;
-
-pub use {codestream_header::*, common::*, decoder::*, encoder::*};
+pub mod stats;
+pub mod types;
#[cfg(feature = "threads")]
pub mod thread_parallel_runner;
@@ -36,10 +35,14 @@ pub mod resizable_parallel_runner;
#[cfg(test)]
mod test {
- use super::*;
- use crate::thread_parallel_runner::{
- JxlThreadParallelRunner, JxlThreadParallelRunnerCreate,
- JxlThreadParallelRunnerDefaultNumWorkerThreads, JxlThreadParallelRunnerDestroy,
+ use crate::{
+ decode::*,
+ encode::*,
+ thread_parallel_runner::{
+ JxlThreadParallelRunner, JxlThreadParallelRunnerCreate,
+ JxlThreadParallelRunnerDefaultNumWorkerThreads, JxlThreadParallelRunnerDestroy,
+ },
+ types::*,
};
use std::{mem::MaybeUninit, ptr};
@@ -78,8 +81,8 @@ mod test {
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_version() {
unsafe {
- assert_eq!(JxlDecoderVersion(), 8002);
- assert_eq!(JxlEncoderVersion(), 8002);
+ assert_eq!(JxlDecoderVersion(), 9001);
+ assert_eq!(JxlEncoderVersion(), 9001);
}
}
diff --git a/jpegxl-sys/src/stats.rs b/jpegxl-sys/src/stats.rs
new file mode 100644
index 0000000..15ca650
--- /dev/null
+++ b/jpegxl-sys/src/stats.rs
@@ -0,0 +1,43 @@
+#[repr(C)]
+pub struct JxlEncoderStats {
+ _unused: [u8; 0],
+}
+
+extern "C" {
+ pub fn JxlEncoderStatsCreate() -> *mut JxlEncoderStats;
+ pub fn JxlEncoderStatsDestroy(stats: *mut JxlEncoderStats);
+ pub fn JxlEncoderStatsGet(stats: *const JxlEncoderStats, key: JxlEncoderStatsKey) -> usize;
+ pub fn JxlEncoderStatsMerge(stats: *mut JxlEncoderStats, other: *const JxlEncoderStats);
+}
+
+#[repr(C)]
+#[derive(Debug, Clone)]
+pub enum JxlEncoderStatsKey {
+ HeaderBits,
+ TocBits,
+ DictionaryBits,
+ SplinesBits,
+ NoiseBits,
+ QuantBits,
+ ModularTreeBits,
+ ModularGlobalBits,
+ DcBits,
+ ModularDcGroupBits,
+ ControlFieldsBits,
+ CoefOrderBits,
+ AcHistogramBits,
+ AcBits,
+ ModularAcGroupBits,
+ NumSmallBlocks,
+ NumDct4x8Blocks,
+ NumAfvBlocks,
+ NumDct8Blocks,
+ NumDct8x32Blocks,
+ NumDct16Blocks,
+ NumDct16x32Blocks,
+ NumDct32Blocks,
+ NumDct32x64Blocks,
+ NumDct64Blocks,
+ NumButteraugliIters,
+ NumStats,
+}
diff --git a/jpegxl-sys/src/common.rs b/jpegxl-sys/src/types.rs
similarity index 53%
rename from jpegxl-sys/src/common.rs
rename to jpegxl-sys/src/types.rs
index 661a38b..1f0c08a 100644
--- a/jpegxl-sys/src/common.rs
+++ b/jpegxl-sys/src/types.rs
@@ -77,86 +77,3 @@ pub struct JxlBitDepth {
}
pub type JxlBoxType = [c_char; 4];
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlProgressiveDetail {
- Frames = 0,
- DC = 1,
- LastPasses = 2,
- Passes = 3,
- DCProgressive = 4,
- DCGroups = 5,
- Groups = 6,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlColorSpace {
- Rgb = 0,
- Gray,
- Xyb,
- Unknown,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlWhitePoint {
- D65 = 1,
- Custom = 2,
- E = 10,
- Dci = 11,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlPrimaries {
- SRgb = 1,
- Custom = 2,
- Rec2100 = 9,
- P3 = 11,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlTransferFunction {
- Rec709 = 1,
- Unknown = 2,
- Linear = 8,
- SRgb = 13,
- Pq = 16,
- Dci = 17,
- Hlg = 18,
- Gamma = 65535,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlRenderingIntent {
- Perceptual = 0,
- Relative,
- Saturation,
- Absolute,
-}
-
-#[repr(C)]
-#[derive(Clone, Debug)]
-pub struct JxlColorEncoding {
- pub color_space: JxlColorSpace,
- pub white_point: JxlWhitePoint,
- pub white_point_xy: [f64; 2usize],
- pub primaries: JxlPrimaries,
- pub primaries_red_xy: [f64; 2usize],
- pub primaries_green_xy: [f64; 2usize],
- pub primaries_blue_xy: [f64; 2usize],
- pub transfer_function: JxlTransferFunction,
- pub gamma: f64,
- pub rendering_intent: JxlRenderingIntent,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum JxlColorProfileTarget {
- Original,
- Data,
-}