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

◆ downscaleHalf() [2/2]

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

Definition at line 18 of file downscale.cpp.

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

References x, and y.

Referenced by downscale(), and loop().

+ Here is the caller graph for this function: