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 47 of file downscale.cpp.

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

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

+ Here is the call graph for this function: