35 halp_meta(name,
"Array to texture")
36 halp_meta(category,
"Visuals/Utilities")
37 halp_meta(c_name,
"array_to_texture")
38 halp_meta(description,
"Convert an array of values into texture pixel data.")
39 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/array-to-texture.html")
40 halp_meta(uuid,
"bb5dc513-3430-4671-8c74-2bba78e53709")
44 struct : halp::val_port<
"Input", std::vector<float>>
48 struct : halp::xy_spinboxes_i32<
"Size">
52 struct : halp::enum_t<halp::custom_texture::texture_format,
"Format">
60 halp::texture_output<
"Output", halp::custom_texture> main;
65 const auto format = inputs.format;
66 const auto sz = inputs.size.value;
67 outputs.main.texture.request_format = format;
68 outputs.main.create(sz.x, sz.y);
69 std::size_t to_copy = sz.x * sz.y * outputs.main.texture.components(format);
70 const auto& value = inputs.in.value;
71 to_copy = std::min(to_copy, value.size());
73 auto* out = outputs.main.texture.bytes;
74 using enum halp::custom_texture::texture_format;
83 std::copy_n(value.data(), to_copy, (uint8_t*)out);
88 std::copy_n(value.data(), to_copy, (uint16_t*)out);
94 std::copy_n(value.data(), to_copy, (uint32_t*)out);
99 std::copy_n(value.data(), to_copy, (
float*)out);
105#if (SCORE_LIBC_HAS_FLOAT16 && SCORE_COMPILER_HAS_FLOAT16)
106 std::copy_n(value.data(), to_copy, (_Float16*)out);
111 auto* dst = (uint16_t*)out;
112 for(std::size_t i = 0; i < to_copy; i++)
114 const float f = value.data()[i];
116 std::memcpy(&x, &f, 4);
117 const uint32_t sign = (x >> 16) & 0x8000;
120 dst[i] = sign | 0x7C00 | (x > 0x7F800000 ? 0x200 : 0);
121 else if(x < 0x38800000)
123 const uint32_t shift = 126 - (x >> 23);
127 const uint32_t mant = (x & 0x7FFFFF) | 0x800000;
128 half = mant >> shift;
129 half += ((mant >> (shift - 1)) & 1)
130 && ((mant & ((1u << (shift - 1)) - 1)) || (half & 1));
132 dst[i] = sign | half;
136 uint32_t half = ((x - 0x38000000) >> 13);
137 half += ((x >> 12) & 1) && ((x & 0xFFF) || (half & 1));
138 dst[i] = sign | half;
148 outputs.main.upload();
Definition ArrayToTexture.hpp:33
Definition ArrayToTexture.hpp:43