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

◆ upscaleRectangular()

void fl::upscaleRectangular ( const CRGB * input,
CRGB * output,
u16 inputWidth,
u16 inputHeight,
u16 outputWidth,
u16 outputHeight )

Optimized upscale for rectangular/line-by-line XY maps.

Parameters
inputThe input grid to read from.
outputThe output grid to write into the interpolated values.
inputWidthThe width of the input grid.
inputHeightThe height of the input grid.
outputWidthThe width of the output grid.
outputHeightThe height of the output grid. This version bypasses XY mapping overhead for rectangular layouts.

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

20 {
21 const u16 scale_factor = 256; // Using 8 bits for the fractional part
22
23 for (u16 y = 0; y < outputHeight; y++) {
24 for (u16 x = 0; x < outputWidth; x++) {
25 // Calculate the corresponding position in the input grid
26 u32 fx = ((u32)x * (inputWidth - 1) * scale_factor) /
27 (outputWidth - 1);
28 u32 fy = ((u32)y * (inputHeight - 1) * scale_factor) /
29 (outputHeight - 1);
30
31 u16 ix = fx / scale_factor; // Integer part of x
32 u16 iy = fy / scale_factor; // Integer part of y
33 u16 dx = fx % scale_factor; // Fractional part of x
34 u16 dy = fy % scale_factor; // Fractional part of y
35
36 u16 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
37 u16 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
38
39 // Direct array access - no XY mapping overhead
40 u16 i00 = iy * inputWidth + ix;
41 u16 i10 = iy * inputWidth + ix1;
42 u16 i01 = iy1 * inputWidth + ix;
43 u16 i11 = iy1 * inputWidth + ix1;
44
45 CRGB c00 = input[i00];
46 CRGB c10 = input[i10];
47 CRGB c01 = input[i01];
48 CRGB c11 = input[i11];
49
51 result.r = bilinearInterpolate(c00.r, c10.r, c01.r, c11.r, dx, dy);
52 result.g = bilinearInterpolate(c00.g, c10.g, c01.g, c11.g, dx, dy);
53 result.b = bilinearInterpolate(c00.b, c10.b, c01.b, c11.b, dx, dy);
54
55 // Direct array access - no XY mapping overhead
56 u16 idx = y * outputWidth + x;
57 output[idx] = result;
58 }
59 }
60}
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, and y.

Referenced by upscale().

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