blob: f08736310c7341155ed57f5cb4d01c7b7e512a41 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2017 The Chromium Authors
hubbeb97f42d2017-01-27 21:04:092// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Elly Fong-Jonesa8ea66f12024-07-24 18:37:105#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 Pitrus802fc7d2022-10-21 03:55:0010#include <cstring>
11
hubbeb97f42d2017-01-27 21:04:0912#include "ui/gfx/half_float.h"
13
14namespace gfx {
15
16void 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 Pitrus802fc7d2022-10-21 03:55:0019 uint32_t tmp2;
20 std::memcpy(&tmp2, &tmp, 4);
21 tmp2 += (1 << 12);
hubbeb97f42d2017-01-27 21:04:0922 output[i] = (tmp2 & 0x80000000UL) >> 16 | (tmp2 >> 13);
23 }
24}
Nico Weberca5f9592019-01-31 14:35:4125
26} // namespace gfx