10 CRGB *dst, uint16_t dstWidth, uint16_t dstHeight) {
12 const uint16_t SHIFT = 8;
13 const uint16_t FP_ONE = 1 << SHIFT;
14 const uint16_t WEIGHT_SHIFT =
16 const uint16_t rounding = 1 << (WEIGHT_SHIFT - 1);
20 uint16_t
scaleX = (srcWidth << SHIFT) / dstWidth;
21 uint16_t scaleY = (srcHeight << SHIFT) / dstHeight;
24 for (
int y = 0;
y < dstHeight; ++
y) {
26 int srcYFixed =
y * scaleY;
27 int y0 = srcYFixed >> SHIFT;
28 int yFrac = srcYFixed & (FP_ONE - 1);
30 MIN(y0 + 1, srcHeight - 1);
32 for (
int x = 0;
x < dstWidth; ++
x) {
35 int x0 = srcXFixed >> SHIFT;
36 int xFrac = srcXFixed & (FP_ONE - 1);
37 int x1 =
MIN(x0 + 1, srcWidth - 1);
40 int w00 = (FP_ONE - xFrac) * (FP_ONE - yFrac);
41 int w10 = xFrac * (FP_ONE - yFrac);
42 int w01 = (FP_ONE - xFrac) * yFrac;
43 int w11 = xFrac * yFrac;
46 int r = (w00 * src[y0 * srcWidth + x0].r +
47 w10 * src[y0 * srcWidth + x1].r +
48 w01 * src[y1 * srcWidth + x0].r +
49 w11 * src[y1 * srcWidth + x1].r + rounding) >>
52 int g = (w00 * src[y0 * srcWidth + x0].g +
53 w10 * src[y0 * srcWidth + x1].g +
54 w01 * src[y1 * srcWidth + x0].g +
55 w11 * src[y1 * srcWidth + x1].g + rounding) >>
58 int b = (w00 * src[y0 * srcWidth + x0].b +
59 w10 * src[y0 * srcWidth + x1].b +
60 w01 * src[y1 * srcWidth + x0].b +
61 w11 * src[y1 * srcWidth + x1].b + rounding) >>
65 dst[
y * dstWidth +
x] =
CRGB(
static_cast<unsigned char>(r),
66 static_cast<unsigned char>(g),
67 static_cast<unsigned char>(b));