MCPcopy Create free account
hub / github.com/FastLED/FastLED / ensureBuffer

Function ensureBuffer

src/chipsets.h:287–303  ·  view source on GitHub ↗

@brief Ensures the internal RGBW buffer is large enough for the LED count @param num_leds Number of RGB LEDs to convert to RGBW @details Reallocates the buffer if needed, accounting for the 4:3 byte ratio when packing RGBW data into RGB format

Source from the content-addressed store, hash-verified

285 /// @details Reallocates the buffer if needed, accounting for the 4:3 byte ratio
286 /// when packing RGBW data into RGB format
287 void ensureBuffer(fl::i32 num_leds) {
288 if (num_leds != mNumRGBLeds) {
289 mNumRGBLeds = num_leds;
290 // The delegate controller expects the raw pixel byte data in multiples of 3.
291 // In the case of src data not a multiple of 3, then we need to
292 // add pad bytes so that the delegate controller doesn't walk off the end
293 // of the array and invoke a buffer overflow panic.
294 fl::u32 new_size = Rgbw::size_as_rgb(num_leds);
295 mRGBWPixels.reset(new CRGB[new_size]); // ok bare allocation (array new)
296 // showPixels may never clear the last two pixels.
297 for (fl::u32 i = 0; i < new_size; i++) {
298 mRGBWPixels[i] = CRGB(0, 0, 0);
299 }
300
301 mController.setLeds(mRGBWPixels.get(), new_size);
302 }
303 }
304
305 fl::unique_ptr<CRGB[]> mRGBWPixels; ///< Internal buffer for packed RGBW data
306 fl::i32 mNumRGBLeds = 0; ///< Number of RGB LEDs in the original array

Callers 1

showPixelsFunction · 0.85

Calls 4

CRGBClass · 0.50
resetMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected