FastLED 3.10.8
Loading...
Searching...
No Matches
splat.cpp.hpp
Go to the documentation of this file.
1
2#include "fl/gfx/tile2x2.h"
3#include "fl/gfx/splat.h"
4#include "fl/math/math.h"
5#include "fl/stl/noexcept.h"
6
7namespace fl {
8
9static u8 to_uint8(float f) FL_NO_EXCEPT {
10 // convert to [0..255] range
11 u8 i = static_cast<u8>(f * 255.0f + .5f);
12 return fl::min(i, 255);
13}
14
16 // 1) collect values.
17 float x = xy.x;
18 float y = xy.y;
19
20 // 2) integer cell indices
21 i16 cx = static_cast<i16>(floorf(x));
22 i16 cy = static_cast<i16>(floorf(y));
23
24 // 3) fractional offsets in [0..1)
25 float fx = x - cx;
26 float fy = y - cy;
27
28 // 4) bilinear weights
29 float w_ll = (1 - fx) * (1 - fy); // lower‑left
30 float w_lr = fx * (1 - fy); // lower‑right
31 float w_ul = (1 - fx) * fy; // upper‑left
32 float w_ur = fx * fy; // upper‑right
33
34 // 5) build Tile2x2_u8 anchored at (cx,cy)
35 Tile2x2_u8 out(vec2<u16>(cx, cy));
36 out.lower_left() = to_uint8(w_ll);
37 out.lower_right() = to_uint8(w_lr);
38 out.upper_left() = to_uint8(w_ul);
39 out.upper_right() = to_uint8(w_ur);
40
41 return out;
42}
43
44} // namespace
unsigned int xy(unsigned int x, unsigned int y)
u8 & lower_left() FL_NO_EXCEPT
Definition tile2x2.h:37
u8 & lower_right() FL_NO_EXCEPT
Definition tile2x2.h:39
u8 & upper_left() FL_NO_EXCEPT
Definition tile2x2.h:38
u8 & upper_right() FL_NO_EXCEPT
Definition tile2x2.h:40
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
vec2< float > vec2f
Definition geometry.h:333
Tile2x2_u8 splat(vec2f xy) FL_NO_EXCEPT
"Splat" as in "splat pixel rendering" takes a pixel value in float x,y coordinates and "splats" it in...
Definition splat.cpp.hpp:15
float floorf(float value) FL_NO_EXCEPT
Definition math.h:312
static u8 to_uint8(float f) FL_NO_EXCEPT
Definition splat.cpp.hpp:9
Base definition for an LED controller.
Definition crgb.hpp:179