Coverage Report

Created: 2026-06-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/base/common.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
#ifndef LIB_JXL_BASE_COMMON_H_
7
#define LIB_JXL_BASE_COMMON_H_
8
9
// Shared constants and helper functions.
10
11
#include <array>
12
#include <cstddef>
13
#include <cstdint>
14
#include <cstdio>
15
#include <limits>
16
#include <memory>
17
#include <string>
18
#include <type_traits>
19
#include <vector>
20
21
#if JXL_COMPILER_MSVC
22
#include <intrin.h>
23
#endif
24
25
#include "lib/jxl/base/compiler_specific.h"
26
27
namespace jxl {
28
// Some enums and typedefs used by more than one header file.
29
30
constexpr size_t kBitsPerByte = 8;  // more clear than CHAR_BIT
31
32
47.0k
constexpr inline size_t RoundUpBitsToByteMultiple(size_t bits) {
33
47.0k
  return (bits + 7) & ~static_cast<size_t>(7);
34
47.0k
}
35
36
26.7k
constexpr inline size_t RoundUpToBlockDim(size_t dim) {
37
26.7k
  return (dim + 7) & ~static_cast<size_t>(7);
38
26.7k
}
39
40
template <typename U,
41
          class = typename std::enable_if<std::is_unsigned<U>::value>::type>
42
83.9M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
83.9M
  sum = a + b;
44
83.9M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
83.9M
}
decode.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
157k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
157k
  sum = a + b;
44
157k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
157k
}
fields.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
1.75M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
1.75M
  sum = a + b;
44
1.75M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
1.75M
}
memory_manager_internal.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
82.0M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
82.0M
  sum = a + b;
44
82.0M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
82.0M
}
dec_external_image.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
2.19k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
2.19k
  sum = a + b;
44
2.19k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
2.19k
}
Unexecuted instantiation: enc_external_image.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
46
47
template <typename U,
48
          class = typename std::enable_if<std::is_unsigned<U>::value>::type>
49
39.4M
static inline bool SafeMul(const U a, const U b, U& product) {
50
39.4M
  product = 0;
51
39.4M
  if (a == 0 || b == 0) return true;
52
39.4M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
39.4M
  product = a * b;
54
39.4M
  return true;
55
39.4M
}
decode.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
344k
static inline bool SafeMul(const U a, const U b, U& product) {
50
344k
  product = 0;
51
344k
  if (a == 0 || b == 0) return true;
52
344k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
344k
  product = a * b;
54
344k
  return true;
55
344k
}
enc_heuristics.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
13.4k
static inline bool SafeMul(const U a, const U b, U& product) {
50
13.4k
  product = 0;
51
13.4k
  if (a == 0 || b == 0) return true;
52
13.4k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
13.4k
  product = a * b;
54
13.4k
  return true;
55
13.4k
}
dec_external_image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
4.39k
static inline bool SafeMul(const U a, const U b, U& product) {
50
4.39k
  product = 0;
51
4.39k
  if (a == 0 || b == 0) return true;
52
4.39k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
4.39k
  product = a * b;
54
4.39k
  return true;
55
4.39k
}
image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
39.1M
static inline bool SafeMul(const U a, const U b, U& product) {
50
39.1M
  product = 0;
51
39.1M
  if (a == 0 || b == 0) return true;
52
39.1M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
39.1M
  product = a * b;
54
39.1M
  return true;
55
39.1M
}
Unexecuted instantiation: enc_adaptive_quantization.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Unexecuted instantiation: enc_external_image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
56
57
22.5M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
22.5M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
22.5M
  return __builtin_sub_overflow(a, b, &c);
61
#elif JXL_COMPILER_MSVC >= 1937
62
  return _sub_overflow_i32(/*carry*/ 0, a, b, &c);
63
#else
64
  uint32_t ua = static_cast<uint32_t>(a);
65
  uint32_t ub = static_cast<uint32_t>(b);
66
  uint32_t uc = ua - ub;
67
  c = static_cast<int32_t>(uc);
68
  return !!(((ua ^ ub) & (ua ^ uc)) >> 31);
69
#endif
70
22.5M
}
Unexecuted instantiation: encode.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_jpeg_data.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_jpeg_data_reader.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_jpeg_huffman_decode.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: color_encoding_internal.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: decode.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: fields.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: frame_header.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: headers.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: icc_codec.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: icc_codec_common.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_metadata.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: loop_filter.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: luminance.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: memory_manager_internal.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: encoding.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: modular_image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: squeeze_params.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: transform.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: quant_weights.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: quantizer.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: decode_to_jpeg.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_jpeg_data.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_jpeg_data_writer.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: jpeg_data.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_aux_out.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_bit_writer.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_fast_lossless.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_fields.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_frame.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_group.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_heuristics.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_icc_codec.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_modular.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_modular_simd.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_patch_dictionary.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_photon_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_progressive_split.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_quant_weights.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_splines.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_toc.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_xyb.cc:jxl::SubOverflow(int, int, int&)
enc_encoding.cc:jxl::SubOverflow(int, int, int&)
Line
Count
Source
57
22.5M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
22.5M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
22.5M
  return __builtin_sub_overflow(a, b, &c);
61
#elif JXL_COMPILER_MSVC >= 1937
62
  return _sub_overflow_i32(/*carry*/ 0, a, b, &c);
63
#else
64
  uint32_t ua = static_cast<uint32_t>(a);
65
  uint32_t ub = static_cast<uint32_t>(b);
66
  uint32_t uc = ua - ub;
67
  c = static_cast<int32_t>(uc);
68
  return !!(((ua ^ ub) & (ua ^ uc)) >> 31);
69
#endif
70
22.5M
}
Unexecuted instantiation: enc_ma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_rct.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_transform.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: ac_strategy.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: chroma_from_luma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: compressed_dc.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_ans.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_bit_reader.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_cache.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_context_map.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_external_image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_frame.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_group.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_huffman.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_modular.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_patch_dictionary.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_xyb.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: entropy_coder.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: epf.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_bundle.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_ops.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_ma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: palette.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: rct.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: squeeze.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: opsin_params.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: passes_state.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: render_pipeline.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: simple_render_pipeline.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_blending.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_chroma_upsampling.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_cms.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_epf.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_from_linear.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_gaborish.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_patches.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_splines.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_spot.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_to_linear.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_tone_mapping.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_upsampling.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_write.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_xyb.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: stage_ycbcr.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: splines.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: toc.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: butteraugli.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_ac_strategy.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_adaptive_quantization.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_ans.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_ans_simd.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_butteraugli_comparator.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_cache.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_cluster.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_coeff_order.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_context_map.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_convolve_separable5.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_debug_image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_dot_dictionary.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_entropy_coder.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_external_image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_gaborish.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_huffman.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_huffman_tree.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_image_bundle.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_lz77.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_palette.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_squeeze.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: alpha.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: ans_common.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: blending.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: coeff_order.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: convolve_slow.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: convolve_symmetric5.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: low_memory_render_pipeline.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: render_pipeline_stage.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_detect_dots.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_linalg.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_group_border.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: jxl_cms.cc:jxl::SubOverflow(int, int, int&)
71
72
template <typename T1, typename T2>
73
150M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
150M
  return (a + b - 1) / b;
75
150M
}
unsigned long jxl::DivCeil<unsigned long, unsigned long>(unsigned long, unsigned long)
Line
Count
Source
73
133M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
133M
  return (a + b - 1) / b;
75
133M
}
unsigned long jxl::DivCeil<unsigned long, int>(unsigned long, int)
Line
Count
Source
73
15.5M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
15.5M
  return (a + b - 1) / b;
75
15.5M
}
int jxl::DivCeil<int, int>(int, int)
Line
Count
Source
73
790k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
790k
  return (a + b - 1) / b;
75
790k
}
unsigned long jxl::DivCeil<unsigned long, long>(unsigned long, long)
Line
Count
Source
73
727k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
727k
  return (a + b - 1) / b;
75
727k
}
76
77
// Works for any `align`; if a power of two, compiler emits ADD+AND.
78
111M
constexpr inline size_t RoundUpTo(size_t what, size_t align) {
79
111M
  return DivCeil(what, align) * align;
80
111M
}
81
82
constexpr double kPi = 3.14159265358979323846264338327950288;
83
84
// Multiplier for conversion of log2(x) result to ln(x).
85
// print(1.0 / math.log2(math.e))
86
constexpr float kInvLog2e = 0.6931471805599453;
87
88
// Reasonable default for sRGB, matches common monitors. We map white to this
89
// many nits (cd/m^2) by default. Butteraugli was tuned for 250 nits, which is
90
// very close.
91
// NB: This constant is not very "base", but it is shared between modules.
92
static constexpr float kDefaultIntensityTarget = 255;
93
94
template <typename T>
95
constexpr T Pi(T multiplier) {
96
  return static_cast<T>(multiplier * kPi);
97
}
98
99
// Prior to C++14 (i.e. C++11): provide our own make_unique
100
#if __cplusplus < 201402L
101
template <typename T, typename... Args>
102
std::unique_ptr<T> make_unique(Args&&... args) {
103
  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
104
}
105
#else
106
using std::make_unique;
107
#endif
108
109
template <typename T>
110
struct UninitializedAllocator : std::allocator<T> {
111
  static_assert(std::is_trivially_copyable<T>::value,
112
                "Uninitialized values have to be trivially destructible");
113
  using value_type = T;
114
115
28.8k
  UninitializedAllocator() noexcept = default;
116
  UninitializedAllocator(const UninitializedAllocator& other) noexcept =
117
      default;
118
119
  template <typename U>
120
  explicit UninitializedAllocator(
121
      const UninitializedAllocator<U>& other) noexcept {}
122
123
  template <typename U>
124
  struct rebind {
125
    using other = UninitializedAllocator<U>;
126
  };
127
128
  template <typename U, typename... Args>
129
534k
  void construct(U* place, Args&&... args) {}
130
131
  template <typename U>
132
534k
  void destroy(U* place) {}
133
};
134
135
template <typename T>
136
using uninitialized_vector = std::vector<T, UninitializedAllocator<T>>;
137
138
template <typename T>
139
28.8k
uninitialized_vector<T> make_uninitialized_vector(size_t n) {
140
28.8k
  return uninitialized_vector<T>(n, UninitializedAllocator<T>());
141
28.8k
}
142
143
typedef std::array<float, 3> Color;
144
145
// Backported std::experimental::to_array
146
147
template <typename T>
148
using remove_cv_t = typename std::remove_cv<T>::type;
149
150
template <size_t... I>
151
struct index_sequence {};
152
153
template <size_t N, size_t... I>
154
struct make_index_sequence : make_index_sequence<N - 1, N - 1, I...> {};
155
156
template <size_t... I>
157
struct make_index_sequence<0, I...> : index_sequence<I...> {};
158
159
namespace detail {
160
161
template <typename T, size_t N, size_t... I>
162
constexpr auto to_array(T (&&arr)[N], index_sequence<I...> _)
163
0
    -> std::array<remove_cv_t<T>, N> {
164
0
  return {{std::move(arr[I])...}};
165
0
}
166
167
}  // namespace detail
168
169
template <typename T, size_t N>
170
0
constexpr auto to_array(T (&&arr)[N]) -> std::array<remove_cv_t<T>, N> {
171
0
  return detail::to_array(std::move(arr), make_index_sequence<N>());
172
0
}
173
174
template <typename T>
175
487M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
487M
  return val < low ? low : val > hi ? hi : val;
177
487M
}
float jxl::Clamp1<float>(float, float, float)
Line
Count
Source
175
347M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
347M
  return val < low ? low : val > hi ? hi : val;
177
347M
}
double jxl::Clamp1<double>(double, double, double)
Line
Count
Source
175
105k
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
105k
  return val < low ? low : val > hi ? hi : val;
177
105k
}
int jxl::Clamp1<int>(int, int, int)
Line
Count
Source
175
140M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
140M
  return val < low ? low : val > hi ? hi : val;
177
140M
}
Unexecuted instantiation: unsigned char jxl::Clamp1<unsigned char>(unsigned char, unsigned char, unsigned char)
Unexecuted instantiation: long jxl::Clamp1<long>(long, long, long)
178
179
// conversion from integer to string.
180
template <typename T>
181
20.8k
std::string ToString(T n) {
182
20.8k
  char data[32] = {};
183
20.8k
  if (std::is_floating_point<T>::value) {
184
    // float
185
20.8k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
20.8k
  } else if (std::is_unsigned<T>::value) {
187
    // unsigned
188
0
    snprintf(data, sizeof(data), "%llu", static_cast<unsigned long long>(n));
189
0
  } else {
190
    // signed
191
0
    snprintf(data, sizeof(data), "%lld", static_cast<long long>(n));
192
0
  }
193
20.8k
  return data;
194
20.8k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > jxl::ToString<double>(double)
Line
Count
Source
181
20.8k
std::string ToString(T n) {
182
20.8k
  char data[32] = {};
183
20.8k
  if (std::is_floating_point<T>::value) {
184
    // float
185
20.8k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
20.8k
  } else if (std::is_unsigned<T>::value) {
187
    // unsigned
188
0
    snprintf(data, sizeof(data), "%llu", static_cast<unsigned long long>(n));
189
0
  } else {
190
    // signed
191
0
    snprintf(data, sizeof(data), "%lld", static_cast<long long>(n));
192
0
  }
193
20.8k
  return data;
194
20.8k
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > jxl::ToString<int>(int)
195
196
#define JXL_JOIN(x, y) JXL_DO_JOIN(x, y)
197
#define JXL_DO_JOIN(x, y) x##y
198
199
}  // namespace jxl
200
201
#endif  // LIB_JXL_BASE_COMMON_H_