83 {
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();
88
89 const fl::u32 FP_ONE = 256;
90
91 FASTLED_ASSERT(dstWidth <= srcWidth,
92 "Destination width must be <= source width");
93 FASTLED_ASSERT(dstHeight <= srcHeight,
94 "Destination height must be <= source height");
95
96 for (fl::u16 dy = 0; dy < dstHeight; ++dy) {
97
98 fl::u32 dstY0 = (dy * srcHeight * FP_ONE) / dstHeight;
99 fl::u32 dstY1 = ((dy + 1) * srcHeight * FP_ONE) / dstHeight;
100
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;
104
105 fl::u64 rSum = 0, gSum = 0, bSum = 0;
106 fl::u32 totalWeight = 0;
107
108
109 fl::u16 srcY_start = dstY0 / FP_ONE;
110 fl::u16 srcY_end = (dstY1 + FP_ONE - 1) / FP_ONE;
111
112 fl::u16 srcX_start = dstX0 / FP_ONE;
113 fl::u16 srcX_end = (dstX1 + FP_ONE - 1) / FP_ONE;
114
115 for (fl::u16 sy = srcY_start; sy < srcY_end; ++sy) {
116
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);
120 if (y_overlap == 0)
121 continue;
122
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);
127 if (x_overlap == 0)
128 continue;
129
130 fl::u32 weight = (x_overlap * y_overlap + (FP_ONE >> 1)) >>
131 8;
132
134 rSum += p.r * weight;
135 gSum += p.g * weight;
136 bSum += p.b * weight;
137 totalWeight += weight;
138 }
139 }
140
141
143 totalWeight ? (rSum + (totalWeight >> 1)) / totalWeight : 0;
145 totalWeight ? (gSum + (totalWeight >> 1)) / totalWeight : 0;
147 totalWeight ? (bSum + (totalWeight >> 1)) / totalWeight : 0;
148
149 dst[dstXY.
mapToIndex(dx, dy)] = CRGB(r, g, b);
150 }
151 }
152}
u16 mapToIndex(const u16 &x, const u16 &y) const
Representation of an RGB pixel (Red, Green, Blue)