Coverage Report

Created: 2025-11-16 07:22

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