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

◆ bilinearExpandPowerOf2()

void fl::bilinearExpandPowerOf2 ( const CRGB * input,
CRGB * output,
uint8_t inputWidth,
uint8_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 86 of file bilinear_expansion.cpp.

86 {
87 uint8_t width = xyMap.getWidth();
88 uint8_t height = xyMap.getHeight();
89 if (width != xyMap.getWidth() || height != xyMap.getHeight()) {
90 // xyMap has width and height that do not fit in an uint16_t.
91 return;
92 }
93 uint16_t n = xyMap.getTotal();
94
95 for (uint8_t y = 0; y < height; y++) {
96 for (uint8_t x = 0; x < width; x++) {
97 // Use 8-bit fixed-point arithmetic with 8 fractional bits
98 // (scale factor of 256)
99 uint16_t fx = ((uint16_t)x * (inputWidth - 1) * 256) / (width - 1);
100 uint16_t fy =
101 ((uint16_t)y * (inputHeight - 1) * 256) / (height - 1);
102
103 uint8_t ix = fx >> 8; // Integer part
104 uint8_t iy = fy >> 8;
105 uint8_t dx = fx & 0xFF; // Fractional part
106 uint8_t dy = fy & 0xFF;
107
108 uint8_t ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
109 uint8_t iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
110
111 uint16_t i00 = iy * inputWidth + ix;
112 uint16_t i10 = iy * inputWidth + ix1;
113 uint16_t i01 = iy1 * inputWidth + ix;
114 uint16_t i11 = iy1 * inputWidth + ix1;
115
116 CRGB c00 = input[i00];
117 CRGB c10 = input[i10];
118 CRGB c01 = input[i01];
119 CRGB c11 = input[i11];
120
121 CRGB result;
122 result.r = bilinearInterpolatePowerOf2(c00.r, c10.r, c01.r, c11.r, dx, dy);
123 result.g = bilinearInterpolatePowerOf2(c00.g, c10.g, c01.g, c11.g, dx, dy);
124 result.b = bilinearInterpolatePowerOf2(c00.b, c10.b, c01.b, c11.b, dx, dy);
125
126 uint16_t idx = xyMap.mapToIndex(x, y);
127 if (idx < n) {
128 output[idx] = result;
129 }
130 }
131 }
132}
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 bilinearInterpolatePowerOf2(uint8_t v00, uint8_t v10, uint8_t v01, uint8_t v11, uint8_t dx, uint8_t dy)
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

References bilinearInterpolatePowerOf2(), 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: