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

Function resize_opencv

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

Source from the content-addressed store, hash-verified

1789
1790template <typename T>
1791void resize_opencv(const Mat<T>& src, Mat<T>& dst, InterpolationMode ip) {
1792 // fake area mode missing here
1793 int dwidth = dst.width();
1794 int dheight = dst.height();
1795 int swidth = src.width();
1796 int sheight = src.height();
1797 int xmin = 0, xmax = dwidth, width = dwidth * dst.channels();
1798 double inv_scale_x = static_cast<double>(dwidth) / swidth;
1799 double inv_scale_y = static_cast<double>(dheight) / sheight;
1800 double scale_x = 1.0 / inv_scale_x;
1801 double scale_y = 1.0 / inv_scale_y;
1802 int dx, sx, dy, sy, k;
1803 float fx, fy;
1804 int cn = src.channels();
1805 {
1806 int iscale_x = saturate_cast<int>(scale_x);
1807 int iscale_y = saturate_cast<int>(scale_y);
1808
1809 bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON &&
1810 std::abs(scale_y - iscale_y) < DBL_EPSILON;
1811 if (ip == IMode::INTER_LINEAR && is_area_fast && iscale_x == 2 &&
1812 iscale_y == 2) {
1813 ip = IMode::INTER_AREA;
1814 }
1815 if (ip == IMode::INTER_AREA && scale_x >= 1 && scale_y >= 1) {
1816 if (is_area_fast) {
1817 int area = iscale_x * iscale_y;
1818 size_t srcstep = src.step();
1819 AlignedVector<int> _ofs(area + dwidth * cn);
1820 int* ofs = _ofs.data();
1821 int* xofs = ofs + area;
1822 ResizeAreaFastFunc<T> func =
1823 get_resize_area_fast_func<T>(); /// need change
1824 for (sy = 0, k = 0; sy < iscale_y; ++sy)
1825 for (sx = 0; sx < iscale_x; ++sx)
1826 ofs[k++] = static_cast<int>(sy * srcstep + sx * cn);
1827 for (dx = 0; dx < dwidth; ++dx) {
1828 int j = dx * cn;
1829 sx = iscale_x * j;
1830 for (k = 0; k < cn; ++k)
1831 xofs[j + k] = sx + k;
1832 }
1833 func(src, dst, ofs, xofs, iscale_x, iscale_y);
1834 return;
1835 }
1836 ResizeAreaFunc<T> func = get_resize_area_func<T>();
1837 AlignedVector<DecimateAlpha> _xytab((swidth + sheight) * 2);
1838 DecimateAlpha *xtab = _xytab.data(), *ytab = xtab + swidth * 2;
1839 int xtab_size = compute_resize_area_tab(swidth, dwidth, cn, scale_x, xtab);
1840 int ytab_size = compute_resize_area_tab(sheight, dheight, 1, scale_y, ytab);
1841 AlignedVector<int> _tabofs(dheight + 1);
1842 int* tabofs = _tabofs.data();
1843 for (k = 0, dy = 0; k < ytab_size; ++k) {
1844 if (k == 0 || ytab[k].di != ytab[k - 1].di) {
1845 megdnn_assert(ytab[k].di == dy);
1846 tabofs[dy++] = k;
1847 }
1848 }

Callers

nothing calls this directly

Calls 12

compute_resize_area_tabFunction · 0.70
interpolate_cubicFunction · 0.70
interpolate_lanczos4Function · 0.70
absFunction · 0.50
funcFunction · 0.50
floorFunction · 0.50
minFunction · 0.50
widthMethod · 0.45
heightMethod · 0.45
channelsMethod · 0.45
stepMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected