/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 "lib/jxl/enc_params.h" |
15 | | |
16 | | namespace jxl { |
17 | | |
18 | | struct HistogramParams { |
19 | | enum class ClusteringType { |
20 | | kFastest, // Only 4 clusters. |
21 | | kFast, |
22 | | kBest, |
23 | | }; |
24 | | |
25 | | enum class HybridUintMethod { |
26 | | kNone, // just use kHybridUint420Config. |
27 | | k000, // force the fastest option. |
28 | | kFast, // just try a couple of options. |
29 | | kContextMap, // fast choice for ctx map. |
30 | | kBest, |
31 | | }; |
32 | | |
33 | | enum class LZ77Method { |
34 | | kNone, // do not try lz77. |
35 | | kRLE, // only try doing RLE. |
36 | | kLZ77, // try lz77 with backward references. |
37 | | kOptimal, // optimal-matching LZ77 parsing. |
38 | | }; |
39 | | |
40 | | enum class ANSHistogramStrategy { |
41 | | kFast, // Only try some methods, early exit. |
42 | | kApproximate, // Only try some methods. |
43 | | kPrecise, // Try all methods. |
44 | | }; |
45 | | |
46 | 184 | HistogramParams() = default; |
47 | | |
48 | 92 | HistogramParams(SpeedTier tier, size_t num_ctx) { |
49 | 92 | if (tier > SpeedTier::kFalcon) { |
50 | 0 | clustering = ClusteringType::kFastest; |
51 | 0 | lz77_method = LZ77Method::kNone; |
52 | 92 | } else if (tier > SpeedTier::kTortoise) { |
53 | 92 | clustering = ClusteringType::kFast; |
54 | 92 | } else { |
55 | 0 | clustering = ClusteringType::kBest; |
56 | 0 | } |
57 | 92 | if (tier > SpeedTier::kTortoise) { |
58 | 92 | uint_method = HybridUintMethod::kNone; |
59 | 92 | } |
60 | 92 | if (tier >= SpeedTier::kSquirrel) { |
61 | 92 | ans_histogram_strategy = ANSHistogramStrategy::kApproximate; |
62 | 92 | } |
63 | 92 | } |
64 | | |
65 | | ClusteringType clustering = ClusteringType::kBest; |
66 | | HybridUintMethod uint_method = HybridUintMethod::kBest; |
67 | | LZ77Method lz77_method = LZ77Method::kRLE; |
68 | | ANSHistogramStrategy ans_histogram_strategy = ANSHistogramStrategy::kPrecise; |
69 | | std::vector<size_t> image_widths; |
70 | | size_t max_histograms = ~0; |
71 | | bool force_huffman = false; |
72 | | }; |
73 | | |
74 | | } // namespace jxl |
75 | | |
76 | | #endif // LIB_JXL_ENC_ANS_PARAMS_H_ |