/src/libjxl/lib/jxl/dct_util.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef LIB_JXL_DCT_UTIL_H_ |
7 | | #define LIB_JXL_DCT_UTIL_H_ |
8 | | |
9 | | #include <jxl/memory_manager.h> |
10 | | |
11 | | #include <cstddef> |
12 | | #include <cstdint> |
13 | | #include <memory> |
14 | | #include <type_traits> |
15 | | |
16 | | #include "lib/jxl/base/common.h" |
17 | | #include "lib/jxl/base/status.h" |
18 | | #include "lib/jxl/image.h" |
19 | | #include "lib/jxl/image_ops.h" |
20 | | |
21 | | namespace jxl { |
22 | | |
23 | | union ACPtr { |
24 | | int32_t* ptr32; |
25 | | int16_t* ptr16; |
26 | | ACPtr() = default; |
27 | 12 | explicit ACPtr(int16_t* p) : ptr16(p) {} |
28 | 8.92k | explicit ACPtr(int32_t* p) : ptr32(p) {} |
29 | | }; |
30 | | |
31 | | union ConstACPtr { |
32 | | const int32_t* ptr32; |
33 | | const int16_t* ptr16; |
34 | | ConstACPtr() = default; |
35 | 0 | explicit ConstACPtr(const int16_t* p) : ptr16(p) {} |
36 | 1.71k | explicit ConstACPtr(const int32_t* p) : ptr32(p) {} |
37 | | }; |
38 | | |
39 | | enum class ACType { k16 = 0, k32 = 1 }; |
40 | | |
41 | | class ACImage { |
42 | | public: |
43 | 11.9k | virtual ~ACImage() = default; |
44 | | virtual ACType Type() const = 0; |
45 | | virtual ACPtr PlaneRow(size_t c, size_t y, size_t xbase) = 0; |
46 | | virtual ConstACPtr PlaneRow(size_t c, size_t y, size_t xbase) const = 0; |
47 | | virtual size_t PixelsPerRow() const = 0; |
48 | | virtual void ZeroFill() = 0; |
49 | | virtual void ZeroFillPlane(size_t c) = 0; |
50 | | virtual bool IsEmpty() const = 0; |
51 | | }; |
52 | | |
53 | | template <typename T> |
54 | | class ACImageT final : public ACImage { |
55 | | public: |
56 | 11.9k | ACImageT() = default; jxl::ACImageT<int>::ACImageT() Line | Count | Source | 56 | 10.3k | ACImageT() = default; |
jxl::ACImageT<short>::ACImageT() Line | Count | Source | 56 | 1.56k | ACImageT() = default; |
|
57 | | |
58 | | static StatusOr<std::unique_ptr<ACImageT>> Make( |
59 | 1.87k | JxlMemoryManager* memory_manager, size_t xsize, size_t ysize) { |
60 | 1.87k | static_assert( |
61 | 1.87k | std::is_same<T, int16_t>::value || std::is_same<T, int32_t>::value, |
62 | 1.87k | "ACImage must be either 32- or 16- bit"); |
63 | 1.87k | std::unique_ptr<ACImageT> result = jxl::make_unique<ACImageT>(); |
64 | 1.87k | JXL_ASSIGN_OR_RETURN(result->img_, |
65 | 1.87k | Image3<T>::Create(memory_manager, xsize, ysize)); |
66 | 1.87k | return result; |
67 | 1.87k | } jxl::ACImageT<int>::Make(JxlMemoryManagerStruct*, unsigned long, unsigned long) Line | Count | Source | 59 | 316 | JxlMemoryManager* memory_manager, size_t xsize, size_t ysize) { | 60 | 316 | static_assert( | 61 | 316 | std::is_same<T, int16_t>::value || std::is_same<T, int32_t>::value, | 62 | 316 | "ACImage must be either 32- or 16- bit"); | 63 | 316 | std::unique_ptr<ACImageT> result = jxl::make_unique<ACImageT>(); | 64 | 316 | JXL_ASSIGN_OR_RETURN(result->img_, | 65 | 316 | Image3<T>::Create(memory_manager, xsize, ysize)); | 66 | 316 | return result; | 67 | 316 | } |
jxl::ACImageT<short>::Make(JxlMemoryManagerStruct*, unsigned long, unsigned long) Line | Count | Source | 59 | 1.56k | JxlMemoryManager* memory_manager, size_t xsize, size_t ysize) { | 60 | 1.56k | static_assert( | 61 | 1.56k | std::is_same<T, int16_t>::value || std::is_same<T, int32_t>::value, | 62 | 1.56k | "ACImage must be either 32- or 16- bit"); | 63 | 1.56k | std::unique_ptr<ACImageT> result = jxl::make_unique<ACImageT>(); | 64 | 1.56k | JXL_ASSIGN_OR_RETURN(result->img_, | 65 | 1.56k | Image3<T>::Create(memory_manager, xsize, ysize)); | 66 | 1.56k | return result; | 67 | 1.56k | } |
|
68 | | |
69 | 7.02k | ACType Type() const override { |
70 | 7.02k | return sizeof(T) == 2 ? ACType::k16 : ACType::k32; |
71 | 7.02k | } jxl::ACImageT<int>::Type() const Line | Count | Source | 69 | 5.46k | ACType Type() const override { | 70 | 5.46k | return sizeof(T) == 2 ? ACType::k16 : ACType::k32; | 71 | 5.46k | } |
jxl::ACImageT<short>::Type() const Line | Count | Source | 69 | 1.56k | ACType Type() const override { | 70 | 1.56k | return sizeof(T) == 2 ? ACType::k16 : ACType::k32; | 71 | 1.56k | } |
|
72 | 8.94k | ACPtr PlaneRow(size_t c, size_t y, size_t xbase) override { |
73 | 8.94k | return ACPtr(img_.PlaneRow(c, y) + xbase); |
74 | 8.94k | } jxl::ACImageT<int>::PlaneRow(unsigned long, unsigned long, unsigned long) Line | Count | Source | 72 | 8.92k | ACPtr PlaneRow(size_t c, size_t y, size_t xbase) override { | 73 | 8.92k | return ACPtr(img_.PlaneRow(c, y) + xbase); | 74 | 8.92k | } |
jxl::ACImageT<short>::PlaneRow(unsigned long, unsigned long, unsigned long) Line | Count | Source | 72 | 12 | ACPtr PlaneRow(size_t c, size_t y, size_t xbase) override { | 73 | 12 | return ACPtr(img_.PlaneRow(c, y) + xbase); | 74 | 12 | } |
|
75 | 1.71k | ConstACPtr PlaneRow(size_t c, size_t y, size_t xbase) const override { |
76 | 1.71k | return ConstACPtr(img_.PlaneRow(c, y) + xbase); |
77 | 1.71k | } jxl::ACImageT<int>::PlaneRow(unsigned long, unsigned long, unsigned long) const Line | Count | Source | 75 | 1.71k | ConstACPtr PlaneRow(size_t c, size_t y, size_t xbase) const override { | 76 | 1.71k | return ConstACPtr(img_.PlaneRow(c, y) + xbase); | 77 | 1.71k | } |
Unexecuted instantiation: jxl::ACImageT<short>::PlaneRow(unsigned long, unsigned long, unsigned long) const |
78 | | |
79 | 0 | size_t PixelsPerRow() const override { return img_.PixelsPerRow(); } Unexecuted instantiation: jxl::ACImageT<int>::PixelsPerRow() const Unexecuted instantiation: jxl::ACImageT<short>::PixelsPerRow() const |
80 | | |
81 | 5 | void ZeroFill() override { ZeroFillImage(&img_); } jxl::ACImageT<int>::ZeroFill() Line | Count | Source | 81 | 1 | void ZeroFill() override { ZeroFillImage(&img_); } |
jxl::ACImageT<short>::ZeroFill() Line | Count | Source | 81 | 4 | void ZeroFill() override { ZeroFillImage(&img_); } |
|
82 | | |
83 | 0 | void ZeroFillPlane(size_t c) override { ZeroFillImage(&img_.Plane(c)); } Unexecuted instantiation: jxl::ACImageT<int>::ZeroFillPlane(unsigned long) Unexecuted instantiation: jxl::ACImageT<short>::ZeroFillPlane(unsigned long) |
84 | | |
85 | 3.48k | bool IsEmpty() const override { |
86 | 3.48k | return img_.xsize() == 0 || img_.ysize() == 0; |
87 | 3.48k | } jxl::ACImageT<int>::IsEmpty() const Line | Count | Source | 85 | 1.91k | bool IsEmpty() const override { | 86 | 1.91k | return img_.xsize() == 0 || img_.ysize() == 0; | 87 | 1.91k | } |
jxl::ACImageT<short>::IsEmpty() const Line | Count | Source | 85 | 1.56k | bool IsEmpty() const override { | 86 | 1.56k | return img_.xsize() == 0 || img_.ysize() == 0; | 87 | 1.56k | } |
|
88 | | |
89 | | private: |
90 | | Image3<T> img_; |
91 | | }; |
92 | | |
93 | | } // namespace jxl |
94 | | |
95 | | #endif // LIB_JXL_DCT_UTIL_H_ |