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

◆ upscalePowerOf2()

void fl::upscalePowerOf2 ( const CRGB * input,
CRGB * output,
u8 inputWidth,
u8 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 170 of file upscale.cpp.

171 {
172 u8 width = xyMap.getWidth();
173 u8 height = xyMap.getHeight();
174 if (width != xyMap.getWidth() || height != xyMap.getHeight()) {
175 // xyMap has width and height that do not fit in an u16.
176 return;
177 }
178 u16 n = xyMap.getTotal();
179
180 for (u8 y = 0; y < height; y++) {
181 for (u8 x = 0; x < width; x++) {
182 // Use 8-bit fixed-point arithmetic with 8 fractional bits
183 // (scale factor of 256)
184 u16 fx = ((u16)x * (inputWidth - 1) * 256) / (width - 1);
185 u16 fy =
186 ((u16)y * (inputHeight - 1) * 256) / (height - 1);
187
188 u8 ix = fx >> 8; // Integer part
189 u8 iy = fy >> 8;
190 u8 dx = fx & 0xFF; // Fractional part
191 u8 dy = fy & 0xFF;
192
193 u8 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
194 u8 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
195
196 u16 i00 = iy * inputWidth + ix;
197 u16 i10 = iy * inputWidth + ix1;
198 u16 i01 = iy1 * inputWidth + ix;
199 u16 i11 = iy1 * inputWidth + ix1;
200
201 CRGB c00 = input[i00];
202 CRGB c10 = input[i10];
203 CRGB c01 = input[i01];
204 CRGB c11 = input[i11];
205
206 CRGB result;
207 result.r =
208 bilinearInterpolatePowerOf2(c00.r, c10.r, c01.r, c11.r, dx, dy);
209 result.g =
210 bilinearInterpolatePowerOf2(c00.g, c10.g, c01.g, c11.g, dx, dy);
211 result.b =
212 bilinearInterpolatePowerOf2(c00.b, c10.b, c01.b, c11.b, dx, dy);
213
214 u16 idx = xyMap.mapToIndex(x, y);
215 if (idx < n) {
216 output[idx] = result;
217 }
218 }
219 }
220}
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::XYMap xyMap
Definition ColorBoost.h:61
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, 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: