Coverage Report

Created: 2026-05-16 07:22

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
24.3k
constexpr inline size_t RoundUpBitsToByteMultiple(size_t bits) {
33
24.3k
  return (bits + 7) & ~static_cast<size_t>(7);
34
24.3k
}
35
36
14.1k
constexpr inline size_t RoundUpToBlockDim(size_t dim) {
37
14.1k
  return (dim + 7) & ~static_cast<size_t>(7);
38
14.1k
}
39
40
template <typename U,
41
          class = typename std::enable_if<std::is_unsigned<U>::value>::type>
42
59.7M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
59.7M
  sum = a + b;
44
59.7M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
59.7M
}
Unexecuted instantiation: enc_external_image.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
dec_external_image.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
1.15k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
1.15k
  sum = a + b;
44
1.15k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
1.15k
}
decode.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
13.1k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
13.1k
  sum = a + b;
44
13.1k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
13.1k
}
fields.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
45.3k
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
45.3k
  sum = a + b;
44
45.3k
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
45.3k
}
memory_manager_internal.cc:bool jxl::SafeAdd<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
42
59.6M
static inline bool SafeAdd(const U a, const U b, U& sum) {
43
59.6M
  sum = a + b;
44
59.6M
  return sum >= a;  // no need to check b - either sum >= both or < both.
45
59.6M
}
46
47
template <typename U,
48
          class = typename std::enable_if<std::is_unsigned<U>::value>::type>
49
29.1M
static inline bool SafeMul(const U a, const U b, U& product) {
50
29.1M
  product = 0;
51
29.1M
  if (a == 0 || b == 0) return true;
52
29.1M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
29.1M
  product = a * b;
54
29.1M
  return true;
55
29.1M
}
Unexecuted instantiation: enc_external_image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
enc_heuristics.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
7.95k
static inline bool SafeMul(const U a, const U b, U& product) {
50
7.95k
  product = 0;
51
7.95k
  if (a == 0 || b == 0) return true;
52
7.95k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
7.95k
  product = a * b;
54
7.95k
  return true;
55
7.95k
}
Unexecuted instantiation: enc_adaptive_quantization.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
dec_external_image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
2.30k
static inline bool SafeMul(const U a, const U b, U& product) {
50
2.30k
  product = 0;
51
2.30k
  if (a == 0 || b == 0) return true;
52
2.30k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
2.30k
  product = a * b;
54
2.30k
  return true;
55
2.30k
}
decode.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
39.2k
static inline bool SafeMul(const U a, const U b, U& product) {
50
39.2k
  product = 0;
51
39.2k
  if (a == 0 || b == 0) return true;
52
39.2k
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
39.2k
  product = a * b;
54
39.2k
  return true;
55
39.2k
}
image.cc:bool jxl::SafeMul<unsigned long, void>(unsigned long, unsigned long, unsigned long&)
Line
Count
Source
49
29.1M
static inline bool SafeMul(const U a, const U b, U& product) {
50
29.1M
  product = 0;
51
29.1M
  if (a == 0 || b == 0) return true;
52
29.1M
  if (b > (std::numeric_limits<U>::max() / a)) return false;
53
29.1M
  product = a * b;
54
29.1M
  return true;
55
29.1M
}
56
57
12.9M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
12.9M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
12.9M
  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
12.9M
}
Unexecuted instantiation: encode.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_fields.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_bit_writer.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_icc_codec.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_ans.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_ans_simd.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_cluster.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_context_map.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_lz77.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_fast_lossless.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_frame.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_modular.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_patch_dictionary.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_detect_dots.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_convolve_separable5.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_linalg.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_gaborish.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_quant_weights.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_modular_simd.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_coeff_order.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&)
Unexecuted instantiation: enc_image_bundle.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_external_image.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_photon_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_noise.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_heuristics.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: butteraugli.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_adaptive_quantization.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_group.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_progressive_split.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_splines.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_chroma_from_luma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_ac_strategy.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_entropy_coder.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_aux_out.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: jxl_cms.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&)
enc_encoding.cc:jxl::SubOverflow(int, int, int&)
Line
Count
Source
57
12.9M
static inline bool SubOverflow(const int32_t a, const int32_t b, int32_t& c) {
58
  // Clang 3.8+ / GCC 5.1+
59
12.9M
#if JXL_COMPILER_GCC || JXL_COMPILER_CLANG
60
12.9M
  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
12.9M
}
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: enc_palette.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: enc_squeeze.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: ac_strategy.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: ans_common.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: chroma_from_luma.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: coeff_order.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: color_encoding_internal.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: compressed_dc.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: 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: blending.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: alpha.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: decode.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: 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.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_bundle.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_metadata.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: image_ops.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: dec_ma.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.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: rct.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: palette.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: quant_weights.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: quantizer.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: render_pipeline.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: low_memory_render_pipeline.cc:jxl::SubOverflow(int, int, int&)
Unexecuted instantiation: dec_group_border.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: render_pipeline_stage.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: 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&)
71
72
template <typename T1, typename T2>
73
63.8M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
63.8M
  return (a + b - 1) / b;
75
63.8M
}
unsigned long jxl::DivCeil<unsigned long, unsigned long>(unsigned long, unsigned long)
Line
Count
Source
73
56.2M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
56.2M
  return (a + b - 1) / b;
75
56.2M
}
unsigned long jxl::DivCeil<unsigned long, int>(unsigned long, int)
Line
Count
Source
73
6.93M
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
6.93M
  return (a + b - 1) / b;
75
6.93M
}
int jxl::DivCeil<int, int>(int, int)
Line
Count
Source
73
248k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
248k
  return (a + b - 1) / b;
75
248k
}
unsigned long jxl::DivCeil<unsigned long, long>(unsigned long, long)
Line
Count
Source
73
380k
constexpr inline T1 DivCeil(T1 a, T2 b) {
74
380k
  return (a + b - 1) / b;
75
380k
}
76
77
// Works for any `align`; if a power of two, compiler emits ADD+AND.
78
47.2M
constexpr inline size_t RoundUpTo(size_t what, size_t align) {
79
47.2M
  return DivCeil(what, align) * align;
80
47.2M
}
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
12.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
345k
  void construct(U* place, Args&&... args) {}
130
131
  template <typename U>
132
345k
  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
12.8k
uninitialized_vector<T> make_uninitialized_vector(size_t n) {
140
12.8k
  return uninitialized_vector<T>(n, UninitializedAllocator<T>());
141
12.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
478M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
478M
  return val < low ? low : val > hi ? hi : val;
177
478M
}
float jxl::Clamp1<float>(float, float, float)
Line
Count
Source
175
111M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
111M
  return val < low ? low : val > hi ? hi : val;
177
111M
}
double jxl::Clamp1<double>(double, double, double)
Line
Count
Source
175
13.9k
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
13.9k
  return val < low ? low : val > hi ? hi : val;
177
13.9k
}
int jxl::Clamp1<int>(int, int, int)
Line
Count
Source
175
366M
JXL_INLINE T Clamp1(T val, T low, T hi) {
176
366M
  return val < low ? low : val > hi ? hi : val;
177
366M
}
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
3.07k
std::string ToString(T n) {
182
3.07k
  char data[32] = {};
183
3.07k
  if (std::is_floating_point<T>::value) {
184
    // float
185
3.07k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
3.07k
  } 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
3.07k
  return data;
194
3.07k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > jxl::ToString<double>(double)
Line
Count
Source
181
3.07k
std::string ToString(T n) {
182
3.07k
  char data[32] = {};
183
3.07k
  if (std::is_floating_point<T>::value) {
184
    // float
185
3.07k
    snprintf(data, sizeof(data), "%g", static_cast<double>(n));
186
3.07k
  } 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
3.07k
  return data;
194
3.07k
}
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_