roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
interpolation.cpp
Go to the documentation of this file.
2
3namespace roo_display {
4
6 if (c1 == c2) return c1;
7 uint16_t c1_a = c1.a();
8 uint16_t c2_a = c2.a();
10 int16_t f1 = 256 - fraction;
11 uint8_t a;
12 if (c1_a == c2_a) {
13 // Common case, e.g. both colors opaque. Leave fractions as-is.
14 a = c1_a;
15 } else {
16 uint16_t a_mult = (c1_a * f1 + c2_a * f2);
17 a = a_mult / 256;
18 if (c1_a == 0) {
19 f1 = 0;
20 f2 = 256;
21 } else if (c2_a == 0) {
22 f1 = 256;
23 f2 = 0;
24 } else {
25 f2 = (uint32_t)256 * f2 * c2_a / a_mult;
26 f1 = 256 - f2;
27 }
28 }
29 uint32_t mask1 = 0x00FF00FF;
30 uint32_t mask2 = 0x0000FF00;
32 (((((c1.asArgb() & mask1) * f1) + ((c2.asArgb() & mask1) * f2)) / 256) &
33 mask1) |
34 (((((c1.asArgb() & mask2) * f1) + ((c2.asArgb() & mask2) * f2)) / 256) &
35 mask2);
36 return Color(a << 24 | rgb);
37}
38
40 if (c1 == c2) return c1;
42 int16_t f1 = 256 - fraction;
43 uint32_t mask1 = 0x00FF00FF;
44 uint32_t mask2 = 0x0000FF00;
46 (((((c1.asArgb() & mask1) * f1) + ((c2.asArgb() & mask1) * f2)) / 256) &
47 mask1) |
48 (((((c1.asArgb() & mask2) * f1) + ((c2.asArgb() & mask2) * f2)) / 256) &
49 mask2);
50 return Color(0xFF000000 | rgb);
51}
52
56
57} // namespace roo_display
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
Defines 140 opaque HTML named colors.
Color InterpolateColorWithTransparency(Color c, int16_t fraction_color)
Equivalent to InterpolateColors(Transparent, c, fraction_color).
Color InterpolateColors(Color c1, Color c2, int16_t fraction)
Interpolate between two colors with fraction in [0, 256].
Color InterpolateOpaqueColors(Color c1, Color c2, int16_t fraction)
Interpolate between two opaque colors with fraction in [0, 256].