20 fl::u16 dstWidth = srcWidth / 2;
21 fl::u16 dstHeight = srcHeight / 2;
23 for (fl::u16
y = 0;
y < dstHeight; ++
y) {
24 for (fl::u16
x = 0;
x < dstWidth; ++
x) {
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)];
37 (p00.r + p10.r + p01.r + p11.r + 2) / 4;
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;
84 const fl::u16 srcWidth = srcXY.
getWidth();
85 const fl::u16 srcHeight = srcXY.
getHeight();
86 const fl::u16 dstWidth = dstXY.
getWidth();
87 const fl::u16 dstHeight = dstXY.
getHeight();
89 const fl::u32 FP_ONE = 256;
91 FASTLED_ASSERT(dstWidth <= srcWidth,
92 "Destination width must be <= source width");
93 FASTLED_ASSERT(dstHeight <= srcHeight,
94 "Destination height must be <= source height");
96 for (fl::u16 dy = 0; dy < dstHeight; ++dy) {
98 fl::u32 dstY0 = (dy * srcHeight * FP_ONE) / dstHeight;
99 fl::u32 dstY1 = ((dy + 1) * srcHeight * FP_ONE) / dstHeight;
101 for (fl::u16 dx = 0; dx < dstWidth; ++dx) {
102 fl::u32 dstX0 = (dx * srcWidth * FP_ONE) / dstWidth;
103 fl::u32 dstX1 = ((dx + 1) * srcWidth * FP_ONE) / dstWidth;
105 fl::u64 rSum = 0, gSum = 0, bSum = 0;
106 fl::u32 totalWeight = 0;
109 fl::u16 srcY_start = dstY0 / FP_ONE;
110 fl::u16 srcY_end = (dstY1 + FP_ONE - 1) / FP_ONE;
112 fl::u16 srcX_start = dstX0 / FP_ONE;
113 fl::u16 srcX_end = (dstX1 + FP_ONE - 1) / FP_ONE;
115 for (fl::u16 sy = srcY_start; sy < srcY_end; ++sy) {
117 fl::u32 sy0 = sy * FP_ONE;
118 fl::u32 sy1 = (sy + 1) * FP_ONE;
119 fl::u32 y_overlap =
MIN(dstY1, sy1) -
MAX(dstY0, sy0);
123 for (fl::u16 sx = srcX_start; sx < srcX_end; ++sx) {
124 fl::u32 sx0 = sx * FP_ONE;
125 fl::u32 sx1 = (sx + 1) * FP_ONE;
126 fl::u32 x_overlap =
MIN(dstX1, sx1) -
MAX(dstX0, sx0);
130 fl::u32 weight = (x_overlap * y_overlap + (FP_ONE >> 1)) >>
134 rSum += p.r * weight;
135 gSum += p.g * weight;
136 bSum += p.b * weight;
137 totalWeight += weight;
143 totalWeight ? (rSum + (totalWeight >> 1)) / totalWeight : 0;
145 totalWeight ? (gSum + (totalWeight >> 1)) / totalWeight : 0;
147 totalWeight ? (bSum + (totalWeight >> 1)) / totalWeight : 0;
155 const XYMap &dstXY) {
156 fl::u16 srcWidth = srcXY.
getWidth();
158 fl::u16 dstWidth = dstXY.
getWidth();
161 FASTLED_ASSERT(dstWidth <= srcWidth,
162 "Destination width must be <= source width");
163 FASTLED_ASSERT(dstHeight <= srcHeight,
164 "Destination height must be <= source height");
165 const bool destination_is_half_of_source =
166 (dstWidth * 2 == srcWidth) && (dstHeight * 2 == srcHeight);
169 if (destination_is_half_of_source) {
172 if (both_rectangles) {