jpegxl_sys\encoder/stats.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//! API to collect various statistics from JXL encoder.
19
20#[cfg(doc)]
21use crate::encoder::encode::JxlEncoderCollectStats;
22
23/// Opaque structure that holds the encoder statistics.
24///
25/// Allocated and initialized with [`JxlEncoderStatsCreate`].
26/// Cleaned up and deallocated with [`JxlEncoderStatsDestroy`].
27#[repr(C)]
28pub struct JxlEncoderStats {
29 _unused: [u8; 0],
30}
31
32extern "C-unwind" {
33 /// Creates an instance of [`JxlEncoderStats`] and initializes it.
34 ///
35 /// # Returns
36 /// A pointer to the initialized [`JxlEncoderStats`] instance.
37 pub fn JxlEncoderStatsCreate() -> *mut JxlEncoderStats;
38
39 /// Deinitializes and frees [`JxlEncoderStats`] instance.
40 ///
41 /// # Parameters
42 /// - `stats`: Instance to be cleaned up and deallocated. No-op if `stats` is
43 /// a null pointer.
44 pub fn JxlEncoderStatsDestroy(stats: *mut JxlEncoderStats);
45
46 /// Returns the value of the statistics corresponding to the given key.
47 ///
48 /// # Parameters
49 /// - `stats`: Object that was passed to the encoder with a
50 /// [`JxlEncoderCollectStats`] function.
51 /// - `key`: The particular statistics to query.
52 ///
53 /// # Returns
54 /// The value of the statistics.
55 pub fn JxlEncoderStatsGet(stats: *const JxlEncoderStats, key: JxlEncoderStatsKey) -> usize;
56
57 /** Updates the values of the given stats object with that of an other.
58 *
59 * @param stats object whose values will be updated (usually added together)
60 * @param other stats object whose values will be merged with stats
61 */
62 pub fn JxlEncoderStatsMerge(stats: *mut JxlEncoderStats, other: *const JxlEncoderStats);
63}
64
65/// Data type for querying [`JxlEncoderStats`] object
66#[repr(C)]
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
68pub enum JxlEncoderStatsKey {
69 HeaderBits,
70 TocBits,
71 DictionaryBits,
72 SplinesBits,
73 NoiseBits,
74 QuantBits,
75 ModularTreeBits,
76 ModularGlobalBits,
77 DcBits,
78 ModularDcGroupBits,
79 ControlFieldsBits,
80 CoefOrderBits,
81 AcHistogramBits,
82 AcBits,
83 ModularAcGroupBits,
84 NumSmallBlocks,
85 NumDct4x8Blocks,
86 NumAfvBlocks,
87 NumDct8Blocks,
88 NumDct8x32Blocks,
89 NumDct16Blocks,
90 NumDct16x32Blocks,
91 NumDct32Blocks,
92 NumDct32x64Blocks,
93 NumDct64Blocks,
94 NumButteraugliIters,
95 NumStats,
96}