jpegxl_sys\color/
cms_interface.rs

1/*
2This file is part of jpegxl-sys.
3
4jpegxl-sys is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 3 of the License, or
7(at your option) any later version.
8
9jpegxl-sys is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with jpegxl-sys.  If not, see <https://www.gnu.org/licenses/>.
16*/
17
18//! Interface to allow the injection of different color management systems
19//! (CMSes, also called color management modules, or CMMs) in JPEG XL.
20//!
21//! A CMS is needed by the JPEG XL encoder and decoder to perform colorspace
22//! conversions. This defines an interface that can be implemented for different
23//! CMSes and then passed to the library.
24
25use std::ffi::c_void;
26
27use crate::common::types::JxlBool;
28
29use super::color_encoding::JxlColorEncoding;
30
31pub type JpegXlCmsSetFieldsFromIccFunc = extern "C-unwind" fn(
32    user_data: *mut c_void,
33    icc_data: *const u8,
34    icc_size: usize,
35    c: *mut JxlColorEncoding,
36    cmyk: *mut JxlBool,
37) -> JxlBool;
38
39#[repr(C)]
40#[derive(Debug, Clone)]
41pub struct JxlColorProfileIcc {
42    data: *const u8,
43    size: usize,
44}
45
46#[repr(C)]
47#[derive(Debug, Clone)]
48pub struct JxlColorProfile {
49    pub icc: JxlColorProfileIcc,
50    pub color_encoding: JxlColorEncoding,
51    pub num_channels: usize,
52}
53
54pub type JpegXlCmsInitFunc = extern "C-unwind" fn(
55    init_data: *mut c_void,
56    num_threads: usize,
57    pixels_per_thread: usize,
58    input_profile: *const JxlColorProfile,
59    output_profile: *const JxlColorProfile,
60    intensity_target: f32,
61) -> *mut c_void;
62
63pub type JpegXlCmsGetBufferFunc =
64    extern "C-unwind" fn(user_data: *mut c_void, thread: usize) -> *mut f32;
65
66pub type JpegXlCmsRunFunc = extern "C-unwind" fn(
67    user_data: *mut c_void,
68    thread: usize,
69    input_buffer: *const f32,
70    output_buffer: *mut f32,
71    num_pixels: usize,
72) -> JxlBool;
73
74pub type JpegXlCmsDestroyFun = extern "C-unwind" fn(user_data: *mut c_void);
75
76#[repr(C)]
77#[derive(Debug, Clone)]
78pub struct JxlCmsInterface {
79    pub set_fields_data: *mut c_void,
80    pub set_fields_from_icc: JpegXlCmsSetFieldsFromIccFunc,
81    pub init_data: *mut c_void,
82    pub init: JpegXlCmsInitFunc,
83    pub get_src_buf: JpegXlCmsGetBufferFunc,
84    pub get_dst_buf: JpegXlCmsGetBufferFunc,
85    pub run: JpegXlCmsRunFunc,
86    pub destroy: JpegXlCmsDestroyFun,
87}