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

◆ downscaleHalf() [1/2]

void fl::downscaleHalf ( const CRGB * src,
const XYMap & srcXY,
CRGB * dst,
const XYMap & dstXY )

Definition at line 46 of file downscale.cpp.

47 {
48 uint16_t dstWidth = dstXY.getWidth();
49 uint16_t dstHeight = dstXY.getHeight();
50
51 FASTLED_ASSERT(srcXY.getWidth() == dstXY.getWidth() * 2,
52 "Source width must be double the destination width");
53 FASTLED_ASSERT(srcXY.getHeight() == dstXY.getHeight() * 2,
54 "Source height must be double the destination height");
55
56 for (uint16_t y = 0; y < dstHeight; ++y) {
57 for (uint16_t x = 0; x < dstWidth; ++x) {
58 // Map to top-left of the 2x2 block in source
59 uint16_t srcX = x * 2;
60 uint16_t srcY = y * 2;
61
62 // Fetch 2x2 block
63 const CRGB &p00 = src[srcXY.mapToIndex(srcX, srcY)];
64 const CRGB &p10 = src[srcXY.mapToIndex(srcX + 1, srcY)];
65 const CRGB &p01 = src[srcXY.mapToIndex(srcX, srcY + 1)];
66 const CRGB &p11 = src[srcXY.mapToIndex(srcX + 1, srcY + 1)];
67
68 // Average each color channel
69 uint16_t r =
70 (p00.r + p10.r + p01.r + p11.r + 2) / 4; // +2 for rounding
71 uint16_t g = (p00.g + p10.g + p01.g + p11.g + 2) / 4;
72 uint16_t b = (p00.b + p10.b + p01.b + p11.b + 2) / 4;
73
74 // Store result
75 dst[dstXY.mapToIndex(x, y)] =
76 CRGB((uint8_t)r, (uint8_t)g, (uint8_t)b);
77 }
78 }
79}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
uint16_t getWidth() const
Definition xymap.cpp:124
uint16_t mapToIndex(const uint16_t &x, const uint16_t &y) const
Definition xymap.cpp:97
uint16_t getHeight() const
Definition xymap.cpp:126
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

References fl::XYMap::getHeight(), fl::XYMap::getWidth(), fl::XYMap::mapToIndex(), x, and y.

+ Here is the call graph for this function: