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 232 of file bilinear_expansion.cpp.

233 {
234 uint8_t outputWidth = xyMap.getWidth();
235 uint8_t outputHeight = xyMap.getHeight();
236 if (outputWidth != xyMap.getWidth() || outputHeight != xyMap.getHeight()) {
237 // xyMap has width and height that do not fit in a uint8_t.
238 return;
239 }
240 uint16_t n = xyMap.getTotal();
241
242 for (uint8_t y = 0; y < outputHeight; y++) {
243 for (uint8_t x = 0; x < outputWidth; x++) {
244 // Map output pixel to input grid position
245 float fx =
246 static_cast<float>(x) * (inputWidth - 1) / (outputWidth - 1);
247 float fy =
248 static_cast<float>(y) * (inputHeight - 1) / (outputHeight - 1);
249
250 uint8_t ix = static_cast<uint8_t>(fx);
251 uint8_t iy = static_cast<uint8_t>(fy);
252 float dx = fx - ix;
253 float dy = fy - iy;
254
255 uint8_t ix1 = (ix + 1 < inputWidth) ? ix + 1 : ix;
256 uint8_t iy1 = (iy + 1 < inputHeight) ? iy + 1 : iy;
257
258 uint16_t i00 = iy * inputWidth + ix;
259 uint16_t i10 = iy * inputWidth + ix1;
260 uint16_t i01 = iy1 * inputWidth + ix;
261 uint16_t i11 = iy1 * inputWidth + ix1;
262
263 CRGB c00 = input[i00];
264 CRGB c10 = input[i10];
265 CRGB c01 = input[i01];
266 CRGB c11 = input[i11];
267
268 CRGB result;
269 result.r =
270 bilinearInterpolateFloat(c00.r, c10.r, c01.r, c11.r, dx, dy);
271 result.g =
272 bilinearInterpolateFloat(c00.g, c10.g, c01.g, c11.g, dx, dy);
273 result.b =
274 bilinearInterpolateFloat(c00.b, c10.b, c01.b, c11.b, dx, dy);
275
276 uint16_t idx = xyMap.mapToIndex(x, y);
277 if (idx < n) {
278 output[idx] = result;
279 }
280 }
281 }
282}
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
XYMap xyMap(WIDTH, HEIGHT, false)
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:55

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: