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 63 of file upscale.cpp.

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

References bilinearInterpolatePowerOf2(), x, and y.

Referenced by upscale().

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