10uint16_t FloatToHalf(
float f) {
11 static const FloatUIntUnion magic = { 15 << 23 };
12 static const uint32_t round_mask = ~0xfffu;
13 FloatUIntUnion floatUnion;
14 floatUnion.fFloat = f;
15 uint32_t
sign = floatUnion.fUInt & 0x80000000u;
16 floatUnion.fUInt ^=
sign;
17 floatUnion.fUInt &= round_mask;
18 floatUnion.fFloat *= magic.fFloat;
19 floatUnion.fUInt -= round_mask;
20 return (floatUnion.fUInt >> 13) | (
sign >> 16);
24 canvas->
scale(16, 16);
27 bitmap.allocPixels(imageInfo);
31 auto H = [](
float c) -> uint16_t {
32 return FloatToHalf(c);
35 uint16_t red_f16[][4] = { {
H(1.0),
H(0.0),
H(0.0),
H(1.0) },
36 {
H(.75),
H(0.0),
H(0.0),
H(1.0) },
37 {
H(.50),
H(0.0),
H(0.0),
H(1.0) },
38 {
H(.25),
H(0.0),
H(0.0),
H(1.0) } };
39 uint16_t blue_f16[][4] = { {
H(0.0),
H(0.0),
H(1.0),
H(1.0) },
40 {
H(0.0),
H(0.0),
H(.75),
H(1.0) },
41 {
H(0.0),
H(0.0),
H(.50),
H(1.0) },
42 {
H(0.0),
H(0.0),
H(.25),
H(1.0) } };
44 if (
bitmap.writePixels(redPixmap, 0, 0)) {
48 if (
bitmap.writePixels(bluePixmap, 0, 0)) {