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

◆ upscaleRectangularPowerOf2()

void fl::upscaleRectangularPowerOf2 ( const CRGB * input,
CRGB * output,
u8 inputWidth,
u8 inputHeight,
u8 outputWidth,
u8 outputHeight )

Optimized upscale for rectangular/line-by-line XY maps (power-of-2 version).

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

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

63 {
64 for (u8 y = 0; y < outputHeight; y++) {
65 for (u8 x = 0; x < outputWidth; x++) {
66 // Use 8-bit fixed-point arithmetic with 8 fractional bits
67 // (scale factor of 256)
68 u16 fx = ((u16)x * (inputWidth - 1) * 256) / (outputWidth - 1);
69 u16 fy = ((u16)y * (inputHeight - 1) * 256) / (outputHeight - 1);
70
71 u8 ix = fx >> 8; // Integer part
72 u8 iy = fy >> 8;
73 u8 dx = fx & 0xFF; // Fractional part
74 u8 dy = fy & 0xFF;
75
76 u8 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
77 u8 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
78
79 // Direct array access - no XY mapping overhead
80 u16 i00 = iy * inputWidth + ix;
81 u16 i10 = iy * inputWidth + ix1;
82 u16 i01 = iy1 * inputWidth + ix;
83 u16 i11 = iy1 * inputWidth + ix1;
84
85 CRGB c00 = input[i00];
86 CRGB c10 = input[i10];
87 CRGB c01 = input[i01];
88 CRGB c11 = input[i11];
89
91 result.r =
92 bilinearInterpolatePowerOf2(c00.r, c10.r, c01.r, c11.r, dx, dy);
93 result.g =
94 bilinearInterpolatePowerOf2(c00.g, c10.g, c01.g, c11.g, dx, dy);
95 result.b =
96 bilinearInterpolatePowerOf2(c00.b, c10.b, c01.b, c11.b, dx, dy);
97
98 // Direct array access - no XY mapping overhead
99 u16 idx = y * outputWidth + x;
100 output[idx] = result;
101 }
102 }
103}
unsigned char u8
Definition stdint.h:131
u8 bilinearInterpolatePowerOf2(u8 v00, u8 v10, u8 v01, u8 v11, u8 dx, u8 dy)
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References bilinearInterpolatePowerOf2(), x, and y.

Referenced by upscale().

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