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

◆ bilinearExpandArbitrary()

void fl::bilinearExpandArbitrary ( const CRGB * input,
CRGB * output,
uint16_t inputWidth,
uint16_t inputHeight,
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 22 of file bilinear_expansion.cpp.

23 {
24 uint16_t n = xyMap.getTotal();
25 uint16_t outputWidth = xyMap.getWidth();
26 uint16_t outputHeight = xyMap.getHeight();
27 const uint16_t scale_factor = 256; // Using 8 bits for the fractional part
28
29 for (uint16_t y = 0; y < outputHeight; y++) {
30 for (uint16_t x = 0; x < outputWidth; x++) {
31 // Calculate the corresponding position in the input grid
32 uint32_t fx = ((uint32_t)x * (inputWidth - 1) * scale_factor) /
33 (outputWidth - 1);
34 uint32_t fy = ((uint32_t)y * (inputHeight - 1) * scale_factor) /
35 (outputHeight - 1);
36
37 uint16_t ix = fx / scale_factor; // Integer part of x
38 uint16_t iy = fy / scale_factor; // Integer part of y
39 uint16_t dx = fx % scale_factor; // Fractional part of x
40 uint16_t dy = fy % scale_factor; // Fractional part of y
41
42 uint16_t ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
43 uint16_t iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
44
45 uint16_t i00 = iy * inputWidth + ix;
46 uint16_t i10 = iy * inputWidth + ix1;
47 uint16_t i01 = iy1 * inputWidth + ix;
48 uint16_t i11 = iy1 * inputWidth + ix1;
49
50 CRGB c00 = input[i00];
51 CRGB c10 = input[i10];
52 CRGB c01 = input[i01];
53 CRGB c11 = input[i11];
54
55 CRGB result;
56 result.r = bilinearInterpolate(c00.r, c10.r, c01.r, c11.r, dx, dy);
57 result.g = bilinearInterpolate(c00.g, c10.g, c01.g, c11.g, dx, dy);
58 result.b = bilinearInterpolate(c00.b, c10.b, c01.b, c11.b, dx, dy);
59
60 uint16_t idx = xyMap.mapToIndex(x, y);
61 if (idx < n) {
62 output[idx] = result;
63 }
64 }
65 }
66}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
XYMap xyMap(HEIGHT, WIDTH, SERPENTINE)
uint8_t bilinearInterpolate(uint8_t v00, uint8_t v10, uint8_t v01, uint8_t v11, uint16_t dx, uint16_t dy)
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

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

Referenced by bilinearExpand(), and fl::ScaleUp::expand().

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