Coverage Report

Created: 2025-11-14 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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/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 ptrdiff_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;
82
  float splitting_heuristics_node_threshold = 96;
83
  size_t max_property_values = 32;
84
85
  // Predictor to use for each channel.
86
  Predictor predictor = kUndefinedPredictor;
87
88
  int wp_mode = 0;
89
90
  float fast_decode_multiplier = 1.01f;
91
92
  // Forces the encoder to produce a tree that is compatible with the WP-only
93
  // decode path (or with the no-wp path, or the gradient-only path).
94
  enum class TreeMode { kGradientOnly, kWPOnly, kNoWP, kDefault };
95
  TreeMode wp_tree_mode = TreeMode::kDefault;
96
97
  // Skip fast paths in the encoder.
98
  bool skip_encoder_fast_path = false;
99
100
  // Kind of tree to use.
101
  // TODO(veluca): add tree kinds for JPEG recompression with CfL enabled,
102
  // general AC metadata, different DC qualities, and others.
103
  enum class TreeKind {
104
    kTrivialTreeNoPredictor,
105
    kLearn,
106
    kJpegTranscodeACMeta,
107
    kFalconACMeta,
108
    kACMeta,
109
    kWPFixedDC,
110
    kGradientFixedDC,
111
  };
112
  TreeKind tree_kind = TreeKind::kLearn;
113
114
  HistogramParams histogram_params;
115
116
  // Ignore the image and just pretend all tokens are zeroes
117
  bool zero_tokens = false;
118
119
69.5k
  ModularOptions() {
120
    // GCC has complaints about inline vector initialization; do it manually.
121
69.5k
    static const std::vector<uint32_t> kDefaultSplittingHeuristicsProperties = {
122
69.5k
        0, 1, 15, 9, 10, 11, 12, 13};
123
69.5k
    splitting_heuristics_properties = kDefaultSplittingHeuristicsProperties;
124
69.5k
  }
125
};
126
127
}  // namespace jxl
128
129
#endif  // LIB_JXL_MODULAR_OPTIONS_H_