Coverage Report

Created: 2026-05-24 07: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
8.87M
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
8.87M
  return Max(a, b);
61
8.87M
#endif
62
8.87M
}
Unexecuted instantiation: hwy::N_SSE4::Vec128<float, 1ul> jxl::N_SSE4::MaxWorkaround<hwy::N_SSE4::Vec128<float, 1ul> >(hwy::N_SSE4::Vec128<float, 1ul>, hwy::N_SSE4::Vec128<float, 1ul>)
Unexecuted instantiation: hwy::N_SSE4::Vec128<float, 4ul> jxl::N_SSE4::MaxWorkaround<hwy::N_SSE4::Vec128<float, 4ul> >(hwy::N_SSE4::Vec128<float, 4ul>, hwy::N_SSE4::Vec128<float, 4ul>)
hwy::N_AVX2::Vec128<float, 1ul> jxl::N_AVX2::MaxWorkaround<hwy::N_AVX2::Vec128<float, 1ul> >(hwy::N_AVX2::Vec128<float, 1ul>, hwy::N_AVX2::Vec128<float, 1ul>)
Line
Count
Source
55
7.15M
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
7.15M
  return Max(a, b);
61
7.15M
#endif
62
7.15M
}
hwy::N_AVX2::Vec256<float> jxl::N_AVX2::MaxWorkaround<hwy::N_AVX2::Vec256<float> >(hwy::N_AVX2::Vec256<float>, hwy::N_AVX2::Vec256<float>)
Line
Count
Source
55
1.72M
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
1.72M
  return Max(a, b);
61
1.72M
#endif
62
1.72M
}
Unexecuted instantiation: hwy::N_AVX3::Vec128<float, 1ul> jxl::N_AVX3::MaxWorkaround<hwy::N_AVX3::Vec128<float, 1ul> >(hwy::N_AVX3::Vec128<float, 1ul>, hwy::N_AVX3::Vec128<float, 1ul>)
Unexecuted instantiation: hwy::N_AVX3::Vec512<float> jxl::N_AVX3::MaxWorkaround<hwy::N_AVX3::Vec512<float> >(hwy::N_AVX3::Vec512<float>, hwy::N_AVX3::Vec512<float>)
Unexecuted instantiation: hwy::N_AVX3_ZEN4::Vec128<float, 1ul> jxl::N_AVX3_ZEN4::MaxWorkaround<hwy::N_AVX3_ZEN4::Vec128<float, 1ul> >(hwy::N_AVX3_ZEN4::Vec128<float, 1ul>, hwy::N_AVX3_ZEN4::Vec128<float, 1ul>)
Unexecuted instantiation: hwy::N_AVX3_ZEN4::Vec512<float> jxl::N_AVX3_ZEN4::MaxWorkaround<hwy::N_AVX3_ZEN4::Vec512<float> >(hwy::N_AVX3_ZEN4::Vec512<float>, hwy::N_AVX3_ZEN4::Vec512<float>)
Unexecuted instantiation: hwy::N_AVX3_SPR::Vec128<float, 1ul> jxl::N_AVX3_SPR::MaxWorkaround<hwy::N_AVX3_SPR::Vec128<float, 1ul> >(hwy::N_AVX3_SPR::Vec128<float, 1ul>, hwy::N_AVX3_SPR::Vec128<float, 1ul>)
Unexecuted instantiation: hwy::N_AVX3_SPR::Vec512<float> jxl::N_AVX3_SPR::MaxWorkaround<hwy::N_AVX3_SPR::Vec512<float> >(hwy::N_AVX3_SPR::Vec512<float>, hwy::N_AVX3_SPR::Vec512<float>)
Unexecuted instantiation: 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>)
Unexecuted instantiation: 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>)
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
8.87M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
8.87M
  const auto tl = LoadU(d, row_top + x - 1);
73
8.87M
  const auto tc = Load(d, row_top + x);
74
8.87M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
8.87M
  const auto ml = LoadU(d, row + x - 1);
77
8.87M
  *mc = Load(d, row + x);
78
8.87M
  const auto mr = LoadU(d, row + x + 1);
79
80
8.87M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
8.87M
  const auto bc = Load(d, row_bottom + x);
82
8.87M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
8.87M
  const auto w_center = Set(d, w0);
85
8.87M
  const auto w_side = Set(d, w1);
86
8.87M
  const auto w_corner = Set(d, w2);
87
88
8.87M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
8.87M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
8.87M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
8.87M
  const auto dc_quant = Set(d, dc_factor);
93
8.87M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
8.87M
}
Unexecuted instantiation: void jxl::N_SSE4::ComputePixelChannel<hwy::N_SSE4::Simd<float, 1ul, 0> >(hwy::N_SSE4::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_SSE4::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_SSE4::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_SSE4::Simd<float, 1ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::ComputePixelChannel<hwy::N_SSE4::Simd<float, 4ul, 0> >(hwy::N_SSE4::Simd<float, 4ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_SSE4::Simd<float, 4ul, 0>)()))*, decltype (Zero((hwy::N_SSE4::Simd<float, 4ul, 0>)()))*, decltype (Zero((hwy::N_SSE4::Simd<float, 4ul, 0>)()))*, unsigned long)
void jxl::N_AVX2::ComputePixelChannel<hwy::N_AVX2::Simd<float, 1ul, 0> >(hwy::N_AVX2::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX2::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX2::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX2::Simd<float, 1ul, 0>)()))*, unsigned long)
Line
Count
Source
71
7.15M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
7.15M
  const auto tl = LoadU(d, row_top + x - 1);
73
7.15M
  const auto tc = Load(d, row_top + x);
74
7.15M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
7.15M
  const auto ml = LoadU(d, row + x - 1);
77
7.15M
  *mc = Load(d, row + x);
78
7.15M
  const auto mr = LoadU(d, row + x + 1);
79
80
7.15M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
7.15M
  const auto bc = Load(d, row_bottom + x);
82
7.15M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
7.15M
  const auto w_center = Set(d, w0);
85
7.15M
  const auto w_side = Set(d, w1);
86
7.15M
  const auto w_corner = Set(d, w2);
87
88
7.15M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
7.15M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
7.15M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
7.15M
  const auto dc_quant = Set(d, dc_factor);
93
7.15M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
7.15M
}
void jxl::N_AVX2::ComputePixelChannel<hwy::N_AVX2::Simd<float, 8ul, 0> >(hwy::N_AVX2::Simd<float, 8ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX2::Simd<float, 8ul, 0>)()))*, decltype (Zero((hwy::N_AVX2::Simd<float, 8ul, 0>)()))*, decltype (Zero((hwy::N_AVX2::Simd<float, 8ul, 0>)()))*, unsigned long)
Line
Count
Source
71
1.72M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
1.72M
  const auto tl = LoadU(d, row_top + x - 1);
73
1.72M
  const auto tc = Load(d, row_top + x);
74
1.72M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
1.72M
  const auto ml = LoadU(d, row + x - 1);
77
1.72M
  *mc = Load(d, row + x);
78
1.72M
  const auto mr = LoadU(d, row + x + 1);
79
80
1.72M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
1.72M
  const auto bc = Load(d, row_bottom + x);
82
1.72M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
1.72M
  const auto w_center = Set(d, w0);
85
1.72M
  const auto w_side = Set(d, w1);
86
1.72M
  const auto w_corner = Set(d, w2);
87
88
1.72M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
1.72M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
1.72M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
1.72M
  const auto dc_quant = Set(d, dc_factor);
93
1.72M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
1.72M
}
Unexecuted instantiation: void jxl::N_AVX3::ComputePixelChannel<hwy::N_AVX3::Simd<float, 1ul, 0> >(hwy::N_AVX3::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3::Simd<float, 1ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3::ComputePixelChannel<hwy::N_AVX3::Simd<float, 16ul, 0> >(hwy::N_AVX3::Simd<float, 16ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3::Simd<float, 16ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::ComputePixelChannel<hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0> >(hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::ComputePixelChannel<hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0> >(hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_SPR::ComputePixelChannel<hwy::N_AVX3_SPR::Simd<float, 1ul, 0> >(hwy::N_AVX3_SPR::Simd<float, 1ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 1ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 1ul, 0>)()))*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_SPR::ComputePixelChannel<hwy::N_AVX3_SPR::Simd<float, 16ul, 0> >(hwy::N_AVX3_SPR::Simd<float, 16ul, 0>, float, float const*, float const*, float const*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 16ul, 0>)()))*, decltype (Zero((hwy::N_AVX3_SPR::Simd<float, 16ul, 0>)()))*, unsigned long)
Unexecuted instantiation: 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)
Unexecuted instantiation: 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)
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
2.95M
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
2.95M
  const D d;
104
2.95M
  auto mc_x = Undefined(d);
105
2.95M
  auto mc_y = Undefined(d);
106
2.95M
  auto mc_b = Undefined(d);
107
2.95M
  auto sm_x = Undefined(d);
108
2.95M
  auto sm_y = Undefined(d);
109
2.95M
  auto sm_b = Undefined(d);
110
2.95M
  auto gap = Set(d, 0.5f);
111
2.95M
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
2.95M
                      &mc_x, &sm_x, &gap, x);
113
2.95M
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
2.95M
                      &mc_y, &sm_y, &gap, x);
115
2.95M
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
2.95M
                      &mc_b, &sm_b, &gap, x);
117
2.95M
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
2.95M
  factor = ZeroIfNegative(factor);
119
120
2.95M
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
2.95M
  Store(out, d, out_rows[0] + x);
122
2.95M
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
2.95M
  Store(out, d, out_rows[1] + x);
124
2.95M
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
2.95M
  Store(out, d, out_rows[2] + x);
126
2.95M
}
Unexecuted instantiation: void jxl::N_SSE4::ComputePixel<hwy::N_SSE4::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::ComputePixel<hwy::N_SSE4::Simd<float, 4ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
void jxl::N_AVX2::ComputePixel<hwy::N_AVX2::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Line
Count
Source
102
2.38M
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
2.38M
  const D d;
104
2.38M
  auto mc_x = Undefined(d);
105
2.38M
  auto mc_y = Undefined(d);
106
2.38M
  auto mc_b = Undefined(d);
107
2.38M
  auto sm_x = Undefined(d);
108
2.38M
  auto sm_y = Undefined(d);
109
2.38M
  auto sm_b = Undefined(d);
110
2.38M
  auto gap = Set(d, 0.5f);
111
2.38M
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
2.38M
                      &mc_x, &sm_x, &gap, x);
113
2.38M
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
2.38M
                      &mc_y, &sm_y, &gap, x);
115
2.38M
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
2.38M
                      &mc_b, &sm_b, &gap, x);
117
2.38M
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
2.38M
  factor = ZeroIfNegative(factor);
119
120
2.38M
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
2.38M
  Store(out, d, out_rows[0] + x);
122
2.38M
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
2.38M
  Store(out, d, out_rows[1] + x);
124
2.38M
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
2.38M
  Store(out, d, out_rows[2] + x);
126
2.38M
}
void jxl::N_AVX2::ComputePixel<hwy::N_AVX2::Simd<float, 8ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Line
Count
Source
102
574k
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
574k
  const D d;
104
574k
  auto mc_x = Undefined(d);
105
574k
  auto mc_y = Undefined(d);
106
574k
  auto mc_b = Undefined(d);
107
574k
  auto sm_x = Undefined(d);
108
574k
  auto sm_y = Undefined(d);
109
574k
  auto sm_b = Undefined(d);
110
574k
  auto gap = Set(d, 0.5f);
111
574k
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
574k
                      &mc_x, &sm_x, &gap, x);
113
574k
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
574k
                      &mc_y, &sm_y, &gap, x);
115
574k
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
574k
                      &mc_b, &sm_b, &gap, x);
117
574k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
574k
  factor = ZeroIfNegative(factor);
119
120
574k
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
574k
  Store(out, d, out_rows[0] + x);
122
574k
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
574k
  Store(out, d, out_rows[1] + x);
124
574k
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
574k
  Store(out, d, out_rows[2] + x);
126
574k
}
Unexecuted instantiation: void jxl::N_AVX3::ComputePixel<hwy::N_AVX3::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3::ComputePixel<hwy::N_AVX3::Simd<float, 16ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::ComputePixel<hwy::N_AVX3_ZEN4::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_ZEN4::ComputePixel<hwy::N_AVX3_ZEN4::Simd<float, 16ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_SPR::ComputePixel<hwy::N_AVX3_SPR::Simd<float, 1ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX3_SPR::ComputePixel<hwy::N_AVX3_SPR::Simd<float, 16ul, 0> >(float const*, float const* restrict*, float const* restrict*, float const* restrict*, float* restrict*, unsigned long)
Unexecuted instantiation: 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)
Unexecuted instantiation: 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)
127
128
Status AdaptiveDCSmoothing(JxlMemoryManager* memory_manager,
129
                           const float* dc_factors, Image3F* dc,
130
40.3k
                           ThreadPool* pool) {
131
40.3k
  const size_t xsize = dc->xsize();
132
40.3k
  const size_t ysize = dc->ysize();
133
40.3k
  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
6.03k
  JXL_ENSURE(w1 + w2 < 0.25f);
139
140
12.0k
  JXL_ASSIGN_OR_RETURN(Image3F smoothed,
141
12.0k
                       Image3F::Create(memory_manager, xsize, ysize));
142
  // Fill in borders that the loop below will not. First and last are unused.
143
24.1k
  for (size_t c = 0; c < 3; c++) {
144
36.2k
    for (size_t y : {static_cast<size_t>(0), ysize - 1}) {
145
36.2k
      memcpy(smoothed.PlaneRow(c, y), dc->PlaneRow(c, y),
146
36.2k
             xsize * sizeof(float));
147
36.2k
    }
148
18.1k
  }
149
225k
  auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
150
225k
    const float* JXL_RESTRICT rows_top[3]{
151
225k
        dc->ConstPlaneRow(0, y - 1),
152
225k
        dc->ConstPlaneRow(1, y - 1),
153
225k
        dc->ConstPlaneRow(2, y - 1),
154
225k
    };
155
225k
    const float* JXL_RESTRICT rows[3] = {
156
225k
        dc->ConstPlaneRow(0, y),
157
225k
        dc->ConstPlaneRow(1, y),
158
225k
        dc->ConstPlaneRow(2, y),
159
225k
    };
160
225k
    const float* JXL_RESTRICT rows_bottom[3] = {
161
225k
        dc->ConstPlaneRow(0, y + 1),
162
225k
        dc->ConstPlaneRow(1, y + 1),
163
225k
        dc->ConstPlaneRow(2, y + 1),
164
225k
    };
165
225k
    float* JXL_RESTRICT rows_out[3] = {
166
225k
        smoothed.PlaneRow(0, y),
167
225k
        smoothed.PlaneRow(1, y),
168
225k
        smoothed.PlaneRow(2, y),
169
225k
    };
170
450k
    for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
171
1.80M
      for (size_t c = 0; c < 3; c++) {
172
1.35M
        rows_out[c][x] = rows[c][x];
173
1.35M
      }
174
450k
    }
175
176
225k
    size_t x = 1;
177
    // First pixels
178
225k
    const size_t N = Lanes(D());
179
1.77M
    for (; x < std::min(N, xsize - 1); x++) {
180
1.54M
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
181
1.54M
                            x);
182
1.54M
    }
183
    // Full vectors.
184
799k
    for (; x + N <= xsize - 1; x += N) {
185
574k
      ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
186
574k
    }
187
    // Last pixels.
188
1.06M
    for (; x < xsize - 1; x++) {
189
838k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
190
838k
                            x);
191
838k
    }
192
225k
    return true;
193
225k
  };
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
compressed_dc.cc:jxl::N_AVX2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Line
Count
Source
149
225k
  auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
150
225k
    const float* JXL_RESTRICT rows_top[3]{
151
225k
        dc->ConstPlaneRow(0, y - 1),
152
225k
        dc->ConstPlaneRow(1, y - 1),
153
225k
        dc->ConstPlaneRow(2, y - 1),
154
225k
    };
155
225k
    const float* JXL_RESTRICT rows[3] = {
156
225k
        dc->ConstPlaneRow(0, y),
157
225k
        dc->ConstPlaneRow(1, y),
158
225k
        dc->ConstPlaneRow(2, y),
159
225k
    };
160
225k
    const float* JXL_RESTRICT rows_bottom[3] = {
161
225k
        dc->ConstPlaneRow(0, y + 1),
162
225k
        dc->ConstPlaneRow(1, y + 1),
163
225k
        dc->ConstPlaneRow(2, y + 1),
164
225k
    };
165
225k
    float* JXL_RESTRICT rows_out[3] = {
166
225k
        smoothed.PlaneRow(0, y),
167
225k
        smoothed.PlaneRow(1, y),
168
225k
        smoothed.PlaneRow(2, y),
169
225k
    };
170
450k
    for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
171
1.80M
      for (size_t c = 0; c < 3; c++) {
172
1.35M
        rows_out[c][x] = rows[c][x];
173
1.35M
      }
174
450k
    }
175
176
225k
    size_t x = 1;
177
    // First pixels
178
225k
    const size_t N = Lanes(D());
179
1.77M
    for (; x < std::min(N, xsize - 1); x++) {
180
1.54M
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
181
1.54M
                            x);
182
1.54M
    }
183
    // Full vectors.
184
799k
    for (; x + N <= xsize - 1; x += N) {
185
574k
      ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
186
574k
    }
187
    // Last pixels.
188
1.06M
    for (; x < xsize - 1; x++) {
189
838k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
190
838k
                            x);
191
838k
    }
192
225k
    return true;
193
225k
  };
Unexecuted instantiation: compressed_dc.cc:jxl::N_AVX3::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Unexecuted instantiation: compressed_dc.cc:jxl::N_AVX3_ZEN4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Unexecuted instantiation: compressed_dc.cc:jxl::N_AVX3_SPR::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
194
12.0k
  JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize - 1, ThreadPool::NoInit,
195
12.0k
                                process_row, "DCSmoothingRow"));
196
6.03k
  dc->Swap(smoothed);
197
6.03k
  return true;
198
12.0k
}
Unexecuted instantiation: jxl::N_SSE4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
jxl::N_AVX2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
Line
Count
Source
130
40.3k
                           ThreadPool* pool) {
131
40.3k
  const size_t xsize = dc->xsize();
132
40.3k
  const size_t ysize = dc->ysize();
133
40.3k
  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
6.03k
  JXL_ENSURE(w1 + w2 < 0.25f);
139
140
12.0k
  JXL_ASSIGN_OR_RETURN(Image3F smoothed,
141
12.0k
                       Image3F::Create(memory_manager, xsize, ysize));
142
  // Fill in borders that the loop below will not. First and last are unused.
143
24.1k
  for (size_t c = 0; c < 3; c++) {
144
36.2k
    for (size_t y : {static_cast<size_t>(0), ysize - 1}) {
145
36.2k
      memcpy(smoothed.PlaneRow(c, y), dc->PlaneRow(c, y),
146
36.2k
             xsize * sizeof(float));
147
36.2k
    }
148
18.1k
  }
149
12.0k
  auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
150
12.0k
    const float* JXL_RESTRICT rows_top[3]{
151
12.0k
        dc->ConstPlaneRow(0, y - 1),
152
12.0k
        dc->ConstPlaneRow(1, y - 1),
153
12.0k
        dc->ConstPlaneRow(2, y - 1),
154
12.0k
    };
155
12.0k
    const float* JXL_RESTRICT rows[3] = {
156
12.0k
        dc->ConstPlaneRow(0, y),
157
12.0k
        dc->ConstPlaneRow(1, y),
158
12.0k
        dc->ConstPlaneRow(2, y),
159
12.0k
    };
160
12.0k
    const float* JXL_RESTRICT rows_bottom[3] = {
161
12.0k
        dc->ConstPlaneRow(0, y + 1),
162
12.0k
        dc->ConstPlaneRow(1, y + 1),
163
12.0k
        dc->ConstPlaneRow(2, y + 1),
164
12.0k
    };
165
12.0k
    float* JXL_RESTRICT rows_out[3] = {
166
12.0k
        smoothed.PlaneRow(0, y),
167
12.0k
        smoothed.PlaneRow(1, y),
168
12.0k
        smoothed.PlaneRow(2, y),
169
12.0k
    };
170
12.0k
    for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
171
12.0k
      for (size_t c = 0; c < 3; c++) {
172
12.0k
        rows_out[c][x] = rows[c][x];
173
12.0k
      }
174
12.0k
    }
175
176
12.0k
    size_t x = 1;
177
    // First pixels
178
12.0k
    const size_t N = Lanes(D());
179
12.0k
    for (; x < std::min(N, xsize - 1); x++) {
180
12.0k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
181
12.0k
                            x);
182
12.0k
    }
183
    // Full vectors.
184
12.0k
    for (; x + N <= xsize - 1; x += N) {
185
12.0k
      ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
186
12.0k
    }
187
    // Last pixels.
188
12.0k
    for (; x < xsize - 1; x++) {
189
12.0k
      ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
190
12.0k
                            x);
191
12.0k
    }
192
12.0k
    return true;
193
12.0k
  };
194
12.0k
  JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize - 1, ThreadPool::NoInit,
195
12.0k
                                process_row, "DCSmoothingRow"));
196
6.03k
  dc->Swap(smoothed);
197
6.03k
  return true;
198
12.0k
}
Unexecuted instantiation: jxl::N_AVX3::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
Unexecuted instantiation: jxl::N_AVX3_ZEN4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
Unexecuted instantiation: jxl::N_AVX3_SPR::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
Unexecuted instantiation: jxl::N_SSE2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::ThreadPool*)
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
53.9k
               const BlockCtxMap& bctx) {
205
53.9k
  const HWY_FULL(float) df;
206
53.9k
  const Rebind<pixel_type, HWY_FULL(float)> di;  // assumes pixel_type <= float
207
53.9k
  if (chroma_subsampling.Is444()) {
208
52.1k
    const auto fac_x = Set(df, dc_factors[0] * mul);
209
52.1k
    const auto fac_y = Set(df, dc_factors[1] * mul);
210
52.1k
    const auto fac_b = Set(df, dc_factors[2] * mul);
211
52.1k
    const auto cfl_fac_x = Set(df, cfl_factors[0]);
212
52.1k
    const auto cfl_fac_b = Set(df, cfl_factors[2]);
213
504k
    for (size_t y = 0; y < r.ysize(); y++) {
214
452k
      float* dec_row_x = r.PlaneRow(dc, 0, y);
215
452k
      float* dec_row_y = r.PlaneRow(dc, 1, y);
216
452k
      float* dec_row_b = r.PlaneRow(dc, 2, y);
217
452k
      const int32_t* quant_row_x = in.channel[1].plane.Row(y);
218
452k
      const int32_t* quant_row_y = in.channel[0].plane.Row(y);
219
452k
      const int32_t* quant_row_b = in.channel[2].plane.Row(y);
220
1.80M
      for (size_t x = 0; x < r.xsize(); x += Lanes(di)) {
221
1.34M
        const auto in_q_x = Load(di, quant_row_x + x);
222
1.34M
        const auto in_q_y = Load(di, quant_row_y + x);
223
1.34M
        const auto in_q_b = Load(di, quant_row_b + x);
224
1.34M
        const auto in_x = Mul(ConvertTo(df, in_q_x), fac_x);
225
1.34M
        const auto in_y = Mul(ConvertTo(df, in_q_y), fac_y);
226
1.34M
        const auto in_b = Mul(ConvertTo(df, in_q_b), fac_b);
227
1.34M
        Store(in_y, df, dec_row_y + x);
228
1.34M
        Store(MulAdd(in_y, cfl_fac_x, in_x), df, dec_row_x + x);
229
1.34M
        Store(MulAdd(in_y, cfl_fac_b, in_b), df, dec_row_b + x);
230
1.34M
      }
231
452k
    }
232
52.1k
  } else {
233
5.51k
    for (size_t c : {1, 0, 2}) {
234
5.51k
      Rect rect(r.x0() >> chroma_subsampling.HShift(c),
235
5.51k
                r.y0() >> chroma_subsampling.VShift(c),
236
5.51k
                r.xsize() >> chroma_subsampling.HShift(c),
237
5.51k
                r.ysize() >> chroma_subsampling.VShift(c));
238
5.51k
      const auto fac = Set(df, dc_factors[c] * mul);
239
5.51k
      const Channel& ch = in.channel[c < 2 ? c ^ 1 : c];
240
213k
      for (size_t y = 0; y < rect.ysize(); y++) {
241
208k
        const int32_t* quant_row = ch.plane.Row(y);
242
208k
        float* row = rect.PlaneRow(dc, c, y);
243
662k
        for (size_t x = 0; x < rect.xsize(); x += Lanes(di)) {
244
454k
          const auto in_q = Load(di, quant_row + x);
245
454k
          const auto out = Mul(ConvertTo(df, in_q), fac);
246
454k
          Store(out, df, row + x);
247
454k
        }
248
208k
      }
249
5.51k
    }
250
1.83k
  }
251
53.9k
  if (bctx.num_dc_ctxs <= 1) {
252
507k
    for (size_t y = 0; y < r.ysize(); y++) {
253
456k
      uint8_t* qdc_row = r.Row(quant_dc, y);
254
456k
      memset(qdc_row, 0, sizeof(*qdc_row) * r.xsize());
255
456k
    }
256
51.1k
  } else {
257
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
258
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(0) <
259
2.81k
                    in.channel[1].plane.ysize());
260
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
261
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(1) <
262
2.81k
                    in.channel[0].plane.ysize());
263
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
264
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(2) <
265
2.81k
                    in.channel[2].plane.ysize());
266
68.7k
    for (size_t y = 0; y < r.ysize(); y++) {
267
65.9k
      uint8_t* qdc_row_val = r.Row(quant_dc, y);
268
65.9k
      const int32_t* quant_row_x =
269
65.9k
          in.channel[1].plane.Row(y >> chroma_subsampling.VShift(0));
270
65.9k
      const int32_t* quant_row_y =
271
65.9k
          in.channel[0].plane.Row(y >> chroma_subsampling.VShift(1));
272
65.9k
      const int32_t* quant_row_b =
273
65.9k
          in.channel[2].plane.Row(y >> chroma_subsampling.VShift(2));
274
1.33M
      for (size_t x = 0; x < r.xsize(); x++) {
275
1.26M
        int bucket_x = 0;
276
1.26M
        int bucket_y = 0;
277
1.26M
        int bucket_b = 0;
278
8.89M
        for (int t : bctx.dc_thresholds[0]) {
279
8.89M
          if (quant_row_x[x >> chroma_subsampling.HShift(0)] > t) bucket_x++;
280
8.89M
        }
281
1.26M
        for (int t : bctx.dc_thresholds[1]) {
282
273k
          if (quant_row_y[x >> chroma_subsampling.HShift(1)] > t) bucket_y++;
283
273k
        }
284
1.26M
        for (int t : bctx.dc_thresholds[2]) {
285
166k
          if (quant_row_b[x >> chroma_subsampling.HShift(2)] > t) bucket_b++;
286
166k
        }
287
1.26M
        int bucket = bucket_x;
288
1.26M
        bucket *= bctx.dc_thresholds[2].size() + 1;
289
1.26M
        bucket += bucket_b;
290
1.26M
        bucket *= bctx.dc_thresholds[1].size() + 1;
291
1.26M
        bucket += bucket_y;
292
1.26M
        qdc_row_val[x] = bucket;
293
1.26M
      }
294
65.9k
    }
295
2.81k
  }
296
53.9k
}
Unexecuted instantiation: jxl::N_SSE4::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
jxl::N_AVX2::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
Line
Count
Source
204
53.9k
               const BlockCtxMap& bctx) {
205
53.9k
  const HWY_FULL(float) df;
206
53.9k
  const Rebind<pixel_type, HWY_FULL(float)> di;  // assumes pixel_type <= float
207
53.9k
  if (chroma_subsampling.Is444()) {
208
52.1k
    const auto fac_x = Set(df, dc_factors[0] * mul);
209
52.1k
    const auto fac_y = Set(df, dc_factors[1] * mul);
210
52.1k
    const auto fac_b = Set(df, dc_factors[2] * mul);
211
52.1k
    const auto cfl_fac_x = Set(df, cfl_factors[0]);
212
52.1k
    const auto cfl_fac_b = Set(df, cfl_factors[2]);
213
504k
    for (size_t y = 0; y < r.ysize(); y++) {
214
452k
      float* dec_row_x = r.PlaneRow(dc, 0, y);
215
452k
      float* dec_row_y = r.PlaneRow(dc, 1, y);
216
452k
      float* dec_row_b = r.PlaneRow(dc, 2, y);
217
452k
      const int32_t* quant_row_x = in.channel[1].plane.Row(y);
218
452k
      const int32_t* quant_row_y = in.channel[0].plane.Row(y);
219
452k
      const int32_t* quant_row_b = in.channel[2].plane.Row(y);
220
1.80M
      for (size_t x = 0; x < r.xsize(); x += Lanes(di)) {
221
1.34M
        const auto in_q_x = Load(di, quant_row_x + x);
222
1.34M
        const auto in_q_y = Load(di, quant_row_y + x);
223
1.34M
        const auto in_q_b = Load(di, quant_row_b + x);
224
1.34M
        const auto in_x = Mul(ConvertTo(df, in_q_x), fac_x);
225
1.34M
        const auto in_y = Mul(ConvertTo(df, in_q_y), fac_y);
226
1.34M
        const auto in_b = Mul(ConvertTo(df, in_q_b), fac_b);
227
1.34M
        Store(in_y, df, dec_row_y + x);
228
1.34M
        Store(MulAdd(in_y, cfl_fac_x, in_x), df, dec_row_x + x);
229
1.34M
        Store(MulAdd(in_y, cfl_fac_b, in_b), df, dec_row_b + x);
230
1.34M
      }
231
452k
    }
232
52.1k
  } else {
233
5.51k
    for (size_t c : {1, 0, 2}) {
234
5.51k
      Rect rect(r.x0() >> chroma_subsampling.HShift(c),
235
5.51k
                r.y0() >> chroma_subsampling.VShift(c),
236
5.51k
                r.xsize() >> chroma_subsampling.HShift(c),
237
5.51k
                r.ysize() >> chroma_subsampling.VShift(c));
238
5.51k
      const auto fac = Set(df, dc_factors[c] * mul);
239
5.51k
      const Channel& ch = in.channel[c < 2 ? c ^ 1 : c];
240
213k
      for (size_t y = 0; y < rect.ysize(); y++) {
241
208k
        const int32_t* quant_row = ch.plane.Row(y);
242
208k
        float* row = rect.PlaneRow(dc, c, y);
243
662k
        for (size_t x = 0; x < rect.xsize(); x += Lanes(di)) {
244
454k
          const auto in_q = Load(di, quant_row + x);
245
454k
          const auto out = Mul(ConvertTo(df, in_q), fac);
246
454k
          Store(out, df, row + x);
247
454k
        }
248
208k
      }
249
5.51k
    }
250
1.83k
  }
251
53.9k
  if (bctx.num_dc_ctxs <= 1) {
252
507k
    for (size_t y = 0; y < r.ysize(); y++) {
253
456k
      uint8_t* qdc_row = r.Row(quant_dc, y);
254
456k
      memset(qdc_row, 0, sizeof(*qdc_row) * r.xsize());
255
456k
    }
256
51.1k
  } else {
257
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
258
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(0) <
259
2.81k
                    in.channel[1].plane.ysize());
260
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
261
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(1) <
262
2.81k
                    in.channel[0].plane.ysize());
263
2.81k
    JXL_DASSERT(r.ysize() == 0 ||
264
2.81k
                (r.ysize() - 1) >> chroma_subsampling.VShift(2) <
265
2.81k
                    in.channel[2].plane.ysize());
266
68.7k
    for (size_t y = 0; y < r.ysize(); y++) {
267
65.9k
      uint8_t* qdc_row_val = r.Row(quant_dc, y);
268
65.9k
      const int32_t* quant_row_x =
269
65.9k
          in.channel[1].plane.Row(y >> chroma_subsampling.VShift(0));
270
65.9k
      const int32_t* quant_row_y =
271
65.9k
          in.channel[0].plane.Row(y >> chroma_subsampling.VShift(1));
272
65.9k
      const int32_t* quant_row_b =
273
65.9k
          in.channel[2].plane.Row(y >> chroma_subsampling.VShift(2));
274
1.33M
      for (size_t x = 0; x < r.xsize(); x++) {
275
1.26M
        int bucket_x = 0;
276
1.26M
        int bucket_y = 0;
277
1.26M
        int bucket_b = 0;
278
8.89M
        for (int t : bctx.dc_thresholds[0]) {
279
8.89M
          if (quant_row_x[x >> chroma_subsampling.HShift(0)] > t) bucket_x++;
280
8.89M
        }
281
1.26M
        for (int t : bctx.dc_thresholds[1]) {
282
273k
          if (quant_row_y[x >> chroma_subsampling.HShift(1)] > t) bucket_y++;
283
273k
        }
284
1.26M
        for (int t : bctx.dc_thresholds[2]) {
285
166k
          if (quant_row_b[x >> chroma_subsampling.HShift(2)] > t) bucket_b++;
286
166k
        }
287
1.26M
        int bucket = bucket_x;
288
1.26M
        bucket *= bctx.dc_thresholds[2].size() + 1;
289
1.26M
        bucket += bucket_b;
290
1.26M
        bucket *= bctx.dc_thresholds[1].size() + 1;
291
1.26M
        bucket += bucket_y;
292
1.26M
        qdc_row_val[x] = bucket;
293
1.26M
      }
294
65.9k
    }
295
2.81k
  }
296
53.9k
}
Unexecuted instantiation: jxl::N_AVX3::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
Unexecuted instantiation: jxl::N_AVX3_ZEN4::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
Unexecuted instantiation: jxl::N_AVX3_SPR::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
Unexecuted instantiation: jxl::N_SSE2::DequantDC(jxl::RectT<unsigned long> const&, jxl::Image3<float>*, jxl::Plane<unsigned char>*, jxl::Image const&, float const*, float, float const*, jxl::YCbCrChromaSubsampling const&, jxl::BlockCtxMap const&)
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
40.3k
                           ThreadPool* pool) {
311
40.3k
  return HWY_DYNAMIC_DISPATCH(AdaptiveDCSmoothing)(memory_manager, dc_factors,
312
40.3k
                                                   dc, pool);
313
40.3k
}
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
53.9k
               const BlockCtxMap& bctx) {
319
53.9k
  HWY_DYNAMIC_DISPATCH(DequantDC)
320
53.9k
  (r, dc, quant_dc, in, dc_factors, mul, cfl_factors, chroma_subsampling, bctx);
321
53.9k
}
322
323
}  // namespace jxl
324
#endif  // HWY_ONCE