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

◆ bilinearExpandFloat()

void fl::bilinearExpandFloat ( const CRGB * input,
CRGB * output,
uint8_t inputWidth,
uint8_t inputHeight,
XYMap xyMap )

Definition at line 225 of file bilinear_expansion.cpp.

227 {
228 uint8_t outputWidth = xyMap.getWidth();
229 uint8_t outputHeight = xyMap.getHeight();
230 if (outputWidth != xyMap.getWidth() || outputHeight != xyMap.getHeight()) {
231 // xyMap has width and height that do not fit in a uint8_t.
232 return;
233 }
234 uint16_t n = xyMap.getTotal();
235
236 for (uint8_t y = 0; y < outputHeight; y++) {
237 for (uint8_t x = 0; x < outputWidth; x++) {
238 // Map output pixel to input grid position
239 float fx = static_cast<float>(x) * (inputWidth - 1) / (outputWidth - 1);
240 float fy = static_cast<float>(y) * (inputHeight - 1) / (outputHeight - 1);
241
242 uint8_t ix = static_cast<uint8_t>(fx);
243 uint8_t iy = static_cast<uint8_t>(fy);
244 float dx = fx - ix;
245 float dy = fy - iy;
246
247 uint8_t ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
248 uint8_t iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
249
250 uint16_t i00 = iy * inputWidth + ix;
251 uint16_t i10 = iy * inputWidth + ix1;
252 uint16_t i01 = iy1 * inputWidth + ix;
253 uint16_t i11 = iy1 * inputWidth + ix1;
254
255 CRGB c00 = input[i00];
256 CRGB c10 = input[i10];
257 CRGB c01 = input[i01];
258 CRGB c11 = input[i11];
259
260 CRGB result;
261 result.r = bilinearInterpolateFloat(c00.r, c10.r, c01.r, c11.r, dx, dy);
262 result.g = bilinearInterpolateFloat(c00.g, c10.g, c01.g, c11.g, dx, dy);
263 result.b = bilinearInterpolateFloat(c00.b, c10.b, c01.b, c11.b, dx, dy);
264
265 uint16_t idx = xyMap.mapToIndex(x, y);
266 if (idx < n) {
267 output[idx] = result;
268 }
269 }
270 }
271}
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 bilinearInterpolateFloat(uint8_t v00, uint8_t v10, uint8_t v01, uint8_t v11, float dx, float dy)
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

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

Referenced by fl::ScaleUp::expand().

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