/src/libjxl/lib/jxl/dct_block-inl.h
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 | | // Adapters for DCT input/output: from/to contiguous blocks or image rows. |
7 | | |
8 | | #if defined(LIB_JXL_DCT_BLOCK_INL_H_) == defined(HWY_TARGET_TOGGLE) |
9 | | #ifdef LIB_JXL_DCT_BLOCK_INL_H_ |
10 | | #undef LIB_JXL_DCT_BLOCK_INL_H_ |
11 | | #else |
12 | | #define LIB_JXL_DCT_BLOCK_INL_H_ |
13 | | #endif |
14 | | |
15 | | #include <stddef.h> |
16 | | |
17 | | #include <hwy/highway.h> |
18 | | |
19 | | #include "lib/jxl/base/status.h" |
20 | | HWY_BEFORE_NAMESPACE(); |
21 | | namespace jxl { |
22 | | namespace HWY_NAMESPACE { |
23 | | namespace { |
24 | | |
25 | | // These templates are not found via ADL. |
26 | | using hwy::HWY_NAMESPACE::Vec; |
27 | | |
28 | | // Block: (x, y) <-> (N * y + x) |
29 | | // Lines: (x, y) <-> (stride * y + x) |
30 | | // |
31 | | // I.e. Block is a specialization of Lines with fixed stride. |
32 | | // |
33 | | // FromXXX should implement Read and Load (Read vector). |
34 | | // ToXXX should implement Write and Store (Write vector). |
35 | | |
36 | | template <size_t N> |
37 | | using BlockDesc = HWY_CAPPED(float, N); |
38 | | |
39 | | // Here and in the following, the SZ template parameter specifies the number of |
40 | | // values to load/store. Needed because we want to handle 4x4 sub-blocks of |
41 | | // 16x16 blocks. |
42 | | class DCTFrom { |
43 | | public: |
44 | 2.13M | DCTFrom(const float* data, size_t stride) : stride_(stride), data_(data) {} Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::DCTFrom(float const*, unsigned long) dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::DCTFrom(float const*, unsigned long) Line | Count | Source | 44 | 2.13M | DCTFrom(const float* data, size_t stride) : stride_(stride), data_(data) {} |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::DCTFrom(float const*, unsigned long) Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::DCTFrom(float const*, unsigned long) |
45 | | |
46 | | template <typename D> |
47 | 556k | HWY_INLINE Vec<D> LoadPart(D /* tag */, const size_t row, size_t i) const { |
48 | 556k | JXL_DASSERT(Lanes(D()) <= stride_); |
49 | | // Since these functions are used also for DC, no alignment at all is |
50 | | // guaranteed in the case of floating blocks. |
51 | | // TODO(veluca): consider using a different class for DC-to-LF and |
52 | | // DC-from-LF, or copying DC values to/from a temporary aligned location. |
53 | 556k | return LoadU(D(), Address(row, i)); |
54 | 556k | } Unexecuted instantiation: enc_group.cc:decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) jxl::N_SCALAR::(anonymous namespace)::DCTFrom::LoadPart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, unsigned long, unsigned long) const dec_group.cc:decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) jxl::N_SCALAR::(anonymous namespace)::DCTFrom::LoadPart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, unsigned long, unsigned long) const Line | Count | Source | 47 | 556k | HWY_INLINE Vec<D> LoadPart(D /* tag */, const size_t row, size_t i) const { | 48 | 556k | JXL_DASSERT(Lanes(D()) <= stride_); | 49 | | // Since these functions are used also for DC, no alignment at all is | 50 | | // guaranteed in the case of floating blocks. | 51 | | // TODO(veluca): consider using a different class for DC-to-LF and | 52 | | // DC-from-LF, or copying DC values to/from a temporary aligned location. | 53 | 556k | return LoadU(D(), Address(row, i)); | 54 | 556k | } |
Unexecuted instantiation: enc_ac_strategy.cc:decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) jxl::N_SCALAR::(anonymous namespace)::DCTFrom::LoadPart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) jxl::N_SCALAR::(anonymous namespace)::DCTFrom::LoadPart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) jxl::N_SCALAR::(anonymous namespace)::DCTFrom::LoadPart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, unsigned long, unsigned long) const |
55 | | |
56 | 55.8M | HWY_INLINE float Read(const size_t row, const size_t i) const { |
57 | 55.8M | return *Address(row, i); |
58 | 55.8M | } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Read(unsigned long, unsigned long) const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Read(unsigned long, unsigned long) const Line | Count | Source | 56 | 55.8M | HWY_INLINE float Read(const size_t row, const size_t i) const { | 57 | 55.8M | return *Address(row, i); | 58 | 55.8M | } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Read(unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Read(unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Read(unsigned long, unsigned long) const |
59 | | |
60 | | constexpr HWY_INLINE const float* Address(const size_t row, |
61 | 65.4M | const size_t i) const { |
62 | 65.4M | return data_ + row * stride_ + i; |
63 | 65.4M | } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Address(unsigned long, unsigned long) const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Address(unsigned long, unsigned long) const Line | Count | Source | 61 | 65.4M | const size_t i) const { | 62 | 65.4M | return data_ + row * stride_ + i; | 63 | 65.4M | } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Address(unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Address(unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Address(unsigned long, unsigned long) const |
64 | | |
65 | 9.65M | size_t Stride() const { return stride_; } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Stride() const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Stride() const Line | Count | Source | 65 | 9.65M | size_t Stride() const { return stride_; } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Stride() const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Stride() const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTFrom::Stride() const |
66 | | |
67 | | private: |
68 | | size_t stride_; |
69 | | const float* JXL_RESTRICT data_; |
70 | | }; |
71 | | |
72 | | class DCTTo { |
73 | | public: |
74 | 2.14M | DCTTo(float* data, size_t stride) : stride_(stride), data_(data) {} Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::DCTTo(float*, unsigned long) dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::DCTTo(float*, unsigned long) Line | Count | Source | 74 | 2.14M | DCTTo(float* data, size_t stride) : stride_(stride), data_(data) {} |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::DCTTo(float*, unsigned long) Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::DCTTo(float*, unsigned long) |
75 | | |
76 | | template <typename D> |
77 | | HWY_INLINE void StorePart(D /* tag */, const Vec<D>& v, const size_t row, |
78 | 556k | size_t i) const { |
79 | 556k | JXL_DASSERT(Lanes(D()) <= stride_); |
80 | | // Since these functions are used also for DC, no alignment at all is |
81 | | // guaranteed in the case of floating blocks. |
82 | | // TODO(veluca): consider using a different class for DC-to-LF and |
83 | | // DC-from-LF, or copying DC values to/from a temporary aligned location. |
84 | 556k | StoreU(v, D(), Address(row, i)); |
85 | 556k | } Unexecuted instantiation: enc_group.cc:void jxl::N_SCALAR::(anonymous namespace)::DCTTo::StorePart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) const&, unsigned long, unsigned long) const dec_group.cc:void jxl::N_SCALAR::(anonymous namespace)::DCTTo::StorePart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) const&, unsigned long, unsigned long) const Line | Count | Source | 78 | 556k | size_t i) const { | 79 | 556k | JXL_DASSERT(Lanes(D()) <= stride_); | 80 | | // Since these functions are used also for DC, no alignment at all is | 81 | | // guaranteed in the case of floating blocks. | 82 | | // TODO(veluca): consider using a different class for DC-to-LF and | 83 | | // DC-from-LF, or copying DC values to/from a temporary aligned location. | 84 | 556k | StoreU(v, D(), Address(row, i)); | 85 | 556k | } |
Unexecuted instantiation: enc_ac_strategy.cc:void jxl::N_SCALAR::(anonymous namespace)::DCTTo::StorePart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) const&, unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:void jxl::N_SCALAR::(anonymous namespace)::DCTTo::StorePart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) const&, unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:void jxl::N_SCALAR::(anonymous namespace)::DCTTo::StorePart<hwy::N_SCALAR::Simd<float, 1ul, 0> >(hwy::N_SCALAR::Simd<float, 1ul, 0>, decltype (Zero((hwy::N_SCALAR::Simd<float, 1ul, 0>)())) const&, unsigned long, unsigned long) const |
86 | | |
87 | 55.8M | HWY_INLINE void Write(float v, const size_t row, const size_t i) const { |
88 | 55.8M | *Address(row, i) = v; |
89 | 55.8M | } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Write(float, unsigned long, unsigned long) const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Write(float, unsigned long, unsigned long) const Line | Count | Source | 87 | 55.8M | HWY_INLINE void Write(float v, const size_t row, const size_t i) const { | 88 | 55.8M | *Address(row, i) = v; | 89 | 55.8M | } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Write(float, unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Write(float, unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Write(float, unsigned long, unsigned long) const |
90 | | |
91 | 65.4M | constexpr HWY_INLINE float* Address(const size_t row, const size_t i) const { |
92 | 65.4M | return data_ + row * stride_ + i; |
93 | 65.4M | } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Address(unsigned long, unsigned long) const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Address(unsigned long, unsigned long) const Line | Count | Source | 91 | 65.4M | constexpr HWY_INLINE float* Address(const size_t row, const size_t i) const { | 92 | 65.4M | return data_ + row * stride_ + i; | 93 | 65.4M | } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Address(unsigned long, unsigned long) const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Address(unsigned long, unsigned long) const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Address(unsigned long, unsigned long) const |
94 | | |
95 | 9.65M | size_t Stride() const { return stride_; } Unexecuted instantiation: enc_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Stride() const dec_group.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Stride() const Line | Count | Source | 95 | 9.65M | size_t Stride() const { return stride_; } |
Unexecuted instantiation: enc_ac_strategy.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Stride() const Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Stride() const Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::N_SCALAR::(anonymous namespace)::DCTTo::Stride() const |
96 | | |
97 | | private: |
98 | | size_t stride_; |
99 | | float* JXL_RESTRICT data_; |
100 | | }; |
101 | | |
102 | | } // namespace |
103 | | // NOLINTNEXTLINE(google-readability-namespace-comments) |
104 | | } // namespace HWY_NAMESPACE |
105 | | } // namespace jxl |
106 | | HWY_AFTER_NAMESPACE(); |
107 | | |
108 | | #endif // LIB_JXL_DCT_BLOCK_INL_H_ |