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

107 {
108 u16 n = xyMap.getTotal();
109 u16 outputWidth = xyMap.getWidth();
110 u16 outputHeight = xyMap.getHeight();
111 const u16 scale_factor = 256; // Using 8 bits for the fractional part
112
113 for (u16 y = 0; y < outputHeight; y++) {
114 for (u16 x = 0; x < outputWidth; x++) {
115 // Calculate the corresponding position in the input grid
116 u32 fx = ((u32)x * (inputWidth - 1) * scale_factor) /
117 (outputWidth - 1);
118 u32 fy = ((u32)y * (inputHeight - 1) * scale_factor) /
119 (outputHeight - 1);
120
121 u16 ix = fx / scale_factor; // Integer part of x
122 u16 iy = fy / scale_factor; // Integer part of y
123 u16 dx = fx % scale_factor; // Fractional part of x
124 u16 dy = fy % scale_factor; // Fractional part of y
125
126 u16 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
127 u16 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
128
129 u16 i00 = iy * inputWidth + ix;
130 u16 i10 = iy * inputWidth + ix1;
131 u16 i01 = iy1 * inputWidth + ix;
132 u16 i11 = iy1 * inputWidth + ix1;
133
134 CRGB c00 = input[i00];
135 CRGB c10 = input[i10];
136 CRGB c01 = input[i01];
137 CRGB c11 = input[i11];
138
139 CRGB result;
140 result.r = bilinearInterpolate(c00.r, c10.r, c01.r, c11.r, dx, dy);
141 result.g = bilinearInterpolate(c00.g, c10.g, c01.g, c11.g, dx, dy);
142 result.b = bilinearInterpolate(c00.b, c10.b, c01.b, c11.b, dx, dy);
143
144 u16 idx = xyMap.mapToIndex(x, y);
145 if (idx < n) {
146 output[idx] = result;
147 }
148 }
149 }
150}
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::XYMap xyMap
Definition ColorBoost.h:61
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, 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: