MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / resizeArea_

Function resizeArea_

dnn/src/fallback/resize/gi/resize_cv.cpp:1149–1219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1147// Resize Area
1148template <typename T, typename WT>
1149static void resizeArea_(
1150 const Mat<T>& src, Mat<T>& dst, const DecimateAlpha* xtab, int xtab_size,
1151 const DecimateAlpha* ytab, int ytab_size, const int* tabofs) {
1152 // parallel_for_(Range(0, dst.rows),
1153 // ResizeArea_Invoker<T, WT>(src, dst, xtab, xtab_size, ytab, ytab_size,
1154 // tabofs), dst.total()/((double)(1 << 16)));
1155 (void)ytab_size;
1156 int dwidth = dst.width(), dheight = dst.height();
1157 int cn = dst.channels();
1158 dwidth *= cn;
1159 AlignedVector<WT> _buffer(dwidth * 2);
1160 WT *buf = _buffer.data(), *sum = buf + dwidth;
1161 int j_start = tabofs[0], j_end = tabofs[dheight], j, k, dx,
1162 prev_dy = ytab[j_start].di;
1163
1164 for (dx = 0; dx < dwidth; dx++)
1165 sum[dx] = (WT)0;
1166
1167 for (j = j_start; j < j_end; j++) {
1168 WT beta = ytab[j].alpha;
1169 int dy = ytab[j].di;
1170 int sy = ytab[j].si;
1171
1172 {
1173 const T* S = (const T*)(src.ptr(sy));
1174 for (dx = 0; dx < dwidth; dx++)
1175 buf[dx] = (WT)0;
1176
1177 if (cn == 1)
1178 for (k = 0; k < xtab_size; k++) {
1179 int dxn = xtab[k].di;
1180 WT alpha = xtab[k].alpha;
1181 buf[dxn] += S[xtab[k].si] * alpha;
1182 }
1183 else if (cn == 3)
1184 for (k = 0; k < xtab_size; k++) {
1185 int sxn = xtab[k].si;
1186 int dxn = xtab[k].di;
1187 WT alpha = xtab[k].alpha;
1188 WT t0 = buf[dxn] + S[sxn] * alpha;
1189 WT t1 = buf[dxn + 1] + S[sxn + 1] * alpha;
1190 WT t2 = buf[dxn + 2] + S[sxn + 2] * alpha;
1191 buf[dxn] = t0;
1192 buf[dxn + 1] = t1;
1193 buf[dxn + 2] = t2;
1194 }
1195 else {
1196 megdnn_throw(("nr. of channels must be 1 or 3"));
1197 }
1198 }
1199
1200 if (dy != prev_dy) {
1201 T* D = dst.ptr(prev_dy);
1202
1203 for (dx = 0; dx < dwidth; dx++) {
1204 D[dx] = saturate_cast<T>(sum[dx]);
1205 sum[dx] = beta * buf[dx];
1206 }

Callers

nothing calls this directly

Calls 5

widthMethod · 0.45
heightMethod · 0.45
channelsMethod · 0.45
dataMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected