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

Function resizeArea_

dnn/src/arm_common/resize/resize_cv.cpp:1705–1775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1703// Resize Area
1704template <typename T, typename WT>
1705static void resizeArea_(
1706 const Mat<T>& src, Mat<T>& dst, const DecimateAlpha* xtab, int xtab_size,
1707 const DecimateAlpha* ytab, int ytab_size, const int* tabofs) {
1708 // parallel_for_(Range(0, dst.rows),
1709 // ResizeArea_Invoker<T, WT>(src, dst, xtab, xtab_size, ytab, ytab_size,
1710 // tabofs), dst.total()/((double)(1 << 16)));
1711 (void)ytab_size;
1712 int dwidth = dst.width(), dheight = dst.height();
1713 int cn = dst.channels();
1714 dwidth *= cn;
1715 AlignedVector<WT> _buffer(dwidth * 2);
1716 WT *buf = _buffer.data(), *sum = buf + dwidth;
1717 int j_start = tabofs[0], j_end = tabofs[dheight], j, k, dx,
1718 prev_dy = ytab[j_start].di;
1719
1720 for (dx = 0; dx < dwidth; dx++)
1721 sum[dx] = (WT)0;
1722
1723 for (j = j_start; j < j_end; j++) {
1724 WT beta = ytab[j].alpha;
1725 int dy = ytab[j].di;
1726 int sy = ytab[j].si;
1727
1728 {
1729 const T* S = (const T*)(src.ptr(sy));
1730 for (dx = 0; dx < dwidth; dx++)
1731 buf[dx] = (WT)0;
1732
1733 if (cn == 1)
1734 for (k = 0; k < xtab_size; k++) {
1735 int dxn = xtab[k].di;
1736 WT alpha = xtab[k].alpha;
1737 buf[dxn] += S[xtab[k].si] * alpha;
1738 }
1739 else if (cn == 3)
1740 for (k = 0; k < xtab_size; k++) {
1741 int sxn = xtab[k].si;
1742 int dxn = xtab[k].di;
1743 WT alpha = xtab[k].alpha;
1744 WT t0 = buf[dxn] + S[sxn] * alpha;
1745 WT t1 = buf[dxn + 1] + S[sxn + 1] * alpha;
1746 WT t2 = buf[dxn + 2] + S[sxn + 2] * alpha;
1747 buf[dxn] = t0;
1748 buf[dxn + 1] = t1;
1749 buf[dxn + 2] = t2;
1750 }
1751 else {
1752 megdnn_throw(("nr. of channels must be 1 or 3"));
1753 }
1754 }
1755
1756 if (dy != prev_dy) {
1757 T* D = dst.ptr(prev_dy);
1758
1759 for (dx = 0; dx < dwidth; dx++) {
1760 D[dx] = saturate_cast<T>(sum[dx]);
1761 sum[dx] = beta * buf[dx];
1762 }

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