Coverage Report

Created: 2026-10-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/compressed_dc.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/compressed_dc.h"
7
8
#include <jxl/memory_manager.h>
9
10
#include <algorithm>
11
#include <cstdint>
12
#include <cstdlib>
13
#include <cstring>
14
#include <vector>
15
16
#include "lib/jxl/ac_context.h"
17
#include "lib/jxl/frame_header.h"
18
#include "lib/jxl/modular/modular_image.h"
19
20
#undef HWY_TARGET_INCLUDE
21
#define HWY_TARGET_INCLUDE "lib/jxl/compressed_dc.cc"
22
#include <hwy/foreach_target.h>
23
#include <hwy/highway.h>
24
25
#include "lib/jxl/base/compiler_specific.h"
26
#include "lib/jxl/base/data_parallel.h"
27
#include "lib/jxl/base/rect.h"
28
#include "lib/jxl/base/status.h"
29
#include "lib/jxl/image.h"
30
HWY_BEFORE_NAMESPACE();
31
namespace jxl {
32
namespace HWY_NAMESPACE {
33
34
using D = HWY_FULL(float);
35
using DScalar = HWY_CAPPED(float, 1);
36
37
// These templates are not found via ADL.
38
using hwy::HWY_NAMESPACE::Abs;
39
using hwy::HWY_NAMESPACE::Add;
40
using hwy::HWY_NAMESPACE::Div;
41
using hwy::HWY_NAMESPACE::Max;
42
using hwy::HWY_NAMESPACE::Mul;
43
using hwy::HWY_NAMESPACE::MulAdd;
44
using hwy::HWY_NAMESPACE::Rebind;
45
using hwy::HWY_NAMESPACE::Sub;
46
using hwy::HWY_NAMESPACE::Vec;
47
using hwy::HWY_NAMESPACE::ZeroIfNegative;
48
49
// TODO(veluca): optimize constants.
50
const float w1 = 0.20345139757231578f;
51
const float w2 = 0.0334829185968739f;
52
const float w0 = 1.0f - 4.0f * (w1 + w2);
53
54
template <class V>
55
598k
V MaxWorkaround(V a, V b) {
56
#if (HWY_TARGET == HWY_AVX3) && HWY_COMPILER_CLANG <= 800
57
  // Prevents "Do not know how to split the result of this operator" error
58
  return IfThenElse(a > b, a, b);
59
#else
60
598k
  return Max(a, b);
61
598k
#endif
62
598k
}
hwy::N_SSE2::Vec128<float, 1ul> jxl::N_SSE2::MaxWorkaround<hwy::N_SSE2::Vec128<float, 1ul> >(hwy::N_SSE2::Vec128<float, 1ul>, hwy::N_SSE2::Vec128<float, 1ul>)
Line
Count
Source
55
249k
V MaxWorkaround(V a, V b) {
56
#if (HWY_TARGET == HWY_AVX3) && HWY_COMPILER_CLANG <= 800
57
  // Prevents "Do not know how to split the result of this operator" error
58
  return IfThenElse(a > b, a, b);
59
#else
60
249k
  return Max(a, b);
61
249k
#endif
62
249k
}
hwy::N_SSE2::Vec128<float, 4ul> jxl::N_SSE2::MaxWorkaround<hwy::N_SSE2::Vec128<float, 4ul> >(hwy::N_SSE2::Vec128<float, 4ul>, hwy::N_SSE2::Vec128<float, 4ul>)
Line
Count
Source
55
349k
V MaxWorkaround(V a, V b) {
56
#if (HWY_TARGET == HWY_AVX3) && HWY_COMPILER_CLANG <= 800
57
  // Prevents "Do not know how to split the result of this operator" error
58
  return IfThenElse(a > b, a, b);
59
#else
60
349k
  return Max(a, b);
61
349k
#endif
62
349k
}
63
64
template <typename D>
65
JXL_INLINE void ComputePixelChannel(const D d, const float dc_factor,
66
                                    const float* JXL_RESTRICT row_top,
67
                                    const float* JXL_RESTRICT row,
68
                                    const float* JXL_RESTRICT row_bottom,
69
                                    Vec<D>* JXL_RESTRICT mc,
70
                                    Vec<D>* JXL_RESTRICT sm,
71
594k
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
594k
  const auto tl = LoadU(d, row_top + x - 1);
73
594k
  const auto tc = Load(d, row_top + x);
74
594k
  const auto tr = LoadU(d, row_top + x + 1);
75
76
594k
  const auto ml = LoadU(d, row + x - 1);
77
594k
  *mc = Load(d, row + x);
78
594k
  const auto mr = LoadU(d, row + x + 1);
79
80
594k
  const auto bl = LoadU(d, row_bottom + x - 1);
81
594k
  const auto bc = Load(d, row_bottom + x);
82
594k
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
594k
  const auto w_center = Set(d, w0);
85
594k
  const auto w_side = Set(d, w1);
86
594k
  const auto w_corner = Set(d, w2);
87
88
594k
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
594k
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
594k
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
594k
  const auto dc_quant = Set(d, dc_factor);
93
594k
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
594k
}
void jxl::N_SSE2::ComputePixelChannel<hwy::N_SSE2::Simd<float, 1ul, 0> >(hwy::N_SSE2::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_SSE2::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_SSE2::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_SSE2::Simd<float, 1ul, 0>)()))*, unsigned long)
Line
Count
Source
71
218k
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
218k
  const auto tl = LoadU(d, row_top + x - 1);
73
218k
  const auto tc = Load(d, row_top + x);
74
218k
  const auto tr = LoadU(d, row_top + x + 1);
75
76
218k
  const auto ml = LoadU(d, row + x - 1);
77
218k
  *mc = Load(d, row + x);
78
218k
  const auto mr = LoadU(d, row + x + 1);
79
80
218k
  const auto bl = LoadU(d, row_bottom + x - 1);
81
218k
  const auto bc = Load(d, row_bottom + x);
82
218k
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
218k
  const auto w_center = Set(d, w0);
85
218k
  const auto w_side = Set(d, w1);
86
218k
  const auto w_corner = Set(d, w2);
87
88
218k
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
218k
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
218k
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
218k
  const auto dc_quant = Set(d, dc_factor);
93
218k
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
218k
}
void jxl::N_SSE2::ComputePixelChannel<hwy::N_SSE2::Simd<float, 4ul, 0> >(hwy::N_SSE2::Simd<float, 4ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_SSE2::Simd<float, 4ul, 0>)()))*, decltype (Zero((hwy::N_SSE2::Simd<float, 4ul, 0>)()))*, decltype (Zero((hwy::N_SSE2::Simd<float, 4ul, 0>)()))*, unsigned long)
Line
Count
Source
71
375k
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
375k
  const auto tl = LoadU(d, row_top + x - 1);
73
375k
  const auto tc = Load(d, row_top + x);
74
375k
  const auto tr = LoadU(d, row_top + x + 1);
75
76
375k
  const auto ml = LoadU(d, row + x - 1);
77
375k
  *mc = Load(d, row + x);
78
375k
  const auto mr = LoadU(d, row + x + 1);
79
80
375k
  const auto bl = LoadU(d, row_bottom + x - 1);
81
375k
  const auto bc = Load(d, row_bottom + x);
82
375k
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
375k
  const auto w_center = Set(d, w0);
85
375k
  const auto w_side = Set(d, w1);
86
375k
  const auto w_corner = Set(d, w2);
87
88
375k
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
375k
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
375k
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
375k
  const auto dc_quant = Set(d, dc_factor);
93
375k
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
375k
}
95
96
template <typename D>
97
JXL_INLINE void ComputePixel(
98
    const float* JXL_RESTRICT dc_factors,
99
    const float* JXL_RESTRICT* JXL_RESTRICT rows_top,
100
    const float* JXL_RESTRICT* JXL_RESTRICT rows,
101
    const float* JXL_RESTRICT* JXL_RESTRICT rows_bottom,
102
246k
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
246k
  const D d;
104
246k
  auto mc_x = Undefined(d);
105
246k
  auto mc_y = Undefined(d);
106
246k
  auto mc_b = Undefined(d);
107
246k
  auto sm_x = Undefined(d);
108
246k
  auto sm_y = Undefined(d);
109
246k
  auto sm_b = Undefined(d);
110
246k
  auto gap = Set(d, 0.5f);
111
246k
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
246k
                      &mc_x, &sm_x, &gap, x);
113
246k
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
246k
                      &mc_y, &sm_y, &gap, x);
115
246k
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
246k
                      &mc_b, &sm_b, &gap, x);
117
246k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
246k
  factor = ZeroIfNegative(factor);
119
120
246k
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
246k
  Store(out, d, out_rows[0] + x);
122
246k
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
246k
  Store(out, d, out_rows[1] + x);
124
246k
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
246k
  Store(out, d, out_rows[2] + x);
126
246k
}
void jxl::N_SSE2::ComputePixel<hwy::N_SSE2::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Line
Count
Source
102
118k
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
118k
  const D d;
104
118k
  auto mc_x = Undefined(d);
105
118k
  auto mc_y = Undefined(d);
106
118k
  auto mc_b = Undefined(d);
107
118k
  auto sm_x = Undefined(d);
108
118k
  auto sm_y = Undefined(d);
109
118k
  auto sm_b = Undefined(d);
110
118k
  auto gap = Set(d, 0.5f);
111
118k
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
118k
                      &mc_x, &sm_x, &gap, x);
113
118k
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
118k
                      &mc_y, &sm_y, &gap, x);
115
118k
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
118k
                      &mc_b, &sm_b, &gap, x);
117
118k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
118k
  factor = ZeroIfNegative(factor);
119
120
118k
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
118k
  Store(out, d, out_rows[0] + x);
122
118k
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
118k
  Store(out, d, out_rows[1] + x);
124
118k
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
118k
  Store(out, d, out_rows[2] + x);
126
118k
}
void jxl::N_SSE2::ComputePixel<hwy::N_SSE2::Simd<float, 4ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Line
Count
Source
102
127k
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
127k
  const D d;
104
127k
  auto mc_x = Undefined(d);
105
127k
  auto mc_y = Undefined(d);
106
127k
  auto mc_b = Undefined(d);
107
127k
  auto sm_x = Undefined(d);
108
127k
  auto sm_y = Undefined(d);
109
127k
  auto sm_b = Undefined(d);
110
127k
  auto gap = Set(d, 0.5f);
111
127k
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
127k
                      &mc_x, &sm_x, &gap, x);
113
127k
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
127k
                      &mc_y, &sm_y, &gap, x);
115
127k
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
127k
                      &mc_b, &sm_b, &gap, x);
117
127k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
127k
  factor = ZeroIfNegative(factor);
119
120
127k
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
127k
  Store(out, d, out_rows[0] + x);
122
127k
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
127k
  Store(out, d, out_rows[1] + x);
124
127k
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
127k
  Store(out, d, out_rows[2] + x);
126
127k
}
127
128
Status AdaptiveDCSmoothing(JxlMemoryManager* memory_manager,
129
                           const float* dc_factors, Image3F* dc,
130
6.43k
                           ThreadPool* pool) {
131
6.43k
  const size_t xsize = dc->xsize();
132
6.43k
  const size_t ysize = dc->ysize();
133
6.43k
  if (ysize <= 2 || xsize <= 2) return true;
134
135
  // TODO(veluca): use tile-based processing?
136
  // TODO(veluca): decide if changes to the y channel should be propagated to
137
  // the x and b channels through color correlation.
138
1.65k
  JXL_ENSURE(w1 + w2 < 0.25f);
139
140
3.30k
  JXL_ASSIGN_OR_RETURN(Image3F smoothed,
141
3.30k
                       Image3F::Create(memory_manager, xsize, ysize));
142
  // Fill in borders that the loop below will not. First and last are unused.
143
6.61k
  for (size_t c = 0; c < 3; c++) {
144
9.92k
    for (size_t y : {static_cast<size_t>(0), ysize - 1}) {
145
9.92k
      memcpy(smoothed.PlaneRow(c, y), dc->PlaneRow(c, y),
146
9.92k
             xsize * sizeof(float));
147
9.92k
    }
148
4.96k
  }
149
40.8k
  auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
150
40.8k
    const float* JXL_RESTRICT rows_top[3]{
151
40.8k
        dc->ConstPlaneRow(0, y - 1),
152
40.8k
        dc->ConstPlaneRow(1, y - 1),
153
40.8k
        dc->ConstPlaneRow(2, y - 1),
154
40.8k
    };
155
40.8k
    const float* JXL_RESTRICT rows[3] = {
156
40.8k
        dc->ConstPlaneRow(0, y),
157
40.8k
        dc->ConstPlaneRow(1, y),
158
40.8k
        dc->ConstPlaneRow(2, y),
159
40.8k
    };
160
40.8k
    const float* JXL_RESTRICT rows_bottom[3] = {
161
40.8k
        dc->ConstPlaneRow(0, y + 1),
162
40.8k
        dc->ConstPlaneRow(1, y + 1),
163
40.8k
        dc->ConstPlaneRow(2, y + 1),
164
40.8k
    };
165
40.8k
    float* JXL_RESTRICT rows_out[3] = {
166
40.8k
        smoothed.PlaneRow(0, y),
167
40.8k
        smoothed.PlaneRow(1, y),
168
40.8k
        smoothed.PlaneRow(2, y),
169
40.8k
    };
170
74.8k
    for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
171
297k
      for (size_t c = 0; c < 3; c++) {
172
222k
        rows_out[c][x] = rows[c][x];
173
222k
      }
174
74.8k
    }
175
176
40.8k
    size_t x = 1;
177
    // First pixels
178
40.8k
    const size_t N = Lanes(D());
179
141k
    for (; x < std::min(N, xsize - 1); x++) {
180
101k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
181
101k
                            x);
182
101k
    }
183
    // Full vectors.
184
184k
    for (; x + N <= xsize - 1; x += N) {
185
143k
      ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
186
143k
    }
187
    // Last pixels.
188
71.0k
    for (; x < xsize - 1; x++) {
189
30.2k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
190
30.2k
                            x);
191
30.2k
    }
192
40.8k
    return true;
193
40.8k
  };
194
3.30k
  JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize - 1, ThreadPool::NoInit,
195
3.30k
                                process_row, "DCSmoothingRow"));
196
1.65k
  dc->Swap(smoothed);
197
1.65k
  return true;
198
3.30k
}
199
200
// DC dequantization.
201
void DequantDC(const Rect& r, Image3F* dc, ImageB* quant_dc, const Image& in,
202
               const float* dc_factors, float mul, const float* cfl_factors,
203
               const YCbCrChromaSubsampling& chroma_subsampling,
204
7.30k
               const BlockCtxMap& bctx) {
205
7.30k
  const HWY_FULL(float) df;
206
7.30k
  const Rebind<pixel_type, HWY_FULL(float)> di;  // assumes pixel_type <= float
207
7.30k
  if (chroma_subsampling.Is444()) {
208
6.77k
    const auto fac_x = Set(df, dc_factors[0] * mul);
209
6.77k
    const auto fac_y = Set(df, dc_factors[1] * mul);
210
6.77k
    const auto fac_b = Set(df, dc_factors[2] * mul);
211
6.77k
    const auto cfl_fac_x = Set(df, cfl_factors[0]);
212
6.77k
    const auto cfl_fac_b = Set(df, cfl_factors[2]);
213
85.0k
    for (size_t y = 0; y < r.ysize(); y++) {
214
78.2k
      float* dec_row_x = r.PlaneRow(dc, 0, y);
215
78.2k
      float* dec_row_y = r.PlaneRow(dc, 1, y);
216
78.2k
      float* dec_row_b = r.PlaneRow(dc, 2, y);
217
78.2k
      const int32_t* quant_row_x = in.channel[1].plane.Row(y);
218
78.2k
      const int32_t* quant_row_y = in.channel[0].plane.Row(y);
219
78.2k
      const int32_t* quant_row_b = in.channel[2].plane.Row(y);
220
505k
      for (size_t x = 0; x < r.xsize(); x += Lanes(di)) {
221
427k
        const auto in_q_x = Load(di, quant_row_x + x);
222
427k
        const auto in_q_y = Load(di, quant_row_y + x);
223
427k
        const auto in_q_b = Load(di, quant_row_b + x);
224
427k
        const auto in_x = Mul(ConvertTo(df, in_q_x), fac_x);
225
427k
        const auto in_y = Mul(ConvertTo(df, in_q_y), fac_y);
226
427k
        const auto in_b = Mul(ConvertTo(df, in_q_b), fac_b);
227
427k
        Store(in_y, df, dec_row_y + x);
228
427k
        Store(MulAdd(in_y, cfl_fac_x, in_x), df, dec_row_x + x);
229
427k
        Store(MulAdd(in_y, cfl_fac_b, in_b), df, dec_row_b + x);
230
427k
      }
231
78.2k
    }
232
6.77k
  } else {
233
1.56k
    for (size_t c : {1, 0, 2}) {
234
1.56k
      Rect rect(r.x0() >> chroma_subsampling.HShift(c),
235
1.56k
                r.y0() >> chroma_subsampling.VShift(c),
236
1.56k
                r.xsize() >> chroma_subsampling.HShift(c),
237
1.56k
                r.ysize() >> chroma_subsampling.VShift(c));
238
1.56k
      const auto fac = Set(df, dc_factors[c] * mul);
239
1.56k
      const Channel& ch = in.channel[c < 2 ? c ^ 1 : c];
240
19.5k
      for (size_t y = 0; y < rect.ysize(); y++) {
241
17.9k
        const int32_t* quant_row = ch.plane.Row(y);
242
17.9k
        float* row = rect.PlaneRow(dc, c, y);
243
127k
        for (size_t x = 0; x < rect.xsize(); x += Lanes(di)) {
244
109k
          const auto in_q = Load(di, quant_row + x);
245
109k
          const auto out = Mul(ConvertTo(df, in_q), fac);
246
109k
          Store(out, df, row + x);
247
109k
        }
248
17.9k
      }
249
1.56k
    }
250
522
  }
251
7.30k
  if (bctx.num_dc_ctxs <= 1) {
252
89.3k
    for (size_t y = 0; y < r.ysize(); y++) {
253
83.0k
      uint8_t* qdc_row = r.Row(quant_dc, y);
254
83.0k
      memset(qdc_row, 0, sizeof(*qdc_row) * r.xsize());
255
83.0k
    }
256
6.30k
  } else {
257
998
    JXL_DASSERT(r.ysize() == 0 ||
258
998
                (r.ysize() - 1) >> chroma_subsampling.VShift(0) <
259
998
                    in.channel[1].plane.ysize());
260
998
    JXL_DASSERT(r.ysize() == 0 ||
261
998
                (r.ysize() - 1) >> chroma_subsampling.VShift(1) <
262
998
                    in.channel[0].plane.ysize());
263
998
    JXL_DASSERT(r.ysize() == 0 ||
264
998
                (r.ysize() - 1) >> chroma_subsampling.VShift(2) <
265
998
                    in.channel[2].plane.ysize());
266
4.56k
    for (size_t y = 0; y < r.ysize(); y++) {
267
3.56k
      uint8_t* qdc_row_val = r.Row(quant_dc, y);
268
3.56k
      const int32_t* quant_row_x =
269
3.56k
          in.channel[1].plane.Row(y >> chroma_subsampling.VShift(0));
270
3.56k
      const int32_t* quant_row_y =
271
3.56k
          in.channel[0].plane.Row(y >> chroma_subsampling.VShift(1));
272
3.56k
      const int32_t* quant_row_b =
273
3.56k
          in.channel[2].plane.Row(y >> chroma_subsampling.VShift(2));
274
20.8k
      for (size_t x = 0; x < r.xsize(); x++) {
275
17.3k
        int bucket_x = 0;
276
17.3k
        int bucket_y = 0;
277
17.3k
        int bucket_b = 0;
278
17.3k
        for (int t : bctx.dc_thresholds[0]) {
279
17.1k
          if (quant_row_x[x >> chroma_subsampling.HShift(0)] > t) bucket_x++;
280
17.1k
        }
281
17.3k
        for (int t : bctx.dc_thresholds[1]) {
282
17.3k
          if (quant_row_y[x >> chroma_subsampling.HShift(1)] > t) bucket_y++;
283
17.3k
        }
284
17.3k
        for (int t : bctx.dc_thresholds[2]) {
285
12.5k
          if (quant_row_b[x >> chroma_subsampling.HShift(2)] > t) bucket_b++;
286
12.5k
        }
287
17.3k
        int bucket = bucket_x;
288
17.3k
        bucket *= bctx.dc_thresholds[2].size() + 1;
289
17.3k
        bucket += bucket_b;
290
17.3k
        bucket *= bctx.dc_thresholds[1].size() + 1;
291
17.3k
        bucket += bucket_y;
292
17.3k
        qdc_row_val[x] = bucket;
293
17.3k
      }
294
3.56k
    }
295
998
  }
296
7.30k
}
297
298
// NOLINTNEXTLINE(google-readability-namespace-comments)
299
}  // namespace HWY_NAMESPACE
300
}  // namespace jxl
301
HWY_AFTER_NAMESPACE();
302
303
#if HWY_ONCE
304
namespace jxl {
305
306
HWY_EXPORT(DequantDC);
307
HWY_EXPORT(AdaptiveDCSmoothing);
308
Status AdaptiveDCSmoothing(JxlMemoryManager* memory_manager,
309
                           const float* dc_factors, Image3F* dc,
310
6.43k
                           ThreadPool* pool) {
311
6.43k
  return HWY_DYNAMIC_DISPATCH(AdaptiveDCSmoothing)(memory_manager, dc_factors,
312
6.43k
                                                   dc, pool);
313
6.43k
}
314
315
void DequantDC(const Rect& r, Image3F* dc, ImageB* quant_dc, const Image& in,
316
               const float* dc_factors, float mul, const float* cfl_factors,
317
               const YCbCrChromaSubsampling& chroma_subsampling,
318
7.30k
               const BlockCtxMap& bctx) {
319
7.30k
  HWY_DYNAMIC_DISPATCH(DequantDC)
320
7.30k
  (r, dc, quant_dc, in, dc_factors, mul, cfl_factors, chroma_subsampling, bctx);
321
7.30k
}
322
323
}  // namespace jxl
324
#endif  // HWY_ONCE