Coverage Report

Created: 2025-10-12 07:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/modular/encoding/context_predict.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_ENCODING_CONTEXT_PREDICT_H_
7
#define LIB_JXL_MODULAR_ENCODING_CONTEXT_PREDICT_H_
8
9
#include <algorithm>
10
#include <array>
11
#include <cmath>
12
#include <cstddef>
13
#include <cstdint>
14
#include <vector>
15
16
#include "lib/jxl/base/bits.h"
17
#include "lib/jxl/base/compiler_specific.h"
18
#include "lib/jxl/base/status.h"
19
#include "lib/jxl/field_encodings.h"
20
#include "lib/jxl/fields.h"
21
#include "lib/jxl/image_ops.h"
22
#include "lib/jxl/modular/modular_image.h"
23
#include "lib/jxl/modular/options.h"
24
25
namespace jxl {
26
27
namespace weighted {
28
constexpr static size_t kNumPredictors = 4;
29
constexpr static int64_t kPredExtraBits = 3;
30
constexpr static int64_t kPredictionRound = ((1 << kPredExtraBits) >> 1) - 1;
31
constexpr static size_t kNumProperties = 1;
32
33
struct Header : public Fields {
34
  JXL_FIELDS_NAME(WeightedPredictorHeader)
35
  // TODO(janwas): move to cc file, avoid including fields.h.
36
203k
  Header() { Bundle::Init(this); }
37
38
304k
  Status VisitFields(Visitor *JXL_RESTRICT visitor) override {
39
304k
    if (visitor->AllDefault(*this, &all_default)) {
40
      // Overwrite all serialized fields, but not any nonserialized_*.
41
49.3k
      visitor->SetDefault(this);
42
49.3k
      return true;
43
49.3k
    }
44
1.78M
    auto visit_p = [visitor](pixel_type val, pixel_type *p) -> Status {
45
1.78M
      uint32_t up = *p;
46
1.78M
      JXL_QUIET_RETURN_IF_ERROR(visitor->Bits(5, val, &up));
47
1.78M
      *p = up;
48
1.78M
      return true;
49
1.78M
    };
50
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(16, &p1C));
51
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(10, &p2C));
52
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(7, &p3Ca));
53
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(7, &p3Cb));
54
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(7, &p3Cc));
55
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(0, &p3Cd));
56
255k
    JXL_QUIET_RETURN_IF_ERROR(visit_p(0, &p3Ce));
57
255k
    JXL_QUIET_RETURN_IF_ERROR(visitor->Bits(4, 0xd, &w[0]));
58
255k
    JXL_QUIET_RETURN_IF_ERROR(visitor->Bits(4, 0xc, &w[1]));
59
255k
    JXL_QUIET_RETURN_IF_ERROR(visitor->Bits(4, 0xc, &w[2]));
60
255k
    JXL_QUIET_RETURN_IF_ERROR(visitor->Bits(4, 0xc, &w[3]));
61
255k
    return true;
62
255k
  }
63
64
  bool all_default;
65
  pixel_type p1C = 0, p2C = 0, p3Ca = 0, p3Cb = 0, p3Cc = 0, p3Cd = 0, p3Ce = 0;
66
  uint32_t w[kNumPredictors] = {};
67
};
68
69
struct State {
70
  pixel_type_w prediction[kNumPredictors] = {};
71
  pixel_type_w pred = 0;  // *before* removing the added bits.
72
  std::vector<uint32_t> pred_errors[kNumPredictors];
73
  std::vector<int32_t> error;
74
  const Header &header;
75
76
  // Allows to approximate division by a number from 1 to 64.
77
  //  for (int i = 0; i < 64; i++) divlookup[i] = (1 << 24) / (i + 1);
78
79
  const uint32_t divlookup[64] = {
80
      16777216, 8388608, 5592405, 4194304, 3355443, 2796202, 2396745, 2097152,
81
      1864135,  1677721, 1525201, 1398101, 1290555, 1198372, 1118481, 1048576,
82
      986895,   932067,  883011,  838860,  798915,  762600,  729444,  699050,
83
      671088,   645277,  621378,  599186,  578524,  559240,  541200,  524288,
84
      508400,   493447,  479349,  466033,  453438,  441505,  430185,  419430,
85
      409200,   399457,  390167,  381300,  372827,  364722,  356962,  349525,
86
      342392,   335544,  328965,  322638,  316551,  310689,  305040,  299593,
87
      294337,   289262,  284359,  279620,  275036,  270600,  266305,  262144};
88
89
1.04G
  constexpr static pixel_type_w AddBits(pixel_type_w x) {
90
1.04G
    return static_cast<uint64_t>(x) << kPredExtraBits;
91
1.04G
  }
92
93
33.6k
  State(const Header &header, size_t xsize, size_t ysize) : header(header) {
94
    // Extra margin to avoid out-of-bounds writes.
95
    // All have space for two rows of data.
96
134k
    for (auto &pred_error : pred_errors) {
97
134k
      pred_error.resize((xsize + 2) * 2);
98
134k
    }
99
33.6k
    error.resize((xsize + 2) * 2);
100
33.6k
  }
101
102
  // Approximates 4+(maxweight<<24)/(x+1), avoiding division
103
683M
  JXL_INLINE uint32_t ErrorWeight(uint64_t x, uint32_t maxweight) const {
104
683M
    int shift = static_cast<int>(FloorLog2Nonzero(x + 1)) - 5;
105
683M
    if (shift < 0) shift = 0;
106
683M
    return 4 + ((maxweight * divlookup[x >> shift]) >> shift);
107
683M
  }
108
109
  // Approximates the weighted average of the input values with the given
110
  // weights, avoiding division. Weights must sum to at least 16.
111
  JXL_INLINE pixel_type_w
112
  WeightedAverage(const pixel_type_w *JXL_RESTRICT p,
113
170M
                  std::array<uint32_t, kNumPredictors> w) const {
114
170M
    uint32_t weight_sum = 0;
115
854M
    for (size_t i = 0; i < kNumPredictors; i++) {
116
683M
      weight_sum += w[i];
117
683M
    }
118
170M
    JXL_DASSERT(weight_sum > 15);
119
170M
    uint32_t log_weight = FloorLog2Nonzero(weight_sum);  // at least 4.
120
170M
    weight_sum = 0;
121
854M
    for (size_t i = 0; i < kNumPredictors; i++) {
122
683M
      w[i] >>= log_weight - 4;
123
683M
      weight_sum += w[i];
124
683M
    }
125
    // for rounding.
126
170M
    pixel_type_w sum = (weight_sum >> 1) - 1;
127
854M
    for (size_t i = 0; i < kNumPredictors; i++) {
128
683M
      sum += p[i] * w[i];
129
683M
    }
130
170M
    return (sum * divlookup[weight_sum - 1]) >> 24;
131
170M
  }
132
133
  template <bool compute_properties>
134
  JXL_INLINE pixel_type_w Predict(size_t x, size_t y, size_t xsize,
135
                                  pixel_type_w N, pixel_type_w W,
136
                                  pixel_type_w NE, pixel_type_w NW,
137
                                  pixel_type_w NN, Properties *properties,
138
170M
                                  size_t offset) {
139
170M
    size_t cur_row = y & 1 ? 0 : (xsize + 2);
140
170M
    size_t prev_row = y & 1 ? (xsize + 2) : 0;
141
170M
    size_t pos_N = prev_row + x;
142
170M
    size_t pos_NE = x < xsize - 1 ? pos_N + 1 : pos_N;
143
170M
    size_t pos_NW = x > 0 ? pos_N - 1 : pos_N;
144
170M
    std::array<uint32_t, kNumPredictors> weights;
145
854M
    for (size_t i = 0; i < kNumPredictors; i++) {
146
      // pred_errors[pos_N] also contains the error of pixel W.
147
      // pred_errors[pos_NW] also contains the error of pixel WW.
148
683M
      weights[i] = pred_errors[i][pos_N] + pred_errors[i][pos_NE] +
149
683M
                   pred_errors[i][pos_NW];
150
683M
      weights[i] = ErrorWeight(weights[i], header.w[i]);
151
683M
    }
152
153
170M
    N = AddBits(N);
154
170M
    W = AddBits(W);
155
170M
    NE = AddBits(NE);
156
170M
    NW = AddBits(NW);
157
170M
    NN = AddBits(NN);
158
159
170M
    pixel_type_w teW = x == 0 ? 0 : error[cur_row + x - 1];
160
170M
    pixel_type_w teN = error[pos_N];
161
170M
    pixel_type_w teNW = error[pos_NW];
162
170M
    pixel_type_w sumWN = teN + teW;
163
170M
    pixel_type_w teNE = error[pos_NE];
164
165
170M
    if (compute_properties) {
166
158M
      pixel_type_w p = teW;
167
158M
      if (std::abs(teN) > std::abs(p)) p = teN;
168
158M
      if (std::abs(teNW) > std::abs(p)) p = teNW;
169
158M
      if (std::abs(teNE) > std::abs(p)) p = teNE;
170
158M
      (*properties)[offset++] = p;
171
158M
    }
172
173
170M
    prediction[0] = W + NE - N;
174
170M
    prediction[1] = N - (((sumWN + teNE) * header.p1C) >> 5);
175
170M
    prediction[2] = W - (((sumWN + teNW) * header.p2C) >> 5);
176
170M
    prediction[3] =
177
170M
        N - ((teNW * header.p3Ca + teN * header.p3Cb + teNE * header.p3Cc +
178
170M
              (NN - N) * header.p3Cd + (NW - W) * header.p3Ce) >>
179
170M
             5);
180
181
170M
    pred = WeightedAverage(prediction, weights);
182
183
    // If all three have the same sign, skip clamping.
184
170M
    if (((teN ^ teW) | (teN ^ teNW)) > 0) {
185
45.5M
      return (pred + kPredictionRound) >> kPredExtraBits;
186
45.5M
    }
187
188
    // Otherwise, clamp to min/max of neighbouring pixels (just W, NE, N).
189
125M
    pixel_type_w mx = std::max(W, std::max(NE, N));
190
125M
    pixel_type_w mn = std::min(W, std::min(NE, N));
191
125M
    pred = std::max(mn, std::min(mx, pred));
192
125M
    return (pred + kPredictionRound) >> kPredExtraBits;
193
170M
  }
long jxl::weighted::State::Predict<false>(unsigned long, unsigned long, unsigned long, long, long, long, long, long, std::__1::vector<int, std::__1::allocator<int> >*, unsigned long)
Line
Count
Source
138
12.9M
                                  size_t offset) {
139
12.9M
    size_t cur_row = y & 1 ? 0 : (xsize + 2);
140
12.9M
    size_t prev_row = y & 1 ? (xsize + 2) : 0;
141
12.9M
    size_t pos_N = prev_row + x;
142
12.9M
    size_t pos_NE = x < xsize - 1 ? pos_N + 1 : pos_N;
143
12.9M
    size_t pos_NW = x > 0 ? pos_N - 1 : pos_N;
144
12.9M
    std::array<uint32_t, kNumPredictors> weights;
145
64.8M
    for (size_t i = 0; i < kNumPredictors; i++) {
146
      // pred_errors[pos_N] also contains the error of pixel W.
147
      // pred_errors[pos_NW] also contains the error of pixel WW.
148
51.8M
      weights[i] = pred_errors[i][pos_N] + pred_errors[i][pos_NE] +
149
51.8M
                   pred_errors[i][pos_NW];
150
51.8M
      weights[i] = ErrorWeight(weights[i], header.w[i]);
151
51.8M
    }
152
153
12.9M
    N = AddBits(N);
154
12.9M
    W = AddBits(W);
155
12.9M
    NE = AddBits(NE);
156
12.9M
    NW = AddBits(NW);
157
12.9M
    NN = AddBits(NN);
158
159
12.9M
    pixel_type_w teW = x == 0 ? 0 : error[cur_row + x - 1];
160
12.9M
    pixel_type_w teN = error[pos_N];
161
12.9M
    pixel_type_w teNW = error[pos_NW];
162
12.9M
    pixel_type_w sumWN = teN + teW;
163
12.9M
    pixel_type_w teNE = error[pos_NE];
164
165
12.9M
    if (compute_properties) {
166
0
      pixel_type_w p = teW;
167
0
      if (std::abs(teN) > std::abs(p)) p = teN;
168
0
      if (std::abs(teNW) > std::abs(p)) p = teNW;
169
0
      if (std::abs(teNE) > std::abs(p)) p = teNE;
170
0
      (*properties)[offset++] = p;
171
0
    }
172
173
12.9M
    prediction[0] = W + NE - N;
174
12.9M
    prediction[1] = N - (((sumWN + teNE) * header.p1C) >> 5);
175
12.9M
    prediction[2] = W - (((sumWN + teNW) * header.p2C) >> 5);
176
12.9M
    prediction[3] =
177
12.9M
        N - ((teNW * header.p3Ca + teN * header.p3Cb + teNE * header.p3Cc +
178
12.9M
              (NN - N) * header.p3Cd + (NW - W) * header.p3Ce) >>
179
12.9M
             5);
180
181
12.9M
    pred = WeightedAverage(prediction, weights);
182
183
    // If all three have the same sign, skip clamping.
184
12.9M
    if (((teN ^ teW) | (teN ^ teNW)) > 0) {
185
1.66M
      return (pred + kPredictionRound) >> kPredExtraBits;
186
1.66M
    }
187
188
    // Otherwise, clamp to min/max of neighbouring pixels (just W, NE, N).
189
11.3M
    pixel_type_w mx = std::max(W, std::max(NE, N));
190
11.3M
    pixel_type_w mn = std::min(W, std::min(NE, N));
191
11.3M
    pred = std::max(mn, std::min(mx, pred));
192
11.3M
    return (pred + kPredictionRound) >> kPredExtraBits;
193
12.9M
  }
long jxl::weighted::State::Predict<true>(unsigned long, unsigned long, unsigned long, long, long, long, long, long, std::__1::vector<int, std::__1::allocator<int> >*, unsigned long)
Line
Count
Source
138
158M
                                  size_t offset) {
139
158M
    size_t cur_row = y & 1 ? 0 : (xsize + 2);
140
158M
    size_t prev_row = y & 1 ? (xsize + 2) : 0;
141
158M
    size_t pos_N = prev_row + x;
142
158M
    size_t pos_NE = x < xsize - 1 ? pos_N + 1 : pos_N;
143
158M
    size_t pos_NW = x > 0 ? pos_N - 1 : pos_N;
144
158M
    std::array<uint32_t, kNumPredictors> weights;
145
790M
    for (size_t i = 0; i < kNumPredictors; i++) {
146
      // pred_errors[pos_N] also contains the error of pixel W.
147
      // pred_errors[pos_NW] also contains the error of pixel WW.
148
632M
      weights[i] = pred_errors[i][pos_N] + pred_errors[i][pos_NE] +
149
632M
                   pred_errors[i][pos_NW];
150
632M
      weights[i] = ErrorWeight(weights[i], header.w[i]);
151
632M
    }
152
153
158M
    N = AddBits(N);
154
158M
    W = AddBits(W);
155
158M
    NE = AddBits(NE);
156
158M
    NW = AddBits(NW);
157
158M
    NN = AddBits(NN);
158
159
158M
    pixel_type_w teW = x == 0 ? 0 : error[cur_row + x - 1];
160
158M
    pixel_type_w teN = error[pos_N];
161
158M
    pixel_type_w teNW = error[pos_NW];
162
158M
    pixel_type_w sumWN = teN + teW;
163
158M
    pixel_type_w teNE = error[pos_NE];
164
165
158M
    if (compute_properties) {
166
158M
      pixel_type_w p = teW;
167
158M
      if (std::abs(teN) > std::abs(p)) p = teN;
168
158M
      if (std::abs(teNW) > std::abs(p)) p = teNW;
169
158M
      if (std::abs(teNE) > std::abs(p)) p = teNE;
170
158M
      (*properties)[offset++] = p;
171
158M
    }
172
173
158M
    prediction[0] = W + NE - N;
174
158M
    prediction[1] = N - (((sumWN + teNE) * header.p1C) >> 5);
175
158M
    prediction[2] = W - (((sumWN + teNW) * header.p2C) >> 5);
176
158M
    prediction[3] =
177
158M
        N - ((teNW * header.p3Ca + teN * header.p3Cb + teNE * header.p3Cc +
178
158M
              (NN - N) * header.p3Cd + (NW - W) * header.p3Ce) >>
179
158M
             5);
180
181
158M
    pred = WeightedAverage(prediction, weights);
182
183
    // If all three have the same sign, skip clamping.
184
158M
    if (((teN ^ teW) | (teN ^ teNW)) > 0) {
185
43.8M
      return (pred + kPredictionRound) >> kPredExtraBits;
186
43.8M
    }
187
188
    // Otherwise, clamp to min/max of neighbouring pixels (just W, NE, N).
189
114M
    pixel_type_w mx = std::max(W, std::max(NE, N));
190
114M
    pixel_type_w mn = std::min(W, std::min(NE, N));
191
114M
    pred = std::max(mn, std::min(mx, pred));
192
114M
    return (pred + kPredictionRound) >> kPredExtraBits;
193
158M
  }
194
195
  JXL_INLINE void UpdateErrors(pixel_type_w val, size_t x, size_t y,
196
191M
                               size_t xsize) {
197
191M
    size_t cur_row = y & 1 ? 0 : (xsize + 2);
198
191M
    size_t prev_row = y & 1 ? (xsize + 2) : 0;
199
191M
    val = AddBits(val);
200
191M
    error[cur_row + x] = pred - val;
201
959M
    for (size_t i = 0; i < kNumPredictors; i++) {
202
767M
      pixel_type_w err =
203
767M
          (std::abs(prediction[i] - val) + kPredictionRound) >> kPredExtraBits;
204
      // For predicting in the next row.
205
767M
      pred_errors[i][cur_row + x] = err;
206
      // Add the error on this pixel to the error on the NE pixel. This has the
207
      // effect of adding the error on this pixel to the E and EE pixels.
208
767M
      pred_errors[i][prev_row + x + 1] += err;
209
767M
    }
210
191M
  }
211
};
212
213
// Encoder helper function to set the parameters to some presets.
214
2.52k
inline void PredictorMode(int i, Header *header) {
215
2.52k
  switch (i) {
216
2.52k
    case 0:
217
      // ~ lossless16 predictor
218
2.52k
      header->w[0] = 0xd;
219
2.52k
      header->w[1] = 0xc;
220
2.52k
      header->w[2] = 0xc;
221
2.52k
      header->w[3] = 0xc;
222
2.52k
      header->p1C = 16;
223
2.52k
      header->p2C = 10;
224
2.52k
      header->p3Ca = 7;
225
2.52k
      header->p3Cb = 7;
226
2.52k
      header->p3Cc = 7;
227
2.52k
      header->p3Cd = 0;
228
2.52k
      header->p3Ce = 0;
229
2.52k
      break;
230
0
    case 1:
231
      // ~ default lossless8 predictor
232
0
      header->w[0] = 0xd;
233
0
      header->w[1] = 0xc;
234
0
      header->w[2] = 0xc;
235
0
      header->w[3] = 0xb;
236
0
      header->p1C = 8;
237
0
      header->p2C = 8;
238
0
      header->p3Ca = 4;
239
0
      header->p3Cb = 0;
240
0
      header->p3Cc = 3;
241
0
      header->p3Cd = 23;
242
0
      header->p3Ce = 2;
243
0
      break;
244
0
    case 2:
245
      // ~ west lossless8 predictor
246
0
      header->w[0] = 0xd;
247
0
      header->w[1] = 0xc;
248
0
      header->w[2] = 0xd;
249
0
      header->w[3] = 0xc;
250
0
      header->p1C = 10;
251
0
      header->p2C = 9;
252
0
      header->p3Ca = 7;
253
0
      header->p3Cb = 0;
254
0
      header->p3Cc = 0;
255
0
      header->p3Cd = 16;
256
0
      header->p3Ce = 9;
257
0
      break;
258
0
    case 3:
259
      // ~ north lossless8 predictor
260
0
      header->w[0] = 0xd;
261
0
      header->w[1] = 0xd;
262
0
      header->w[2] = 0xc;
263
0
      header->w[3] = 0xc;
264
0
      header->p1C = 16;
265
0
      header->p2C = 8;
266
0
      header->p3Ca = 0;
267
0
      header->p3Cb = 16;
268
0
      header->p3Cc = 0;
269
0
      header->p3Cd = 23;
270
0
      header->p3Ce = 0;
271
0
      break;
272
0
    case 4:
273
0
    default:
274
      // something else, because why not
275
0
      header->w[0] = 0xd;
276
0
      header->w[1] = 0xc;
277
0
      header->w[2] = 0xc;
278
0
      header->w[3] = 0xc;
279
0
      header->p1C = 10;
280
0
      header->p2C = 10;
281
0
      header->p3Ca = 5;
282
0
      header->p3Cb = 5;
283
0
      header->p3Cc = 5;
284
0
      header->p3Cd = 12;
285
0
      header->p3Ce = 4;
286
0
      break;
287
2.52k
  }
288
2.52k
}
289
}  // namespace weighted
290
291
// Stores a node and its two children at the same time. This significantly
292
// reduces the number of branches needed during decoding.
293
struct FlatDecisionNode {
294
  // Property + splitval of the top node.
295
  int32_t property0;  // -1 if leaf.
296
  union {
297
    PropertyVal splitval0;
298
    Predictor predictor;
299
  };
300
  // Property+splitval of the two child nodes.
301
  union {
302
    PropertyVal splitvals[2];
303
    int32_t multiplier;
304
  };
305
  uint32_t childID;  // childID is ctx id if leaf.
306
  union {
307
    int16_t properties[2];
308
    int32_t predictor_offset;
309
  };
310
};
311
using FlatTree = std::vector<FlatDecisionNode>;
312
313
class MATreeLookup {
314
 public:
315
49.0k
  explicit MATreeLookup(const FlatTree &tree) : nodes_(tree) {}
316
  struct LookupResult {
317
    uint32_t context;
318
    Predictor predictor;
319
    int32_t offset;
320
    int32_t multiplier;
321
  };
322
142M
  JXL_INLINE LookupResult Lookup(const Properties &properties) const {
323
142M
    uint32_t pos = 0;
324
244M
    while (true) {
325
244M
#define TRAVERSE_THE_TREE                                                \
326
401M
  {                                                                      \
327
401M
    const FlatDecisionNode &node = nodes_[pos];                          \
328
401M
    if (node.property0 < 0) {                                            \
329
142M
      return {node.childID, node.predictor, node.predictor_offset,       \
330
142M
              node.multiplier};                                          \
331
142M
    }                                                                    \
332
401M
    bool p0 = properties[node.property0] <= node.splitval0;              \
333
258M
    uint32_t off0 = properties[node.properties[0]] <= node.splitvals[0]; \
334
258M
    uint32_t off1 =                                                      \
335
258M
        2 | int{properties[node.properties[1]] <= node.splitvals[1]};    \
336
258M
    pos = node.childID + (p0 ? off1 : off0);                             \
337
258M
  }
338
339
244M
      TRAVERSE_THE_TREE;
340
156M
      TRAVERSE_THE_TREE;
341
101M
    }
342
142M
  }
343
344
 private:
345
  const FlatTree &nodes_;
346
};
347
348
static constexpr size_t kExtraPropsPerChannel = 4;
349
static constexpr size_t kNumNonrefProperties =
350
    kNumStaticProperties + 13 + weighted::kNumProperties;
351
352
constexpr size_t kWPProp = kNumNonrefProperties - weighted::kNumProperties;
353
constexpr size_t kGradientProp = 9;
354
355
// Clamps gradient to the min/max of n, w (and l, implicitly).
356
static JXL_INLINE int32_t ClampedGradient(const int32_t n, const int32_t w,
357
162M
                                          const int32_t l) {
358
162M
  const int32_t m = std::min(n, w);
359
162M
  const int32_t M = std::max(n, w);
360
  // The end result of this operation doesn't overflow or underflow if the
361
  // result is between m and M, but the intermediate value may overflow, so we
362
  // do the intermediate operations in uint32_t and check later if we had an
363
  // overflow or underflow condition comparing m, M and l directly.
364
  // grad = M + m - l = n + w - l
365
162M
  const int32_t grad =
366
162M
      static_cast<int32_t>(static_cast<uint32_t>(n) + static_cast<uint32_t>(w) -
367
162M
                           static_cast<uint32_t>(l));
368
  // We use two sets of ternary operators to force the evaluation of them in
369
  // any case, allowing the compiler to avoid branches and use cmovl/cmovg in
370
  // x86.
371
162M
  const int32_t grad_clamp_M = (l < m) ? M : grad;
372
162M
  return (l > M) ? m : grad_clamp_M;
373
162M
}
Unexecuted instantiation: enc_frame.cc:jxl::ClampedGradient(int, int, int)
enc_modular.cc:jxl::ClampedGradient(int, int, int)
Line
Count
Source
357
7.76M
                                          const int32_t l) {
358
7.76M
  const int32_t m = std::min(n, w);
359
7.76M
  const int32_t M = std::max(n, w);
360
  // The end result of this operation doesn't overflow or underflow if the
361
  // result is between m and M, but the intermediate value may overflow, so we
362
  // do the intermediate operations in uint32_t and check later if we had an
363
  // overflow or underflow condition comparing m, M and l directly.
364
  // grad = M + m - l = n + w - l
365
7.76M
  const int32_t grad =
366
7.76M
      static_cast<int32_t>(static_cast<uint32_t>(n) + static_cast<uint32_t>(w) -
367
7.76M
                           static_cast<uint32_t>(l));
368
  // We use two sets of ternary operators to force the evaluation of them in
369
  // any case, allowing the compiler to avoid branches and use cmovl/cmovg in
370
  // x86.
371
7.76M
  const int32_t grad_clamp_M = (l < m) ? M : grad;
372
7.76M
  return (l > M) ? m : grad_clamp_M;
373
7.76M
}
Unexecuted instantiation: enc_patch_dictionary.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_quant_weights.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_heuristics.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_cache.cc:jxl::ClampedGradient(int, int, int)
enc_encoding.cc:jxl::ClampedGradient(int, int, int)
Line
Count
Source
357
140M
                                          const int32_t l) {
358
140M
  const int32_t m = std::min(n, w);
359
140M
  const int32_t M = std::max(n, w);
360
  // The end result of this operation doesn't overflow or underflow if the
361
  // result is between m and M, but the intermediate value may overflow, so we
362
  // do the intermediate operations in uint32_t and check later if we had an
363
  // overflow or underflow condition comparing m, M and l directly.
364
  // grad = M + m - l = n + w - l
365
140M
  const int32_t grad =
366
140M
      static_cast<int32_t>(static_cast<uint32_t>(n) + static_cast<uint32_t>(w) -
367
140M
                           static_cast<uint32_t>(l));
368
  // We use two sets of ternary operators to force the evaluation of them in
369
  // any case, allowing the compiler to avoid branches and use cmovl/cmovg in
370
  // x86.
371
140M
  const int32_t grad_clamp_M = (l < m) ? M : grad;
372
140M
  return (l > M) ? m : grad_clamp_M;
373
140M
}
Unexecuted instantiation: enc_ma.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_rct.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_transform.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: enc_palette.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: coeff_order.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: dec_frame.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: dec_modular.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: decode.cc:jxl::ClampedGradient(int, int, int)
encoding.cc:jxl::ClampedGradient(int, int, int)
Line
Count
Source
357
14.8M
                                          const int32_t l) {
358
14.8M
  const int32_t m = std::min(n, w);
359
14.8M
  const int32_t M = std::max(n, w);
360
  // The end result of this operation doesn't overflow or underflow if the
361
  // result is between m and M, but the intermediate value may overflow, so we
362
  // do the intermediate operations in uint32_t and check later if we had an
363
  // overflow or underflow condition comparing m, M and l directly.
364
  // grad = M + m - l = n + w - l
365
14.8M
  const int32_t grad =
366
14.8M
      static_cast<int32_t>(static_cast<uint32_t>(n) + static_cast<uint32_t>(w) -
367
14.8M
                           static_cast<uint32_t>(l));
368
  // We use two sets of ternary operators to force the evaluation of them in
369
  // any case, allowing the compiler to avoid branches and use cmovl/cmovg in
370
  // x86.
371
14.8M
  const int32_t grad_clamp_M = (l < m) ? M : grad;
372
14.8M
  return (l > M) ? m : grad_clamp_M;
373
14.8M
}
Unexecuted instantiation: modular_image.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: transform.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: rct.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: palette.cc:jxl::ClampedGradient(int, int, int)
Unexecuted instantiation: quant_weights.cc:jxl::ClampedGradient(int, int, int)
374
375
3.16M
inline pixel_type_w Select(pixel_type_w a, pixel_type_w b, pixel_type_w c) {
376
3.16M
  pixel_type_w p = a + b - c;
377
3.16M
  pixel_type_w pa = std::abs(p - a);
378
3.16M
  pixel_type_w pb = std::abs(p - b);
379
3.16M
  return pa < pb ? a : b;
380
3.16M
}
381
382
inline void PrecomputeReferences(const Channel &ch, size_t y,
383
                                 const Image &image, uint32_t i,
384
1.74M
                                 Channel *references) {
385
1.74M
  ZeroFillImage(&references->plane);
386
1.74M
  uint32_t offset = 0;
387
1.74M
  size_t num_extra_props = references->w;
388
1.74M
  intptr_t onerow = references->plane.PixelsPerRow();
389
1.74M
  for (int32_t j = static_cast<int32_t>(i) - 1;
390
2.02M
       j >= 0 && offset < num_extra_props; j--) {
391
283k
    if (image.channel[j].w != image.channel[i].w ||
392
241k
        image.channel[j].h != image.channel[i].h) {
393
241k
      continue;
394
241k
    }
395
42.2k
    if (image.channel[j].hshift != image.channel[i].hshift) continue;
396
35.9k
    if (image.channel[j].vshift != image.channel[i].vshift) continue;
397
34.3k
    pixel_type *JXL_RESTRICT rp = references->Row(0) + offset;
398
34.3k
    const pixel_type *JXL_RESTRICT rpp = image.channel[j].Row(y);
399
34.3k
    const pixel_type *JXL_RESTRICT rpprev = image.channel[j].Row(y ? y - 1 : 0);
400
309k
    for (size_t x = 0; x < ch.w; x++, rp += onerow) {
401
274k
      pixel_type_w v = rpp[x];
402
274k
      rp[0] = std::abs(v);
403
274k
      rp[1] = v;
404
274k
      pixel_type_w vleft = (x ? rpp[x - 1] : 0);
405
274k
      pixel_type_w vtop = (y ? rpprev[x] : vleft);
406
274k
      pixel_type_w vtopleft = (x && y ? rpprev[x - 1] : vleft);
407
274k
      pixel_type_w vpredicted = ClampedGradient(vleft, vtop, vtopleft);
408
274k
      rp[2] = std::abs(v - vpredicted);
409
274k
      rp[3] = v - vpredicted;
410
274k
    }
411
412
34.3k
    offset += kExtraPropsPerChannel;
413
34.3k
  }
414
1.74M
}
415
416
struct PredictionResult {
417
  int context = 0;
418
  pixel_type_w guess = 0;
419
  Predictor predictor;
420
  int32_t multiplier;
421
};
422
423
inline void InitPropsRow(
424
    Properties *p,
425
    const std::array<pixel_type, kNumStaticProperties> &static_props,
426
1.74M
    const int y) {
427
5.23M
  for (size_t i = 0; i < kNumStaticProperties; i++) {
428
3.49M
    (*p)[i] = static_props[i];
429
3.49M
  }
430
1.74M
  (*p)[2] = y;
431
1.74M
  (*p)[9] = 0;  // local gradient.
432
1.74M
}
433
434
namespace detail {
435
enum PredictorMode {
436
  kUseTree = 1,
437
  kUseWP = 2,
438
  kForceComputeProperties = 4,
439
  kAllPredictions = 8,
440
  kNoEdgeCases = 16
441
};
442
443
JXL_INLINE pixel_type_w PredictOne(Predictor p, pixel_type_w left,
444
                                   pixel_type_w top, pixel_type_w toptop,
445
                                   pixel_type_w topleft, pixel_type_w topright,
446
                                   pixel_type_w leftleft,
447
                                   pixel_type_w toprightright,
448
281M
                                   pixel_type_w wp_pred) {
449
281M
  switch (p) {
450
41.7M
    case Predictor::Zero:
451
41.7M
      return pixel_type_w{0};
452
22.1M
    case Predictor::Left:
453
22.1M
      return left;
454
30.9M
    case Predictor::Top:
455
30.9M
      return top;
456
3.16M
    case Predictor::Select:
457
3.16M
      return Select(left, top, topleft);
458
16.3M
    case Predictor::Weighted:
459
16.3M
      return wp_pred;
460
151M
    case Predictor::Gradient:
461
151M
      return pixel_type_w{ClampedGradient(left, top, topleft)};
462
1.42M
    case Predictor::TopLeft:
463
1.42M
      return topleft;
464
160k
    case Predictor::TopRight:
465
160k
      return topright;
466
866k
    case Predictor::LeftLeft:
467
866k
      return leftleft;
468
2.48M
    case Predictor::Average0:
469
2.48M
      return (left + top) / 2;
470
75.3k
    case Predictor::Average1:
471
75.3k
      return (left + topleft) / 2;
472
174k
    case Predictor::Average2:
473
174k
      return (topleft + top) / 2;
474
2.75M
    case Predictor::Average3:
475
2.75M
      return (top + topright) / 2;
476
7.53M
    case Predictor::Average4:
477
7.53M
      return (6 * top - 2 * toptop + 7 * left + 1 * leftleft +
478
7.53M
              1 * toprightright + 3 * topright + 8) /
479
7.53M
             16;
480
0
    default:
481
0
      return pixel_type_w{0};
482
281M
  }
483
281M
}
484
485
template <int mode>
486
JXL_INLINE PredictionResult Predict(
487
    Properties *p, size_t w, const pixel_type *JXL_RESTRICT pp,
488
    const intptr_t onerow, const size_t x, const size_t y, Predictor predictor,
489
    const MATreeLookup *lookup, const Channel *references,
490
281M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
281M
  size_t offset = 3;
493
281M
  constexpr bool compute_properties =
494
281M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
281M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
281M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
281M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
281M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
281M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
281M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
281M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
281M
  pixel_type_w toprightright =
503
281M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
281M
  if (compute_properties) {
506
    // location
507
212M
    (*p)[offset++] = x;
508
    // neighbors
509
212M
    (*p)[offset++] = top > 0 ? top : -top;
510
212M
    (*p)[offset++] = left > 0 ? left : -left;
511
212M
    (*p)[offset++] = top;
512
212M
    (*p)[offset++] = left;
513
514
    // local gradient
515
212M
    (*p)[offset] = left - (*p)[offset + 1];
516
212M
    offset++;
517
    // local gradient
518
212M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
212M
    (*p)[offset++] = left - topleft;
522
212M
    (*p)[offset++] = topleft - top;
523
212M
    (*p)[offset++] = top - topright;
524
212M
    (*p)[offset++] = top - toptop;
525
212M
    (*p)[offset++] = left - leftleft;
526
212M
  }
527
528
281M
  pixel_type_w wp_pred = 0;
529
281M
  if (mode & kUseWP) {
530
158M
    wp_pred = wp_state->Predict<compute_properties>(
531
158M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
158M
  }
533
281M
  if (!nec && compute_properties) {
534
79.9M
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
79.9M
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
89.4M
    for (size_t i = 0; i < references->w; i++) {
538
9.50M
      (*p)[offset++] = rp[i];
539
9.50M
    }
540
79.9M
  }
541
281M
  PredictionResult result;
542
281M
  if (mode & kUseTree) {
543
142M
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
142M
    result.context = lr.context;
545
142M
    result.guess = lr.offset;
546
142M
    result.multiplier = lr.multiplier;
547
142M
    predictor = lr.predictor;
548
142M
  }
549
281M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
281M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
281M
                             leftleft, toprightright, wp_pred);
558
281M
  result.predictor = predictor;
559
560
281M
  return result;
561
281M
}
jxl::PredictionResult jxl::detail::Predict<0>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
56.5M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
56.5M
  size_t offset = 3;
493
56.5M
  constexpr bool compute_properties =
494
56.5M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
56.5M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
56.5M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
56.5M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
56.5M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
56.5M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
56.5M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
56.5M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
56.5M
  pixel_type_w toprightright =
503
56.5M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
56.5M
  if (compute_properties) {
506
    // location
507
0
    (*p)[offset++] = x;
508
    // neighbors
509
0
    (*p)[offset++] = top > 0 ? top : -top;
510
0
    (*p)[offset++] = left > 0 ? left : -left;
511
0
    (*p)[offset++] = top;
512
0
    (*p)[offset++] = left;
513
514
    // local gradient
515
0
    (*p)[offset] = left - (*p)[offset + 1];
516
0
    offset++;
517
    // local gradient
518
0
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
0
    (*p)[offset++] = left - topleft;
522
0
    (*p)[offset++] = topleft - top;
523
0
    (*p)[offset++] = top - topright;
524
0
    (*p)[offset++] = top - toptop;
525
0
    (*p)[offset++] = left - leftleft;
526
0
  }
527
528
56.5M
  pixel_type_w wp_pred = 0;
529
56.5M
  if (mode & kUseWP) {
530
0
    wp_pred = wp_state->Predict<compute_properties>(
531
0
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
0
  }
533
56.5M
  if (!nec && compute_properties) {
534
0
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
0
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
0
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
0
  }
541
56.5M
  PredictionResult result;
542
56.5M
  if (mode & kUseTree) {
543
0
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
0
    result.context = lr.context;
545
0
    result.guess = lr.offset;
546
0
    result.multiplier = lr.multiplier;
547
0
    predictor = lr.predictor;
548
0
  }
549
56.5M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
56.5M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
56.5M
                             leftleft, toprightright, wp_pred);
558
56.5M
  result.predictor = predictor;
559
560
56.5M
  return result;
561
56.5M
}
jxl::PredictionResult jxl::detail::Predict<2>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
12.9M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
12.9M
  size_t offset = 3;
493
12.9M
  constexpr bool compute_properties =
494
12.9M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
12.9M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
12.9M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
12.9M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
12.9M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
12.9M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
12.9M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
12.9M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
12.9M
  pixel_type_w toprightright =
503
12.9M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
12.9M
  if (compute_properties) {
506
    // location
507
0
    (*p)[offset++] = x;
508
    // neighbors
509
0
    (*p)[offset++] = top > 0 ? top : -top;
510
0
    (*p)[offset++] = left > 0 ? left : -left;
511
0
    (*p)[offset++] = top;
512
0
    (*p)[offset++] = left;
513
514
    // local gradient
515
0
    (*p)[offset] = left - (*p)[offset + 1];
516
0
    offset++;
517
    // local gradient
518
0
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
0
    (*p)[offset++] = left - topleft;
522
0
    (*p)[offset++] = topleft - top;
523
0
    (*p)[offset++] = top - topright;
524
0
    (*p)[offset++] = top - toptop;
525
0
    (*p)[offset++] = left - leftleft;
526
0
  }
527
528
12.9M
  pixel_type_w wp_pred = 0;
529
12.9M
  if (mode & kUseWP) {
530
12.9M
    wp_pred = wp_state->Predict<compute_properties>(
531
12.9M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
12.9M
  }
533
12.9M
  if (!nec && compute_properties) {
534
0
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
0
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
0
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
0
  }
541
12.9M
  PredictionResult result;
542
12.9M
  if (mode & kUseTree) {
543
0
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
0
    result.context = lr.context;
545
0
    result.guess = lr.offset;
546
0
    result.multiplier = lr.multiplier;
547
0
    predictor = lr.predictor;
548
0
  }
549
12.9M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
12.9M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
12.9M
                             leftleft, toprightright, wp_pred);
558
12.9M
  result.predictor = predictor;
559
560
12.9M
  return result;
561
12.9M
}
jxl::PredictionResult jxl::detail::Predict<1>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
14.7M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
14.7M
  size_t offset = 3;
493
14.7M
  constexpr bool compute_properties =
494
14.7M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
14.7M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
14.7M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
14.7M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
14.7M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
14.7M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
14.7M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
14.7M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
14.7M
  pixel_type_w toprightright =
503
14.7M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
14.7M
  if (compute_properties) {
506
    // location
507
14.7M
    (*p)[offset++] = x;
508
    // neighbors
509
14.7M
    (*p)[offset++] = top > 0 ? top : -top;
510
14.7M
    (*p)[offset++] = left > 0 ? left : -left;
511
14.7M
    (*p)[offset++] = top;
512
14.7M
    (*p)[offset++] = left;
513
514
    // local gradient
515
14.7M
    (*p)[offset] = left - (*p)[offset + 1];
516
14.7M
    offset++;
517
    // local gradient
518
14.7M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
14.7M
    (*p)[offset++] = left - topleft;
522
14.7M
    (*p)[offset++] = topleft - top;
523
14.7M
    (*p)[offset++] = top - topright;
524
14.7M
    (*p)[offset++] = top - toptop;
525
14.7M
    (*p)[offset++] = left - leftleft;
526
14.7M
  }
527
528
14.7M
  pixel_type_w wp_pred = 0;
529
14.7M
  if (mode & kUseWP) {
530
0
    wp_pred = wp_state->Predict<compute_properties>(
531
0
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
0
  }
533
14.7M
  if (!nec && compute_properties) {
534
14.7M
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
14.7M
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
21.1M
    for (size_t i = 0; i < references->w; i++) {
538
6.46M
      (*p)[offset++] = rp[i];
539
6.46M
    }
540
14.7M
  }
541
14.7M
  PredictionResult result;
542
14.7M
  if (mode & kUseTree) {
543
14.7M
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
14.7M
    result.context = lr.context;
545
14.7M
    result.guess = lr.offset;
546
14.7M
    result.multiplier = lr.multiplier;
547
14.7M
    predictor = lr.predictor;
548
14.7M
  }
549
14.7M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
14.7M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
14.7M
                             leftleft, toprightright, wp_pred);
558
14.7M
  result.predictor = predictor;
559
560
14.7M
  return result;
561
14.7M
}
jxl::PredictionResult jxl::detail::Predict<17>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
51.7M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
51.7M
  size_t offset = 3;
493
51.7M
  constexpr bool compute_properties =
494
51.7M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
51.7M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
51.7M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
51.7M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
51.7M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
51.7M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
51.7M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
51.7M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
51.7M
  pixel_type_w toprightright =
503
51.7M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
51.7M
  if (compute_properties) {
506
    // location
507
51.7M
    (*p)[offset++] = x;
508
    // neighbors
509
51.7M
    (*p)[offset++] = top > 0 ? top : -top;
510
51.7M
    (*p)[offset++] = left > 0 ? left : -left;
511
51.7M
    (*p)[offset++] = top;
512
51.7M
    (*p)[offset++] = left;
513
514
    // local gradient
515
51.7M
    (*p)[offset] = left - (*p)[offset + 1];
516
51.7M
    offset++;
517
    // local gradient
518
51.7M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
51.7M
    (*p)[offset++] = left - topleft;
522
51.7M
    (*p)[offset++] = topleft - top;
523
51.7M
    (*p)[offset++] = top - topright;
524
51.7M
    (*p)[offset++] = top - toptop;
525
51.7M
    (*p)[offset++] = left - leftleft;
526
51.7M
  }
527
528
51.7M
  pixel_type_w wp_pred = 0;
529
51.7M
  if (mode & kUseWP) {
530
0
    wp_pred = wp_state->Predict<compute_properties>(
531
0
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
0
  }
533
51.7M
  if (!nec && compute_properties) {
534
0
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
0
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
0
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
0
  }
541
51.7M
  PredictionResult result;
542
51.7M
  if (mode & kUseTree) {
543
51.7M
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
51.7M
    result.context = lr.context;
545
51.7M
    result.guess = lr.offset;
546
51.7M
    result.multiplier = lr.multiplier;
547
51.7M
    predictor = lr.predictor;
548
51.7M
  }
549
51.7M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
51.7M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
51.7M
                             leftleft, toprightright, wp_pred);
558
51.7M
  result.predictor = predictor;
559
560
51.7M
  return result;
561
51.7M
}
jxl::PredictionResult jxl::detail::Predict<3>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
62.1M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
62.1M
  size_t offset = 3;
493
62.1M
  constexpr bool compute_properties =
494
62.1M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
62.1M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
62.1M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
62.1M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
62.1M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
62.1M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
62.1M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
62.1M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
62.1M
  pixel_type_w toprightright =
503
62.1M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
62.1M
  if (compute_properties) {
506
    // location
507
62.1M
    (*p)[offset++] = x;
508
    // neighbors
509
62.1M
    (*p)[offset++] = top > 0 ? top : -top;
510
62.1M
    (*p)[offset++] = left > 0 ? left : -left;
511
62.1M
    (*p)[offset++] = top;
512
62.1M
    (*p)[offset++] = left;
513
514
    // local gradient
515
62.1M
    (*p)[offset] = left - (*p)[offset + 1];
516
62.1M
    offset++;
517
    // local gradient
518
62.1M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
62.1M
    (*p)[offset++] = left - topleft;
522
62.1M
    (*p)[offset++] = topleft - top;
523
62.1M
    (*p)[offset++] = top - topright;
524
62.1M
    (*p)[offset++] = top - toptop;
525
62.1M
    (*p)[offset++] = left - leftleft;
526
62.1M
  }
527
528
62.1M
  pixel_type_w wp_pred = 0;
529
62.1M
  if (mode & kUseWP) {
530
62.1M
    wp_pred = wp_state->Predict<compute_properties>(
531
62.1M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
62.1M
  }
533
62.1M
  if (!nec && compute_properties) {
534
62.1M
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
62.1M
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
65.1M
    for (size_t i = 0; i < references->w; i++) {
538
3.03M
      (*p)[offset++] = rp[i];
539
3.03M
    }
540
62.1M
  }
541
62.1M
  PredictionResult result;
542
62.1M
  if (mode & kUseTree) {
543
62.1M
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
62.1M
    result.context = lr.context;
545
62.1M
    result.guess = lr.offset;
546
62.1M
    result.multiplier = lr.multiplier;
547
62.1M
    predictor = lr.predictor;
548
62.1M
  }
549
62.1M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
62.1M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
62.1M
                             leftleft, toprightright, wp_pred);
558
62.1M
  result.predictor = predictor;
559
560
62.1M
  return result;
561
62.1M
}
jxl::PredictionResult jxl::detail::Predict<19>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
14.2M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
14.2M
  size_t offset = 3;
493
14.2M
  constexpr bool compute_properties =
494
14.2M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
14.2M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
14.2M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
14.2M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
14.2M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
14.2M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
14.2M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
14.2M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
14.2M
  pixel_type_w toprightright =
503
14.2M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
14.2M
  if (compute_properties) {
506
    // location
507
14.2M
    (*p)[offset++] = x;
508
    // neighbors
509
14.2M
    (*p)[offset++] = top > 0 ? top : -top;
510
14.2M
    (*p)[offset++] = left > 0 ? left : -left;
511
14.2M
    (*p)[offset++] = top;
512
14.2M
    (*p)[offset++] = left;
513
514
    // local gradient
515
14.2M
    (*p)[offset] = left - (*p)[offset + 1];
516
14.2M
    offset++;
517
    // local gradient
518
14.2M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
14.2M
    (*p)[offset++] = left - topleft;
522
14.2M
    (*p)[offset++] = topleft - top;
523
14.2M
    (*p)[offset++] = top - topright;
524
14.2M
    (*p)[offset++] = top - toptop;
525
14.2M
    (*p)[offset++] = left - leftleft;
526
14.2M
  }
527
528
14.2M
  pixel_type_w wp_pred = 0;
529
14.2M
  if (mode & kUseWP) {
530
14.2M
    wp_pred = wp_state->Predict<compute_properties>(
531
14.2M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
14.2M
  }
533
14.2M
  if (!nec && compute_properties) {
534
0
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
0
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
0
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
0
  }
541
14.2M
  PredictionResult result;
542
14.2M
  if (mode & kUseTree) {
543
14.2M
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
14.2M
    result.context = lr.context;
545
14.2M
    result.guess = lr.offset;
546
14.2M
    result.multiplier = lr.multiplier;
547
14.2M
    predictor = lr.predictor;
548
14.2M
  }
549
14.2M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
14.2M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
14.2M
                             leftleft, toprightright, wp_pred);
558
14.2M
  result.predictor = predictor;
559
560
14.2M
  return result;
561
14.2M
}
jxl::PredictionResult jxl::detail::Predict<6>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
3.10M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
3.10M
  size_t offset = 3;
493
3.10M
  constexpr bool compute_properties =
494
3.10M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
3.10M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
3.10M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
3.10M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
3.10M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
3.10M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
3.10M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
3.10M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
3.10M
  pixel_type_w toprightright =
503
3.10M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
3.10M
  if (compute_properties) {
506
    // location
507
3.10M
    (*p)[offset++] = x;
508
    // neighbors
509
3.10M
    (*p)[offset++] = top > 0 ? top : -top;
510
3.10M
    (*p)[offset++] = left > 0 ? left : -left;
511
3.10M
    (*p)[offset++] = top;
512
3.10M
    (*p)[offset++] = left;
513
514
    // local gradient
515
3.10M
    (*p)[offset] = left - (*p)[offset + 1];
516
3.10M
    offset++;
517
    // local gradient
518
3.10M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
3.10M
    (*p)[offset++] = left - topleft;
522
3.10M
    (*p)[offset++] = topleft - top;
523
3.10M
    (*p)[offset++] = top - topright;
524
3.10M
    (*p)[offset++] = top - toptop;
525
3.10M
    (*p)[offset++] = left - leftleft;
526
3.10M
  }
527
528
3.10M
  pixel_type_w wp_pred = 0;
529
3.10M
  if (mode & kUseWP) {
530
3.10M
    wp_pred = wp_state->Predict<compute_properties>(
531
3.10M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
3.10M
  }
533
3.10M
  if (!nec && compute_properties) {
534
3.10M
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
3.10M
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
3.10M
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
3.10M
  }
541
3.10M
  PredictionResult result;
542
3.10M
  if (mode & kUseTree) {
543
0
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
0
    result.context = lr.context;
545
0
    result.guess = lr.offset;
546
0
    result.multiplier = lr.multiplier;
547
0
    predictor = lr.predictor;
548
0
  }
549
3.10M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
3.10M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
3.10M
                             leftleft, toprightright, wp_pred);
558
3.10M
  result.predictor = predictor;
559
560
3.10M
  return result;
561
3.10M
}
Unexecuted instantiation: jxl::PredictionResult jxl::detail::Predict<14>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
jxl::PredictionResult jxl::detail::Predict<22>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Line
Count
Source
490
66.1M
    weighted::State *wp_state, pixel_type_w *predictions) {
491
  // We start in position 3 because of 2 static properties + y.
492
66.1M
  size_t offset = 3;
493
66.1M
  constexpr bool compute_properties =
494
66.1M
      !!(mode & kUseTree) || !!(mode & kForceComputeProperties);
495
66.1M
  constexpr bool nec = !!(mode & kNoEdgeCases);
496
66.1M
  pixel_type_w left = (nec || x ? pp[-1] : (y ? pp[-onerow] : 0));
497
66.1M
  pixel_type_w top = (nec || y ? pp[-onerow] : left);
498
66.1M
  pixel_type_w topleft = (nec || (x && y) ? pp[-1 - onerow] : left);
499
66.1M
  pixel_type_w topright = (nec || (x + 1 < w && y) ? pp[1 - onerow] : top);
500
66.1M
  pixel_type_w leftleft = (nec || x > 1 ? pp[-2] : left);
501
66.1M
  pixel_type_w toptop = (nec || y > 1 ? pp[-onerow - onerow] : top);
502
66.1M
  pixel_type_w toprightright =
503
66.1M
      (nec || (x + 2 < w && y) ? pp[2 - onerow] : topright);
504
505
66.1M
  if (compute_properties) {
506
    // location
507
66.1M
    (*p)[offset++] = x;
508
    // neighbors
509
66.1M
    (*p)[offset++] = top > 0 ? top : -top;
510
66.1M
    (*p)[offset++] = left > 0 ? left : -left;
511
66.1M
    (*p)[offset++] = top;
512
66.1M
    (*p)[offset++] = left;
513
514
    // local gradient
515
66.1M
    (*p)[offset] = left - (*p)[offset + 1];
516
66.1M
    offset++;
517
    // local gradient
518
66.1M
    (*p)[offset++] = left + top - topleft;
519
520
    // FFV1 context properties
521
66.1M
    (*p)[offset++] = left - topleft;
522
66.1M
    (*p)[offset++] = topleft - top;
523
66.1M
    (*p)[offset++] = top - topright;
524
66.1M
    (*p)[offset++] = top - toptop;
525
66.1M
    (*p)[offset++] = left - leftleft;
526
66.1M
  }
527
528
66.1M
  pixel_type_w wp_pred = 0;
529
66.1M
  if (mode & kUseWP) {
530
66.1M
    wp_pred = wp_state->Predict<compute_properties>(
531
66.1M
        x, y, w, top, left, topright, topleft, toptop, p, offset);
532
66.1M
  }
533
66.1M
  if (!nec && compute_properties) {
534
0
    offset += weighted::kNumProperties;
535
    // Extra properties.
536
0
    const pixel_type *JXL_RESTRICT rp = references->Row(x);
537
0
    for (size_t i = 0; i < references->w; i++) {
538
0
      (*p)[offset++] = rp[i];
539
0
    }
540
0
  }
541
66.1M
  PredictionResult result;
542
66.1M
  if (mode & kUseTree) {
543
0
    MATreeLookup::LookupResult lr = lookup->Lookup(*p);
544
0
    result.context = lr.context;
545
0
    result.guess = lr.offset;
546
0
    result.multiplier = lr.multiplier;
547
0
    predictor = lr.predictor;
548
0
  }
549
66.1M
  if (mode & kAllPredictions) {
550
0
    for (size_t i = 0; i < kNumModularPredictors; i++) {
551
0
      predictions[i] =
552
0
          PredictOne(static_cast<Predictor>(i), left, top, toptop, topleft,
553
0
                     topright, leftleft, toprightright, wp_pred);
554
0
    }
555
0
  }
556
66.1M
  result.guess += PredictOne(predictor, left, top, toptop, topleft, topright,
557
66.1M
                             leftleft, toprightright, wp_pred);
558
66.1M
  result.predictor = predictor;
559
560
66.1M
  return result;
561
66.1M
}
Unexecuted instantiation: jxl::PredictionResult jxl::detail::Predict<30>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
Unexecuted instantiation: jxl::PredictionResult jxl::detail::Predict<8>(std::__1::vector<int, std::__1::allocator<int> >*, unsigned long, int const*, long, unsigned long, unsigned long, jxl::Predictor, jxl::MATreeLookup const*, jxl::Channel const*, jxl::weighted::State*, long*)
562
}  // namespace detail
563
564
inline PredictionResult PredictNoTreeNoWP(size_t w,
565
                                          const pixel_type *JXL_RESTRICT pp,
566
                                          const intptr_t onerow, const int x,
567
56.5M
                                          const int y, Predictor predictor) {
568
56.5M
  return detail::Predict</*mode=*/0>(
569
56.5M
      /*p=*/nullptr, w, pp, onerow, x, y, predictor, /*lookup=*/nullptr,
570
56.5M
      /*references=*/nullptr, /*wp_state=*/nullptr, /*predictions=*/nullptr);
571
56.5M
}
572
573
inline PredictionResult PredictNoTreeWP(size_t w,
574
                                        const pixel_type *JXL_RESTRICT pp,
575
                                        const intptr_t onerow, const int x,
576
                                        const int y, Predictor predictor,
577
12.9M
                                        weighted::State *wp_state) {
578
12.9M
  return detail::Predict<detail::kUseWP>(
579
12.9M
      /*p=*/nullptr, w, pp, onerow, x, y, predictor, /*lookup=*/nullptr,
580
12.9M
      /*references=*/nullptr, wp_state, /*predictions=*/nullptr);
581
12.9M
}
582
583
inline PredictionResult PredictTreeNoWP(Properties *p, size_t w,
584
                                        const pixel_type *JXL_RESTRICT pp,
585
                                        const intptr_t onerow, const int x,
586
                                        const int y,
587
                                        const MATreeLookup &tree_lookup,
588
14.7M
                                        const Channel &references) {
589
14.7M
  return detail::Predict<detail::kUseTree>(
590
14.7M
      p, w, pp, onerow, x, y, Predictor::Zero, &tree_lookup, &references,
591
14.7M
      /*wp_state=*/nullptr, /*predictions=*/nullptr);
592
14.7M
}
593
// Only use for y > 1, x > 1, x < w-2, and empty references
594
JXL_INLINE PredictionResult
595
PredictTreeNoWPNEC(Properties *p, size_t w, const pixel_type *JXL_RESTRICT pp,
596
                   const intptr_t onerow, const int x, const int y,
597
51.7M
                   const MATreeLookup &tree_lookup, const Channel &references) {
598
51.7M
  return detail::Predict<detail::kUseTree | detail::kNoEdgeCases>(
599
51.7M
      p, w, pp, onerow, x, y, Predictor::Zero, &tree_lookup, &references,
600
51.7M
      /*wp_state=*/nullptr, /*predictions=*/nullptr);
601
51.7M
}
602
603
inline PredictionResult PredictTreeWP(Properties *p, size_t w,
604
                                      const pixel_type *JXL_RESTRICT pp,
605
                                      const intptr_t onerow, const int x,
606
                                      const int y,
607
                                      const MATreeLookup &tree_lookup,
608
                                      const Channel &references,
609
62.1M
                                      weighted::State *wp_state) {
610
62.1M
  return detail::Predict<detail::kUseTree | detail::kUseWP>(
611
62.1M
      p, w, pp, onerow, x, y, Predictor::Zero, &tree_lookup, &references,
612
62.1M
      wp_state, /*predictions=*/nullptr);
613
62.1M
}
614
JXL_INLINE PredictionResult PredictTreeWPNEC(Properties *p, size_t w,
615
                                             const pixel_type *JXL_RESTRICT pp,
616
                                             const intptr_t onerow, const int x,
617
                                             const int y,
618
                                             const MATreeLookup &tree_lookup,
619
                                             const Channel &references,
620
14.2M
                                             weighted::State *wp_state) {
621
14.2M
  return detail::Predict<detail::kUseTree | detail::kUseWP |
622
14.2M
                         detail::kNoEdgeCases>(
623
14.2M
      p, w, pp, onerow, x, y, Predictor::Zero, &tree_lookup, &references,
624
14.2M
      wp_state, /*predictions=*/nullptr);
625
14.2M
}
626
627
inline PredictionResult PredictLearn(Properties *p, size_t w,
628
                                     const pixel_type *JXL_RESTRICT pp,
629
                                     const intptr_t onerow, const int x,
630
                                     const int y, Predictor predictor,
631
                                     const Channel &references,
632
3.10M
                                     weighted::State *wp_state) {
633
3.10M
  return detail::Predict<detail::kForceComputeProperties | detail::kUseWP>(
634
3.10M
      p, w, pp, onerow, x, y, predictor, /*lookup=*/nullptr, &references,
635
3.10M
      wp_state, /*predictions=*/nullptr);
636
3.10M
}
637
638
inline void PredictLearnAll(Properties *p, size_t w,
639
                            const pixel_type *JXL_RESTRICT pp,
640
                            const intptr_t onerow, const int x, const int y,
641
                            const Channel &references,
642
                            weighted::State *wp_state,
643
0
                            pixel_type_w *predictions) {
644
0
  detail::Predict<detail::kForceComputeProperties | detail::kUseWP |
645
0
                  detail::kAllPredictions>(
646
0
      p, w, pp, onerow, x, y, Predictor::Zero,
647
0
      /*lookup=*/nullptr, &references, wp_state, predictions);
648
0
}
649
inline PredictionResult PredictLearnNEC(Properties *p, size_t w,
650
                                        const pixel_type *JXL_RESTRICT pp,
651
                                        const intptr_t onerow, const int x,
652
                                        const int y, Predictor predictor,
653
                                        const Channel &references,
654
66.1M
                                        weighted::State *wp_state) {
655
66.1M
  return detail::Predict<detail::kForceComputeProperties | detail::kUseWP |
656
66.1M
                         detail::kNoEdgeCases>(
657
66.1M
      p, w, pp, onerow, x, y, predictor, /*lookup=*/nullptr, &references,
658
66.1M
      wp_state, /*predictions=*/nullptr);
659
66.1M
}
660
661
inline void PredictLearnAllNEC(Properties *p, size_t w,
662
                               const pixel_type *JXL_RESTRICT pp,
663
                               const intptr_t onerow, const int x, const int y,
664
                               const Channel &references,
665
                               weighted::State *wp_state,
666
0
                               pixel_type_w *predictions) {
667
0
  detail::Predict<detail::kForceComputeProperties | detail::kUseWP |
668
0
                  detail::kAllPredictions | detail::kNoEdgeCases>(
669
0
      p, w, pp, onerow, x, y, Predictor::Zero,
670
0
      /*lookup=*/nullptr, &references, wp_state, predictions);
671
0
}
672
673
inline void PredictAllNoWP(size_t w, const pixel_type *JXL_RESTRICT pp,
674
                           const intptr_t onerow, const int x, const int y,
675
0
                           pixel_type_w *predictions) {
676
0
  detail::Predict<detail::kAllPredictions>(
677
0
      /*p=*/nullptr, w, pp, onerow, x, y, Predictor::Zero,
678
0
      /*lookup=*/nullptr,
679
0
      /*references=*/nullptr, /*wp_state=*/nullptr, predictions);
680
0
}
681
}  // namespace jxl
682
683
#endif  // LIB_JXL_MODULAR_ENCODING_CONTEXT_PREDICT_H_