/src/libjxl/lib/jxl/noise.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_NOISE_H_ |
7 | | #define LIB_JXL_NOISE_H_ |
8 | | |
9 | | // Noise parameters shared by encoder/decoder. |
10 | | |
11 | | #include <stddef.h> |
12 | | |
13 | | #include <algorithm> |
14 | | #include <array> |
15 | | #include <cmath> |
16 | | #include <utility> |
17 | | |
18 | | #include "lib/jxl/base/compiler_specific.h" |
19 | | |
20 | | namespace jxl { |
21 | | |
22 | | const float kNoisePrecision = 1 << 10; |
23 | | |
24 | | struct NoiseParams { |
25 | | // LUT index is an intensity of pixel / mean intensity of patch |
26 | | static constexpr size_t kNumNoisePoints = 8; |
27 | | using Lut = std::array<float, kNumNoisePoints>; |
28 | | |
29 | | Lut lut; |
30 | | |
31 | 0 | void Clear() { |
32 | 0 | for (float& i : lut) i = 0.f; |
33 | 0 | } |
34 | 155k | bool HasAny() const { |
35 | 182k | for (float i : lut) { |
36 | 182k | if (std::abs(i) > 1e-3f) return true; |
37 | 182k | } |
38 | 614 | return false; |
39 | 155k | } |
40 | | }; |
41 | | |
42 | 0 | static inline std::pair<int, float> IndexAndFrac(float x) { |
43 | 0 | constexpr size_t kScaleNumerator = NoiseParams::kNumNoisePoints - 2; |
44 | | // TODO(user): instead of 1, this should be a proper Y range. |
45 | 0 | constexpr float kScale = kScaleNumerator / 1.0f; |
46 | 0 | float scaled_x = std::max(0.f, x * kScale); |
47 | 0 | float floor_x; |
48 | 0 | float frac_x = std::modf(scaled_x, &floor_x); |
49 | 0 | if (JXL_UNLIKELY(scaled_x >= kScaleNumerator + 1)) { |
50 | 0 | floor_x = kScaleNumerator; |
51 | 0 | frac_x = 1.f; |
52 | 0 | } |
53 | 0 | return std::make_pair(static_cast<int>(floor_x), frac_x); |
54 | 0 | } Unexecuted instantiation: encode.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_frame.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_modular.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_patch_dictionary.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_dot_dictionary.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_detect_dots.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_debug_image.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_quant_weights.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_photon_noise.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_noise.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_heuristics.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_cache.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_group.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: enc_ac_strategy.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_cache.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_external_image.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_frame.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_group.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_modular.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: dec_noise.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: decode.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: epf.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: passes_state.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: quant_weights.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: stage_blending.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: stage_epf.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: stage_noise.cc:jxl::IndexAndFrac(float) Unexecuted instantiation: stage_write.cc:jxl::IndexAndFrac(float) |
55 | | |
56 | | struct NoiseLevel { |
57 | | float noise_level; |
58 | | float intensity; |
59 | | }; |
60 | | |
61 | | } // namespace jxl |
62 | | |
63 | | #endif // LIB_JXL_NOISE_H_ |