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

Function resizeGeneric_

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

Source from the content-addressed store, hash-verified

1761
1762template <class HResize, class VResize, class MT>
1763void resizeGeneric_(
1764 const Mat<MT>& src, Mat<MT>& dst, const int* xofs, const void* _alpha,
1765 const int* yofs, const void* _beta, int xmin, int xmax, int ksize) {
1766 typedef typename HResize::value_type T;
1767 typedef typename HResize::buf_type WT;
1768 typedef typename HResize::alpha_type AT;
1769
1770 const AT* beta = static_cast<const AT*>(_beta);
1771 const AT* alpha = static_cast<const AT*>(_alpha);
1772 int swidth = src.width();
1773 int sheight = src.height();
1774 int dwidth = dst.width();
1775 int dheight = dst.height();
1776 int cn = src.channels();
1777 swidth *= cn;
1778 dwidth *= cn;
1779 xmin *= cn;
1780 xmax *= cn;
1781 // image resize is a separable operation. In case of not too strong
1782 // dsize.height
1783 int dy;
1784 HResize hresize;
1785 VResize vresize;
1786
1787 int bufstep = static_cast<int>(align_size(dwidth, 16));
1788 AlignedVector<WT> _buffer(bufstep * ksize);
1789 WT* buffer = _buffer.data();
1790 const T* srows[16] = {0};
1791 WT* rows[16] = {0};
1792 int prev_sy[16];
1793
1794 for (int k = 0; k < ksize; ++k) {
1795 prev_sy[k] = -1;
1796 rows[k] = buffer + bufstep * k;
1797 }
1798
1799 for (dy = 0; dy < dheight; ++dy, beta += ksize) {
1800 int sy0 = yofs[dy], k0 = ksize, k1 = 0, ksize2 = ksize / 2;
1801
1802 for (int k = 0; k < ksize; ++k) {
1803 int sy = saturate(sy0 - ksize2 + 1 + k, 0, sheight);
1804 for (k1 = std::max(k1, k); k1 < ksize; ++k1) {
1805 if (sy == prev_sy[k1]) {
1806 if (k1 > k)
1807 memcpy(rows[k], rows[k1], bufstep * sizeof(rows[0][0]));
1808 break;
1809 }
1810 }
1811 if (k1 == ksize)
1812 k0 = std::min(k0, k);
1813 srows[k] = src.ptr(sy);
1814 prev_sy[k] = sy;
1815 }
1816 if (k0 < ksize)
1817 hresize(srows + k0, rows + k0, ksize - k0, xofs, alpha, swidth, dwidth, cn,
1818 xmin, xmax);
1819 vresize((const WT**)(rows), dst.ptr(dy), beta, dwidth);
1820 }

Callers

nothing calls this directly

Calls 9

maxFunction · 0.85
align_sizeFunction · 0.50
saturateFunction · 0.50
minFunction · 0.50
widthMethod · 0.45
heightMethod · 0.45
channelsMethod · 0.45
dataMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected