Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
hubbe | b97f42d | 2017-01-27 21:04:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Elly Fong-Jones | a8ea66f1 | 2024-07-24 18:37:10 | [diff] [blame] | 5 | #ifdef UNSAFE_BUFFERS_BUILD |
| 6 | // TODO(crbug.com/354829279): Remove this and convert code to safer constructs. |
| 7 | #pragma allow_unsafe_buffers |
| 8 | #endif |
| 9 | |
Bruno Pitrus | 802fc7d | 2022-10-21 03:55:00 | [diff] [blame] | 10 | #include <cstring> |
| 11 | |
hubbe | b97f42d | 2017-01-27 21:04:09 | [diff] [blame] | 12 | #include "ui/gfx/half_float.h" |
| 13 | |
| 14 | namespace gfx { |
| 15 | |
| 16 | void FloatToHalfFloat(const float* input, HalfFloat* output, size_t num) { |
| 17 | for (size_t i = 0; i < num; i++) { |
| 18 | float tmp = input[i] * 1.9259299444e-34f; |
Bruno Pitrus | 802fc7d | 2022-10-21 03:55:00 | [diff] [blame] | 19 | uint32_t tmp2; |
| 20 | std::memcpy(&tmp2, &tmp, 4); |
| 21 | tmp2 += (1 << 12); |
hubbe | b97f42d | 2017-01-27 21:04:09 | [diff] [blame] | 22 | output[i] = (tmp2 & 0x80000000UL) >> 16 | (tmp2 >> 13); |
| 23 | } |
| 24 | } |
Nico Weber | ca5f959 | 2019-01-31 14:35:41 | [diff] [blame] | 25 | |
| 26 | } // namespace gfx |