libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

options.h (3440B)


      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 <stdint.h>
     10 
     11 #include <array>
     12 #include <vector>
     13 
     14 #include "lib/jxl/enc_ans_params.h"
     15 
     16 namespace jxl {
     17 
     18 using PropertyVal = int32_t;
     19 using Properties = std::vector<PropertyVal>;
     20 
     21 enum class Predictor : uint32_t {
     22   Zero = 0,
     23   Left = 1,
     24   Top = 2,
     25   Average0 = 3,
     26   Select = 4,
     27   Gradient = 5,
     28   Weighted = 6,
     29   TopRight = 7,
     30   TopLeft = 8,
     31   LeftLeft = 9,
     32   Average1 = 10,
     33   Average2 = 11,
     34   Average3 = 12,
     35   Average4 = 13,
     36   // The following predictors are encoder-only.
     37   Best = 14,  // Best of Gradient and Weighted
     38   Variable =
     39       15,  // Find the best decision tree for predictors/predictor per row
     40 };
     41 
     42 constexpr Predictor kUndefinedPredictor = static_cast<Predictor>(~0u);
     43 
     44 constexpr size_t kNumModularPredictors =
     45     static_cast<size_t>(Predictor::Average4) + 1;
     46 constexpr size_t kNumModularEncoderPredictors =
     47     static_cast<size_t>(Predictor::Variable) + 1;
     48 
     49 static constexpr ssize_t kNumStaticProperties = 2;  // channel, group_id.
     50 
     51 using StaticPropRange =
     52     std::array<std::array<uint32_t, 2>, kNumStaticProperties>;
     53 
     54 struct ModularMultiplierInfo {
     55   StaticPropRange range;
     56   uint32_t multiplier;
     57 };
     58 
     59 struct ModularOptions {
     60   /// Used in both encode and decode:
     61 
     62   // Stop encoding/decoding when reaching a (non-meta) channel that has a
     63   // dimension bigger than max_chan_size.
     64   size_t max_chan_size = 0xFFFFFF;
     65 
     66   // Used during decoding for validation of transforms (sqeeezing) scheme.
     67   size_t group_dim = 0x1FFFFFFF;
     68 
     69   /// Encode options:
     70   // Fraction of pixels to look at to learn a MA tree
     71   // Number of iterations to do to learn a MA tree
     72   // (if zero there is no MA context model)
     73   float nb_repeats = .5f;
     74 
     75   // Maximum number of (previous channel) properties to use in the MA trees
     76   int max_properties = 0;  // no previous channels
     77 
     78   // Alternative heuristic tweaks.
     79   // Properties default to channel, group, weighted, gradient residual, W-NW,
     80   // NW-N, N-NE, N-NN
     81   std::vector<uint32_t> splitting_heuristics_properties = {0,  1,  15, 9,
     82                                                            10, 11, 12, 13};
     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 
    121 }  // namespace jxl
    122 
    123 #endif  // LIB_JXL_MODULAR_OPTIONS_H_