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

◆ upscalePowerOf2()

void fl::upscalePowerOf2 ( 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 84 of file upscale.cpp.

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

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

Referenced by bilinearExpandPowerOf2(), fl::ScaleUp::expand(), and upscale().

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