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