Coverage Report

Created: 2026-09-14 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/dec_group.cc
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
#include "lib/jxl/dec_group.h"
7
8
#include <jxl/memory_manager.h>
9
10
#include <algorithm>
11
#include <array>
12
#include <cstddef>
13
#include <cstdint>
14
#include <cstdio>
15
#include <cstdlib>
16
#include <cstring>
17
#include <memory>
18
#include <utility>
19
#include <vector>
20
21
#include "lib/jxl/base/compiler_specific.h"
22
#include "lib/jxl/chroma_from_luma.h"
23
#include "lib/jxl/coeff_order_fwd.h"
24
#include "lib/jxl/dct_util.h"
25
#include "lib/jxl/dec_ans.h"
26
#include "lib/jxl/frame_dimensions.h"
27
#include "lib/jxl/frame_header.h"
28
#include "lib/jxl/image.h"
29
#include "lib/jxl/image_ops.h"
30
#include "lib/jxl/jpeg/jpeg_data.h"
31
#include "lib/jxl/render_pipeline/render_pipeline.h"
32
#include "lib/jxl/render_pipeline/render_pipeline_stage.h"
33
34
#undef HWY_TARGET_INCLUDE
35
#define HWY_TARGET_INCLUDE "lib/jxl/dec_group.cc"
36
#include <hwy/foreach_target.h>
37
#include <hwy/highway.h>
38
39
#include "lib/jxl/ac_context.h"
40
#include "lib/jxl/ac_strategy.h"
41
#include "lib/jxl/base/bits.h"
42
#include "lib/jxl/base/common.h"
43
#include "lib/jxl/base/printf_macros.h"
44
#include "lib/jxl/base/rect.h"
45
#include "lib/jxl/base/status.h"
46
#include "lib/jxl/coeff_order.h"
47
#include "lib/jxl/common.h"  // kMaxNumPasses
48
#include "lib/jxl/dec_cache.h"
49
#include "lib/jxl/dec_transforms-inl.h"
50
#include "lib/jxl/dec_xyb.h"
51
#include "lib/jxl/entropy_coder.h"
52
#include "lib/jxl/quant_weights.h"
53
#include "lib/jxl/quantizer-inl.h"
54
#include "lib/jxl/quantizer.h"
55
56
#ifndef LIB_JXL_DEC_GROUP_CC
57
#define LIB_JXL_DEC_GROUP_CC
58
namespace jxl {
59
60
struct AuxOut;
61
62
// Interface for reading groups for DecodeGroupImpl.
63
class GetBlock {
64
 public:
65
  virtual void StartRow(size_t by) = 0;
66
  virtual Status LoadBlock(size_t bx, size_t by, const AcStrategy& acs,
67
                           size_t size, size_t log2_covered_blocks,
68
                           ACPtr block[3], ACType ac_type) = 0;
69
132k
  virtual ~GetBlock() {}
70
};
71
72
// Controls whether DecodeGroupImpl renders to pixels or not.
73
enum DrawMode {
74
  // Render to pixels.
75
  kDraw = 0,
76
  // Don't render to pixels.
77
  kDontDraw = 1,
78
};
79
80
}  // namespace jxl
81
#endif  // LIB_JXL_DEC_GROUP_CC
82
83
HWY_BEFORE_NAMESPACE();
84
namespace jxl {
85
namespace HWY_NAMESPACE {
86
87
// These templates are not found via ADL.
88
using hwy::HWY_NAMESPACE::AllFalse;
89
using hwy::HWY_NAMESPACE::Gt;
90
using hwy::HWY_NAMESPACE::Le;
91
using hwy::HWY_NAMESPACE::MaskFromVec;
92
using hwy::HWY_NAMESPACE::Or;
93
using hwy::HWY_NAMESPACE::Rebind;
94
using hwy::HWY_NAMESPACE::ShiftRight;
95
96
using D = HWY_FULL(float);
97
using DU = HWY_FULL(uint32_t);
98
using DI = HWY_FULL(int32_t);
99
using DI16 = Rebind<int16_t, DI>;
100
using DI16_FULL = HWY_CAPPED(int16_t, kDCTBlockSize);
101
constexpr D d;
102
constexpr DI di;
103
constexpr DI16 di16;
104
constexpr DI16_FULL di16_full;
105
106
// TODO(veluca): consider SIMDfying.
107
0
void Transpose8x8InPlace(int32_t* JXL_RESTRICT block) {
108
0
  for (size_t x = 0; x < 8; x++) {
109
0
    for (size_t y = x + 1; y < 8; y++) {
110
0
      std::swap(block[y * 8 + x], block[x * 8 + y]);
111
0
    }
112
0
  }
113
0
}
Unexecuted instantiation: jxl::N_SSE4::Transpose8x8InPlace(int*)
Unexecuted instantiation: jxl::N_AVX2::Transpose8x8InPlace(int*)
Unexecuted instantiation: jxl::N_AVX3::Transpose8x8InPlace(int*)
Unexecuted instantiation: jxl::N_AVX3_ZEN4::Transpose8x8InPlace(int*)
Unexecuted instantiation: jxl::N_AVX3_SPR::Transpose8x8InPlace(int*)
Unexecuted instantiation: jxl::N_SSE2::Transpose8x8InPlace(int*)
114
115
template <ACType ac_type>
116
void DequantLane(Vec<D> scaled_dequant_x, Vec<D> scaled_dequant_y,
117
                 Vec<D> scaled_dequant_b,
118
                 const float* JXL_RESTRICT dequant_matrices, size_t size,
119
                 size_t k, Vec<D> x_cc_mul, Vec<D> b_cc_mul,
120
                 const float* JXL_RESTRICT biases, ACPtr qblock[3],
121
205M
                 float* JXL_RESTRICT block) {
122
205M
  const auto x_mul = Mul(Load(d, dequant_matrices + k), scaled_dequant_x);
123
205M
  const auto y_mul =
124
205M
      Mul(Load(d, dequant_matrices + size + k), scaled_dequant_y);
125
205M
  const auto b_mul =
126
205M
      Mul(Load(d, dequant_matrices + 2 * size + k), scaled_dequant_b);
127
128
205M
  Vec<DI> quantized_x_int;
129
205M
  Vec<DI> quantized_y_int;
130
205M
  Vec<DI> quantized_b_int;
131
205M
  if (ac_type == ACType::k16) {
132
18.8M
    quantized_x_int = PromoteTo(di, Load(di16, qblock[0].ptr16 + k));
133
18.8M
    quantized_y_int = PromoteTo(di, Load(di16, qblock[1].ptr16 + k));
134
18.8M
    quantized_b_int = PromoteTo(di, Load(di16, qblock[2].ptr16 + k));
135
186M
  } else {
136
186M
    quantized_x_int = Load(di, qblock[0].ptr32 + k);
137
186M
    quantized_y_int = Load(di, qblock[1].ptr32 + k);
138
186M
    quantized_b_int = Load(di, qblock[2].ptr32 + k);
139
186M
  }
140
141
205M
  const auto dequant_x_cc =
142
205M
      Mul(AdjustQuantBias(di, 0, quantized_x_int, biases), x_mul);
143
205M
  const auto dequant_y =
144
205M
      Mul(AdjustQuantBias(di, 1, quantized_y_int, biases), y_mul);
145
205M
  const auto dequant_b_cc =
146
205M
      Mul(AdjustQuantBias(di, 2, quantized_b_int, biases), b_mul);
147
148
205M
  const auto dequant_x = MulAdd(x_cc_mul, dequant_y, dequant_x_cc);
149
205M
  const auto dequant_b = MulAdd(b_cc_mul, dequant_y, dequant_b_cc);
150
205M
  Store(dequant_x, d, block + k);
151
205M
  Store(dequant_y, d, block + size + k);
152
205M
  Store(dequant_b, d, block + 2 * size + k);
153
205M
}
Unexecuted instantiation: void jxl::N_SSE4::DequantLane<(jxl::ACType)0>(hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, float const*, unsigned long, unsigned long, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_SSE4::DequantLane<(jxl::ACType)1>(hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, float const*, unsigned long, unsigned long, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, float const*, jxl::ACPtr*, float*)
void jxl::N_AVX2::DequantLane<(jxl::ACType)0>(hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, float const*, unsigned long, unsigned long, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, float const*, jxl::ACPtr*, float*)
Line
Count
Source
121
18.8M
                 float* JXL_RESTRICT block) {
122
18.8M
  const auto x_mul = Mul(Load(d, dequant_matrices + k), scaled_dequant_x);
123
18.8M
  const auto y_mul =
124
18.8M
      Mul(Load(d, dequant_matrices + size + k), scaled_dequant_y);
125
18.8M
  const auto b_mul =
126
18.8M
      Mul(Load(d, dequant_matrices + 2 * size + k), scaled_dequant_b);
127
128
18.8M
  Vec<DI> quantized_x_int;
129
18.8M
  Vec<DI> quantized_y_int;
130
18.8M
  Vec<DI> quantized_b_int;
131
18.8M
  if (ac_type == ACType::k16) {
132
18.8M
    quantized_x_int = PromoteTo(di, Load(di16, qblock[0].ptr16 + k));
133
18.8M
    quantized_y_int = PromoteTo(di, Load(di16, qblock[1].ptr16 + k));
134
18.8M
    quantized_b_int = PromoteTo(di, Load(di16, qblock[2].ptr16 + k));
135
18.8M
  } else {
136
0
    quantized_x_int = Load(di, qblock[0].ptr32 + k);
137
0
    quantized_y_int = Load(di, qblock[1].ptr32 + k);
138
0
    quantized_b_int = Load(di, qblock[2].ptr32 + k);
139
0
  }
140
141
18.8M
  const auto dequant_x_cc =
142
18.8M
      Mul(AdjustQuantBias(di, 0, quantized_x_int, biases), x_mul);
143
18.8M
  const auto dequant_y =
144
18.8M
      Mul(AdjustQuantBias(di, 1, quantized_y_int, biases), y_mul);
145
18.8M
  const auto dequant_b_cc =
146
18.8M
      Mul(AdjustQuantBias(di, 2, quantized_b_int, biases), b_mul);
147
148
18.8M
  const auto dequant_x = MulAdd(x_cc_mul, dequant_y, dequant_x_cc);
149
18.8M
  const auto dequant_b = MulAdd(b_cc_mul, dequant_y, dequant_b_cc);
150
18.8M
  Store(dequant_x, d, block + k);
151
18.8M
  Store(dequant_y, d, block + size + k);
152
18.8M
  Store(dequant_b, d, block + 2 * size + k);
153
18.8M
}
void jxl::N_AVX2::DequantLane<(jxl::ACType)1>(hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, float const*, unsigned long, unsigned long, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, float const*, jxl::ACPtr*, float*)
Line
Count
Source
121
186M
                 float* JXL_RESTRICT block) {
122
186M
  const auto x_mul = Mul(Load(d, dequant_matrices + k), scaled_dequant_x);
123
186M
  const auto y_mul =
124
186M
      Mul(Load(d, dequant_matrices + size + k), scaled_dequant_y);
125
186M
  const auto b_mul =
126
186M
      Mul(Load(d, dequant_matrices + 2 * size + k), scaled_dequant_b);
127
128
186M
  Vec<DI> quantized_x_int;
129
186M
  Vec<DI> quantized_y_int;
130
186M
  Vec<DI> quantized_b_int;
131
186M
  if (ac_type == ACType::k16) {
132
0
    quantized_x_int = PromoteTo(di, Load(di16, qblock[0].ptr16 + k));
133
0
    quantized_y_int = PromoteTo(di, Load(di16, qblock[1].ptr16 + k));
134
0
    quantized_b_int = PromoteTo(di, Load(di16, qblock[2].ptr16 + k));
135
186M
  } else {
136
186M
    quantized_x_int = Load(di, qblock[0].ptr32 + k);
137
186M
    quantized_y_int = Load(di, qblock[1].ptr32 + k);
138
186M
    quantized_b_int = Load(di, qblock[2].ptr32 + k);
139
186M
  }
140
141
186M
  const auto dequant_x_cc =
142
186M
      Mul(AdjustQuantBias(di, 0, quantized_x_int, biases), x_mul);
143
186M
  const auto dequant_y =
144
186M
      Mul(AdjustQuantBias(di, 1, quantized_y_int, biases), y_mul);
145
186M
  const auto dequant_b_cc =
146
186M
      Mul(AdjustQuantBias(di, 2, quantized_b_int, biases), b_mul);
147
148
186M
  const auto dequant_x = MulAdd(x_cc_mul, dequant_y, dequant_x_cc);
149
186M
  const auto dequant_b = MulAdd(b_cc_mul, dequant_y, dequant_b_cc);
150
186M
  Store(dequant_x, d, block + k);
151
186M
  Store(dequant_y, d, block + size + k);
152
186M
  Store(dequant_b, d, block + 2 * size + k);
153
186M
}
Unexecuted instantiation: void jxl::N_AVX3::DequantLane<(jxl::ACType)0>(hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_AVX3::DequantLane<(jxl::ACType)1>(hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::DequantLane<(jxl::ACType)0>(hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::DequantLane<(jxl::ACType)1>(hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_AVX3_SPR::DequantLane<(jxl::ACType)0>(hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_AVX3_SPR::DequantLane<(jxl::ACType)1>(hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, float const*, unsigned long, unsigned long, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_SSE2::DequantLane<(jxl::ACType)0>(hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, float const*, unsigned long, unsigned long, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, float const*, jxl::ACPtr*, float*)
Unexecuted instantiation: void jxl::N_SSE2::DequantLane<(jxl::ACType)1>(hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, float const*, unsigned long, unsigned long, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, float const*, jxl::ACPtr*, float*)
154
155
template <ACType ac_type>
156
void DequantBlock(float inv_global_scale, int quant, float x_dm_multiplier,
157
                  float b_dm_multiplier, Vec<D> x_cc_mul, Vec<D> b_cc_mul,
158
                  AcStrategyType kind, size_t size, const Quantizer& quantizer,
159
                  size_t covered_blocks, const size_t* sbx,
160
                  const float* JXL_RESTRICT* JXL_RESTRICT dc_row,
161
                  size_t dc_stride, const float* JXL_RESTRICT biases,
162
                  ACPtr qblock[3], float* JXL_RESTRICT block,
163
12.1M
                  float* JXL_RESTRICT scratch) {
164
12.1M
  const auto scaled_dequant_s = inv_global_scale / quant;
165
166
12.1M
  const auto scaled_dequant_x = Set(d, scaled_dequant_s * x_dm_multiplier);
167
12.1M
  const auto scaled_dequant_y = Set(d, scaled_dequant_s);
168
12.1M
  const auto scaled_dequant_b = Set(d, scaled_dequant_s * b_dm_multiplier);
169
170
12.1M
  const float* dequant_matrices = quantizer.DequantMatrix(kind, 0);
171
172
217M
  for (size_t k = 0; k < covered_blocks * kDCTBlockSize; k += Lanes(d)) {
173
205M
    DequantLane<ac_type>(scaled_dequant_x, scaled_dequant_y, scaled_dequant_b,
174
205M
                         dequant_matrices, size, k, x_cc_mul, b_cc_mul, biases,
175
205M
                         qblock, block);
176
205M
  }
177
48.5M
  for (size_t c = 0; c < 3; c++) {
178
36.3M
    LowestFrequenciesFromDC(kind, dc_row[c] + sbx[c], dc_stride,
179
36.3M
                            block + c * size, scratch);
180
36.3M
  }
181
12.1M
}
Unexecuted instantiation: void jxl::N_SSE4::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_SSE4::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
void jxl::N_AVX2::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Line
Count
Source
163
1.24M
                  float* JXL_RESTRICT scratch) {
164
1.24M
  const auto scaled_dequant_s = inv_global_scale / quant;
165
166
1.24M
  const auto scaled_dequant_x = Set(d, scaled_dequant_s * x_dm_multiplier);
167
1.24M
  const auto scaled_dequant_y = Set(d, scaled_dequant_s);
168
1.24M
  const auto scaled_dequant_b = Set(d, scaled_dequant_s * b_dm_multiplier);
169
170
1.24M
  const float* dequant_matrices = quantizer.DequantMatrix(kind, 0);
171
172
20.1M
  for (size_t k = 0; k < covered_blocks * kDCTBlockSize; k += Lanes(d)) {
173
18.8M
    DequantLane<ac_type>(scaled_dequant_x, scaled_dequant_y, scaled_dequant_b,
174
18.8M
                         dequant_matrices, size, k, x_cc_mul, b_cc_mul, biases,
175
18.8M
                         qblock, block);
176
18.8M
  }
177
4.99M
  for (size_t c = 0; c < 3; c++) {
178
3.74M
    LowestFrequenciesFromDC(kind, dc_row[c] + sbx[c], dc_stride,
179
3.74M
                            block + c * size, scratch);
180
3.74M
  }
181
1.24M
}
void jxl::N_AVX2::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Line
Count
Source
163
10.8M
                  float* JXL_RESTRICT scratch) {
164
10.8M
  const auto scaled_dequant_s = inv_global_scale / quant;
165
166
10.8M
  const auto scaled_dequant_x = Set(d, scaled_dequant_s * x_dm_multiplier);
167
10.8M
  const auto scaled_dequant_y = Set(d, scaled_dequant_s);
168
10.8M
  const auto scaled_dequant_b = Set(d, scaled_dequant_s * b_dm_multiplier);
169
170
10.8M
  const float* dequant_matrices = quantizer.DequantMatrix(kind, 0);
171
172
197M
  for (size_t k = 0; k < covered_blocks * kDCTBlockSize; k += Lanes(d)) {
173
186M
    DequantLane<ac_type>(scaled_dequant_x, scaled_dequant_y, scaled_dequant_b,
174
186M
                         dequant_matrices, size, k, x_cc_mul, b_cc_mul, biases,
175
186M
                         qblock, block);
176
186M
  }
177
43.5M
  for (size_t c = 0; c < 3; c++) {
178
32.6M
    LowestFrequenciesFromDC(kind, dc_row[c] + sbx[c], dc_stride,
179
32.6M
                            block + c * size, scratch);
180
32.6M
  }
181
10.8M
}
Unexecuted instantiation: void jxl::N_AVX3::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_AVX3::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_AVX3_SPR::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_AVX3_SPR::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_SSE2::DequantBlock<(jxl::ACType)0>(float, int, float, float, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
Unexecuted instantiation: void jxl::N_SSE2::DequantBlock<(jxl::ACType)1>(float, int, float, float, hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>, jxl::AcStrategyType, unsigned long, jxl::Quantizer const&, unsigned long, unsigned long const*, float const* restrict*, unsigned long, float const*, jxl::ACPtr*, float*, float*)
182
183
Status DecodeGroupImpl(const FrameHeader& frame_header,
184
                       GetBlock* JXL_RESTRICT get_block,
185
                       GroupDecCache* JXL_RESTRICT group_dec_cache,
186
                       PassesDecoderState* JXL_RESTRICT dec_state,
187
                       size_t thread, size_t group_idx,
188
                       RenderPipelineInput& render_pipeline_input,
189
58.4k
                       jpeg::JPEGData* jpeg_data, DrawMode draw) {
190
  // TODO(veluca): investigate cache usage in this function.
191
58.4k
  const Rect block_rect =
192
58.4k
      dec_state->shared->frame_dim.BlockGroupRect(group_idx);
193
58.4k
  const AcStrategyImage& ac_strategy = dec_state->shared->ac_strategy;
194
195
58.4k
  const size_t xsize_blocks = block_rect.xsize();
196
58.4k
  const size_t ysize_blocks = block_rect.ysize();
197
198
58.4k
  const size_t dc_stride = dec_state->shared->dc->PixelsPerRow();
199
200
58.4k
  const float inv_global_scale = dec_state->shared->quantizer.InvGlobalScale();
201
202
58.4k
  const YCbCrChromaSubsampling& cs = frame_header.chroma_subsampling;
203
204
58.4k
  const auto kJpegDctMin = Set(di16_full, -4095);
205
58.4k
  const auto kJpegDctMax = Set(di16_full, 4095);
206
207
58.4k
  size_t idct_stride[3];
208
233k
  for (size_t c = 0; c < 3; c++) {
209
175k
    idct_stride[c] = render_pipeline_input.GetBuffer(c).first->PixelsPerRow();
210
175k
  }
211
212
58.4k
  HWY_ALIGN int32_t scaled_qtable[64 * 3];
213
214
58.4k
  ACType ac_type = dec_state->coefficients->Type();
215
58.4k
  auto dequant_block = ac_type == ACType::k16 ? DequantBlock<ACType::k16>
216
58.4k
                                              : DequantBlock<ACType::k32>;
217
  // Whether or not coefficients should be stored for future usage, and/or read
218
  // from past usage.
219
58.4k
  bool accumulate = !dec_state->coefficients->IsEmpty();
220
  // Offset of the current block in the group.
221
58.4k
  size_t offset = 0;
222
223
58.4k
  std::array<int, 3> jpeg_c_map;
224
58.4k
  bool jpeg_is_gray = false;
225
58.4k
  std::array<int, 3> dcoff = {};
226
227
  // TODO(veluca): all of this should be done only once per image.
228
58.4k
  const ColorCorrelation& color_correlation = dec_state->shared->cmap.base();
229
58.4k
  if (jpeg_data) {
230
0
    if (!color_correlation.IsJPEGCompatible()) {
231
0
      return JXL_FAILURE("The CfL map is not JPEG-compatible");
232
0
    }
233
0
    jpeg_is_gray = (jpeg_data->components.size() == 1);
234
0
    JXL_ENSURE(frame_header.color_transform != ColorTransform::kXYB);
235
0
    jpeg_c_map = JpegOrder(frame_header.color_transform, jpeg_is_gray);
236
0
    const std::vector<QuantEncoding>& qe =
237
0
        dec_state->shared->matrices.encodings();
238
0
    if (qe.empty() || qe[0].mode != QuantEncoding::Mode::kQuantModeRAW ||
239
0
        std::abs(qe[0].qraw.qtable_den - 1.f / (8 * 255)) > 1e-8f) {
240
0
      return JXL_FAILURE(
241
0
          "Quantization table is not a JPEG quantization table.");
242
0
    }
243
0
    JXL_ENSURE(qe[0].qraw.qtable->size() == 3 * 8 * 8);
244
0
    int* qtable = qe[0].qraw.qtable->data();
245
0
    for (size_t c = 0; c < 3; c++) {
246
0
      if (frame_header.color_transform == ColorTransform::kNone) {
247
0
        dcoff[c] = 1024 / qtable[64 * c];
248
0
      }
249
0
      for (size_t i = 0; i < 64; i++) {
250
        // Transpose the matrix, as it will be used on the transposed block.
251
0
        int num = qtable[64 + i];
252
0
        int den = qtable[64 * c + i];
253
0
        if (num <= 0 || den <= 0 || num >= 65536 || den >= 65536) {
254
0
          return JXL_FAILURE("Invalid JPEG quantization table");
255
0
        }
256
0
        scaled_qtable[64 * c + (i % 8) * 8 + (i / 8)] =
257
0
            (1 << kCFLFixedPointPrecision) * num / den;
258
0
      }
259
0
    }
260
0
  }
261
262
58.4k
  size_t hshift[3] = {cs.HShift(0), cs.HShift(1), cs.HShift(2)};
263
58.4k
  size_t vshift[3] = {cs.VShift(0), cs.VShift(1), cs.VShift(2)};
264
58.4k
  Rect r[3];
265
233k
  for (size_t i = 0; i < 3; i++) {
266
175k
    r[i] =
267
175k
        Rect(block_rect.x0() >> hshift[i], block_rect.y0() >> vshift[i],
268
175k
             block_rect.xsize() >> hshift[i], block_rect.ysize() >> vshift[i]);
269
175k
    if (!r[i].IsInside({0, 0, dec_state->shared->dc->Plane(i).xsize(),
270
175k
                        dec_state->shared->dc->Plane(i).ysize()})) {
271
0
      return JXL_FAILURE("Frame dimensions are too big for the image.");
272
0
    }
273
175k
  }
274
275
1.21M
  for (size_t by = 0; by < ysize_blocks; ++by) {
276
1.15M
    get_block->StartRow(by);
277
1.15M
    size_t sby[3] = {by >> vshift[0], by >> vshift[1], by >> vshift[2]};
278
279
1.15M
    const int32_t* JXL_RESTRICT row_quant =
280
1.15M
        block_rect.ConstRow(dec_state->shared->raw_quant_field, by);
281
282
1.15M
    const float* JXL_RESTRICT dc_rows[3] = {
283
1.15M
        r[0].ConstPlaneRow(*dec_state->shared->dc, 0, sby[0]),
284
1.15M
        r[1].ConstPlaneRow(*dec_state->shared->dc, 1, sby[1]),
285
1.15M
        r[2].ConstPlaneRow(*dec_state->shared->dc, 2, sby[2]),
286
1.15M
    };
287
288
1.15M
    const size_t ty = (block_rect.y0() + by) / kColorTileDimInBlocks;
289
1.15M
    AcStrategyRow acs_row = ac_strategy.ConstRow(block_rect, by);
290
291
1.15M
    const int8_t* JXL_RESTRICT row_cmap[3] = {
292
1.15M
        dec_state->shared->cmap.ytox_map.ConstRow(ty),
293
1.15M
        nullptr,
294
1.15M
        dec_state->shared->cmap.ytob_map.ConstRow(ty),
295
1.15M
    };
296
297
1.15M
    float* JXL_RESTRICT idct_row[3];
298
1.15M
    int16_t* JXL_RESTRICT jpeg_row[3];
299
4.62M
    for (size_t c = 0; c < 3; c++) {
300
3.46M
      const auto& buffer = render_pipeline_input.GetBuffer(c);
301
3.46M
      idct_row[c] = buffer.second.Row(buffer.first, sby[c] * kBlockDim);
302
3.46M
      if (jpeg_data) {
303
0
        auto& component = jpeg_data->components[jpeg_c_map[c]];
304
0
        jpeg_row[c] =
305
0
            component.coeffs.data() +
306
0
            (component.width_in_blocks * (r[c].y0() + sby[c]) + r[c].x0()) *
307
0
                kDCTBlockSize;
308
0
      }
309
3.46M
    }
310
311
1.15M
    size_t bx = 0;
312
4.73M
    for (size_t tx = 0; tx < DivCeil(xsize_blocks, kColorTileDimInBlocks);
313
3.57M
         tx++) {
314
3.57M
      size_t abs_tx = tx + block_rect.x0() / kColorTileDimInBlocks;
315
3.57M
      auto x_cc_mul = Set(d, color_correlation.YtoXRatio(row_cmap[0][abs_tx]));
316
3.57M
      auto b_cc_mul = Set(d, color_correlation.YtoBRatio(row_cmap[2][abs_tx]));
317
      // Increment bx by llf_x because those iterations would otherwise
318
      // immediately continue (!IsFirstBlock). Reduces mispredictions.
319
18.2M
      for (; bx < xsize_blocks && bx < (tx + 1) * kColorTileDimInBlocks;) {
320
14.6M
        size_t sbx[3] = {bx >> hshift[0], bx >> hshift[1], bx >> hshift[2]};
321
14.6M
        AcStrategy acs = acs_row[bx];
322
14.6M
        const size_t llf_x = acs.covered_blocks_x();
323
324
        // Can only happen in the second or lower rows of a varblock.
325
14.6M
        if (JXL_UNLIKELY(!acs.IsFirstBlock())) {
326
2.55M
          bx += llf_x;
327
2.55M
          continue;
328
2.55M
        }
329
12.1M
        const size_t log2_covered_blocks = acs.log2_covered_blocks();
330
331
12.1M
        const size_t covered_blocks = 1 << log2_covered_blocks;
332
12.1M
        const size_t size = covered_blocks * kDCTBlockSize;
333
334
12.1M
        ACPtr qblock[3];
335
12.1M
        if (accumulate) {
336
260
          for (size_t c = 0; c < 3; c++) {
337
195
            qblock[c] = dec_state->coefficients->PlaneRow(c, group_idx, offset);
338
195
          }
339
12.1M
        } else {
340
          // No point in reading from bitstream without accumulating and not
341
          // drawing.
342
12.1M
          JXL_ENSURE(draw == kDraw);
343
12.1M
          if (ac_type == ACType::k16) {
344
1.24M
            memset(group_dec_cache->dec_group_qblock16, 0,
345
1.24M
                   size * 3 * sizeof(int16_t));
346
4.99M
            for (size_t c = 0; c < 3; c++) {
347
3.74M
              qblock[c].ptr16 = group_dec_cache->dec_group_qblock16 + c * size;
348
3.74M
            }
349
10.8M
          } else {
350
10.8M
            memset(group_dec_cache->dec_group_qblock, 0,
351
10.8M
                   size * 3 * sizeof(int32_t));
352
43.5M
            for (size_t c = 0; c < 3; c++) {
353
32.6M
              qblock[c].ptr32 = group_dec_cache->dec_group_qblock + c * size;
354
32.6M
            }
355
10.8M
          }
356
12.1M
        }
357
12.1M
        JXL_RETURN_IF_ERROR(get_block->LoadBlock(
358
12.1M
            bx, by, acs, size, log2_covered_blocks, qblock, ac_type));
359
12.1M
        offset += size;
360
12.1M
        if (draw == kDontDraw) {
361
56
          bx += llf_x;
362
56
          continue;
363
56
        }
364
365
12.1M
        if (JXL_UNLIKELY(jpeg_data)) {
366
0
          if (acs.Strategy() != AcStrategyType::DCT) {
367
0
            return JXL_FAILURE(
368
0
                "Can only decode to JPEG if only DCT-8 is used.");
369
0
          }
370
371
0
          HWY_ALIGN int32_t transposed_dct_y[64];
372
0
          for (size_t c : {1, 0, 2}) {
373
            // Propagate only Y for grayscale.
374
0
            if (jpeg_is_gray && c != 1) {
375
0
              continue;
376
0
            }
377
0
            if ((sbx[c] << hshift[c] != bx) || (sby[c] << vshift[c] != by)) {
378
0
              continue;
379
0
            }
380
0
            int16_t* JXL_RESTRICT jpeg_pos =
381
0
                jpeg_row[c] + sbx[c] * kDCTBlockSize;
382
            // JPEG XL is transposed, JPEG is not.
383
0
            auto* transposed_dct = qblock[c].ptr32;
384
0
            Transpose8x8InPlace(transposed_dct);
385
            // No CfL - no need to store the y block converted to integers.
386
0
            if (!cs.Is444() ||
387
0
                (row_cmap[0][abs_tx] == 0 && row_cmap[2][abs_tx] == 0)) {
388
0
              for (size_t i = 0; i < 64; i += Lanes(d)) {
389
0
                const auto ini = Load(di, transposed_dct + i);
390
0
                const auto ini16 = DemoteTo(di16, ini);
391
0
                StoreU(ini16, di16, jpeg_pos + i);
392
0
              }
393
0
            } else if (c == 1) {
394
              // Y channel: save for restoring X/B, but nothing else to do.
395
0
              for (size_t i = 0; i < 64; i += Lanes(d)) {
396
0
                const auto ini = Load(di, transposed_dct + i);
397
0
                Store(ini, di, transposed_dct_y + i);
398
0
                const auto ini16 = DemoteTo(di16, ini);
399
0
                StoreU(ini16, di16, jpeg_pos + i);
400
0
              }
401
0
            } else {
402
              // transposed_dct_y contains the y channel block, transposed.
403
0
              const auto scale =
404
0
                  Set(di, ColorCorrelation::RatioJPEG(row_cmap[c][abs_tx]));
405
0
              const auto round = Set(di, 1 << (kCFLFixedPointPrecision - 1));
406
0
              for (int i = 0; i < 64; i += Lanes(d)) {
407
0
                auto in = Load(di, transposed_dct + i);
408
0
                auto in_y = Load(di, transposed_dct_y + i);
409
0
                auto qt = Load(di, scaled_qtable + c * size + i);
410
0
                auto coeff_scale = ShiftRight<kCFLFixedPointPrecision>(
411
0
                    Add(Mul(qt, scale), round));
412
0
                auto cfl_factor = ShiftRight<kCFLFixedPointPrecision>(
413
0
                    Add(Mul(in_y, coeff_scale), round));
414
0
                StoreU(DemoteTo(di16, Add(in, cfl_factor)), di16, jpeg_pos + i);
415
0
              }
416
0
            }
417
0
            jpeg_pos[0] =
418
0
                Clamp1<float>(dc_rows[c][sbx[c]] - dcoff[c], -2047, 2047);
419
0
            auto overflow = MaskFromVec(Set(di16_full, 0));
420
0
            auto underflow = MaskFromVec(Set(di16_full, 0));
421
0
            for (int i = 0; i < 64; i += Lanes(di16_full)) {
422
0
              auto in = LoadU(di16_full, jpeg_pos + i);
423
0
              overflow = Or(overflow, Gt(in, kJpegDctMax));
424
0
              underflow = Or(underflow, Lt(in, kJpegDctMin));
425
0
            }
426
0
            if (!AllFalse(di16_full, Or(overflow, underflow))) {
427
0
              return JXL_FAILURE("JPEG DCT coefficients out of range");
428
0
            }
429
0
          }
430
12.1M
        } else {
431
12.1M
          HWY_ALIGN float* const block = group_dec_cache->dec_group_block;
432
          // Dequantize and add predictions.
433
12.1M
          dequant_block(
434
12.1M
              inv_global_scale, row_quant[bx], dec_state->x_dm_multiplier,
435
12.1M
              dec_state->b_dm_multiplier, x_cc_mul, b_cc_mul, acs.Strategy(),
436
12.1M
              size, dec_state->shared->quantizer,
437
12.1M
              acs.covered_blocks_y() * acs.covered_blocks_x(), sbx, dc_rows,
438
12.1M
              dc_stride,
439
12.1M
              dec_state->output_encoding_info.opsin_params.quant_biases, qblock,
440
12.1M
              block, group_dec_cache->scratch_space);
441
442
36.3M
          for (size_t c : {1, 0, 2}) {
443
36.3M
            if ((sbx[c] << hshift[c] != bx) || (sby[c] << vshift[c] != by)) {
444
5.00k
              continue;
445
5.00k
            }
446
            // IDCT
447
36.3M
            float* JXL_RESTRICT idct_pos = idct_row[c] + sbx[c] * kBlockDim;
448
36.3M
            TransformToPixels(acs.Strategy(), block + c * size, idct_pos,
449
36.3M
                              idct_stride[c], group_dec_cache->scratch_space);
450
36.3M
          }
451
12.1M
        }
452
12.1M
        bx += llf_x;
453
12.1M
      }
454
3.57M
    }
455
1.15M
  }
456
57.4k
  return true;
457
58.4k
}
Unexecuted instantiation: jxl::N_SSE4::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
jxl::N_AVX2::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
Line
Count
Source
189
58.4k
                       jpeg::JPEGData* jpeg_data, DrawMode draw) {
190
  // TODO(veluca): investigate cache usage in this function.
191
58.4k
  const Rect block_rect =
192
58.4k
      dec_state->shared->frame_dim.BlockGroupRect(group_idx);
193
58.4k
  const AcStrategyImage& ac_strategy = dec_state->shared->ac_strategy;
194
195
58.4k
  const size_t xsize_blocks = block_rect.xsize();
196
58.4k
  const size_t ysize_blocks = block_rect.ysize();
197
198
58.4k
  const size_t dc_stride = dec_state->shared->dc->PixelsPerRow();
199
200
58.4k
  const float inv_global_scale = dec_state->shared->quantizer.InvGlobalScale();
201
202
58.4k
  const YCbCrChromaSubsampling& cs = frame_header.chroma_subsampling;
203
204
58.4k
  const auto kJpegDctMin = Set(di16_full, -4095);
205
58.4k
  const auto kJpegDctMax = Set(di16_full, 4095);
206
207
58.4k
  size_t idct_stride[3];
208
233k
  for (size_t c = 0; c < 3; c++) {
209
175k
    idct_stride[c] = render_pipeline_input.GetBuffer(c).first->PixelsPerRow();
210
175k
  }
211
212
58.4k
  HWY_ALIGN int32_t scaled_qtable[64 * 3];
213
214
58.4k
  ACType ac_type = dec_state->coefficients->Type();
215
58.4k
  auto dequant_block = ac_type == ACType::k16 ? DequantBlock<ACType::k16>
216
58.4k
                                              : DequantBlock<ACType::k32>;
217
  // Whether or not coefficients should be stored for future usage, and/or read
218
  // from past usage.
219
58.4k
  bool accumulate = !dec_state->coefficients->IsEmpty();
220
  // Offset of the current block in the group.
221
58.4k
  size_t offset = 0;
222
223
58.4k
  std::array<int, 3> jpeg_c_map;
224
58.4k
  bool jpeg_is_gray = false;
225
58.4k
  std::array<int, 3> dcoff = {};
226
227
  // TODO(veluca): all of this should be done only once per image.
228
58.4k
  const ColorCorrelation& color_correlation = dec_state->shared->cmap.base();
229
58.4k
  if (jpeg_data) {
230
0
    if (!color_correlation.IsJPEGCompatible()) {
231
0
      return JXL_FAILURE("The CfL map is not JPEG-compatible");
232
0
    }
233
0
    jpeg_is_gray = (jpeg_data->components.size() == 1);
234
0
    JXL_ENSURE(frame_header.color_transform != ColorTransform::kXYB);
235
0
    jpeg_c_map = JpegOrder(frame_header.color_transform, jpeg_is_gray);
236
0
    const std::vector<QuantEncoding>& qe =
237
0
        dec_state->shared->matrices.encodings();
238
0
    if (qe.empty() || qe[0].mode != QuantEncoding::Mode::kQuantModeRAW ||
239
0
        std::abs(qe[0].qraw.qtable_den - 1.f / (8 * 255)) > 1e-8f) {
240
0
      return JXL_FAILURE(
241
0
          "Quantization table is not a JPEG quantization table.");
242
0
    }
243
0
    JXL_ENSURE(qe[0].qraw.qtable->size() == 3 * 8 * 8);
244
0
    int* qtable = qe[0].qraw.qtable->data();
245
0
    for (size_t c = 0; c < 3; c++) {
246
0
      if (frame_header.color_transform == ColorTransform::kNone) {
247
0
        dcoff[c] = 1024 / qtable[64 * c];
248
0
      }
249
0
      for (size_t i = 0; i < 64; i++) {
250
        // Transpose the matrix, as it will be used on the transposed block.
251
0
        int num = qtable[64 + i];
252
0
        int den = qtable[64 * c + i];
253
0
        if (num <= 0 || den <= 0 || num >= 65536 || den >= 65536) {
254
0
          return JXL_FAILURE("Invalid JPEG quantization table");
255
0
        }
256
0
        scaled_qtable[64 * c + (i % 8) * 8 + (i / 8)] =
257
0
            (1 << kCFLFixedPointPrecision) * num / den;
258
0
      }
259
0
    }
260
0
  }
261
262
58.4k
  size_t hshift[3] = {cs.HShift(0), cs.HShift(1), cs.HShift(2)};
263
58.4k
  size_t vshift[3] = {cs.VShift(0), cs.VShift(1), cs.VShift(2)};
264
58.4k
  Rect r[3];
265
233k
  for (size_t i = 0; i < 3; i++) {
266
175k
    r[i] =
267
175k
        Rect(block_rect.x0() >> hshift[i], block_rect.y0() >> vshift[i],
268
175k
             block_rect.xsize() >> hshift[i], block_rect.ysize() >> vshift[i]);
269
175k
    if (!r[i].IsInside({0, 0, dec_state->shared->dc->Plane(i).xsize(),
270
175k
                        dec_state->shared->dc->Plane(i).ysize()})) {
271
0
      return JXL_FAILURE("Frame dimensions are too big for the image.");
272
0
    }
273
175k
  }
274
275
1.21M
  for (size_t by = 0; by < ysize_blocks; ++by) {
276
1.15M
    get_block->StartRow(by);
277
1.15M
    size_t sby[3] = {by >> vshift[0], by >> vshift[1], by >> vshift[2]};
278
279
1.15M
    const int32_t* JXL_RESTRICT row_quant =
280
1.15M
        block_rect.ConstRow(dec_state->shared->raw_quant_field, by);
281
282
1.15M
    const float* JXL_RESTRICT dc_rows[3] = {
283
1.15M
        r[0].ConstPlaneRow(*dec_state->shared->dc, 0, sby[0]),
284
1.15M
        r[1].ConstPlaneRow(*dec_state->shared->dc, 1, sby[1]),
285
1.15M
        r[2].ConstPlaneRow(*dec_state->shared->dc, 2, sby[2]),
286
1.15M
    };
287
288
1.15M
    const size_t ty = (block_rect.y0() + by) / kColorTileDimInBlocks;
289
1.15M
    AcStrategyRow acs_row = ac_strategy.ConstRow(block_rect, by);
290
291
1.15M
    const int8_t* JXL_RESTRICT row_cmap[3] = {
292
1.15M
        dec_state->shared->cmap.ytox_map.ConstRow(ty),
293
1.15M
        nullptr,
294
1.15M
        dec_state->shared->cmap.ytob_map.ConstRow(ty),
295
1.15M
    };
296
297
1.15M
    float* JXL_RESTRICT idct_row[3];
298
1.15M
    int16_t* JXL_RESTRICT jpeg_row[3];
299
4.62M
    for (size_t c = 0; c < 3; c++) {
300
3.46M
      const auto& buffer = render_pipeline_input.GetBuffer(c);
301
3.46M
      idct_row[c] = buffer.second.Row(buffer.first, sby[c] * kBlockDim);
302
3.46M
      if (jpeg_data) {
303
0
        auto& component = jpeg_data->components[jpeg_c_map[c]];
304
0
        jpeg_row[c] =
305
0
            component.coeffs.data() +
306
0
            (component.width_in_blocks * (r[c].y0() + sby[c]) + r[c].x0()) *
307
0
                kDCTBlockSize;
308
0
      }
309
3.46M
    }
310
311
1.15M
    size_t bx = 0;
312
4.73M
    for (size_t tx = 0; tx < DivCeil(xsize_blocks, kColorTileDimInBlocks);
313
3.57M
         tx++) {
314
3.57M
      size_t abs_tx = tx + block_rect.x0() / kColorTileDimInBlocks;
315
3.57M
      auto x_cc_mul = Set(d, color_correlation.YtoXRatio(row_cmap[0][abs_tx]));
316
3.57M
      auto b_cc_mul = Set(d, color_correlation.YtoBRatio(row_cmap[2][abs_tx]));
317
      // Increment bx by llf_x because those iterations would otherwise
318
      // immediately continue (!IsFirstBlock). Reduces mispredictions.
319
18.2M
      for (; bx < xsize_blocks && bx < (tx + 1) * kColorTileDimInBlocks;) {
320
14.6M
        size_t sbx[3] = {bx >> hshift[0], bx >> hshift[1], bx >> hshift[2]};
321
14.6M
        AcStrategy acs = acs_row[bx];
322
14.6M
        const size_t llf_x = acs.covered_blocks_x();
323
324
        // Can only happen in the second or lower rows of a varblock.
325
14.6M
        if (JXL_UNLIKELY(!acs.IsFirstBlock())) {
326
2.55M
          bx += llf_x;
327
2.55M
          continue;
328
2.55M
        }
329
12.1M
        const size_t log2_covered_blocks = acs.log2_covered_blocks();
330
331
12.1M
        const size_t covered_blocks = 1 << log2_covered_blocks;
332
12.1M
        const size_t size = covered_blocks * kDCTBlockSize;
333
334
12.1M
        ACPtr qblock[3];
335
12.1M
        if (accumulate) {
336
260
          for (size_t c = 0; c < 3; c++) {
337
195
            qblock[c] = dec_state->coefficients->PlaneRow(c, group_idx, offset);
338
195
          }
339
12.1M
        } else {
340
          // No point in reading from bitstream without accumulating and not
341
          // drawing.
342
12.1M
          JXL_ENSURE(draw == kDraw);
343
12.1M
          if (ac_type == ACType::k16) {
344
1.24M
            memset(group_dec_cache->dec_group_qblock16, 0,
345
1.24M
                   size * 3 * sizeof(int16_t));
346
4.99M
            for (size_t c = 0; c < 3; c++) {
347
3.74M
              qblock[c].ptr16 = group_dec_cache->dec_group_qblock16 + c * size;
348
3.74M
            }
349
10.8M
          } else {
350
10.8M
            memset(group_dec_cache->dec_group_qblock, 0,
351
10.8M
                   size * 3 * sizeof(int32_t));
352
43.5M
            for (size_t c = 0; c < 3; c++) {
353
32.6M
              qblock[c].ptr32 = group_dec_cache->dec_group_qblock + c * size;
354
32.6M
            }
355
10.8M
          }
356
12.1M
        }
357
12.1M
        JXL_RETURN_IF_ERROR(get_block->LoadBlock(
358
12.1M
            bx, by, acs, size, log2_covered_blocks, qblock, ac_type));
359
12.1M
        offset += size;
360
12.1M
        if (draw == kDontDraw) {
361
56
          bx += llf_x;
362
56
          continue;
363
56
        }
364
365
12.1M
        if (JXL_UNLIKELY(jpeg_data)) {
366
0
          if (acs.Strategy() != AcStrategyType::DCT) {
367
0
            return JXL_FAILURE(
368
0
                "Can only decode to JPEG if only DCT-8 is used.");
369
0
          }
370
371
0
          HWY_ALIGN int32_t transposed_dct_y[64];
372
0
          for (size_t c : {1, 0, 2}) {
373
            // Propagate only Y for grayscale.
374
0
            if (jpeg_is_gray && c != 1) {
375
0
              continue;
376
0
            }
377
0
            if ((sbx[c] << hshift[c] != bx) || (sby[c] << vshift[c] != by)) {
378
0
              continue;
379
0
            }
380
0
            int16_t* JXL_RESTRICT jpeg_pos =
381
0
                jpeg_row[c] + sbx[c] * kDCTBlockSize;
382
            // JPEG XL is transposed, JPEG is not.
383
0
            auto* transposed_dct = qblock[c].ptr32;
384
0
            Transpose8x8InPlace(transposed_dct);
385
            // No CfL - no need to store the y block converted to integers.
386
0
            if (!cs.Is444() ||
387
0
                (row_cmap[0][abs_tx] == 0 && row_cmap[2][abs_tx] == 0)) {
388
0
              for (size_t i = 0; i < 64; i += Lanes(d)) {
389
0
                const auto ini = Load(di, transposed_dct + i);
390
0
                const auto ini16 = DemoteTo(di16, ini);
391
0
                StoreU(ini16, di16, jpeg_pos + i);
392
0
              }
393
0
            } else if (c == 1) {
394
              // Y channel: save for restoring X/B, but nothing else to do.
395
0
              for (size_t i = 0; i < 64; i += Lanes(d)) {
396
0
                const auto ini = Load(di, transposed_dct + i);
397
0
                Store(ini, di, transposed_dct_y + i);
398
0
                const auto ini16 = DemoteTo(di16, ini);
399
0
                StoreU(ini16, di16, jpeg_pos + i);
400
0
              }
401
0
            } else {
402
              // transposed_dct_y contains the y channel block, transposed.
403
0
              const auto scale =
404
0
                  Set(di, ColorCorrelation::RatioJPEG(row_cmap[c][abs_tx]));
405
0
              const auto round = Set(di, 1 << (kCFLFixedPointPrecision - 1));
406
0
              for (int i = 0; i < 64; i += Lanes(d)) {
407
0
                auto in = Load(di, transposed_dct + i);
408
0
                auto in_y = Load(di, transposed_dct_y + i);
409
0
                auto qt = Load(di, scaled_qtable + c * size + i);
410
0
                auto coeff_scale = ShiftRight<kCFLFixedPointPrecision>(
411
0
                    Add(Mul(qt, scale), round));
412
0
                auto cfl_factor = ShiftRight<kCFLFixedPointPrecision>(
413
0
                    Add(Mul(in_y, coeff_scale), round));
414
0
                StoreU(DemoteTo(di16, Add(in, cfl_factor)), di16, jpeg_pos + i);
415
0
              }
416
0
            }
417
0
            jpeg_pos[0] =
418
0
                Clamp1<float>(dc_rows[c][sbx[c]] - dcoff[c], -2047, 2047);
419
0
            auto overflow = MaskFromVec(Set(di16_full, 0));
420
0
            auto underflow = MaskFromVec(Set(di16_full, 0));
421
0
            for (int i = 0; i < 64; i += Lanes(di16_full)) {
422
0
              auto in = LoadU(di16_full, jpeg_pos + i);
423
0
              overflow = Or(overflow, Gt(in, kJpegDctMax));
424
0
              underflow = Or(underflow, Lt(in, kJpegDctMin));
425
0
            }
426
0
            if (!AllFalse(di16_full, Or(overflow, underflow))) {
427
0
              return JXL_FAILURE("JPEG DCT coefficients out of range");
428
0
            }
429
0
          }
430
12.1M
        } else {
431
12.1M
          HWY_ALIGN float* const block = group_dec_cache->dec_group_block;
432
          // Dequantize and add predictions.
433
12.1M
          dequant_block(
434
12.1M
              inv_global_scale, row_quant[bx], dec_state->x_dm_multiplier,
435
12.1M
              dec_state->b_dm_multiplier, x_cc_mul, b_cc_mul, acs.Strategy(),
436
12.1M
              size, dec_state->shared->quantizer,
437
12.1M
              acs.covered_blocks_y() * acs.covered_blocks_x(), sbx, dc_rows,
438
12.1M
              dc_stride,
439
12.1M
              dec_state->output_encoding_info.opsin_params.quant_biases, qblock,
440
12.1M
              block, group_dec_cache->scratch_space);
441
442
36.3M
          for (size_t c : {1, 0, 2}) {
443
36.3M
            if ((sbx[c] << hshift[c] != bx) || (sby[c] << vshift[c] != by)) {
444
5.00k
              continue;
445
5.00k
            }
446
            // IDCT
447
36.3M
            float* JXL_RESTRICT idct_pos = idct_row[c] + sbx[c] * kBlockDim;
448
36.3M
            TransformToPixels(acs.Strategy(), block + c * size, idct_pos,
449
36.3M
                              idct_stride[c], group_dec_cache->scratch_space);
450
36.3M
          }
451
12.1M
        }
452
12.1M
        bx += llf_x;
453
12.1M
      }
454
3.57M
    }
455
1.15M
  }
456
57.4k
  return true;
457
58.4k
}
Unexecuted instantiation: jxl::N_AVX3::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
Unexecuted instantiation: jxl::N_AVX3_ZEN4::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
Unexecuted instantiation: jxl::N_AVX3_SPR::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
Unexecuted instantiation: jxl::N_SSE2::DecodeGroupImpl(jxl::FrameHeader const&, jxl::GetBlock*, jxl::GroupDecCache*, jxl::PassesDecoderState*, unsigned long, unsigned long, jxl::RenderPipelineInput&, jxl::jpeg::JPEGData*, jxl::DrawMode)
458
459
// NOLINTNEXTLINE(google-readability-namespace-comments)
460
}  // namespace HWY_NAMESPACE
461
}  // namespace jxl
462
HWY_AFTER_NAMESPACE();
463
464
#if HWY_ONCE
465
namespace jxl {
466
namespace {
467
// Decode quantized AC coefficients of DCT blocks.
468
// LLF components in the output block will not be modified.
469
template <ACType ac_type, bool uses_lz77>
470
Status DecodeACVarBlock(size_t ctx_offset, size_t log2_covered_blocks,
471
                        int32_t* JXL_RESTRICT row_nzeros,
472
                        const int32_t* JXL_RESTRICT row_nzeros_top,
473
                        size_t nzeros_stride, size_t c, size_t bx, size_t by,
474
                        size_t lbx, AcStrategy acs,
475
                        const coeff_order_t* JXL_RESTRICT coeff_order,
476
                        BitReader* JXL_RESTRICT br,
477
                        ANSSymbolReader* JXL_RESTRICT decoder,
478
                        const std::vector<uint8_t>& context_map,
479
                        const uint8_t* qdc_row, const int32_t* qf_row,
480
                        const BlockCtxMap& block_ctx_map, ACPtr block,
481
4.11M
                        size_t shift = 0) {
482
  // Equal to number of LLF coefficients.
483
4.11M
  const size_t covered_blocks = 1 << log2_covered_blocks;
484
4.11M
  const size_t size = covered_blocks * kDCTBlockSize;
485
4.11M
  int32_t predicted_nzeros =
486
4.11M
      PredictFromTopAndLeft(row_nzeros_top, row_nzeros, bx, 32);
487
488
4.11M
  size_t ord = kStrategyOrder[acs.RawStrategy()];
489
4.11M
  const coeff_order_t* JXL_RESTRICT order =
490
4.11M
      &coeff_order[CoeffOrderOffset(ord, c)];
491
492
4.11M
  size_t block_ctx = block_ctx_map.Context(qdc_row[lbx], qf_row[bx], ord, c);
493
4.11M
  const int32_t nzero_ctx =
494
4.11M
      block_ctx_map.NonZeroContext(predicted_nzeros, block_ctx) + ctx_offset;
495
496
4.11M
  size_t nzeros =
497
4.11M
      decoder->ReadHybridUintInlined<uses_lz77>(nzero_ctx, br, context_map);
498
4.11M
  if (nzeros > size - covered_blocks) {
499
678
    return JXL_FAILURE("Invalid AC: nzeros %" PRIuS " too large for %" PRIuS
500
678
                       " 8x8 blocks",
501
678
                       nzeros, covered_blocks);
502
678
  }
503
8.95M
  for (size_t y = 0; y < acs.covered_blocks_y(); y++) {
504
12.7M
    for (size_t x = 0; x < acs.covered_blocks_x(); x++) {
505
7.90M
      row_nzeros[bx + x + y * nzeros_stride] =
506
7.90M
          (nzeros + covered_blocks - 1) >> log2_covered_blocks;
507
7.90M
    }
508
4.84M
  }
509
510
4.11M
  const size_t histo_offset =
511
4.11M
      ctx_offset + block_ctx_map.ZeroDensityContextsOffset(block_ctx);
512
513
4.11M
  size_t prev = (nzeros > size / 16 ? 0 : 1);
514
108M
  for (size_t k = covered_blocks; k < size && nzeros != 0; ++k) {
515
104M
    const size_t ctx =
516
104M
        histo_offset + ZeroDensityContext(nzeros, k, covered_blocks,
517
104M
                                          log2_covered_blocks, prev);
518
104M
    const size_t u_coeff =
519
104M
        decoder->ReadHybridUintInlined<uses_lz77>(ctx, br, context_map);
520
    // Hand-rolled version of UnpackSigned, shifting before the conversion to
521
    // signed integer to avoid undefined behavior of shifting negative numbers.
522
104M
    const size_t magnitude = u_coeff >> 1;
523
104M
    const size_t neg_sign = (~u_coeff) & 1;
524
104M
    const ptrdiff_t coeff =
525
104M
        static_cast<ptrdiff_t>((magnitude ^ (neg_sign - 1)) << shift);
526
104M
    if (ac_type == ACType::k16) {
527
98.0M
      block.ptr16[order[k]] += coeff;
528
98.0M
    } else {
529
6.10M
      block.ptr32[order[k]] += coeff;
530
6.10M
    }
531
104M
    prev = static_cast<size_t>(u_coeff != 0);
532
104M
    nzeros -= prev;
533
104M
  }
534
4.11M
  if (JXL_UNLIKELY(nzeros != 0)) {
535
329
    return JXL_FAILURE("Invalid AC: nzeros at end of block is %" PRIuS
536
329
                       ", should be 0. Block (%" PRIuS ", %" PRIuS
537
329
                       "), channel %" PRIuS,
538
329
                       nzeros, bx, by, c);
539
329
  }
540
541
4.11M
  return true;
542
4.11M
}
dec_group.cc:jxl::Status jxl::(anonymous namespace)::DecodeACVarBlock<(jxl::ACType)0, true>(unsigned long, unsigned long, int*, int const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, jxl::AcStrategy, unsigned int const*, jxl::BitReader*, jxl::ANSSymbolReader*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, unsigned char const*, int const*, jxl::BlockCtxMap const&, jxl::ACPtr, unsigned long)
Line
Count
Source
481
232k
                        size_t shift = 0) {
482
  // Equal to number of LLF coefficients.
483
232k
  const size_t covered_blocks = 1 << log2_covered_blocks;
484
232k
  const size_t size = covered_blocks * kDCTBlockSize;
485
232k
  int32_t predicted_nzeros =
486
232k
      PredictFromTopAndLeft(row_nzeros_top, row_nzeros, bx, 32);
487
488
232k
  size_t ord = kStrategyOrder[acs.RawStrategy()];
489
232k
  const coeff_order_t* JXL_RESTRICT order =
490
232k
      &coeff_order[CoeffOrderOffset(ord, c)];
491
492
232k
  size_t block_ctx = block_ctx_map.Context(qdc_row[lbx], qf_row[bx], ord, c);
493
232k
  const int32_t nzero_ctx =
494
232k
      block_ctx_map.NonZeroContext(predicted_nzeros, block_ctx) + ctx_offset;
495
496
232k
  size_t nzeros =
497
232k
      decoder->ReadHybridUintInlined<uses_lz77>(nzero_ctx, br, context_map);
498
232k
  if (nzeros > size - covered_blocks) {
499
81
    return JXL_FAILURE("Invalid AC: nzeros %" PRIuS " too large for %" PRIuS
500
81
                       " 8x8 blocks",
501
81
                       nzeros, covered_blocks);
502
81
  }
503
473k
  for (size_t y = 0; y < acs.covered_blocks_y(); y++) {
504
591k
    for (size_t x = 0; x < acs.covered_blocks_x(); x++) {
505
350k
      row_nzeros[bx + x + y * nzeros_stride] =
506
350k
          (nzeros + covered_blocks - 1) >> log2_covered_blocks;
507
350k
    }
508
241k
  }
509
510
231k
  const size_t histo_offset =
511
231k
      ctx_offset + block_ctx_map.ZeroDensityContextsOffset(block_ctx);
512
513
231k
  size_t prev = (nzeros > size / 16 ? 0 : 1);
514
654k
  for (size_t k = covered_blocks; k < size && nzeros != 0; ++k) {
515
422k
    const size_t ctx =
516
422k
        histo_offset + ZeroDensityContext(nzeros, k, covered_blocks,
517
422k
                                          log2_covered_blocks, prev);
518
422k
    const size_t u_coeff =
519
422k
        decoder->ReadHybridUintInlined<uses_lz77>(ctx, br, context_map);
520
    // Hand-rolled version of UnpackSigned, shifting before the conversion to
521
    // signed integer to avoid undefined behavior of shifting negative numbers.
522
422k
    const size_t magnitude = u_coeff >> 1;
523
422k
    const size_t neg_sign = (~u_coeff) & 1;
524
422k
    const ptrdiff_t coeff =
525
422k
        static_cast<ptrdiff_t>((magnitude ^ (neg_sign - 1)) << shift);
526
422k
    if (ac_type == ACType::k16) {
527
422k
      block.ptr16[order[k]] += coeff;
528
422k
    } else {
529
0
      block.ptr32[order[k]] += coeff;
530
0
    }
531
422k
    prev = static_cast<size_t>(u_coeff != 0);
532
422k
    nzeros -= prev;
533
422k
  }
534
231k
  if (JXL_UNLIKELY(nzeros != 0)) {
535
83
    return JXL_FAILURE("Invalid AC: nzeros at end of block is %" PRIuS
536
83
                       ", should be 0. Block (%" PRIuS ", %" PRIuS
537
83
                       "), channel %" PRIuS,
538
83
                       nzeros, bx, by, c);
539
83
  }
540
541
231k
  return true;
542
231k
}
dec_group.cc:jxl::Status jxl::(anonymous namespace)::DecodeACVarBlock<(jxl::ACType)1, true>(unsigned long, unsigned long, int*, int const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, jxl::AcStrategy, unsigned int const*, jxl::BitReader*, jxl::ANSSymbolReader*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, unsigned char const*, int const*, jxl::BlockCtxMap const&, jxl::ACPtr, unsigned long)
Line
Count
Source
481
62.4k
                        size_t shift = 0) {
482
  // Equal to number of LLF coefficients.
483
62.4k
  const size_t covered_blocks = 1 << log2_covered_blocks;
484
62.4k
  const size_t size = covered_blocks * kDCTBlockSize;
485
62.4k
  int32_t predicted_nzeros =
486
62.4k
      PredictFromTopAndLeft(row_nzeros_top, row_nzeros, bx, 32);
487
488
62.4k
  size_t ord = kStrategyOrder[acs.RawStrategy()];
489
62.4k
  const coeff_order_t* JXL_RESTRICT order =
490
62.4k
      &coeff_order[CoeffOrderOffset(ord, c)];
491
492
62.4k
  size_t block_ctx = block_ctx_map.Context(qdc_row[lbx], qf_row[bx], ord, c);
493
62.4k
  const int32_t nzero_ctx =
494
62.4k
      block_ctx_map.NonZeroContext(predicted_nzeros, block_ctx) + ctx_offset;
495
496
62.4k
  size_t nzeros =
497
62.4k
      decoder->ReadHybridUintInlined<uses_lz77>(nzero_ctx, br, context_map);
498
62.4k
  if (nzeros > size - covered_blocks) {
499
446
    return JXL_FAILURE("Invalid AC: nzeros %" PRIuS " too large for %" PRIuS
500
446
                       " 8x8 blocks",
501
446
                       nzeros, covered_blocks);
502
446
  }
503
131k
  for (size_t y = 0; y < acs.covered_blocks_y(); y++) {
504
220k
    for (size_t x = 0; x < acs.covered_blocks_x(); x++) {
505
150k
      row_nzeros[bx + x + y * nzeros_stride] =
506
150k
          (nzeros + covered_blocks - 1) >> log2_covered_blocks;
507
150k
    }
508
69.6k
  }
509
510
61.9k
  const size_t histo_offset =
511
61.9k
      ctx_offset + block_ctx_map.ZeroDensityContextsOffset(block_ctx);
512
513
61.9k
  size_t prev = (nzeros > size / 16 ? 0 : 1);
514
289k
  for (size_t k = covered_blocks; k < size && nzeros != 0; ++k) {
515
227k
    const size_t ctx =
516
227k
        histo_offset + ZeroDensityContext(nzeros, k, covered_blocks,
517
227k
                                          log2_covered_blocks, prev);
518
227k
    const size_t u_coeff =
519
227k
        decoder->ReadHybridUintInlined<uses_lz77>(ctx, br, context_map);
520
    // Hand-rolled version of UnpackSigned, shifting before the conversion to
521
    // signed integer to avoid undefined behavior of shifting negative numbers.
522
227k
    const size_t magnitude = u_coeff >> 1;
523
227k
    const size_t neg_sign = (~u_coeff) & 1;
524
227k
    const ptrdiff_t coeff =
525
227k
        static_cast<ptrdiff_t>((magnitude ^ (neg_sign - 1)) << shift);
526
227k
    if (ac_type == ACType::k16) {
527
0
      block.ptr16[order[k]] += coeff;
528
227k
    } else {
529
227k
      block.ptr32[order[k]] += coeff;
530
227k
    }
531
227k
    prev = static_cast<size_t>(u_coeff != 0);
532
227k
    nzeros -= prev;
533
227k
  }
534
61.9k
  if (JXL_UNLIKELY(nzeros != 0)) {
535
57
    return JXL_FAILURE("Invalid AC: nzeros at end of block is %" PRIuS
536
57
                       ", should be 0. Block (%" PRIuS ", %" PRIuS
537
57
                       "), channel %" PRIuS,
538
57
                       nzeros, bx, by, c);
539
57
  }
540
541
61.9k
  return true;
542
61.9k
}
dec_group.cc:jxl::Status jxl::(anonymous namespace)::DecodeACVarBlock<(jxl::ACType)0, false>(unsigned long, unsigned long, int*, int const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, jxl::AcStrategy, unsigned int const*, jxl::BitReader*, jxl::ANSSymbolReader*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, unsigned char const*, int const*, jxl::BlockCtxMap const&, jxl::ACPtr, unsigned long)
Line
Count
Source
481
3.50M
                        size_t shift = 0) {
482
  // Equal to number of LLF coefficients.
483
3.50M
  const size_t covered_blocks = 1 << log2_covered_blocks;
484
3.50M
  const size_t size = covered_blocks * kDCTBlockSize;
485
3.50M
  int32_t predicted_nzeros =
486
3.50M
      PredictFromTopAndLeft(row_nzeros_top, row_nzeros, bx, 32);
487
488
3.50M
  size_t ord = kStrategyOrder[acs.RawStrategy()];
489
3.50M
  const coeff_order_t* JXL_RESTRICT order =
490
3.50M
      &coeff_order[CoeffOrderOffset(ord, c)];
491
492
3.50M
  size_t block_ctx = block_ctx_map.Context(qdc_row[lbx], qf_row[bx], ord, c);
493
3.50M
  const int32_t nzero_ctx =
494
3.50M
      block_ctx_map.NonZeroContext(predicted_nzeros, block_ctx) + ctx_offset;
495
496
3.50M
  size_t nzeros =
497
3.50M
      decoder->ReadHybridUintInlined<uses_lz77>(nzero_ctx, br, context_map);
498
3.50M
  if (nzeros > size - covered_blocks) {
499
31
    return JXL_FAILURE("Invalid AC: nzeros %" PRIuS " too large for %" PRIuS
500
31
                       " 8x8 blocks",
501
31
                       nzeros, covered_blocks);
502
31
  }
503
7.62M
  for (size_t y = 0; y < acs.covered_blocks_y(); y++) {
504
10.8M
    for (size_t x = 0; x < acs.covered_blocks_x(); x++) {
505
6.72M
      row_nzeros[bx + x + y * nzeros_stride] =
506
6.72M
          (nzeros + covered_blocks - 1) >> log2_covered_blocks;
507
6.72M
    }
508
4.11M
  }
509
510
3.50M
  const size_t histo_offset =
511
3.50M
      ctx_offset + block_ctx_map.ZeroDensityContextsOffset(block_ctx);
512
513
3.50M
  size_t prev = (nzeros > size / 16 ? 0 : 1);
514
101M
  for (size_t k = covered_blocks; k < size && nzeros != 0; ++k) {
515
97.6M
    const size_t ctx =
516
97.6M
        histo_offset + ZeroDensityContext(nzeros, k, covered_blocks,
517
97.6M
                                          log2_covered_blocks, prev);
518
97.6M
    const size_t u_coeff =
519
97.6M
        decoder->ReadHybridUintInlined<uses_lz77>(ctx, br, context_map);
520
    // Hand-rolled version of UnpackSigned, shifting before the conversion to
521
    // signed integer to avoid undefined behavior of shifting negative numbers.
522
97.6M
    const size_t magnitude = u_coeff >> 1;
523
97.6M
    const size_t neg_sign = (~u_coeff) & 1;
524
97.6M
    const ptrdiff_t coeff =
525
97.6M
        static_cast<ptrdiff_t>((magnitude ^ (neg_sign - 1)) << shift);
526
97.6M
    if (ac_type == ACType::k16) {
527
97.6M
      block.ptr16[order[k]] += coeff;
528
97.6M
    } else {
529
0
      block.ptr32[order[k]] += coeff;
530
0
    }
531
97.6M
    prev = static_cast<size_t>(u_coeff != 0);
532
97.6M
    nzeros -= prev;
533
97.6M
  }
534
3.50M
  if (JXL_UNLIKELY(nzeros != 0)) {
535
135
    return JXL_FAILURE("Invalid AC: nzeros at end of block is %" PRIuS
536
135
                       ", should be 0. Block (%" PRIuS ", %" PRIuS
537
135
                       "), channel %" PRIuS,
538
135
                       nzeros, bx, by, c);
539
135
  }
540
541
3.50M
  return true;
542
3.50M
}
dec_group.cc:jxl::Status jxl::(anonymous namespace)::DecodeACVarBlock<(jxl::ACType)1, false>(unsigned long, unsigned long, int*, int const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, jxl::AcStrategy, unsigned int const*, jxl::BitReader*, jxl::ANSSymbolReader*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, unsigned char const*, int const*, jxl::BlockCtxMap const&, jxl::ACPtr, unsigned long)
Line
Count
Source
481
317k
                        size_t shift = 0) {
482
  // Equal to number of LLF coefficients.
483
317k
  const size_t covered_blocks = 1 << log2_covered_blocks;
484
317k
  const size_t size = covered_blocks * kDCTBlockSize;
485
317k
  int32_t predicted_nzeros =
486
317k
      PredictFromTopAndLeft(row_nzeros_top, row_nzeros, bx, 32);
487
488
317k
  size_t ord = kStrategyOrder[acs.RawStrategy()];
489
317k
  const coeff_order_t* JXL_RESTRICT order =
490
317k
      &coeff_order[CoeffOrderOffset(ord, c)];
491
492
317k
  size_t block_ctx = block_ctx_map.Context(qdc_row[lbx], qf_row[bx], ord, c);
493
317k
  const int32_t nzero_ctx =
494
317k
      block_ctx_map.NonZeroContext(predicted_nzeros, block_ctx) + ctx_offset;
495
496
317k
  size_t nzeros =
497
317k
      decoder->ReadHybridUintInlined<uses_lz77>(nzero_ctx, br, context_map);
498
317k
  if (nzeros > size - covered_blocks) {
499
120
    return JXL_FAILURE("Invalid AC: nzeros %" PRIuS " too large for %" PRIuS
500
120
                       " 8x8 blocks",
501
120
                       nzeros, covered_blocks);
502
120
  }
503
731k
  for (size_t y = 0; y < acs.covered_blocks_y(); y++) {
504
1.09M
    for (size_t x = 0; x < acs.covered_blocks_x(); x++) {
505
679k
      row_nzeros[bx + x + y * nzeros_stride] =
506
679k
          (nzeros + covered_blocks - 1) >> log2_covered_blocks;
507
679k
    }
508
414k
  }
509
510
317k
  const size_t histo_offset =
511
317k
      ctx_offset + block_ctx_map.ZeroDensityContextsOffset(block_ctx);
512
513
317k
  size_t prev = (nzeros > size / 16 ? 0 : 1);
514
6.19M
  for (size_t k = covered_blocks; k < size && nzeros != 0; ++k) {
515
5.88M
    const size_t ctx =
516
5.88M
        histo_offset + ZeroDensityContext(nzeros, k, covered_blocks,
517
5.88M
                                          log2_covered_blocks, prev);
518
5.88M
    const size_t u_coeff =
519
5.88M
        decoder->ReadHybridUintInlined<uses_lz77>(ctx, br, context_map);
520
    // Hand-rolled version of UnpackSigned, shifting before the conversion to
521
    // signed integer to avoid undefined behavior of shifting negative numbers.
522
5.88M
    const size_t magnitude = u_coeff >> 1;
523
5.88M
    const size_t neg_sign = (~u_coeff) & 1;
524
5.88M
    const ptrdiff_t coeff =
525
5.88M
        static_cast<ptrdiff_t>((magnitude ^ (neg_sign - 1)) << shift);
526
5.88M
    if (ac_type == ACType::k16) {
527
0
      block.ptr16[order[k]] += coeff;
528
5.88M
    } else {
529
5.88M
      block.ptr32[order[k]] += coeff;
530
5.88M
    }
531
5.88M
    prev = static_cast<size_t>(u_coeff != 0);
532
5.88M
    nzeros -= prev;
533
5.88M
  }
534
317k
  if (JXL_UNLIKELY(nzeros != 0)) {
535
54
    return JXL_FAILURE("Invalid AC: nzeros at end of block is %" PRIuS
536
54
                       ", should be 0. Block (%" PRIuS ", %" PRIuS
537
54
                       "), channel %" PRIuS,
538
54
                       nzeros, bx, by, c);
539
54
  }
540
541
317k
  return true;
542
317k
}
543
544
// Structs used by DecodeGroupImpl to get a quantized block.
545
// GetBlockFromBitstream uses ANS decoding (and thus keeps track of row
546
// pointers in row_nzeros), GetBlockFromEncoder simply reads the coefficient
547
// image provided by the encoder.
548
549
struct GetBlockFromBitstream : public GetBlock {
550
218k
  void StartRow(size_t by) override {
551
218k
    qf_row = rect.ConstRow(*qf, by);
552
873k
    for (size_t c = 0; c < 3; c++) {
553
655k
      size_t sby = by >> vshift[c];
554
655k
      quant_dc_row = quant_dc->ConstRow(rect.y0() + by) + rect.x0();
555
1.31M
      for (size_t i = 0; i < num_passes; i++) {
556
655k
        row_nzeros[i][c] = group_dec_cache->num_nzeroes[i].PlaneRow(c, sby);
557
655k
        row_nzeros_top[i][c] =
558
655k
            sby == 0
559
655k
                ? nullptr
560
655k
                : group_dec_cache->num_nzeroes[i].ConstPlaneRow(c, sby - 1);
561
655k
      }
562
655k
    }
563
218k
  }
564
565
  Status LoadBlock(size_t bx, size_t by, const AcStrategy& acs, size_t size,
566
                   size_t log2_covered_blocks, ACPtr block[3],
567
1.37M
                   ACType ac_type) override {
568
1.37M
    ;
569
4.12M
    for (size_t c : {1, 0, 2}) {
570
4.12M
      size_t sbx = bx >> hshift[c];
571
4.12M
      size_t sby = by >> vshift[c];
572
4.12M
      if (JXL_UNLIKELY((sbx << hshift[c] != bx) || (sby << vshift[c] != by))) {
573
5.00k
        continue;
574
5.00k
      }
575
576
8.23M
      for (size_t pass = 0; JXL_UNLIKELY(pass < num_passes); pass++) {
577
4.11M
        auto decode_ac_varblock =
578
4.11M
            decoders[pass].UsesLZ77()
579
4.11M
                ? (ac_type == ACType::k16 ? DecodeACVarBlock<ACType::k16, 1>
580
294k
                                          : DecodeACVarBlock<ACType::k32, 1>)
581
4.11M
                : (ac_type == ACType::k16 ? DecodeACVarBlock<ACType::k16, 0>
582
3.82M
                                          : DecodeACVarBlock<ACType::k32, 0>);
583
4.11M
        JXL_RETURN_IF_ERROR(decode_ac_varblock(
584
4.11M
            ctx_offset[pass], log2_covered_blocks, row_nzeros[pass][c],
585
4.11M
            row_nzeros_top[pass][c], nzeros_stride, c, sbx, sby, bx, acs,
586
4.11M
            &coeff_orders[pass * coeff_order_size], readers[pass],
587
4.11M
            &decoders[pass], context_map[pass], quant_dc_row, qf_row,
588
4.11M
            *block_ctx_map, block[c], shift_for_pass[pass]));
589
4.11M
      }
590
4.11M
    }
591
1.37M
    return true;
592
1.37M
  }
593
594
  Status Init(const FrameHeader& frame_header,
595
              BitReader* JXL_RESTRICT* JXL_RESTRICT readers_,
596
              size_t num_passes_, size_t group_idx, size_t histo_selector_bits,
597
              const Rect& rect_, GroupDecCache* JXL_RESTRICT group_dec_cache_,
598
21.7k
              PassesDecoderState* dec_state, size_t first_pass) {
599
86.8k
    for (size_t i = 0; i < 3; i++) {
600
65.1k
      hshift[i] = frame_header.chroma_subsampling.HShift(i);
601
65.1k
      vshift[i] = frame_header.chroma_subsampling.VShift(i);
602
65.1k
    }
603
21.7k
    coeff_order_size = dec_state->shared->coeff_order_size;
604
21.7k
    coeff_orders =
605
21.7k
        dec_state->shared->coeff_orders.data() + first_pass * coeff_order_size;
606
21.7k
    context_map = dec_state->context_map.data() + first_pass;
607
21.7k
    readers = readers_;
608
21.7k
    num_passes = num_passes_;
609
21.7k
    shift_for_pass = frame_header.passes.shift + first_pass;
610
21.7k
    group_dec_cache = group_dec_cache_;
611
21.7k
    rect = rect_;
612
21.7k
    block_ctx_map = &dec_state->shared->block_ctx_map;
613
21.7k
    qf = &dec_state->shared->raw_quant_field;
614
21.7k
    quant_dc = &dec_state->shared->quant_dc;
615
616
43.4k
    for (size_t pass = 0; pass < num_passes; pass++) {
617
      // Select which histogram set to use among those of the current pass.
618
21.8k
      size_t cur_histogram = 0;
619
21.8k
      if (histo_selector_bits != 0) {
620
5.91k
        cur_histogram = readers[pass]->ReadBits(histo_selector_bits);
621
5.91k
      }
622
21.8k
      if (cur_histogram >= dec_state->shared->num_histograms) {
623
20
        return JXL_FAILURE("Invalid histogram selector");
624
20
      }
625
21.7k
      ctx_offset[pass] = cur_histogram * block_ctx_map->NumACContexts();
626
627
21.7k
      JXL_ASSIGN_OR_RETURN(
628
21.7k
          decoders[pass],
629
21.7k
          ANSSymbolReader::Create(&dec_state->code[pass + first_pass],
630
21.7k
                                  readers[pass]));
631
21.7k
    }
632
21.6k
    nzeros_stride = group_dec_cache->num_nzeroes[0].PixelsPerRow();
633
43.4k
    for (size_t i = 0; i < num_passes; i++) {
634
21.7k
      JXL_ENSURE(
635
21.7k
          nzeros_stride ==
636
21.7k
          static_cast<size_t>(group_dec_cache->num_nzeroes[i].PixelsPerRow()));
637
21.7k
    }
638
21.6k
    return true;
639
21.6k
  }
640
641
  const uint32_t* shift_for_pass = nullptr;  // not owned
642
  const coeff_order_t* JXL_RESTRICT coeff_orders;
643
  size_t coeff_order_size;
644
  const std::vector<uint8_t>* JXL_RESTRICT context_map;
645
  ANSSymbolReader decoders[kMaxNumPasses];
646
  BitReader* JXL_RESTRICT* JXL_RESTRICT readers;
647
  size_t num_passes;
648
  size_t ctx_offset[kMaxNumPasses];
649
  size_t nzeros_stride;
650
  int32_t* JXL_RESTRICT row_nzeros[kMaxNumPasses][3];
651
  const int32_t* JXL_RESTRICT row_nzeros_top[kMaxNumPasses][3];
652
  GroupDecCache* JXL_RESTRICT group_dec_cache;
653
  const BlockCtxMap* block_ctx_map;
654
  const ImageI* qf;
655
  const ImageB* quant_dc;
656
  const int32_t* qf_row;
657
  const uint8_t* quant_dc_row;
658
  Rect rect;
659
  size_t hshift[3], vshift[3];
660
};
661
662
struct GetBlockFromEncoder : public GetBlock {
663
937k
  void StartRow(size_t by) override {}
664
665
  Status LoadBlock(size_t bx, size_t by, const AcStrategy& acs, size_t size,
666
                   size_t log2_covered_blocks, ACPtr block[3],
667
10.7M
                   ACType ac_type) override {
668
10.7M
    JXL_ENSURE(ac_type == ACType::k32);
669
43.0M
    for (size_t c = 0; c < 3; c++) {
670
      // for each pass
671
64.5M
      for (size_t i = 0; i < quantized_ac->size(); i++) {
672
4.44G
        for (size_t k = 0; k < size; k++) {
673
          // TODO(veluca): SIMD.
674
4.41G
          block[c].ptr32[k] +=
675
4.41G
              rows[i][c][offset + k] * (1 << shift_for_pass[i]);
676
4.41G
        }
677
32.2M
      }
678
32.2M
    }
679
10.7M
    offset += size;
680
10.7M
    return true;
681
10.7M
  }
682
683
  static StatusOr<GetBlockFromEncoder> Create(
684
      const std::vector<std::unique_ptr<ACImage>>& ac, size_t group_idx,
685
36.7k
      const uint32_t* shift_for_pass) {
686
36.7k
    GetBlockFromEncoder result(ac, group_idx, shift_for_pass);
687
    // TODO(veluca): not supported with chroma subsampling.
688
73.5k
    for (size_t i = 0; i < ac.size(); i++) {
689
36.7k
      JXL_ENSURE(ac[i]->Type() == ACType::k32);
690
147k
      for (size_t c = 0; c < 3; c++) {
691
110k
        result.rows[i][c] = ac[i]->PlaneRow(c, group_idx, 0).ptr32;
692
110k
      }
693
36.7k
    }
694
36.7k
    return result;
695
36.7k
  }
696
697
  const std::vector<std::unique_ptr<ACImage>>* JXL_RESTRICT quantized_ac;
698
  size_t offset = 0;
699
  const int32_t* JXL_RESTRICT rows[kMaxNumPasses][3];
700
  const uint32_t* shift_for_pass = nullptr;  // not owned
701
702
 private:
703
  GetBlockFromEncoder(const std::vector<std::unique_ptr<ACImage>>& ac,
704
                      size_t group_idx, const uint32_t* shift_for_pass)
705
36.7k
      : quantized_ac(&ac), shift_for_pass(shift_for_pass) {}
706
};
707
708
HWY_EXPORT(DecodeGroupImpl);
709
710
}  // namespace
711
712
Status DecodeGroup(const FrameHeader& frame_header,
713
                   BitReader* JXL_RESTRICT* JXL_RESTRICT readers,
714
                   size_t num_passes, size_t group_idx,
715
                   PassesDecoderState* JXL_RESTRICT dec_state,
716
                   GroupDecCache* JXL_RESTRICT group_dec_cache, size_t thread,
717
                   RenderPipelineInput& render_pipeline_input,
718
                   jpeg::JPEGData* JXL_RESTRICT jpeg_data, size_t first_pass,
719
21.7k
                   bool force_draw, bool dc_only, bool* should_run_pipeline) {
720
21.7k
  JxlMemoryManager* memory_manager = dec_state->memory_manager();
721
21.7k
  DrawMode draw =
722
21.7k
      (num_passes + first_pass == frame_header.passes.num_passes) || force_draw
723
21.7k
          ? kDraw
724
21.7k
          : kDontDraw;
725
726
21.7k
  if (should_run_pipeline) {
727
21.7k
    *should_run_pipeline = draw != kDontDraw;
728
21.7k
  }
729
730
21.7k
  if (draw == kDraw && num_passes == 0 && first_pass == 0) {
731
0
    JXL_RETURN_IF_ERROR(group_dec_cache->InitDCBufferOnce(memory_manager));
732
0
    const YCbCrChromaSubsampling& cs = frame_header.chroma_subsampling;
733
0
    for (size_t c : {0, 1, 2}) {
734
0
      size_t hs = cs.HShift(c);
735
0
      size_t vs = cs.VShift(c);
736
      // We reuse filter_input_storage here as it is not currently in use.
737
0
      const Rect src_rect_precs =
738
0
          dec_state->shared->frame_dim.BlockGroupRect(group_idx);
739
0
      const Rect src_rect =
740
0
          Rect(src_rect_precs.x0() >> hs, src_rect_precs.y0() >> vs,
741
0
               src_rect_precs.xsize() >> hs, src_rect_precs.ysize() >> vs);
742
0
      const Rect copy_rect(kRenderPipelineXOffset, 2, src_rect.xsize(),
743
0
                           src_rect.ysize());
744
0
      JXL_RETURN_IF_ERROR(
745
0
          CopyImageToWithPadding(src_rect, dec_state->shared->dc->Plane(c), 2,
746
0
                                 copy_rect, &group_dec_cache->dc_buffer));
747
      // Mirrorpad. Interleaving left and right padding ensures that padding
748
      // works out correctly even for images with DC size of 1.
749
0
      for (size_t y = 0; y < src_rect.ysize() + 4; y++) {
750
0
        size_t xend = kRenderPipelineXOffset +
751
0
                      (dec_state->shared->dc->Plane(c).xsize() >> hs) -
752
0
                      src_rect.x0();
753
0
        for (size_t ix = 0; ix < 2; ix++) {
754
0
          if (src_rect.x0() == 0) {
755
0
            group_dec_cache->dc_buffer.Row(y)[kRenderPipelineXOffset - ix - 1] =
756
0
                group_dec_cache->dc_buffer.Row(y)[kRenderPipelineXOffset + ix];
757
0
          }
758
0
          if (src_rect.x0() + src_rect.xsize() + 2 >=
759
0
              (dec_state->shared->dc->xsize() >> hs)) {
760
0
            group_dec_cache->dc_buffer.Row(y)[xend + ix] =
761
0
                group_dec_cache->dc_buffer.Row(y)[xend - ix - 1];
762
0
          }
763
0
        }
764
0
      }
765
0
      const auto& buffer = render_pipeline_input.GetBuffer(c);
766
0
      Rect dst_rect = buffer.second;
767
0
      ImageF* upsampling_dst = buffer.first;
768
0
      JXL_ENSURE(dst_rect.IsInside(*upsampling_dst));
769
770
0
      RenderPipelineStage::RowInfo input_rows(1, std::vector<float*>(5));
771
0
      RenderPipelineStage::RowInfo output_rows(1, std::vector<float*>(8));
772
0
      for (size_t y = src_rect.y0(); y < src_rect.y0() + src_rect.ysize();
773
0
           y++) {
774
0
        for (ptrdiff_t iy = 0; iy < 5; iy++) {
775
0
          input_rows[0][iy] = group_dec_cache->dc_buffer.Row(
776
0
              Mirror(static_cast<ptrdiff_t>(y) + iy - 2,
777
0
                     dec_state->shared->dc->Plane(c).ysize() >> vs) +
778
0
              2 - src_rect.y0());
779
0
        }
780
0
        for (size_t iy = 0; iy < 8; iy++) {
781
0
          output_rows[0][iy] =
782
0
              dst_rect.Row(upsampling_dst, ((y - src_rect.y0()) << 3) + iy) -
783
0
              kRenderPipelineXOffset;
784
0
        }
785
        // Arguments set to 0/nullptr are not used.
786
0
        JXL_RETURN_IF_ERROR(dec_state->upsampler8x->ProcessRow(
787
0
            input_rows, output_rows, /*xextra_left=*/0, /*xextra_right=*/0,
788
0
            src_rect.xsize(), 0, 0, thread));
789
0
      }
790
0
    }
791
0
    return true;
792
0
  }
793
794
21.7k
  size_t histo_selector_bits = 0;
795
21.7k
  if (dc_only) {
796
0
    JXL_ENSURE(num_passes == 0);
797
21.7k
  } else {
798
21.7k
    JXL_ENSURE(dec_state->shared->num_histograms > 0);
799
21.7k
    histo_selector_bits = CeilLog2Nonzero(dec_state->shared->num_histograms);
800
21.7k
  }
801
802
21.7k
  auto get_block = jxl::make_unique<GetBlockFromBitstream>();
803
21.7k
  JXL_RETURN_IF_ERROR(get_block->Init(
804
21.7k
      frame_header, readers, num_passes, group_idx, histo_selector_bits,
805
21.7k
      dec_state->shared->frame_dim.BlockGroupRect(group_idx), group_dec_cache,
806
21.7k
      dec_state, first_pass));
807
808
21.6k
  JXL_RETURN_IF_ERROR(HWY_DYNAMIC_DISPATCH(DecodeGroupImpl)(
809
21.6k
      frame_header, get_block.get(), group_dec_cache, dec_state, thread,
810
21.6k
      group_idx, render_pipeline_input, jpeg_data, draw));
811
812
41.4k
  for (size_t pass = 0; pass < num_passes; pass++) {
813
20.7k
    if (!get_block->decoders[pass].CheckANSFinalState()) {
814
0
      return JXL_FAILURE("ANS checksum failure.");
815
0
    }
816
20.7k
  }
817
20.6k
  return true;
818
20.6k
}
819
820
Status DecodeGroupForRoundtrip(const FrameHeader& frame_header,
821
                               const std::vector<std::unique_ptr<ACImage>>& ac,
822
                               size_t group_idx,
823
                               PassesDecoderState* JXL_RESTRICT dec_state,
824
                               GroupDecCache* JXL_RESTRICT group_dec_cache,
825
                               size_t thread,
826
                               RenderPipelineInput& render_pipeline_input,
827
                               jpeg::JPEGData* JXL_RESTRICT jpeg_data,
828
36.7k
                               AuxOut* aux_out) {
829
36.7k
  JxlMemoryManager* memory_manager = dec_state->memory_manager();
830
36.7k
  JXL_ASSIGN_OR_RETURN(
831
36.7k
      GetBlockFromEncoder get_block,
832
36.7k
      GetBlockFromEncoder::Create(ac, group_idx, frame_header.passes.shift));
833
36.7k
  JXL_RETURN_IF_ERROR(group_dec_cache->InitOnce(
834
36.7k
      memory_manager,
835
36.7k
      /*num_passes=*/0,
836
36.7k
      /*used_acs=*/(1u << AcStrategy::kNumValidStrategies) - 1));
837
838
36.7k
  return HWY_DYNAMIC_DISPATCH(DecodeGroupImpl)(
839
36.7k
      frame_header, &get_block, group_dec_cache, dec_state, thread, group_idx,
840
36.7k
      render_pipeline_input, jpeg_data, kDraw);
841
36.7k
}
842
843
}  // namespace jxl
844
#endif  // HWY_ONCE