Coverage Report

Created: 2026-11-12 07:35

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
4.69M
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
4.69M
  return Max(a, b);
61
4.69M
#endif
62
4.69M
}
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
3.10M
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
3.10M
  return Max(a, b);
61
3.10M
#endif
62
3.10M
}
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.58M
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.58M
  return Max(a, b);
61
1.58M
#endif
62
1.58M
}
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
4.69M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
4.69M
  const auto tl = LoadU(d, row_top + x - 1);
73
4.69M
  const auto tc = Load(d, row_top + x);
74
4.69M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
4.69M
  const auto ml = LoadU(d, row + x - 1);
77
4.69M
  *mc = Load(d, row + x);
78
4.69M
  const auto mr = LoadU(d, row + x + 1);
79
80
4.69M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
4.69M
  const auto bc = Load(d, row_bottom + x);
82
4.69M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
4.69M
  const auto w_center = Set(d, w0);
85
4.69M
  const auto w_side = Set(d, w1);
86
4.69M
  const auto w_corner = Set(d, w2);
87
88
4.69M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
4.69M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
4.69M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
4.69M
  const auto dc_quant = Set(d, dc_factor);
93
4.69M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
4.69M
}
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
3.10M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
3.10M
  const auto tl = LoadU(d, row_top + x - 1);
73
3.10M
  const auto tc = Load(d, row_top + x);
74
3.10M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
3.10M
  const auto ml = LoadU(d, row + x - 1);
77
3.10M
  *mc = Load(d, row + x);
78
3.10M
  const auto mr = LoadU(d, row + x + 1);
79
80
3.10M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
3.10M
  const auto bc = Load(d, row_bottom + x);
82
3.10M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
3.10M
  const auto w_center = Set(d, w0);
85
3.10M
  const auto w_side = Set(d, w1);
86
3.10M
  const auto w_corner = Set(d, w2);
87
88
3.10M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
3.10M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
3.10M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
3.10M
  const auto dc_quant = Set(d, dc_factor);
93
3.10M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
3.10M
}
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.58M
                                    Vec<D>* JXL_RESTRICT gap, size_t x) {
72
1.58M
  const auto tl = LoadU(d, row_top + x - 1);
73
1.58M
  const auto tc = Load(d, row_top + x);
74
1.58M
  const auto tr = LoadU(d, row_top + x + 1);
75
76
1.58M
  const auto ml = LoadU(d, row + x - 1);
77
1.58M
  *mc = Load(d, row + x);
78
1.58M
  const auto mr = LoadU(d, row + x + 1);
79
80
1.58M
  const auto bl = LoadU(d, row_bottom + x - 1);
81
1.58M
  const auto bc = Load(d, row_bottom + x);
82
1.58M
  const auto br = LoadU(d, row_bottom + x + 1);
83
84
1.58M
  const auto w_center = Set(d, w0);
85
1.58M
  const auto w_side = Set(d, w1);
86
1.58M
  const auto w_corner = Set(d, w2);
87
88
1.58M
  const auto corner = Add(Add(tl, tr), Add(bl, br));
89
1.58M
  const auto side = Add(Add(ml, mr), Add(tc, bc));
90
1.58M
  *sm = MulAdd(corner, w_corner, MulAdd(side, w_side, Mul(*mc, w_center)));
91
92
1.58M
  const auto dc_quant = Set(d, dc_factor);
93
1.58M
  *gap = MaxWorkaround(*gap, Abs(Div(Sub(*mc, *sm), dc_quant)));
94
1.58M
}
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
1.56M
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
1.56M
  const D d;
104
1.56M
  auto mc_x = Undefined(d);
105
1.56M
  auto mc_y = Undefined(d);
106
1.56M
  auto mc_b = Undefined(d);
107
1.56M
  auto sm_x = Undefined(d);
108
1.56M
  auto sm_y = Undefined(d);
109
1.56M
  auto sm_b = Undefined(d);
110
1.56M
  auto gap = Set(d, 0.5f);
111
1.56M
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
1.56M
                      &mc_x, &sm_x, &gap, x);
113
1.56M
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
1.56M
                      &mc_y, &sm_y, &gap, x);
115
1.56M
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
1.56M
                      &mc_b, &sm_b, &gap, x);
117
1.56M
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
1.56M
  factor = ZeroIfNegative(factor);
119
120
1.56M
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
1.56M
  Store(out, d, out_rows[0] + x);
122
1.56M
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
1.56M
  Store(out, d, out_rows[1] + x);
124
1.56M
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
1.56M
  Store(out, d, out_rows[2] + x);
126
1.56M
}
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
1.03M
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
1.03M
  const D d;
104
1.03M
  auto mc_x = Undefined(d);
105
1.03M
  auto mc_y = Undefined(d);
106
1.03M
  auto mc_b = Undefined(d);
107
1.03M
  auto sm_x = Undefined(d);
108
1.03M
  auto sm_y = Undefined(d);
109
1.03M
  auto sm_b = Undefined(d);
110
1.03M
  auto gap = Set(d, 0.5f);
111
1.03M
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
1.03M
                      &mc_x, &sm_x, &gap, x);
113
1.03M
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
1.03M
                      &mc_y, &sm_y, &gap, x);
115
1.03M
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
1.03M
                      &mc_b, &sm_b, &gap, x);
117
1.03M
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
1.03M
  factor = ZeroIfNegative(factor);
119
120
1.03M
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
1.03M
  Store(out, d, out_rows[0] + x);
122
1.03M
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
1.03M
  Store(out, d, out_rows[1] + x);
124
1.03M
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
1.03M
  Store(out, d, out_rows[2] + x);
126
1.03M
}
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
528k
    float* JXL_RESTRICT* JXL_RESTRICT out_rows, size_t x) {
103
528k
  const D d;
104
528k
  auto mc_x = Undefined(d);
105
528k
  auto mc_y = Undefined(d);
106
528k
  auto mc_b = Undefined(d);
107
528k
  auto sm_x = Undefined(d);
108
528k
  auto sm_y = Undefined(d);
109
528k
  auto sm_b = Undefined(d);
110
528k
  auto gap = Set(d, 0.5f);
111
528k
  ComputePixelChannel(d, dc_factors[0], rows_top[0], rows[0], rows_bottom[0],
112
528k
                      &mc_x, &sm_x, &gap, x);
113
528k
  ComputePixelChannel(d, dc_factors[1], rows_top[1], rows[1], rows_bottom[1],
114
528k
                      &mc_y, &sm_y, &gap, x);
115
528k
  ComputePixelChannel(d, dc_factors[2], rows_top[2], rows[2], rows_bottom[2],
116
528k
                      &mc_b, &sm_b, &gap, x);
117
528k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
118
528k
  factor = ZeroIfNegative(factor);
119
120
528k
  auto out = MulAdd(Sub(sm_x, mc_x), factor, mc_x);
121
528k
  Store(out, d, out_rows[0] + x);
122
528k
  out = MulAdd(Sub(sm_y, mc_y), factor, mc_y);
123
528k
  Store(out, d, out_rows[1] + x);
124
528k
  out = MulAdd(Sub(sm_b, mc_b), factor, mc_b);
125
528k
  Store(out, d, out_rows[2] + x);
126
528k
}
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
template <typename D>
129
JXL_INLINE void ComputePixelSingleChannel(const float dc_factor,
130
                                          const float* JXL_RESTRICT row_top,
131
                                          const float* JXL_RESTRICT row,
132
                                          const float* JXL_RESTRICT row_bottom,
133
                                          float* JXL_RESTRICT out_row,
134
2.14k
                                          size_t x) {
135
2.14k
  const D d;
136
2.14k
  auto mc = Undefined(d);
137
2.14k
  auto sm = Undefined(d);
138
2.14k
  auto gap = Set(d, 0.5f);
139
2.14k
  ComputePixelChannel(d, dc_factor, row_top, row, row_bottom, &mc, &sm, &gap,
140
2.14k
                      x);
141
2.14k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
142
2.14k
  factor = ZeroIfNegative(factor);
143
144
2.14k
  auto out = MulAdd(Sub(sm, mc), factor, mc);
145
2.14k
  Store(out, d, out_row + x);
146
2.14k
}
Unexecuted instantiation: void jxl::N_SSE4::ComputePixelSingleChannel<hwy::N_SSE4::Simd<float, 1ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::ComputePixelSingleChannel<hwy::N_SSE4::Simd<float, 4ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
void jxl::N_AVX2::ComputePixelSingleChannel<hwy::N_AVX2::Simd<float, 1ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
Line
Count
Source
134
1.61k
                                          size_t x) {
135
1.61k
  const D d;
136
1.61k
  auto mc = Undefined(d);
137
1.61k
  auto sm = Undefined(d);
138
1.61k
  auto gap = Set(d, 0.5f);
139
1.61k
  ComputePixelChannel(d, dc_factor, row_top, row, row_bottom, &mc, &sm, &gap,
140
1.61k
                      x);
141
1.61k
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
142
1.61k
  factor = ZeroIfNegative(factor);
143
144
1.61k
  auto out = MulAdd(Sub(sm, mc), factor, mc);
145
1.61k
  Store(out, d, out_row + x);
146
1.61k
}
void jxl::N_AVX2::ComputePixelSingleChannel<hwy::N_AVX2::Simd<float, 8ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
Line
Count
Source
134
530
                                          size_t x) {
135
530
  const D d;
136
530
  auto mc = Undefined(d);
137
530
  auto sm = Undefined(d);
138
530
  auto gap = Set(d, 0.5f);
139
530
  ComputePixelChannel(d, dc_factor, row_top, row, row_bottom, &mc, &sm, &gap,
140
530
                      x);
141
530
  auto factor = MulAdd(Set(d, -4.0f), gap, Set(d, 3.0f));
142
530
  factor = ZeroIfNegative(factor);
143
144
530
  auto out = MulAdd(Sub(sm, mc), factor, mc);
145
530
  Store(out, d, out_row + x);
146
530
}
Unexecuted instantiation: void jxl::N_SSE2::ComputePixelSingleChannel<hwy::N_SSE2::Simd<float, 1ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::ComputePixelSingleChannel<hwy::N_SSE2::Simd<float, 4ul, 0> >(float, float const*, float const*, float const*, float*, unsigned long)
147
148
Status AdaptiveDCSmoothing(JxlMemoryManager* memory_manager,
149
                           const float* dc_factors, Image3F* dc,
150
                           const YCbCrChromaSubsampling& chroma_subsampling,
151
7.96k
                           ThreadPool* pool) {
152
7.96k
  const size_t xsize = dc->xsize();
153
7.96k
  const size_t ysize = dc->ysize();
154
7.96k
  if (ysize <= 2 || xsize <= 2) return true;
155
156
  // TODO(veluca): use tile-based processing?
157
  // TODO(veluca): decide if changes to the y channel should be propagated to
158
  // the x and b channels through color correlation.
159
3.40k
  JXL_ENSURE(w1 + w2 < 0.25f);
160
161
3.40k
  if (chroma_subsampling.Is444()) {
162
3.40k
    JXL_ASSIGN_OR_RETURN(Image3F smoothed,
163
3.40k
                         Image3F::Create(memory_manager, xsize, ysize));
164
    // Fill in borders that the loop below will not. First and last are unused.
165
13.6k
    for (size_t c = 0; c < 3; c++) {
166
20.4k
      for (size_t y : {static_cast<size_t>(0), ysize - 1}) {
167
20.4k
        memcpy(smoothed.PlaneRow(c, y), dc->PlaneRow(c, y),
168
20.4k
               xsize * sizeof(float));
169
20.4k
      }
170
10.2k
    }
171
102k
    auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
172
102k
      const float* JXL_RESTRICT rows_top[3]{
173
102k
          dc->ConstPlaneRow(0, y - 1),
174
102k
          dc->ConstPlaneRow(1, y - 1),
175
102k
          dc->ConstPlaneRow(2, y - 1),
176
102k
      };
177
102k
      const float* JXL_RESTRICT rows[3] = {
178
102k
          dc->ConstPlaneRow(0, y),
179
102k
          dc->ConstPlaneRow(1, y),
180
102k
          dc->ConstPlaneRow(2, y),
181
102k
      };
182
102k
      const float* JXL_RESTRICT rows_bottom[3] = {
183
102k
          dc->ConstPlaneRow(0, y + 1),
184
102k
          dc->ConstPlaneRow(1, y + 1),
185
102k
          dc->ConstPlaneRow(2, y + 1),
186
102k
      };
187
102k
      float* JXL_RESTRICT rows_out[3] = {
188
102k
          smoothed.PlaneRow(0, y),
189
102k
          smoothed.PlaneRow(1, y),
190
102k
          smoothed.PlaneRow(2, y),
191
102k
      };
192
205k
      for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
193
820k
        for (size_t c = 0; c < 3; c++) {
194
615k
          rows_out[c][x] = rows[c][x];
195
615k
        }
196
205k
      }
197
198
102k
      size_t x = 1;
199
      // First pixels
200
102k
      const size_t N = Lanes(D());
201
802k
      for (; x < std::min(N, xsize - 1); x++) {
202
700k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
203
700k
                              x);
204
700k
      }
205
      // Full vectors.
206
631k
      for (; x + N <= xsize - 1; x += N) {
207
528k
        ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
208
528k
      }
209
      // Last pixels.
210
437k
      for (; x < xsize - 1; x++) {
211
334k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
212
334k
                              x);
213
334k
      }
214
102k
      return true;
215
102k
    };
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
compressed_dc.cc:jxl::N_AVX2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Line
Count
Source
171
102k
    auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
172
102k
      const float* JXL_RESTRICT rows_top[3]{
173
102k
          dc->ConstPlaneRow(0, y - 1),
174
102k
          dc->ConstPlaneRow(1, y - 1),
175
102k
          dc->ConstPlaneRow(2, y - 1),
176
102k
      };
177
102k
      const float* JXL_RESTRICT rows[3] = {
178
102k
          dc->ConstPlaneRow(0, y),
179
102k
          dc->ConstPlaneRow(1, y),
180
102k
          dc->ConstPlaneRow(2, y),
181
102k
      };
182
102k
      const float* JXL_RESTRICT rows_bottom[3] = {
183
102k
          dc->ConstPlaneRow(0, y + 1),
184
102k
          dc->ConstPlaneRow(1, y + 1),
185
102k
          dc->ConstPlaneRow(2, y + 1),
186
102k
      };
187
102k
      float* JXL_RESTRICT rows_out[3] = {
188
102k
          smoothed.PlaneRow(0, y),
189
102k
          smoothed.PlaneRow(1, y),
190
102k
          smoothed.PlaneRow(2, y),
191
102k
      };
192
205k
      for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
193
820k
        for (size_t c = 0; c < 3; c++) {
194
615k
          rows_out[c][x] = rows[c][x];
195
615k
        }
196
205k
      }
197
198
102k
      size_t x = 1;
199
      // First pixels
200
102k
      const size_t N = Lanes(D());
201
802k
      for (; x < std::min(N, xsize - 1); x++) {
202
700k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
203
700k
                              x);
204
700k
      }
205
      // Full vectors.
206
631k
      for (; x + N <= xsize - 1; x += N) {
207
528k
        ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
208
528k
      }
209
      // Last pixels.
210
437k
      for (; x < xsize - 1; x++) {
211
334k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
212
334k
                              x);
213
334k
      }
214
102k
      return true;
215
102k
    };
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
216
3.40k
    JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize - 1, ThreadPool::NoInit,
217
3.40k
                                  process_row, "DCSmoothingRow"));
218
3.40k
    dc->Swap(smoothed);
219
3.40k
  } else {
220
4
    JXL_ASSIGN_OR_RETURN(ImageF smoothed,
221
4
                         ImageF::Create(memory_manager, xsize, ysize));
222
16
    for (size_t c = 0; c < 3; c++) {
223
12
      const size_t xsize_c = xsize >> chroma_subsampling.HShift(c);
224
12
      const size_t ysize_c = ysize >> chroma_subsampling.VShift(c);
225
12
      if (ysize_c <= 2 || xsize_c <= 2) continue;
226
18
      for (size_t y : {static_cast<size_t>(0), ysize_c - 1}) {
227
18
        memcpy(smoothed.Row(y), dc->PlaneRow(c, y), xsize_c * sizeof(float));
228
18
      }
229
131
      auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
230
131
        const float* JXL_RESTRICT row_top = dc->ConstPlaneRow(c, y - 1);
231
131
        const float* JXL_RESTRICT row = dc->ConstPlaneRow(c, y);
232
131
        const float* JXL_RESTRICT row_bottom = dc->ConstPlaneRow(c, y + 1);
233
131
        float* JXL_RESTRICT row_out = smoothed.Row(y);
234
262
        for (size_t x : {static_cast<size_t>(0), xsize_c - 1}) {
235
262
          row_out[x] = row[x];
236
262
        }
237
238
131
        size_t x = 1;
239
        // First pixels
240
131
        const size_t N = Lanes(D());
241
986
        for (; x < std::min(N, xsize_c - 1); x++) {
242
855
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
243
855
                                             row_bottom, row_out, x);
244
855
        }
245
        // Full vectors.
246
661
        for (; x + N <= xsize_c - 1; x += N) {
247
530
          ComputePixelSingleChannel<D>(dc_factors[c], row_top, row, row_bottom,
248
530
                                       row_out, x);
249
530
        }
250
        // Last pixels.
251
888
        for (; x < xsize_c - 1; x++) {
252
757
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
253
757
                                             row_bottom, row_out, x);
254
757
        }
255
131
        return true;
256
131
      };
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_1::operator()(unsigned int, unsigned long) const
compressed_dc.cc:jxl::N_AVX2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_1::operator()(unsigned int, unsigned long) const
Line
Count
Source
229
131
      auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
230
131
        const float* JXL_RESTRICT row_top = dc->ConstPlaneRow(c, y - 1);
231
131
        const float* JXL_RESTRICT row = dc->ConstPlaneRow(c, y);
232
131
        const float* JXL_RESTRICT row_bottom = dc->ConstPlaneRow(c, y + 1);
233
131
        float* JXL_RESTRICT row_out = smoothed.Row(y);
234
262
        for (size_t x : {static_cast<size_t>(0), xsize_c - 1}) {
235
262
          row_out[x] = row[x];
236
262
        }
237
238
131
        size_t x = 1;
239
        // First pixels
240
131
        const size_t N = Lanes(D());
241
986
        for (; x < std::min(N, xsize_c - 1); x++) {
242
855
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
243
855
                                             row_bottom, row_out, x);
244
855
        }
245
        // Full vectors.
246
661
        for (; x + N <= xsize_c - 1; x += N) {
247
530
          ComputePixelSingleChannel<D>(dc_factors[c], row_top, row, row_bottom,
248
530
                                       row_out, x);
249
530
        }
250
        // Last pixels.
251
888
        for (; x < xsize_c - 1; x++) {
252
757
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
253
757
                                             row_bottom, row_out, x);
254
757
        }
255
131
        return true;
256
131
      };
Unexecuted instantiation: compressed_dc.cc:jxl::N_SSE2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)::$_1::operator()(unsigned int, unsigned long) const
257
9
      JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize_c - 1, ThreadPool::NoInit,
258
9
                                    process_row, "DCSmoothingRow"));
259
9
      dc->Plane(c).Swap(smoothed);
260
9
    }
261
4
  }
262
3.40k
  return true;
263
3.40k
}
Unexecuted instantiation: jxl::N_SSE4::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)
jxl::N_AVX2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)
Line
Count
Source
151
7.96k
                           ThreadPool* pool) {
152
7.96k
  const size_t xsize = dc->xsize();
153
7.96k
  const size_t ysize = dc->ysize();
154
7.96k
  if (ysize <= 2 || xsize <= 2) return true;
155
156
  // TODO(veluca): use tile-based processing?
157
  // TODO(veluca): decide if changes to the y channel should be propagated to
158
  // the x and b channels through color correlation.
159
3.40k
  JXL_ENSURE(w1 + w2 < 0.25f);
160
161
3.40k
  if (chroma_subsampling.Is444()) {
162
3.40k
    JXL_ASSIGN_OR_RETURN(Image3F smoothed,
163
3.40k
                         Image3F::Create(memory_manager, xsize, ysize));
164
    // Fill in borders that the loop below will not. First and last are unused.
165
13.6k
    for (size_t c = 0; c < 3; c++) {
166
20.4k
      for (size_t y : {static_cast<size_t>(0), ysize - 1}) {
167
20.4k
        memcpy(smoothed.PlaneRow(c, y), dc->PlaneRow(c, y),
168
20.4k
               xsize * sizeof(float));
169
20.4k
      }
170
10.2k
    }
171
3.40k
    auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
172
3.40k
      const float* JXL_RESTRICT rows_top[3]{
173
3.40k
          dc->ConstPlaneRow(0, y - 1),
174
3.40k
          dc->ConstPlaneRow(1, y - 1),
175
3.40k
          dc->ConstPlaneRow(2, y - 1),
176
3.40k
      };
177
3.40k
      const float* JXL_RESTRICT rows[3] = {
178
3.40k
          dc->ConstPlaneRow(0, y),
179
3.40k
          dc->ConstPlaneRow(1, y),
180
3.40k
          dc->ConstPlaneRow(2, y),
181
3.40k
      };
182
3.40k
      const float* JXL_RESTRICT rows_bottom[3] = {
183
3.40k
          dc->ConstPlaneRow(0, y + 1),
184
3.40k
          dc->ConstPlaneRow(1, y + 1),
185
3.40k
          dc->ConstPlaneRow(2, y + 1),
186
3.40k
      };
187
3.40k
      float* JXL_RESTRICT rows_out[3] = {
188
3.40k
          smoothed.PlaneRow(0, y),
189
3.40k
          smoothed.PlaneRow(1, y),
190
3.40k
          smoothed.PlaneRow(2, y),
191
3.40k
      };
192
3.40k
      for (size_t x : {static_cast<size_t>(0), xsize - 1}) {
193
3.40k
        for (size_t c = 0; c < 3; c++) {
194
3.40k
          rows_out[c][x] = rows[c][x];
195
3.40k
        }
196
3.40k
      }
197
198
3.40k
      size_t x = 1;
199
      // First pixels
200
3.40k
      const size_t N = Lanes(D());
201
3.40k
      for (; x < std::min(N, xsize - 1); x++) {
202
3.40k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
203
3.40k
                              x);
204
3.40k
      }
205
      // Full vectors.
206
3.40k
      for (; x + N <= xsize - 1; x += N) {
207
3.40k
        ComputePixel<D>(dc_factors, rows_top, rows, rows_bottom, rows_out, x);
208
3.40k
      }
209
      // Last pixels.
210
3.40k
      for (; x < xsize - 1; x++) {
211
3.40k
        ComputePixel<DScalar>(dc_factors, rows_top, rows, rows_bottom, rows_out,
212
3.40k
                              x);
213
3.40k
      }
214
3.40k
      return true;
215
3.40k
    };
216
3.40k
    JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize - 1, ThreadPool::NoInit,
217
3.40k
                                  process_row, "DCSmoothingRow"));
218
3.40k
    dc->Swap(smoothed);
219
3.40k
  } else {
220
4
    JXL_ASSIGN_OR_RETURN(ImageF smoothed,
221
4
                         ImageF::Create(memory_manager, xsize, ysize));
222
16
    for (size_t c = 0; c < 3; c++) {
223
12
      const size_t xsize_c = xsize >> chroma_subsampling.HShift(c);
224
12
      const size_t ysize_c = ysize >> chroma_subsampling.VShift(c);
225
12
      if (ysize_c <= 2 || xsize_c <= 2) continue;
226
18
      for (size_t y : {static_cast<size_t>(0), ysize_c - 1}) {
227
18
        memcpy(smoothed.Row(y), dc->PlaneRow(c, y), xsize_c * sizeof(float));
228
18
      }
229
9
      auto process_row = [&](const uint32_t y, size_t /*thread*/) -> Status {
230
9
        const float* JXL_RESTRICT row_top = dc->ConstPlaneRow(c, y - 1);
231
9
        const float* JXL_RESTRICT row = dc->ConstPlaneRow(c, y);
232
9
        const float* JXL_RESTRICT row_bottom = dc->ConstPlaneRow(c, y + 1);
233
9
        float* JXL_RESTRICT row_out = smoothed.Row(y);
234
9
        for (size_t x : {static_cast<size_t>(0), xsize_c - 1}) {
235
9
          row_out[x] = row[x];
236
9
        }
237
238
9
        size_t x = 1;
239
        // First pixels
240
9
        const size_t N = Lanes(D());
241
9
        for (; x < std::min(N, xsize_c - 1); x++) {
242
9
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
243
9
                                             row_bottom, row_out, x);
244
9
        }
245
        // Full vectors.
246
9
        for (; x + N <= xsize_c - 1; x += N) {
247
9
          ComputePixelSingleChannel<D>(dc_factors[c], row_top, row, row_bottom,
248
9
                                       row_out, x);
249
9
        }
250
        // Last pixels.
251
9
        for (; x < xsize_c - 1; x++) {
252
9
          ComputePixelSingleChannel<DScalar>(dc_factors[c], row_top, row,
253
9
                                             row_bottom, row_out, x);
254
9
        }
255
9
        return true;
256
9
      };
257
9
      JXL_RETURN_IF_ERROR(RunOnPool(pool, 1, ysize_c - 1, ThreadPool::NoInit,
258
9
                                    process_row, "DCSmoothingRow"));
259
9
      dc->Plane(c).Swap(smoothed);
260
9
    }
261
4
  }
262
3.40k
  return true;
263
3.40k
}
Unexecuted instantiation: jxl::N_SSE2::AdaptiveDCSmoothing(JxlMemoryManagerStruct*, float const*, jxl::Image3<float>*, jxl::YCbCrChromaSubsampling const&, jxl::ThreadPool*)
264
265
// DC dequantization.
266
void DequantDC(const Rect& r, Image3F* dc, ImageB* quant_dc, const Image& in,
267
               const float* dc_factors, float mul, const float* cfl_factors,
268
               const YCbCrChromaSubsampling& chroma_subsampling,
269
10.0k
               const BlockCtxMap& bctx) {
270
10.0k
  const HWY_FULL(float) df;
271
10.0k
  const Rebind<pixel_type, HWY_FULL(float)> di;  // assumes pixel_type <= float
272
10.0k
  if (chroma_subsampling.Is444()) {
273
9.75k
    const auto fac_x = Set(df, dc_factors[0] * mul);
274
9.75k
    const auto fac_y = Set(df, dc_factors[1] * mul);
275
9.75k
    const auto fac_b = Set(df, dc_factors[2] * mul);
276
9.75k
    const auto cfl_fac_x = Set(df, cfl_factors[0]);
277
9.75k
    const auto cfl_fac_b = Set(df, cfl_factors[2]);
278
144k
    for (size_t y = 0; y < r.ysize(); y++) {
279
135k
      float* dec_row_x = r.PlaneRow(dc, 0, y);
280
135k
      float* dec_row_y = r.PlaneRow(dc, 1, y);
281
135k
      float* dec_row_b = r.PlaneRow(dc, 2, y);
282
135k
      const int32_t* quant_row_x = in.channel[1].plane.Row(y);
283
135k
      const int32_t* quant_row_y = in.channel[0].plane.Row(y);
284
135k
      const int32_t* quant_row_b = in.channel[2].plane.Row(y);
285
940k
      for (size_t x = 0; x < r.xsize(); x += Lanes(di)) {
286
805k
        const auto in_q_x = Load(di, quant_row_x + x);
287
805k
        const auto in_q_y = Load(di, quant_row_y + x);
288
805k
        const auto in_q_b = Load(di, quant_row_b + x);
289
805k
        const auto in_x = Mul(ConvertTo(df, in_q_x), fac_x);
290
805k
        const auto in_y = Mul(ConvertTo(df, in_q_y), fac_y);
291
805k
        const auto in_b = Mul(ConvertTo(df, in_q_b), fac_b);
292
805k
        Store(in_y, df, dec_row_y + x);
293
805k
        Store(MulAdd(in_y, cfl_fac_x, in_x), df, dec_row_x + x);
294
805k
        Store(MulAdd(in_y, cfl_fac_b, in_b), df, dec_row_b + x);
295
805k
      }
296
135k
    }
297
9.75k
  } else {
298
1.00k
    for (size_t c : {1, 0, 2}) {
299
1.00k
      Rect rect(r.x0() >> chroma_subsampling.HShift(c),
300
1.00k
                r.y0() >> chroma_subsampling.VShift(c),
301
1.00k
                r.xsize() >> chroma_subsampling.HShift(c),
302
1.00k
                r.ysize() >> chroma_subsampling.VShift(c));
303
1.00k
      const auto fac = Set(df, dc_factors[c] * mul);
304
1.00k
      const Channel& ch = in.channel[c < 2 ? c ^ 1 : c];
305
36.3k
      for (size_t y = 0; y < rect.ysize(); y++) {
306
35.3k
        const int32_t* quant_row = ch.plane.Row(y);
307
35.3k
        float* row = rect.PlaneRow(dc, c, y);
308
291k
        for (size_t x = 0; x < rect.xsize(); x += Lanes(di)) {
309
256k
          const auto in_q = Load(di, quant_row + x);
310
256k
          const auto out = Mul(ConvertTo(df, in_q), fac);
311
256k
          Store(out, df, row + x);
312
256k
        }
313
35.3k
      }
314
1.00k
    }
315
334
  }
316
10.0k
  if (bctx.num_dc_ctxs <= 1) {
317
148k
    for (size_t y = 0; y < r.ysize(); y++) {
318
139k
      uint8_t* qdc_row = r.Row(quant_dc, y);
319
139k
      memset(qdc_row, 0, sizeof(*qdc_row) * r.xsize());
320
139k
    }
321
8.57k
  } else {
322
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
323
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(0) <
324
1.51k
                    in.channel[1].plane.ysize());
325
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
326
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(1) <
327
1.51k
                    in.channel[0].plane.ysize());
328
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
329
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(2) <
330
1.51k
                    in.channel[2].plane.ysize());
331
10.9k
    for (size_t y = 0; y < r.ysize(); y++) {
332
9.39k
      uint8_t* qdc_row_val = r.Row(quant_dc, y);
333
9.39k
      const int32_t* quant_row_x =
334
9.39k
          in.channel[1].plane.Row(y >> chroma_subsampling.VShift(0));
335
9.39k
      const int32_t* quant_row_y =
336
9.39k
          in.channel[0].plane.Row(y >> chroma_subsampling.VShift(1));
337
9.39k
      const int32_t* quant_row_b =
338
9.39k
          in.channel[2].plane.Row(y >> chroma_subsampling.VShift(2));
339
347k
      for (size_t x = 0; x < r.xsize(); x++) {
340
337k
        int bucket_x = 0;
341
337k
        int bucket_y = 0;
342
337k
        int bucket_b = 0;
343
1.57M
        for (int t : bctx.dc_thresholds[0]) {
344
1.57M
          if (quant_row_x[x >> chroma_subsampling.HShift(0)] > t) bucket_x++;
345
1.57M
        }
346
337k
        for (int t : bctx.dc_thresholds[1]) {
347
317k
          if (quant_row_y[x >> chroma_subsampling.HShift(1)] > t) bucket_y++;
348
317k
        }
349
351k
        for (int t : bctx.dc_thresholds[2]) {
350
351k
          if (quant_row_b[x >> chroma_subsampling.HShift(2)] > t) bucket_b++;
351
351k
        }
352
337k
        int bucket = bucket_x;
353
337k
        bucket *= bctx.dc_thresholds[2].size() + 1;
354
337k
        bucket += bucket_b;
355
337k
        bucket *= bctx.dc_thresholds[1].size() + 1;
356
337k
        bucket += bucket_y;
357
337k
        qdc_row_val[x] = bucket;
358
337k
      }
359
9.39k
    }
360
1.51k
  }
361
10.0k
}
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
269
10.0k
               const BlockCtxMap& bctx) {
270
10.0k
  const HWY_FULL(float) df;
271
10.0k
  const Rebind<pixel_type, HWY_FULL(float)> di;  // assumes pixel_type <= float
272
10.0k
  if (chroma_subsampling.Is444()) {
273
9.75k
    const auto fac_x = Set(df, dc_factors[0] * mul);
274
9.75k
    const auto fac_y = Set(df, dc_factors[1] * mul);
275
9.75k
    const auto fac_b = Set(df, dc_factors[2] * mul);
276
9.75k
    const auto cfl_fac_x = Set(df, cfl_factors[0]);
277
9.75k
    const auto cfl_fac_b = Set(df, cfl_factors[2]);
278
144k
    for (size_t y = 0; y < r.ysize(); y++) {
279
135k
      float* dec_row_x = r.PlaneRow(dc, 0, y);
280
135k
      float* dec_row_y = r.PlaneRow(dc, 1, y);
281
135k
      float* dec_row_b = r.PlaneRow(dc, 2, y);
282
135k
      const int32_t* quant_row_x = in.channel[1].plane.Row(y);
283
135k
      const int32_t* quant_row_y = in.channel[0].plane.Row(y);
284
135k
      const int32_t* quant_row_b = in.channel[2].plane.Row(y);
285
940k
      for (size_t x = 0; x < r.xsize(); x += Lanes(di)) {
286
805k
        const auto in_q_x = Load(di, quant_row_x + x);
287
805k
        const auto in_q_y = Load(di, quant_row_y + x);
288
805k
        const auto in_q_b = Load(di, quant_row_b + x);
289
805k
        const auto in_x = Mul(ConvertTo(df, in_q_x), fac_x);
290
805k
        const auto in_y = Mul(ConvertTo(df, in_q_y), fac_y);
291
805k
        const auto in_b = Mul(ConvertTo(df, in_q_b), fac_b);
292
805k
        Store(in_y, df, dec_row_y + x);
293
805k
        Store(MulAdd(in_y, cfl_fac_x, in_x), df, dec_row_x + x);
294
805k
        Store(MulAdd(in_y, cfl_fac_b, in_b), df, dec_row_b + x);
295
805k
      }
296
135k
    }
297
9.75k
  } else {
298
1.00k
    for (size_t c : {1, 0, 2}) {
299
1.00k
      Rect rect(r.x0() >> chroma_subsampling.HShift(c),
300
1.00k
                r.y0() >> chroma_subsampling.VShift(c),
301
1.00k
                r.xsize() >> chroma_subsampling.HShift(c),
302
1.00k
                r.ysize() >> chroma_subsampling.VShift(c));
303
1.00k
      const auto fac = Set(df, dc_factors[c] * mul);
304
1.00k
      const Channel& ch = in.channel[c < 2 ? c ^ 1 : c];
305
36.3k
      for (size_t y = 0; y < rect.ysize(); y++) {
306
35.3k
        const int32_t* quant_row = ch.plane.Row(y);
307
35.3k
        float* row = rect.PlaneRow(dc, c, y);
308
291k
        for (size_t x = 0; x < rect.xsize(); x += Lanes(di)) {
309
256k
          const auto in_q = Load(di, quant_row + x);
310
256k
          const auto out = Mul(ConvertTo(df, in_q), fac);
311
256k
          Store(out, df, row + x);
312
256k
        }
313
35.3k
      }
314
1.00k
    }
315
334
  }
316
10.0k
  if (bctx.num_dc_ctxs <= 1) {
317
148k
    for (size_t y = 0; y < r.ysize(); y++) {
318
139k
      uint8_t* qdc_row = r.Row(quant_dc, y);
319
139k
      memset(qdc_row, 0, sizeof(*qdc_row) * r.xsize());
320
139k
    }
321
8.57k
  } else {
322
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
323
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(0) <
324
1.51k
                    in.channel[1].plane.ysize());
325
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
326
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(1) <
327
1.51k
                    in.channel[0].plane.ysize());
328
1.51k
    JXL_DASSERT(r.ysize() == 0 ||
329
1.51k
                (r.ysize() - 1) >> chroma_subsampling.VShift(2) <
330
1.51k
                    in.channel[2].plane.ysize());
331
10.9k
    for (size_t y = 0; y < r.ysize(); y++) {
332
9.39k
      uint8_t* qdc_row_val = r.Row(quant_dc, y);
333
9.39k
      const int32_t* quant_row_x =
334
9.39k
          in.channel[1].plane.Row(y >> chroma_subsampling.VShift(0));
335
9.39k
      const int32_t* quant_row_y =
336
9.39k
          in.channel[0].plane.Row(y >> chroma_subsampling.VShift(1));
337
9.39k
      const int32_t* quant_row_b =
338
9.39k
          in.channel[2].plane.Row(y >> chroma_subsampling.VShift(2));
339
347k
      for (size_t x = 0; x < r.xsize(); x++) {
340
337k
        int bucket_x = 0;
341
337k
        int bucket_y = 0;
342
337k
        int bucket_b = 0;
343
1.57M
        for (int t : bctx.dc_thresholds[0]) {
344
1.57M
          if (quant_row_x[x >> chroma_subsampling.HShift(0)] > t) bucket_x++;
345
1.57M
        }
346
337k
        for (int t : bctx.dc_thresholds[1]) {
347
317k
          if (quant_row_y[x >> chroma_subsampling.HShift(1)] > t) bucket_y++;
348
317k
        }
349
351k
        for (int t : bctx.dc_thresholds[2]) {
350
351k
          if (quant_row_b[x >> chroma_subsampling.HShift(2)] > t) bucket_b++;
351
351k
        }
352
337k
        int bucket = bucket_x;
353
337k
        bucket *= bctx.dc_thresholds[2].size() + 1;
354
337k
        bucket += bucket_b;
355
337k
        bucket *= bctx.dc_thresholds[1].size() + 1;
356
337k
        bucket += bucket_y;
357
337k
        qdc_row_val[x] = bucket;
358
337k
      }
359
9.39k
    }
360
1.51k
  }
361
10.0k
}
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&)
362
363
// NOLINTNEXTLINE(google-readability-namespace-comments)
364
}  // namespace HWY_NAMESPACE
365
}  // namespace jxl
366
HWY_AFTER_NAMESPACE();
367
368
#if HWY_ONCE
369
namespace jxl {
370
371
HWY_EXPORT(DequantDC);
372
HWY_EXPORT(AdaptiveDCSmoothing);
373
Status AdaptiveDCSmoothing(JxlMemoryManager* memory_manager,
374
                           const float* dc_factors, Image3F* dc,
375
                           const YCbCrChromaSubsampling& chroma_subsampling,
376
7.96k
                           ThreadPool* pool) {
377
7.96k
  return HWY_DYNAMIC_DISPATCH(AdaptiveDCSmoothing)(
378
7.96k
      memory_manager, dc_factors, dc, chroma_subsampling, pool);
379
7.96k
}
380
381
void DequantDC(const Rect& r, Image3F* dc, ImageB* quant_dc, const Image& in,
382
               const float* dc_factors, float mul, const float* cfl_factors,
383
               const YCbCrChromaSubsampling& chroma_subsampling,
384
10.0k
               const BlockCtxMap& bctx) {
385
10.0k
  HWY_DYNAMIC_DISPATCH(DequantDC)
386
10.0k
  (r, dc, quant_dc, in, dc_factors, mul, cfl_factors, chroma_subsampling, bctx);
387
10.0k
}
388
389
}  // namespace jxl
390
#endif  // HWY_ONCE