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

◆ downscaleHalf() [2/2]

void fl::downscaleHalf ( const CRGB * src,
uint16_t srcWidth,
uint16_t srcHeight,
CRGB * dst )

Definition at line 17 of file downscale.cpp.

18 {
19 uint16_t dstWidth = srcWidth / 2;
20 uint16_t dstHeight = srcHeight / 2;
21
22 for (uint16_t y = 0; y < dstHeight; ++y) {
23 for (uint16_t x = 0; x < dstWidth; ++x) {
24 // Map to top-left of the 2x2 block in source
25 uint16_t srcX = x * 2;
26 uint16_t srcY = y * 2;
27
28 // Fetch 2x2 block
29 const CRGB &p00 = src[(srcY)*srcWidth + (srcX)];
30 const CRGB &p10 = src[(srcY)*srcWidth + (srcX + 1)];
31 const CRGB &p01 = src[(srcY + 1) * srcWidth + (srcX)];
32 const CRGB &p11 = src[(srcY + 1) * srcWidth + (srcX + 1)];
33
34 // Average each color channel
35 uint16_t r =
36 (p00.r + p10.r + p01.r + p11.r + 2) / 4; // +2 for rounding
37 uint16_t g = (p00.g + p10.g + p01.g + p11.g + 2) / 4;
38 uint16_t b = (p00.b + p10.b + p01.b + p11.b + 2) / 4;
39
40 // Store result
41 dst[y * dstWidth + x] = CRGB((uint8_t)r, (uint8_t)g, (uint8_t)b);
42 }
43 }
44}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

References x, and y.

Referenced by downscale(), and loop().

+ Here is the caller graph for this function: