| 17 | namespace fl { |
| 18 | |
| 19 | void downscaleHalf(const CRGB *src, fl::u16 srcWidth, fl::u16 srcHeight, |
| 20 | CRGB *dst) { |
| 21 | fl::u16 dstWidth = srcWidth / 2; |
| 22 | fl::u16 dstHeight = srcHeight / 2; |
| 23 | |
| 24 | for (fl::u16 y = 0; y < dstHeight; ++y) { |
| 25 | for (fl::u16 x = 0; x < dstWidth; ++x) { |
| 26 | // Map to top-left of the 2x2 block in source |
| 27 | fl::u16 srcX = x * 2; |
| 28 | fl::u16 srcY = y * 2; |
| 29 | |
| 30 | // Fetch 2x2 block |
| 31 | const CRGB &p00 = src[(srcY)*srcWidth + (srcX)]; |
| 32 | const CRGB &p10 = src[(srcY)*srcWidth + (srcX + 1)]; |
| 33 | const CRGB &p01 = src[(srcY + 1) * srcWidth + (srcX)]; |
| 34 | const CRGB &p11 = src[(srcY + 1) * srcWidth + (srcX + 1)]; |
| 35 | |
| 36 | // Average each color channel |
| 37 | fl::u16 r = |
| 38 | (p00.r + p10.r + p01.r + p11.r + 2) / 4; // +2 for rounding |
| 39 | fl::u16 g = (p00.g + p10.g + p01.g + p11.g + 2) / 4; |
| 40 | fl::u16 b = (p00.b + p10.b + p01.b + p11.b + 2) / 4; |
| 41 | |
| 42 | // Store result |
| 43 | dst[y * dstWidth + x] = CRGB((fl::u8)r, (fl::u8)g, (fl::u8)b); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void downscaleHalf(const CRGB *src, const XYMap &srcXY, CRGB *dst, |
| 49 | const XYMap &dstXY) { |
no test coverage detected