19 uint16_t dstWidth = srcWidth / 2;
20 uint16_t dstHeight = srcHeight / 2;
22 for (uint16_t
y = 0;
y < dstHeight; ++
y) {
23 for (uint16_t
x = 0;
x < dstWidth; ++
x) {
25 uint16_t srcX =
x * 2;
26 uint16_t srcY =
y * 2;
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)];
36 (p00.r + p10.r + p01.r + p11.r + 2) / 4;
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;
41 dst[
y * dstWidth +
x] =
CRGB((uint8_t)r, (uint8_t)g, (uint8_t)b);
48 uint16_t dstWidth = dstXY.
getWidth();
52 "Source width must be double the destination width");
54 "Source height must be double the destination height");
56 for (uint16_t
y = 0;
y < dstHeight; ++
y) {
57 for (uint16_t
x = 0;
x < dstWidth; ++
x) {
59 uint16_t srcX =
x * 2;
60 uint16_t srcY =
y * 2;
70 (p00.r + p10.r + p01.r + p11.r + 2) / 4;
71 uint16_t g = (p00.g + p10.g + p01.g + p11.g + 2) / 4;
72 uint16_t b = (p00.b + p10.b + p01.b + p11.b + 2) / 4;
76 CRGB((uint8_t)r, (uint8_t)g, (uint8_t)b);
83 const uint16_t srcWidth = srcXY.
getWidth();
84 const uint16_t srcHeight = srcXY.
getHeight();
85 const uint16_t dstWidth = dstXY.
getWidth();
86 const uint16_t dstHeight = dstXY.
getHeight();
88 const uint32_t FP_ONE = 256;
90 FASTLED_ASSERT(dstWidth <= srcWidth,
91 "Destination width must be <= source width");
92 FASTLED_ASSERT(dstHeight <= srcHeight,
93 "Destination height must be <= source height");
95 for (uint16_t dy = 0; dy < dstHeight; ++dy) {
97 uint32_t dstY0 = (dy * srcHeight * FP_ONE) / dstHeight;
98 uint32_t dstY1 = ((dy + 1) * srcHeight * FP_ONE) / dstHeight;
100 for (uint16_t dx = 0; dx < dstWidth; ++dx) {
101 uint32_t dstX0 = (dx * srcWidth * FP_ONE) / dstWidth;
102 uint32_t dstX1 = ((dx + 1) * srcWidth * FP_ONE) / dstWidth;
104 uint64_t rSum = 0, gSum = 0, bSum = 0;
105 uint32_t totalWeight = 0;
108 uint16_t srcY_start = dstY0 / FP_ONE;
109 uint16_t srcY_end = (dstY1 + FP_ONE - 1) / FP_ONE;
111 uint16_t srcX_start = dstX0 / FP_ONE;
112 uint16_t srcX_end = (dstX1 + FP_ONE - 1) / FP_ONE;
114 for (uint16_t sy = srcY_start; sy < srcY_end; ++sy) {
116 uint32_t sy0 = sy * FP_ONE;
117 uint32_t sy1 = (sy + 1) * FP_ONE;
118 uint32_t y_overlap =
MIN(dstY1, sy1) -
MAX(dstY0, sy0);
122 for (uint16_t sx = srcX_start; sx < srcX_end; ++sx) {
123 uint32_t sx0 = sx * FP_ONE;
124 uint32_t sx1 = (sx + 1) * FP_ONE;
125 uint32_t x_overlap =
MIN(dstX1, sx1) -
MAX(dstX0, sx0);
129 uint32_t weight = (x_overlap * y_overlap + (FP_ONE >> 1)) >>
133 rSum +=
p.r * weight;
134 gSum +=
p.g * weight;
135 bSum +=
p.b * weight;
136 totalWeight += weight;
142 totalWeight ? (rSum + (totalWeight >> 1)) / totalWeight : 0;
144 totalWeight ? (gSum + (totalWeight >> 1)) / totalWeight : 0;
146 totalWeight ? (bSum + (totalWeight >> 1)) / totalWeight : 0;
154 const XYMap &dstXY) {
155 uint16_t srcWidth = srcXY.
getWidth();
157 uint16_t dstWidth = dstXY.
getWidth();
160 FASTLED_ASSERT(dstWidth <= srcWidth,
161 "Destination width must be <= source width");
162 FASTLED_ASSERT(dstHeight <= srcHeight,
163 "Destination height must be <= source height");
164 const bool destination_is_half_of_source =
165 (dstWidth * 2 == srcWidth) && (dstHeight * 2 == srcHeight);
168 if (destination_is_half_of_source) {
171 if (both_rectangles) {