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

Function resizeArea_

dnn/src/x86/resize/resize_cv.cpp:2110–2181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2108// Resize Area
2109template <typename T, typename WT>
2110static void resizeArea_(
2111 const Mat<T>& src, Mat<T>& dst, const DecimateAlpha* xtab, int xtab_size,
2112 const DecimateAlpha* ytab, int ytab_size, const int* tabofs) {
2113 // parallel_for_(Range(0, dst.rows),
2114 // ResizeArea_Invoker<T, WT>(src, dst, xtab, xtab_size, ytab, ytab_size,
2115 // tabofs),
2116 // dst.total()/((double)(1 << 16)));
2117 (void)ytab_size;
2118 int dwidth = dst.width(), dheight = dst.height();
2119 int cn = dst.channels();
2120 dwidth *= cn;
2121 AlignedVector<WT> _buffer(dwidth * 2);
2122 WT *buf = _buffer.data(), *sum = buf + dwidth;
2123 int j_start = tabofs[0], j_end = tabofs[dheight], j, k, dx,
2124 prev_dy = ytab[j_start].di;
2125
2126 for (dx = 0; dx < dwidth; dx++)
2127 sum[dx] = (WT)0;
2128
2129 for (j = j_start; j < j_end; j++) {
2130 WT beta = ytab[j].alpha;
2131 int dy = ytab[j].di;
2132 int sy = ytab[j].si;
2133
2134 {
2135 const T* S = (const T*)(src.ptr(sy));
2136 for (dx = 0; dx < dwidth; dx++)
2137 buf[dx] = (WT)0;
2138
2139 if (cn == 1)
2140 for (k = 0; k < xtab_size; k++) {
2141 int dxn = xtab[k].di;
2142 WT alpha = xtab[k].alpha;
2143 buf[dxn] += S[xtab[k].si] * alpha;
2144 }
2145 else if (cn == 3)
2146 for (k = 0; k < xtab_size; k++) {
2147 int sxn = xtab[k].si;
2148 int dxn = xtab[k].di;
2149 WT alpha = xtab[k].alpha;
2150 WT t0 = buf[dxn] + S[sxn] * alpha;
2151 WT t1 = buf[dxn + 1] + S[sxn + 1] * alpha;
2152 WT t2 = buf[dxn + 2] + S[sxn + 2] * alpha;
2153 buf[dxn] = t0;
2154 buf[dxn + 1] = t1;
2155 buf[dxn + 2] = t2;
2156 }
2157 else {
2158 megdnn_throw(("nr. of channels must be 1 or 3"));
2159 }
2160 }
2161
2162 if (dy != prev_dy) {
2163 T* D = dst.ptr(prev_dy);
2164
2165 for (dx = 0; dx < dwidth; dx++) {
2166 D[dx] = saturate_cast<T>(sum[dx]);
2167 sum[dx] = beta * buf[dx];

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