/src/libjxl/lib/jxl/modular/options.h
Line | Count | Source |
1 | | // Copyright (c) the JPEG XL Project Authors. All rights reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style |
4 | | // license that can be found in the LICENSE file. |
5 | | |
6 | | #ifndef LIB_JXL_MODULAR_OPTIONS_H_ |
7 | | #define LIB_JXL_MODULAR_OPTIONS_H_ |
8 | | |
9 | | #include <array> |
10 | | #include <cstddef> |
11 | | #include <cstdint> |
12 | | #include <vector> |
13 | | |
14 | | #include "lib/jxl/base/compiler_specific.h" // ssize_t |
15 | | #include "lib/jxl/enc_ans_params.h" |
16 | | |
17 | | namespace jxl { |
18 | | |
19 | | using PropertyVal = int32_t; |
20 | | using Properties = std::vector<PropertyVal>; |
21 | | |
22 | | enum class Predictor : uint32_t { |
23 | | Zero = 0, |
24 | | Left = 1, |
25 | | Top = 2, |
26 | | Average0 = 3, |
27 | | Select = 4, |
28 | | Gradient = 5, |
29 | | Weighted = 6, |
30 | | TopRight = 7, |
31 | | TopLeft = 8, |
32 | | LeftLeft = 9, |
33 | | Average1 = 10, |
34 | | Average2 = 11, |
35 | | Average3 = 12, |
36 | | Average4 = 13, |
37 | | // The following predictors are encoder-only. |
38 | | Best = 14, // Best of Gradient and Weighted |
39 | | Variable = |
40 | | 15, // Find the best decision tree for predictors/predictor per row |
41 | | }; |
42 | | |
43 | | constexpr Predictor kUndefinedPredictor = static_cast<Predictor>(~0u); |
44 | | |
45 | | constexpr size_t kNumModularPredictors = |
46 | | static_cast<size_t>(Predictor::Average4) + 1; |
47 | | constexpr size_t kNumModularEncoderPredictors = |
48 | | static_cast<size_t>(Predictor::Variable) + 1; |
49 | | |
50 | | static constexpr ssize_t kNumStaticProperties = 2; // channel, group_id. |
51 | | |
52 | | using StaticPropRange = |
53 | | std::array<std::array<uint32_t, 2>, kNumStaticProperties>; |
54 | | |
55 | | struct ModularMultiplierInfo { |
56 | | StaticPropRange range; |
57 | | uint32_t multiplier; |
58 | | }; |
59 | | |
60 | | struct ModularOptions { |
61 | | /// Used in both encode and decode: |
62 | | |
63 | | // Stop encoding/decoding when reaching a (non-meta) channel that has a |
64 | | // dimension bigger than max_chan_size. |
65 | | size_t max_chan_size = 0xFFFFFF; |
66 | | |
67 | | // Used during decoding for validation of transforms (sqeeezing) scheme. |
68 | | size_t group_dim = 0x1FFFFFFF; |
69 | | |
70 | | /// Encode options: |
71 | | // Fraction of pixels to look at to learn a MA tree |
72 | | // Number of iterations to do to learn a MA tree |
73 | | // (if zero there is no MA context model) |
74 | | float nb_repeats = .5f; |
75 | | |
76 | | // Maximum number of (previous channel) properties to use in the MA trees |
77 | | int max_properties = 0; // no previous channels |
78 | | |
79 | | // Alternative heuristic tweaks. |
80 | | // Properties default to channel, group, weighted, gradient residual, W-NW, |
81 | | // NW-N, N-NE, N-NN |
82 | | std::vector<uint32_t> splitting_heuristics_properties; |
83 | | float splitting_heuristics_node_threshold = 96; |
84 | | size_t max_property_values = 32; |
85 | | |
86 | | // Predictor to use for each channel. |
87 | | Predictor predictor = kUndefinedPredictor; |
88 | | |
89 | | int wp_mode = 0; |
90 | | |
91 | | float fast_decode_multiplier = 1.01f; |
92 | | |
93 | | // Forces the encoder to produce a tree that is compatible with the WP-only |
94 | | // decode path (or with the no-wp path, or the gradient-only path). |
95 | | enum class TreeMode { kGradientOnly, kWPOnly, kNoWP, kDefault }; |
96 | | TreeMode wp_tree_mode = TreeMode::kDefault; |
97 | | |
98 | | // Skip fast paths in the encoder. |
99 | | bool skip_encoder_fast_path = false; |
100 | | |
101 | | // Kind of tree to use. |
102 | | // TODO(veluca): add tree kinds for JPEG recompression with CfL enabled, |
103 | | // general AC metadata, different DC qualities, and others. |
104 | | enum class TreeKind { |
105 | | kTrivialTreeNoPredictor, |
106 | | kLearn, |
107 | | kJpegTranscodeACMeta, |
108 | | kFalconACMeta, |
109 | | kACMeta, |
110 | | kWPFixedDC, |
111 | | kGradientFixedDC, |
112 | | }; |
113 | | TreeKind tree_kind = TreeKind::kLearn; |
114 | | |
115 | | HistogramParams histogram_params; |
116 | | |
117 | | // Ignore the image and just pretend all tokens are zeroes |
118 | | bool zero_tokens = false; |
119 | | |
120 | 34.6k | ModularOptions() { |
121 | | // GCC has complaints about inline vector initialization; do it manually. |
122 | 34.6k | static const std::vector<uint32_t> kDefaultSplittingHeuristicsProperties = { |
123 | 34.6k | 0, 1, 15, 9, 10, 11, 12, 13}; |
124 | 34.6k | splitting_heuristics_properties = kDefaultSplittingHeuristicsProperties; |
125 | 34.6k | } |
126 | | }; |
127 | | |
128 | | } // namespace jxl |
129 | | |
130 | | #endif // LIB_JXL_MODULAR_OPTIONS_H_ |