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