/src/libjxl/lib/jxl/image_ops.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_IMAGE_OPS_H_ |
7 | | #define LIB_JXL_IMAGE_OPS_H_ |
8 | | |
9 | | // Operations on images. |
10 | | |
11 | | #include <jxl/memory_manager.h> |
12 | | |
13 | | #include <algorithm> |
14 | | #include <cstddef> |
15 | | #include <cstdint> |
16 | | #include <limits> |
17 | | |
18 | | #include "lib/jxl/base/common.h" |
19 | | #include "lib/jxl/base/compiler_specific.h" |
20 | | #include "lib/jxl/base/rect.h" |
21 | | #include "lib/jxl/base/status.h" |
22 | | #include "lib/jxl/frame_dimensions.h" |
23 | | #include "lib/jxl/image.h" |
24 | | |
25 | | namespace jxl { |
26 | | |
27 | | // Works for mixed image-like argument types. |
28 | | template <class Image1, class Image2> |
29 | 248k | bool SameSize(const Image1& image1, const Image2& image2) { |
30 | 248k | return image1.xsize() == image2.xsize() && image1.ysize() == image2.ysize(); |
31 | 248k | } bool jxl::SameSize<jxl::RectT<unsigned long>, jxl::RectT<unsigned long> >(jxl::RectT<unsigned long> const&, jxl::RectT<unsigned long> const&) Line | Count | Source | 29 | 64.8k | bool SameSize(const Image1& image1, const Image2& image2) { | 30 | 64.8k | return image1.xsize() == image2.xsize() && image1.ysize() == image2.ysize(); | 31 | 64.8k | } |
bool jxl::SameSize<jxl::Plane<float>, jxl::Plane<float> >(jxl::Plane<float> const&, jxl::Plane<float> const&) Line | Count | Source | 29 | 190 | bool SameSize(const Image1& image1, const Image2& image2) { | 30 | 190 | return image1.xsize() == image2.xsize() && image1.ysize() == image2.ysize(); | 31 | 190 | } |
bool jxl::SameSize<jxl::RectT<unsigned long>, jxl::Plane<float> >(jxl::RectT<unsigned long> const&, jxl::Plane<float> const&) Line | Count | Source | 29 | 183k | bool SameSize(const Image1& image1, const Image2& image2) { | 30 | 183k | return image1.xsize() == image2.xsize() && image1.ysize() == image2.ysize(); | 31 | 183k | } |
Unexecuted instantiation: bool jxl::SameSize<jxl::Image3<float>, jxl::Plane<float> >(jxl::Image3<float> const&, jxl::Plane<float> const&) Unexecuted instantiation: bool jxl::SameSize<jxl::Image3<float>, jxl::Image3<float> >(jxl::Image3<float> const&, jxl::Image3<float> const&) Unexecuted instantiation: bool jxl::SameSize<jxl::Plane<int>, jxl::Plane<int> >(jxl::Plane<int> const&, jxl::Plane<int> const&) Unexecuted instantiation: bool jxl::SameSize<jxl::RectT<unsigned long>, jxl::Image3<float> >(jxl::RectT<unsigned long> const&, jxl::Image3<float> const&) Unexecuted instantiation: bool jxl::SameSize<jxl::Plane<int>, jxl::Plane<float> >(jxl::Plane<int> const&, jxl::Plane<float> const&) |
32 | | |
33 | | template <typename T> |
34 | 190 | Status CopyImageTo(const Plane<T>& from, Plane<T>* JXL_RESTRICT to) { |
35 | 190 | JXL_ENSURE(SameSize(from, *to)); |
36 | 190 | if (from.ysize() == 0 || from.xsize() == 0) return true; |
37 | 55.6k | for (size_t y = 0; y < from.ysize(); ++y) { |
38 | 55.5k | const T* JXL_RESTRICT row_from = from.ConstRow(y); |
39 | 55.5k | T* JXL_RESTRICT row_to = to->Row(y); |
40 | 55.5k | memcpy(row_to, row_from, from.xsize() * sizeof(T)); |
41 | 55.5k | } |
42 | 190 | return true; |
43 | 190 | } jxl::Status jxl::CopyImageTo<float>(jxl::Plane<float> const&, jxl::Plane<float>*) Line | Count | Source | 34 | 190 | Status CopyImageTo(const Plane<T>& from, Plane<T>* JXL_RESTRICT to) { | 35 | 190 | JXL_ENSURE(SameSize(from, *to)); | 36 | 190 | if (from.ysize() == 0 || from.xsize() == 0) return true; | 37 | 55.6k | for (size_t y = 0; y < from.ysize(); ++y) { | 38 | 55.5k | const T* JXL_RESTRICT row_from = from.ConstRow(y); | 39 | 55.5k | T* JXL_RESTRICT row_to = to->Row(y); | 40 | 55.5k | memcpy(row_to, row_from, from.xsize() * sizeof(T)); | 41 | 55.5k | } | 42 | 190 | return true; | 43 | 190 | } |
Unexecuted instantiation: jxl::Status jxl::CopyImageTo<int>(jxl::Plane<int> const&, jxl::Plane<int>*) |
44 | | |
45 | | // Copies `from:rect_from` to `to:rect_to`. |
46 | | template <typename T> |
47 | | Status CopyImageTo(const Rect& rect_from, const Plane<T>& from, |
48 | 56.2k | const Rect& rect_to, Plane<T>* JXL_RESTRICT to) { |
49 | 56.2k | JXL_ENSURE(SameSize(rect_from, rect_to)); |
50 | 56.2k | JXL_ENSURE(rect_from.IsInside(from)); |
51 | 56.2k | JXL_ENSURE(rect_to.IsInside(*to)); |
52 | 56.2k | if (rect_from.xsize() == 0) return true; |
53 | 4.19M | for (size_t y = 0; y < rect_from.ysize(); ++y) { |
54 | 4.13M | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); |
55 | 4.13M | T* JXL_RESTRICT row_to = rect_to.Row(to, y); |
56 | 4.13M | memcpy(row_to, row_from, rect_from.xsize() * sizeof(T)); |
57 | 4.13M | } |
58 | 55.9k | return true; |
59 | 56.2k | } jxl::Status jxl::CopyImageTo<float>(jxl::RectT<unsigned long> const&, jxl::Plane<float> const&, jxl::RectT<unsigned long> const&, jxl::Plane<float>*) Line | Count | Source | 48 | 43.2k | const Rect& rect_to, Plane<T>* JXL_RESTRICT to) { | 49 | 43.2k | JXL_ENSURE(SameSize(rect_from, rect_to)); | 50 | 43.2k | JXL_ENSURE(rect_from.IsInside(from)); | 51 | 43.2k | JXL_ENSURE(rect_to.IsInside(*to)); | 52 | 43.2k | if (rect_from.xsize() == 0) return true; | 53 | 3.65M | for (size_t y = 0; y < rect_from.ysize(); ++y) { | 54 | 3.61M | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); | 55 | 3.61M | T* JXL_RESTRICT row_to = rect_to.Row(to, y); | 56 | 3.61M | memcpy(row_to, row_from, rect_from.xsize() * sizeof(T)); | 57 | 3.61M | } | 58 | 42.9k | return true; | 59 | 43.2k | } |
jxl::Status jxl::CopyImageTo<int>(jxl::RectT<unsigned long> const&, jxl::Plane<int> const&, jxl::RectT<unsigned long> const&, jxl::Plane<int>*) Line | Count | Source | 48 | 13.0k | const Rect& rect_to, Plane<T>* JXL_RESTRICT to) { | 49 | 13.0k | JXL_ENSURE(SameSize(rect_from, rect_to)); | 50 | 13.0k | JXL_ENSURE(rect_from.IsInside(from)); | 51 | 13.0k | JXL_ENSURE(rect_to.IsInside(*to)); | 52 | 13.0k | if (rect_from.xsize() == 0) return true; | 53 | 538k | for (size_t y = 0; y < rect_from.ysize(); ++y) { | 54 | 525k | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); | 55 | 525k | T* JXL_RESTRICT row_to = rect_to.Row(to, y); | 56 | 525k | memcpy(row_to, row_from, rect_from.xsize() * sizeof(T)); | 57 | 525k | } | 58 | 13.0k | return true; | 59 | 13.0k | } |
|
60 | | |
61 | | // Copies `from:rect_from` to `to:rect_to`. |
62 | | template <typename T> |
63 | | Status CopyImageTo(const Rect& rect_from, const Image3<T>& from, |
64 | 162 | const Rect& rect_to, Image3<T>* JXL_RESTRICT to) { |
65 | 162 | JXL_ENSURE(SameSize(rect_from, rect_to)); |
66 | 648 | for (size_t c = 0; c < 3; c++) { |
67 | 486 | JXL_RETURN_IF_ERROR( |
68 | 486 | CopyImageTo(rect_from, from.Plane(c), rect_to, &to->Plane(c))); |
69 | 486 | } |
70 | 162 | return true; |
71 | 162 | } |
72 | | |
73 | | template <typename T, typename U> |
74 | | Status ConvertPlaneAndClamp(const Rect& rect_from, const Plane<T>& from, |
75 | 8.45k | const Rect& rect_to, Plane<U>* JXL_RESTRICT to) { |
76 | 8.45k | JXL_ENSURE(SameSize(rect_from, rect_to)); |
77 | 8.45k | using M = decltype(T() + U()); |
78 | 20.1k | for (size_t y = 0; y < rect_to.ysize(); ++y) { |
79 | 11.6k | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); |
80 | 11.6k | U* JXL_RESTRICT row_to = rect_to.Row(to, y); |
81 | 47.0k | for (size_t x = 0; x < rect_to.xsize(); ++x) { |
82 | 35.4k | row_to[x] = jxl::Clamp1<M>(row_from[x], std::numeric_limits<U>::min(), |
83 | 35.4k | std::numeric_limits<U>::max()); |
84 | 35.4k | } |
85 | 11.6k | } |
86 | 8.45k | return true; |
87 | 8.45k | } jxl::Status jxl::ConvertPlaneAndClamp<signed char, int>(jxl::RectT<unsigned long> const&, jxl::Plane<signed char> const&, jxl::RectT<unsigned long> const&, jxl::Plane<int>*) Line | Count | Source | 75 | 324 | const Rect& rect_to, Plane<U>* JXL_RESTRICT to) { | 76 | 324 | JXL_ENSURE(SameSize(rect_from, rect_to)); | 77 | 324 | using M = decltype(T() + U()); | 78 | 2.16k | for (size_t y = 0; y < rect_to.ysize(); ++y) { | 79 | 1.84k | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); | 80 | 1.84k | U* JXL_RESTRICT row_to = rect_to.Row(to, y); | 81 | 14.8k | for (size_t x = 0; x < rect_to.xsize(); ++x) { | 82 | 12.9k | row_to[x] = jxl::Clamp1<M>(row_from[x], std::numeric_limits<U>::min(), | 83 | 12.9k | std::numeric_limits<U>::max()); | 84 | 12.9k | } | 85 | 1.84k | } | 86 | 324 | return true; | 87 | 324 | } |
jxl::Status jxl::ConvertPlaneAndClamp<int, signed char>(jxl::RectT<unsigned long> const&, jxl::Plane<int> const&, jxl::RectT<unsigned long> const&, jxl::Plane<signed char>*) Line | Count | Source | 75 | 8.13k | const Rect& rect_to, Plane<U>* JXL_RESTRICT to) { | 76 | 8.13k | JXL_ENSURE(SameSize(rect_from, rect_to)); | 77 | 8.13k | using M = decltype(T() + U()); | 78 | 17.9k | for (size_t y = 0; y < rect_to.ysize(); ++y) { | 79 | 9.80k | const T* JXL_RESTRICT row_from = rect_from.ConstRow(from, y); | 80 | 9.80k | U* JXL_RESTRICT row_to = rect_to.Row(to, y); | 81 | 32.2k | for (size_t x = 0; x < rect_to.xsize(); ++x) { | 82 | 22.4k | row_to[x] = jxl::Clamp1<M>(row_from[x], std::numeric_limits<U>::min(), | 83 | 22.4k | std::numeric_limits<U>::max()); | 84 | 22.4k | } | 85 | 9.80k | } | 86 | 8.13k | return true; | 87 | 8.13k | } |
|
88 | | |
89 | | // Copies `from` to `to`. |
90 | | template <typename T> |
91 | 0 | Status CopyImageTo(const T& from, T* JXL_RESTRICT to) { |
92 | 0 | return CopyImageTo(Rect(from), from, Rect(*to), to); |
93 | 0 | } |
94 | | |
95 | | // Copies `from:rect_from` to `to:rect_to`; also copies `padding` pixels of |
96 | | // border around `from:rect_from`, in all directions, whenever they are inside |
97 | | // the first image. |
98 | | template <typename T> |
99 | | Status CopyImageToWithPadding(const Rect& from_rect, const T& from, |
100 | 0 | size_t padding, const Rect& to_rect, T* to) { |
101 | 0 | size_t xextra0 = std::min(padding, from_rect.x0()); |
102 | 0 | size_t xextra1 = |
103 | 0 | std::min(padding, from.xsize() - from_rect.x0() - from_rect.xsize()); |
104 | 0 | size_t yextra0 = std::min(padding, from_rect.y0()); |
105 | 0 | size_t yextra1 = |
106 | 0 | std::min(padding, from.ysize() - from_rect.y0() - from_rect.ysize()); |
107 | 0 | JXL_ENSURE(to_rect.x0() >= xextra0); |
108 | 0 | JXL_ENSURE(to_rect.y0() >= yextra0); |
109 | | |
110 | 0 | return CopyImageTo(Rect(from_rect.x0() - xextra0, from_rect.y0() - yextra0, |
111 | 0 | from_rect.xsize() + xextra0 + xextra1, |
112 | 0 | from_rect.ysize() + yextra0 + yextra1), |
113 | 0 | from, |
114 | 0 | Rect(to_rect.x0() - xextra0, to_rect.y0() - yextra0, |
115 | 0 | to_rect.xsize() + xextra0 + xextra1, |
116 | 0 | to_rect.ysize() + yextra0 + yextra1), |
117 | 0 | to); |
118 | 0 | } |
119 | | |
120 | | // Returns linear combination of two grayscale images. |
121 | | template <typename T> |
122 | | StatusOr<Plane<T>> LinComb(const T lambda1, const Plane<T>& image1, |
123 | 0 | const T lambda2, const Plane<T>& image2) { |
124 | 0 | const size_t xsize = image1.xsize(); |
125 | 0 | const size_t ysize = image1.ysize(); |
126 | 0 | JXL_ENSURE(xsize == image2.xsize()); |
127 | 0 | JXL_ENSURE(ysize == image2.ysize()); |
128 | 0 | JxlMemoryManager* memory_manager = image1.memory_manager(); |
129 | 0 | JXL_ASSIGN_OR_RETURN(Plane<T> out, |
130 | 0 | Plane<T>::Create(memory_manager, xsize, ysize)); |
131 | 0 | for (size_t y = 0; y < ysize; ++y) { |
132 | 0 | const T* const JXL_RESTRICT row1 = image1.Row(y); |
133 | 0 | const T* const JXL_RESTRICT row2 = image2.Row(y); |
134 | 0 | T* const JXL_RESTRICT row_out = out.Row(y); |
135 | 0 | for (size_t x = 0; x < xsize; ++x) { |
136 | 0 | row_out[x] = lambda1 * row1[x] + lambda2 * row2[x]; |
137 | 0 | } |
138 | 0 | } |
139 | 0 | return out; |
140 | 0 | } |
141 | | |
142 | | // Multiplies image by lambda in-place |
143 | | template <typename T> |
144 | 0 | void ScaleImage(const T lambda, Plane<T>* image) { |
145 | 0 | for (size_t y = 0; y < image->ysize(); ++y) { |
146 | 0 | T* const JXL_RESTRICT row = image->Row(y); |
147 | 0 | for (size_t x = 0; x < image->xsize(); ++x) { |
148 | 0 | row[x] = lambda * row[x]; |
149 | 0 | } |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | | // Multiplies image by lambda in-place |
154 | | template <typename T> |
155 | | void ScaleImage(const T lambda, Image3<T>* image) { |
156 | | for (size_t c = 0; c < 3; ++c) { |
157 | | ScaleImage(lambda, &image->Plane(c)); |
158 | | } |
159 | | } |
160 | | |
161 | | template <typename T> |
162 | 16.2k | void FillImage(const T value, Plane<T>* image) { |
163 | 217k | for (size_t y = 0; y < image->ysize(); ++y) { |
164 | 201k | T* const JXL_RESTRICT row = image->Row(y); |
165 | 9.53M | for (size_t x = 0; x < image->xsize(); ++x) { |
166 | 9.33M | row[x] = value; |
167 | 9.33M | } |
168 | 201k | } |
169 | 16.2k | } void jxl::FillImage<unsigned char>(unsigned char, jxl::Plane<unsigned char>*) Line | Count | Source | 162 | 4.14k | void FillImage(const T value, Plane<T>* image) { | 163 | 38.9k | for (size_t y = 0; y < image->ysize(); ++y) { | 164 | 34.8k | T* const JXL_RESTRICT row = image->Row(y); | 165 | 1.62M | for (size_t x = 0; x < image->xsize(); ++x) { | 166 | 1.58M | row[x] = value; | 167 | 1.58M | } | 168 | 34.8k | } | 169 | 4.14k | } |
void jxl::FillImage<float>(float, jxl::Plane<float>*) Line | Count | Source | 162 | 12.1k | void FillImage(const T value, Plane<T>* image) { | 163 | 178k | for (size_t y = 0; y < image->ysize(); ++y) { | 164 | 166k | T* const JXL_RESTRICT row = image->Row(y); | 165 | 7.91M | for (size_t x = 0; x < image->xsize(); ++x) { | 166 | 7.74M | row[x] = value; | 167 | 7.74M | } | 168 | 166k | } | 169 | 12.1k | } |
Unexecuted instantiation: void jxl::FillImage<int>(int, jxl::Plane<int>*) |
170 | | |
171 | | template <typename T> |
172 | 236k | void ZeroFillImage(Plane<T>* image) { |
173 | 236k | if (image->xsize() == 0) return; |
174 | 426k | for (size_t y = 0; y < image->ysize(); ++y) { |
175 | 374k | T* const JXL_RESTRICT row = image->Row(y); |
176 | 374k | memset(row, 0, image->xsize() * sizeof(T)); |
177 | 374k | } |
178 | 51.2k | } void jxl::ZeroFillImage<int>(jxl::Plane<int>*) Line | Count | Source | 172 | 187k | void ZeroFillImage(Plane<T>* image) { | 173 | 187k | if (image->xsize() == 0) return; | 174 | 163k | for (size_t y = 0; y < image->ysize(); ++y) { | 175 | 162k | T* const JXL_RESTRICT row = image->Row(y); | 176 | 162k | memset(row, 0, image->xsize() * sizeof(T)); | 177 | 162k | } | 178 | 1.29k | } |
Unexecuted instantiation: void jxl::ZeroFillImage<float>(jxl::Plane<float>*) void jxl::ZeroFillImage<unsigned char>(jxl::Plane<unsigned char>*) Line | Count | Source | 172 | 496 | void ZeroFillImage(Plane<T>* image) { | 173 | 496 | if (image->xsize() == 0) return; | 174 | 77.6k | for (size_t y = 0; y < image->ysize(); ++y) { | 175 | 77.1k | T* const JXL_RESTRICT row = image->Row(y); | 176 | 77.1k | memset(row, 0, image->xsize() * sizeof(T)); | 177 | 77.1k | } | 178 | 496 | } |
void jxl::ZeroFillImage<signed char>(jxl::Plane<signed char>*) Line | Count | Source | 172 | 49.4k | void ZeroFillImage(Plane<T>* image) { | 173 | 49.4k | if (image->xsize() == 0) return; | 174 | 185k | for (size_t y = 0; y < image->ysize(); ++y) { | 175 | 135k | T* const JXL_RESTRICT row = image->Row(y); | 176 | 135k | memset(row, 0, image->xsize() * sizeof(T)); | 177 | 135k | } | 178 | 49.4k | } |
Unexecuted instantiation: void jxl::ZeroFillImage<short>(jxl::Plane<short>*) |
179 | | |
180 | | // Mirrors out of bounds coordinates and returns valid coordinates unchanged. |
181 | | // We assume the radius (distance outside the image) is small compared to the |
182 | | // image size, otherwise this might not terminate. |
183 | | // The mirror is outside the last column (border pixel is also replicated). |
184 | 70.4M | static inline int64_t Mirror(int64_t x, const int64_t xsize) { |
185 | 70.4M | JXL_DASSERT(xsize != 0); |
186 | | |
187 | | // TODO(janwas): replace with branchless version |
188 | 78.2M | while (x < 0 || x >= xsize) { |
189 | 7.77M | if (x < 0) { |
190 | 3.89M | x = -x - 1; |
191 | 3.89M | } else { |
192 | 3.88M | x = 2 * xsize - 1 - x; |
193 | 3.88M | } |
194 | 7.77M | } |
195 | 70.4M | return x; |
196 | 70.4M | } Unexecuted instantiation: encode.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_fields.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_ans.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_lz77.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_frame.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_modular.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_patch_dictionary.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_dot_dictionary.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_detect_dots.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_convolve_separable5.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_debug_image.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_gaborish.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_quant_weights.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_coeff_order.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_toc.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_xyb.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_image_bundle.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_external_image.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_heuristics.cc:jxl::Mirror(long, long) Unexecuted instantiation: butteraugli.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_butteraugli_comparator.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_cache.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_group.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_progressive_split.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_ac_strategy.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_entropy_coder.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_encoding.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_ma.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_rct.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_transform.cc:jxl::Mirror(long, long) Unexecuted instantiation: enc_palette.cc:jxl::Mirror(long, long) Unexecuted instantiation: ac_strategy.cc:jxl::Mirror(long, long) Unexecuted instantiation: chroma_from_luma.cc:jxl::Mirror(long, long) Unexecuted instantiation: coeff_order.cc:jxl::Mirror(long, long) Unexecuted instantiation: convolve_slow.cc:jxl::Mirror(long, long) convolve_symmetric5.cc:jxl::Mirror(long, long) Line | Count | Source | 184 | 69.4M | static inline int64_t Mirror(int64_t x, const int64_t xsize) { | 185 | 69.4M | JXL_DASSERT(xsize != 0); | 186 | | | 187 | | // TODO(janwas): replace with branchless version | 188 | 76.1M | while (x < 0 || x >= xsize) { | 189 | 6.67M | if (x < 0) { | 190 | 3.33M | x = -x - 1; | 191 | 3.33M | } else { | 192 | 3.33M | x = 2 * xsize - 1 - x; | 193 | 3.33M | } | 194 | 6.67M | } | 195 | 69.4M | return x; | 196 | 69.4M | } |
Unexecuted instantiation: dec_cache.cc:jxl::Mirror(long, long) Unexecuted instantiation: blending.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_external_image.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_frame.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_group.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_modular.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_noise.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_patch_dictionary.cc:jxl::Mirror(long, long) Unexecuted instantiation: dec_xyb.cc:jxl::Mirror(long, long) Unexecuted instantiation: decode.cc:jxl::Mirror(long, long) Unexecuted instantiation: epf.cc:jxl::Mirror(long, long) Unexecuted instantiation: image_bundle.cc:jxl::Mirror(long, long) Unexecuted instantiation: image_metadata.cc:jxl::Mirror(long, long) Unexecuted instantiation: image_ops.cc:jxl::Mirror(long, long) Unexecuted instantiation: encoding.cc:jxl::Mirror(long, long) Unexecuted instantiation: modular_image.cc:jxl::Mirror(long, long) Unexecuted instantiation: transform.cc:jxl::Mirror(long, long) Unexecuted instantiation: rct.cc:jxl::Mirror(long, long) Unexecuted instantiation: palette.cc:jxl::Mirror(long, long) Unexecuted instantiation: passes_state.cc:jxl::Mirror(long, long) Unexecuted instantiation: quant_weights.cc:jxl::Mirror(long, long) Unexecuted instantiation: quantizer.cc:jxl::Mirror(long, long) low_memory_render_pipeline.cc:jxl::Mirror(long, long) Line | Count | Source | 184 | 960k | static inline int64_t Mirror(int64_t x, const int64_t xsize) { | 185 | 960k | JXL_DASSERT(xsize != 0); | 186 | | | 187 | | // TODO(janwas): replace with branchless version | 188 | 2.05M | while (x < 0 || x >= xsize) { | 189 | 1.09M | if (x < 0) { | 190 | 554k | x = -x - 1; | 191 | 554k | } else { | 192 | 543k | x = 2 * xsize - 1 - x; | 193 | 543k | } | 194 | 1.09M | } | 195 | 960k | return x; | 196 | 960k | } |
Unexecuted instantiation: simple_render_pipeline.cc:jxl::Mirror(long, long) Unexecuted instantiation: stage_blending.cc:jxl::Mirror(long, long) Unexecuted instantiation: stage_epf.cc:jxl::Mirror(long, long) Unexecuted instantiation: stage_patches.cc:jxl::Mirror(long, long) Unexecuted instantiation: stage_write.cc:jxl::Mirror(long, long) Unexecuted instantiation: decode_to_jpeg.cc:jxl::Mirror(long, long) |
197 | | |
198 | | // Wrap modes for ensuring X/Y coordinates are in the valid range [0, size): |
199 | | |
200 | | // Mirrors (repeating the edge pixel once). Useful for convolutions. |
201 | | struct WrapMirror { |
202 | 69.4M | JXL_INLINE int64_t operator()(const int64_t coord, const int64_t size) const { |
203 | 69.4M | return Mirror(coord, size); |
204 | 69.4M | } |
205 | | }; |
206 | | |
207 | | // Returns the same coordinate: required for TFNode with Border(), or useful |
208 | | // when we know "coord" is already valid (e.g. interior of an image). |
209 | | struct WrapUnchanged { |
210 | 70.8M | JXL_INLINE int64_t operator()(const int64_t coord, int64_t /*size*/) const { |
211 | 70.8M | return coord; |
212 | 70.8M | } |
213 | | }; |
214 | | |
215 | | // Computes the minimum and maximum pixel value. |
216 | | template <typename T> |
217 | | void ImageMinMax(const Plane<T>& image, T* const JXL_RESTRICT min, |
218 | 0 | T* const JXL_RESTRICT max) { |
219 | 0 | *min = std::numeric_limits<T>::max(); |
220 | 0 | *max = std::numeric_limits<T>::lowest(); |
221 | 0 | for (size_t y = 0; y < image.ysize(); ++y) { |
222 | 0 | const T* const JXL_RESTRICT row = image.Row(y); |
223 | 0 | for (size_t x = 0; x < image.xsize(); ++x) { |
224 | 0 | *min = std::min(*min, row[x]); |
225 | 0 | *max = std::max(*max, row[x]); |
226 | 0 | } |
227 | 0 | } |
228 | 0 | } Unexecuted instantiation: void jxl::ImageMinMax<float>(jxl::Plane<float> const&, float*, float*) Unexecuted instantiation: void jxl::ImageMinMax<unsigned char>(jxl::Plane<unsigned char> const&, unsigned char*, unsigned char*) |
229 | | |
230 | | // Initializes all planes to the same "value". |
231 | | template <typename T> |
232 | | void FillImage(const T value, Image3<T>* image) { |
233 | | for (size_t c = 0; c < 3; ++c) { |
234 | | for (size_t y = 0; y < image->ysize(); ++y) { |
235 | | T* JXL_RESTRICT row = image->PlaneRow(c, y); |
236 | | for (size_t x = 0; x < image->xsize(); ++x) { |
237 | | row[x] = value; |
238 | | } |
239 | | } |
240 | | } |
241 | | } |
242 | | |
243 | | template <typename T> |
244 | 648 | void FillPlane(const T value, Plane<T>* image, Rect rect) { |
245 | 27.5k | for (size_t y = 0; y < rect.ysize(); ++y) { |
246 | 26.8k | T* JXL_RESTRICT row = rect.Row(image, y); |
247 | 1.43M | for (size_t x = 0; x < rect.xsize(); ++x) { |
248 | 1.41M | row[x] = value; |
249 | 1.41M | } |
250 | 26.8k | } |
251 | 648 | } void jxl::FillPlane<unsigned char>(unsigned char, jxl::Plane<unsigned char>*, jxl::RectT<unsigned long>) Line | Count | Source | 244 | 648 | void FillPlane(const T value, Plane<T>* image, Rect rect) { | 245 | 27.5k | for (size_t y = 0; y < rect.ysize(); ++y) { | 246 | 26.8k | T* JXL_RESTRICT row = rect.Row(image, y); | 247 | 1.43M | for (size_t x = 0; x < rect.xsize(); ++x) { | 248 | 1.41M | row[x] = value; | 249 | 1.41M | } | 250 | 26.8k | } | 251 | 648 | } |
Unexecuted instantiation: void jxl::FillPlane<float>(float, jxl::Plane<float>*, jxl::RectT<unsigned long>) |
252 | | |
253 | | template <typename T> |
254 | 168 | void ZeroFillImage(Image3<T>* image) { |
255 | 672 | for (size_t c = 0; c < 3; ++c) { |
256 | 99.9k | for (size_t y = 0; y < image->ysize(); ++y) { |
257 | 99.4k | T* JXL_RESTRICT row = image->PlaneRow(c, y); |
258 | 99.4k | if (image->xsize() != 0) memset(row, 0, image->xsize() * sizeof(T)); |
259 | 99.4k | } |
260 | 504 | } |
261 | 168 | } void jxl::ZeroFillImage<int>(jxl::Image3<int>*) Line | Count | Source | 254 | 8 | void ZeroFillImage(Image3<T>* image) { | 255 | 32 | for (size_t c = 0; c < 3; ++c) { | 256 | 66 | for (size_t y = 0; y < image->ysize(); ++y) { | 257 | 42 | T* JXL_RESTRICT row = image->PlaneRow(c, y); | 258 | 42 | if (image->xsize() != 0) memset(row, 0, image->xsize() * sizeof(T)); | 259 | 42 | } | 260 | 24 | } | 261 | 8 | } |
void jxl::ZeroFillImage<float>(jxl::Image3<float>*) Line | Count | Source | 254 | 140 | void ZeroFillImage(Image3<T>* image) { | 255 | 560 | for (size_t c = 0; c < 3; ++c) { | 256 | 99.7k | for (size_t y = 0; y < image->ysize(); ++y) { | 257 | 99.3k | T* JXL_RESTRICT row = image->PlaneRow(c, y); | 258 | 99.3k | if (image->xsize() != 0) memset(row, 0, image->xsize() * sizeof(T)); | 259 | 99.3k | } | 260 | 420 | } | 261 | 140 | } |
void jxl::ZeroFillImage<short>(jxl::Image3<short>*) Line | Count | Source | 254 | 20 | void ZeroFillImage(Image3<T>* image) { | 255 | 80 | for (size_t c = 0; c < 3; ++c) { | 256 | 144 | for (size_t y = 0; y < image->ysize(); ++y) { | 257 | 84 | T* JXL_RESTRICT row = image->PlaneRow(c, y); | 258 | 84 | if (image->xsize() != 0) memset(row, 0, image->xsize() * sizeof(T)); | 259 | 84 | } | 260 | 60 | } | 261 | 20 | } |
|
262 | | |
263 | | // Same as above, but operates in-place. Assumes that the `in` image was |
264 | | // allocated large enough. |
265 | | Status PadImageToBlockMultipleInPlace(Image3F* JXL_RESTRICT in, |
266 | | size_t block_dim = kBlockDim); |
267 | | |
268 | | // Downsamples an image by a given factor. |
269 | | StatusOr<Image3F> DownsampleImage(const Image3F& opsin, size_t factor); |
270 | | StatusOr<ImageF> DownsampleImage(const ImageF& image, size_t factor); |
271 | | |
272 | | } // namespace jxl |
273 | | |
274 | | #endif // LIB_JXL_IMAGE_OPS_H_ |