FastLED 3.9.15
Loading...
Searching...
No Matches

◆ upscaleArbitrary()

void fl::upscaleArbitrary ( const CRGB * input,
CRGB * output,
u16 inputWidth,
u16 inputHeight,
const fl::XYMap & xyMap )

Performs bilinear interpolation for upscaling an image.

Parameters
outputThe output grid to write into the interpolated values.
inputThe input grid to read from.
inputWidthThe width of the input grid.
inputHeightThe height of the input grid.
xyMapThe XYMap to use to determine where to write the pixel. If the pixel is mapped outside of the range then it is clipped.

Definition at line 105 of file upscale.cpp.hpp.

106 {
107 u16 n = xyMap.getTotal();
108 u16 outputWidth = xyMap.getWidth();
109 u16 outputHeight = xyMap.getHeight();
110 const u16 scale_factor = 256; // Using 8 bits for the fractional part
111
112 for (u16 y = 0; y < outputHeight; y++) {
113 for (u16 x = 0; x < outputWidth; x++) {
114 // Calculate the corresponding position in the input grid
115 u32 fx = ((u32)x * (inputWidth - 1) * scale_factor) /
116 (outputWidth - 1);
117 u32 fy = ((u32)y * (inputHeight - 1) * scale_factor) /
118 (outputHeight - 1);
119
120 u16 ix = fx / scale_factor; // Integer part of x
121 u16 iy = fy / scale_factor; // Integer part of y
122 u16 dx = fx % scale_factor; // Fractional part of x
123 u16 dy = fy % scale_factor; // Fractional part of y
124
125 u16 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
126 u16 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
127
128 u16 i00 = iy * inputWidth + ix;
129 u16 i10 = iy * inputWidth + ix1;
130 u16 i01 = iy1 * inputWidth + ix;
131 u16 i11 = iy1 * inputWidth + ix1;
132
133 CRGB c00 = input[i00];
134 CRGB c10 = input[i10];
135 CRGB c01 = input[i01];
136 CRGB c11 = input[i11];
137
138 CRGB result;
139 result.r = bilinearInterpolate(c00.r, c10.r, c01.r, c11.r, dx, dy);
140 result.g = bilinearInterpolate(c00.g, c10.g, c01.g, c11.g, dx, dy);
141 result.b = bilinearInterpolate(c00.b, c10.b, c01.b, c11.b, dx, dy);
142
143 u16 idx = xyMap.mapToIndex(x, y);
144 if (idx < n) {
145 output[idx] = result;
146 }
147 }
148 }
149}
fl::XYMap xyMap
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
u8 bilinearInterpolate(u8 v00, u8 v10, u8 v01, u8 v11, u16 dx, u16 dy)
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References bilinearInterpolate(), x, xyMap, and y.

Referenced by fl::ScaleUp::expand(), and upscale().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: