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

21 {
22 const u16 scale_factor = 256; // Using 8 bits for the fractional part
23
24 for (u16 y = 0; y < outputHeight; y++) {
25 for (u16 x = 0; x < outputWidth; x++) {
26 // Calculate the corresponding position in the input grid
27 u32 fx = ((u32)x * (inputWidth - 1) * scale_factor) /
28 (outputWidth - 1);
29 u32 fy = ((u32)y * (inputHeight - 1) * scale_factor) /
30 (outputHeight - 1);
31
32 u16 ix = fx / scale_factor; // Integer part of x
33 u16 iy = fy / scale_factor; // Integer part of y
34 u16 dx = fx % scale_factor; // Fractional part of x
35 u16 dy = fy % scale_factor; // Fractional part of y
36
37 u16 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
38 u16 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
39
40 // Direct array access - no XY mapping overhead
41 u16 i00 = iy * inputWidth + ix;
42 u16 i10 = iy * inputWidth + ix1;
43 u16 i01 = iy1 * inputWidth + ix;
44 u16 i11 = iy1 * inputWidth + ix1;
45
46 CRGB c00 = input[i00];
47 CRGB c10 = input[i10];
48 CRGB c01 = input[i01];
49 CRGB c11 = input[i11];
50
52 result.r = bilinearInterpolate(c00.r, c10.r, c01.r, c11.r, dx, dy);
53 result.g = bilinearInterpolate(c00.g, c10.g, c01.g, c11.g, dx, dy);
54 result.b = bilinearInterpolate(c00.b, c10.b, c01.b, c11.b, dx, dy);
55
56 // Direct array access - no XY mapping overhead
57 u16 idx = y * outputWidth + x;
58 output[idx] = result;
59 }
60 }
61}
int y
Definition simple.h:93
int x
Definition simple.h:92
Result type for promise operations.
u8 bilinearInterpolate(u8 v00, u8 v10, u8 v01, u8 v11, u16 dx, u16 dy)
Definition upscale.cpp:151
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86

References bilinearInterpolate(), x, and y.

Referenced by upscale().

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