Coverage Report

Created: 2026-05-24 07:45

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
40.4k
constexpr inline size_t RoundUpBitsToByteMultiple(size_t bits) {
33
40.4k
  return (bits + 7) & ~static_cast<size_t>(7);
34
40.4k
}
35
36
23.2k
constexpr inline size_t RoundUpToBlockDim(size_t dim) {
37
23.2k
  return (dim + 7) & ~static_cast<size_t>(7);
38
23.2k
}
39
40
template <typename U,
41
          class = typename std::enable_if<std::is_unsigned<U>::value>::type>
42
74.4M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
74.4M
  sum = a + b;
44
74.4M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
74.4M
}
decode.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
147k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
147k
  sum = a + b;
44
147k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
147k
}
fields.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
1.70M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
1.70M
  sum = a + b;
44
1.70M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
1.70M
}
memory_manager_internal.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
72.6M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
72.6M
  sum = a + b;
44
72.6M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
72.6M
}
dec_external_image.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
1.84k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
1.84k
  sum = a + b;
44
1.84k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
1.84k
}
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
34.8M
static inline bool SafeMul(const U a, const U b, U& product) {
50
34.8M
  product = 0;
51
34.8M
  if (a == 0 || b == 0) return true;
52
34.8M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
34.8M
  product = a * b;
54
34.8M
  return true;
55
34.8M
}
decode.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
322k
static inline bool SafeMul(const U a, const U b, U& product) {
50
322k
  product = 0;
51
322k
  if (a == 0 || b == 0) return true;
52
322k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
322k
  product = a * b;
54
322k
  return true;
55
322k
}
enc_heuristics.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
11.8k
static inline bool SafeMul(const U a, const U b, U& product) {
50
11.8k
  product = 0;
51
11.8k
  if (a == 0 || b == 0) return true;
52
11.8k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
11.8k
  product = a * b;
54
11.8k
  return true;
55
11.8k
}
dec_external_image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
3.68k
static inline bool SafeMul(const U a, const U b, U& product) {
50
3.68k
  product = 0;
51
3.68k
  if (a == 0 || b == 0) return true;
52
3.68k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
3.68k
  product = a * b;
54
3.68k
  return true;
55
3.68k
}
image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
34.5M
static inline bool SafeMul(const U a, const U b, U& product) {
50
34.5M
  product = 0;
51
34.5M
  if (a == 0 || b == 0) return true;
52
34.5M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
34.5M
  product = a * b;
54
34.5M
  return true;
55
34.5M
}
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
17.2M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
17.2M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
17.2M
  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
17.2M
}
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
17.2M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
17.2M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
17.2M
  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
17.2M
}
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
131M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
131M
  return (a + b - 1) / b;
75
131M
}
unsigned long jxl::DivCeil<unsigned long, unsigned long>(unsigned long, unsigned long)
Line
Count
Source
73
115M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
115M
  return (a + b - 1) / b;
75
115M
}
unsigned long jxl::DivCeil<unsigned long, int>(unsigned long, int)
Line
Count
Source
73
14.1M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
14.1M
  return (a + b - 1) / b;
75
14.1M
}
int jxl::DivCeil<int, int>(int, int)
Line
Count
Source
73
732k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
732k
  return (a + b - 1) / b;
75
732k
}
unsigned long jxl::DivCeil<unsigned long, long>(unsigned long, long)
Line
Count
Source
73
662k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
662k
  return (a + b - 1) / b;
75
662k
}
76
77
// Works for any `align`; if a power of two, compiler emits ADD+AND.
78
96.7M
constexpr inline size_t RoundUpTo(size_t what, size_t align) {
79
96.7M
  return DivCeil(what, align) * align;
80
96.7M
}
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
24.7k
  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
453k
  void construct(U* place, Args&&... args) {}
130
131
  template <typename U>
132
453k
  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
24.7k
uninitialized_vector<T> make_uninitialized_vector(size_t n) {
140
24.7k
  return uninitialized_vector<T>(n, UninitializedAllocator<T>());
141
24.7k
}
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
424M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
424M
  return val < low ? low : val > hi ? hi : val;
177
424M
}
float jxl::Clamp1<float>(float, float, float)
Line
Count
Source
175
292M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
292M
  return val < low ? low : val > hi ? hi : val;
177
292M
}
double jxl::Clamp1<double>(double, double, double)
Line
Count
Source
175
104k
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
104k
  return val < low ? low : val > hi ? hi : val;
177
104k
}
int jxl::Clamp1<int>(int, int, int)
Line
Count
Source
175
131M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
131M
  return val < low ? low : val > hi ? hi : val;
177
131M
}
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
17.9k
std::string ToString(T n) {
182
17.9k
  char data[32] = {};
183
17.9k
  if (std::is_floating_point<T>::value) {
184
    // float
185
17.9k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
17.9k
  } 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
17.9k
  return data;
194
17.9k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > jxl::ToString<double>(double)
Line
Count
Source
181
17.9k
std::string ToString(T n) {
182
17.9k
  char data[32] = {};
183
17.9k
  if (std::is_floating_point<T>::value) {
184
    // float
185
17.9k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
17.9k
  } 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
17.9k
  return data;
194
17.9k
}
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_