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

Function resizeGeneric_

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

Source from the content-addressed store, hash-verified

924
925template <class HResize, class VResize, class MT>
926void resizeGeneric_(
927 const Mat<MT>& src, Mat<MT>& dst, const int* xofs, const void* _alpha,
928 const int* yofs, const void* _beta, int xmin, int xmax, int ksize) {
929 typedef typename HResize::value_type T;
930 typedef typename HResize::buf_type WT;
931 typedef typename HResize::alpha_type AT;
932
933 const AT* beta = static_cast<const AT*>(_beta);
934 const AT* alpha = static_cast<const AT*>(_alpha);
935 int swidth = src.width();
936 int sheight = src.height();
937 int dwidth = dst.width();
938 int dheight = dst.height();
939 int cn = src.channels();
940 swidth *= cn;
941 dwidth *= cn;
942 xmin *= cn;
943 xmax *= cn;
944 // image resize is a separable operation. In case of not too strong
945 // dsize.height
946 int dy;
947 HResize hresize;
948 VResize vresize;
949
950 int bufstep = static_cast<int>(align_size(dwidth, 16));
951 AlignedVector<WT> _buffer(bufstep * ksize);
952 WT* buffer = _buffer.data();
953 const T* srows[16] = {0};
954 WT* rows[16] = {0};
955 int prev_sy[16];
956
957 for (int k = 0; k < ksize; ++k) {
958 prev_sy[k] = -1;
959 rows[k] = buffer + bufstep * k;
960 }
961
962 for (dy = 0; dy < dheight; ++dy, beta += ksize) {
963 int sy0 = yofs[dy], k0 = ksize, k1 = 0, ksize2 = ksize / 2;
964
965 for (int k = 0; k < ksize; ++k) {
966 int sy = saturate(sy0 - ksize2 + 1 + k, 0, sheight);
967 for (k1 = std::max(k1, k); k1 < ksize; ++k1) {
968 if (sy == prev_sy[k1]) {
969 if (k1 > k)
970 memcpy(rows[k], rows[k1], bufstep * sizeof(rows[0][0]));
971 break;
972 }
973 }
974 if (k1 == ksize)
975 k0 = std::min(k0, k);
976 srows[k] = src.ptr(sy);
977 prev_sy[k] = sy;
978 }
979 if (k0 < ksize)
980 hresize(srows + k0, rows + k0, ksize - k0, xofs, alpha, swidth, dwidth, cn,
981 xmin, xmax);
982 vresize((const WT**)(rows), dst.ptr(dy), beta, dwidth);
983 }

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