Coverage Report

Created: 2025-07-23 08:18

/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
constexpr float kNoisePrecision = 1024.0f;  // 10 bits
23
constexpr float kNoiseLutMax = 1023.4999f / kNoisePrecision;
24
// REQUIRED: values up to kNoiseMax
25
// static_assert(std::lround(kNoiseMax * kNoisePrecision) == 1023);
26
27
struct NoiseParams {
28
  // LUT index is an intensity of pixel / mean intensity of patch
29
  static constexpr size_t kNumNoisePoints = 8;
30
  using Lut = std::array<float, kNumNoisePoints>;
31
32
  Lut lut;
33
34
0
  void Clear() {
35
0
    for (float& i : lut) i = 0.f;
36
0
  }
37
78.5k
  bool HasAny() const {
38
104k
    for (float i : lut) {
39
104k
      if (std::abs(i) > 1e-3f) return true;
40
104k
    }
41
535
    return false;
42
78.5k
  }
43
};
44
45
0
static inline std::pair<int, float> IndexAndFrac(float x) {
46
0
  constexpr size_t kScaleNumerator = NoiseParams::kNumNoisePoints - 2;
47
  // TODO(user): instead of 1, this should be a proper Y range.
48
0
  constexpr float kScale = kScaleNumerator / 1.0f;
49
0
  float scaled_x = std::max(0.f, x * kScale);
50
0
  float floor_x;
51
0
  float frac_x = std::modf(scaled_x, &floor_x);
52
0
  if (JXL_UNLIKELY(scaled_x >= kScaleNumerator + 1)) {
53
0
    floor_x = kScaleNumerator;
54
0
    frac_x = 1.f;
55
0
  }
56
0
  return std::make_pair(static_cast<int>(floor_x), frac_x);
57
0
}
Unexecuted instantiation: encode.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: decode.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: quant_weights.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_frame.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_group.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_heuristics.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_modular.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_noise.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_patch_dictionary.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_photon_noise.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_quant_weights.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: epf.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: passes_state.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)
Unexecuted instantiation: enc_ac_strategy.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_cache.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_debug_image.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_dot_dictionary.cc:jxl::IndexAndFrac(float)
Unexecuted instantiation: enc_detect_dots.cc:jxl::IndexAndFrac(float)
58
59
struct NoiseLevel {
60
  float noise_level;
61
  float intensity;
62
};
63
64
}  // namespace jxl
65
66
#endif  // LIB_JXL_NOISE_H_