jpegxl_sys\metadata/
compressed_icc.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//! Utility functions to compress and decompress ICC streams.
19
20use crate::common::{memory_manager, types::JxlBool};
21
22extern "C-unwind" {
23    /// Allocates a buffer using the memory manager, fills it with a compressed
24    /// representation of an ICC profile, returns the result through `output_buffer`
25    /// and indicates its size through `output_size`.
26    ///
27    /// The result must be freed using the memory manager once it is not of any more
28    /// use.
29    ///
30    /// # Parameters
31    ///
32    /// - `memory_manager`: Pointer to a `JxlMemoryManager`.
33    /// - `icc`: Pointer to a buffer containing the uncompressed ICC profile.
34    /// - `icc_size`: Size of the buffer containing the ICC profile.
35    /// - `compressed_icc`: Will be set to a pointer to the buffer containing the result.
36    /// - `compressed_icc_size`: Will be set to the size of the buffer containing the result.
37    ///
38    /// # Returns
39    ///
40    /// Whether compressing the profile was successful.
41    pub fn JxlICCProfileEncode(
42        memory_manager: *const memory_manager::JxlMemoryManager,
43        icc: *const u8,
44        icc_size: usize,
45        compressed_icc: *mut *mut u8,
46        compressed_icc_size: *mut usize,
47    ) -> JxlBool;
48
49    /// Allocates a buffer using the memory manager, fills it with the decompressed
50    /// version of the ICC profile in `compressed_icc`, returns the result through
51    /// `icc` and indicates its size through `icc_size`.
52    ///
53    /// The result must be freed using the memory manager once it is no longer needed.
54    ///
55    /// # Parameters
56    ///
57    /// - `memory_manager`: Pointer to a `JxlMemoryManager`.
58    /// - `compressed_icc`: Pointer to a buffer containing the compressed ICC profile.
59    /// - `compressed_icc_size`: Size of the buffer containing the compressed ICC profile.
60    /// - `icc`: Will be set to a pointer to the buffer containing the result.
61    /// - `icc_size`: Will be set to the size of the buffer containing the result.
62    ///
63    /// # Returns
64    ///
65    /// Whether decompressing the profile was successful.
66    pub fn JxlICCProfileDecode(
67        memory_manager: *const memory_manager::JxlMemoryManager,
68        compressed_icc: *const u8,
69        compressed_icc_size: usize,
70        icc: *mut *mut u8,
71        icc_size: *mut usize,
72    ) -> JxlBool;
73}