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

Function resizeGeneric_

dnn/src/naive/resize/resize_cv.cpp:739–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737
738template <class HResize, class VResize, class MT>
739void resizeGeneric_(
740 const Mat<MT>& src, Mat<MT>& dst, const int* xofs, const void* _alpha,
741 const int* yofs, const void* _beta, int xmin, int xmax, int ksize) {
742 typedef typename HResize::value_type T;
743 typedef typename HResize::buf_type WT;
744 typedef typename HResize::alpha_type AT;
745
746 const AT* beta = static_cast<const AT*>(_beta);
747 const AT* alpha = static_cast<const AT*>(_alpha);
748 int swidth = src.width();
749 int sheight = src.height();
750 int dwidth = dst.width();
751 int dheight = dst.height();
752 int cn = src.channels();
753 swidth *= cn;
754 dwidth *= cn;
755 xmin *= cn;
756 xmax *= cn;
757 // image resize is a separable operation. In case of not too strong
758 // dsize.height
759 int dy;
760 HResize hresize;
761 VResize vresize;
762
763 int bufstep = static_cast<int>(align_size(dwidth, 16));
764 AlignedVector<WT> _buffer(bufstep * ksize);
765 WT* buffer = _buffer.data();
766 const T* srows[16] = {0};
767 WT* rows[16] = {0};
768 int prev_sy[16];
769
770 for (int k = 0; k < ksize; ++k) {
771 prev_sy[k] = -1;
772 rows[k] = buffer + bufstep * k;
773 }
774
775 for (dy = 0; dy < dheight; ++dy, beta += ksize) {
776 int sy0 = yofs[dy], k0 = ksize, k1 = 0, ksize2 = ksize / 2;
777
778 for (int k = 0; k < ksize; ++k) {
779 int sy = saturate(sy0 - ksize2 + 1 + k, 0, sheight);
780 for (k1 = std::max(k1, k); k1 < ksize; ++k1) {
781 if (sy == prev_sy[k1]) {
782 if (k1 > k)
783 memcpy(rows[k], rows[k1], bufstep * sizeof(rows[0][0]));
784 break;
785 }
786 }
787 if (k1 == ksize)
788 k0 = std::min(k0, k);
789 srows[k] = src.ptr(sy);
790 prev_sy[k] = sy;
791 }
792 if (k0 < ksize)
793 hresize(srows + k0, rows + k0, ksize - k0, xofs, alpha, swidth, dwidth, cn,
794 xmin, xmax);
795 vresize((const WT**)(rows), dst.ptr(dy), beta, dwidth);
796 }

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