/src/libjxl/lib/jxl/enc_ans_params.h
Line | Count | Source (jump to first uncovered line) |
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_ENC_ANS_PARAMS_H_ |
7 | | #define LIB_JXL_ENC_ANS_PARAMS_H_ |
8 | | |
9 | | // Encoder-only parameter needed for ANS entropy encoding methods. |
10 | | |
11 | | #include <stdint.h> |
12 | | #include <stdlib.h> |
13 | | |
14 | | #include <vector> |
15 | | |
16 | | #include "lib/jxl/common.h" |
17 | | |
18 | | namespace jxl { |
19 | | |
20 | | // Forward declaration to break include cycle. |
21 | | struct CompressParams; |
22 | | |
23 | | // RebalanceHistogram requires a signed type. |
24 | | using ANSHistBin = int32_t; |
25 | | |
26 | | struct HistogramParams { |
27 | | enum class ClusteringType { |
28 | | kFastest, // Only 4 clusters. |
29 | | kFast, |
30 | | kBest, |
31 | | }; |
32 | | |
33 | | enum class HybridUintMethod { |
34 | | kNone, // just use kHybridUint420Config. |
35 | | k000, // force the fastest option. |
36 | | kFast, // just try a couple of options. |
37 | | kContextMap, // fast choice for ctx map. |
38 | | kBest, |
39 | | }; |
40 | | |
41 | | enum class LZ77Method { |
42 | | kNone, // do not try lz77. |
43 | | kRLE, // only try doing RLE. |
44 | | kLZ77, // try lz77 with backward references. |
45 | | kOptimal, // optimal-matching LZ77 parsing. |
46 | | }; |
47 | | |
48 | | enum class ANSHistogramStrategy { |
49 | | kFast, // Only try some methods, early exit. |
50 | | kApproximate, // Only try some methods. |
51 | | kPrecise, // Try all methods. |
52 | | }; |
53 | | |
54 | 75.5k | HistogramParams() = default; |
55 | | |
56 | 0 | HistogramParams(SpeedTier tier, size_t num_ctx) { |
57 | 0 | if (tier > SpeedTier::kFalcon) { |
58 | 0 | clustering = ClusteringType::kFastest; |
59 | 0 | lz77_method = LZ77Method::kNone; |
60 | 0 | } else if (tier > SpeedTier::kTortoise) { |
61 | 0 | clustering = ClusteringType::kFast; |
62 | 0 | } else { |
63 | 0 | clustering = ClusteringType::kBest; |
64 | 0 | } |
65 | 0 | if (tier > SpeedTier::kTortoise) { |
66 | 0 | uint_method = HybridUintMethod::kNone; |
67 | 0 | } |
68 | 0 | if (tier >= SpeedTier::kSquirrel) { |
69 | 0 | ans_histogram_strategy = ANSHistogramStrategy::kApproximate; |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | static HistogramParams ForModular( |
74 | | const CompressParams& cparams, |
75 | | const std::vector<uint8_t>& extra_dc_precision, bool streaming_mode); |
76 | | |
77 | | ClusteringType clustering = ClusteringType::kBest; |
78 | | HybridUintMethod uint_method = HybridUintMethod::kBest; |
79 | | LZ77Method lz77_method = LZ77Method::kRLE; |
80 | | ANSHistogramStrategy ans_histogram_strategy = ANSHistogramStrategy::kPrecise; |
81 | | std::vector<size_t> image_widths; |
82 | | size_t max_histograms = ~0; |
83 | | bool force_huffman = false; |
84 | | bool initialize_global_state = true; |
85 | | bool streaming_mode = false; |
86 | | bool add_missing_symbols = false; |
87 | | bool add_fixed_histograms = false; |
88 | | }; |
89 | | |
90 | | } // namespace jxl |
91 | | |
92 | | #endif // LIB_JXL_ENC_ANS_PARAMS_H_ |