5 {
6union FloatUIntUnion {
7 uint32_t fUInt;
8 float fFloat;
9};
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);
21}
22
24 canvas->
scale(16, 16);
27 bitmap.allocPixels(imageInfo);
31 auto H = [](
float c) -> uint16_t {
32 return FloatToHalf(c);
33 };
34
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)) {
46 }
48 if (
bitmap.writePixels(bluePixmap, 0, 0)) {
50 }
51}
52}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
constexpr SkColor SK_ColorGREEN
static int sign(SkScalar x)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
void scale(SkScalar sx, SkScalar sy)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
size_t minRowBytes() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)