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

◆ upscaleFloat() [1/2]

void fl::upscaleFloat ( const CRGB * input,
CRGB * output,
u8 inputWidth,
u8 inputHeight,
const XYMap & xyMap )

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

316 {
317 u8 outputWidth = xyMap.getWidth();
318 u8 outputHeight = xyMap.getHeight();
319 if (outputWidth != xyMap.getWidth() || outputHeight != xyMap.getHeight()) {
320 // xyMap has width and height that do not fit in a u8.
321 return;
322 }
323 u16 n = xyMap.getTotal();
324
325 for (u8 y = 0; y < outputHeight; y++) {
326 for (u8 x = 0; x < outputWidth; x++) {
327 // Map output pixel to input grid position
328 float fx =
329 static_cast<float>(x) * (inputWidth - 1) / (outputWidth - 1);
330 float fy =
331 static_cast<float>(y) * (inputHeight - 1) / (outputHeight - 1);
332
333 u8 ix = static_cast<u8>(fx);
334 u8 iy = static_cast<u8>(fy);
335 float dx = fx - ix;
336 float dy = fy - iy;
337
338 u8 ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
339 u8 iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
340
341 u16 i00 = iy * inputWidth + ix;
342 u16 i10 = iy * inputWidth + ix1;
343 u16 i01 = iy1 * inputWidth + ix;
344 u16 i11 = iy1 * inputWidth + ix1;
345
346 CRGB c00 = input[i00];
347 CRGB c10 = input[i10];
348 CRGB c01 = input[i01];
349 CRGB c11 = input[i11];
350
351 CRGB result;
352 result.r =
353 upscaleFloat(c00.r, c10.r, c01.r, c11.r, dx, dy);
354 result.g =
355 upscaleFloat(c00.g, c10.g, c01.g, c11.g, dx, dy);
356 result.b =
357 upscaleFloat(c00.b, c10.b, c01.b, c11.b, dx, dy);
358
359 u16 idx = xyMap.mapToIndex(x, y);
360 if (idx < n) {
361 output[idx] = result;
362 }
363 }
364 }
365}
fl::XYMap xyMap
int y
Definition simple.h:93
int x
Definition simple.h:92
fl::CRGB CRGB
Definition crgb.h:25
unsigned char u8
Definition stdint.h:131
unsigned char u8
Definition stdint.h:131
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
u8 upscaleFloat(u8 v00, u8 v10, u8 v01, u8 v11, float dx, float dy)

References upscaleFloat(), x, xyMap, and y.

+ Here is the call graph for this function: