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

Function resize_nearest_8u

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

Source from the content-addressed store, hash-verified

86// nearest neighbor
87
88void resize_nearest_8u(const Mat8u& src, Mat8u& dst) {
89 AlignedVector<int> tabx(dst.rows());
90 AlignedVector<int> taby(dst.cols());
91 const double fx = static_cast<double>(dst.rows()) / src.rows();
92 const double fy = static_cast<double>(dst.cols()) / src.cols();
93 const double ifx = 1.0f / fx;
94 const double ify = 1.0f / fy;
95 const size_t ch = src.channels();
96 for (size_t dx = 0; dx < tabx.size(); ++dx) {
97 double rx = dx * ifx;
98 int sx = static_cast<int>(floor(rx));
99 sx = megcv::saturate(sx, 0, static_cast<int>(src.rows()));
100 tabx[dx] = sx;
101 }
102 for (size_t dy = 0; dy < taby.size(); ++dy) {
103 double ry = dy * ify;
104 int sy = static_cast<int>(floor(ry));
105 sy = megcv::saturate(sy, 0, static_cast<int>(src.cols()));
106 taby[dy] = sy;
107 }
108
109 int tabxsize = tabx.size();
110 int tabysize = taby.size();
111 if (ch == 1) {
112 for (int dx = 0; dx < tabxsize; ++dx) {
113 uchar* pdst = dst.ptr(dx);
114 const uchar* psrc = src.ptr(tabx[dx]);
115 for (int dy = 0; dy < tabysize; ++dy) {
116 uchar* pcdst = pdst + dy;
117 const uchar* pcsrc = psrc + taby[dy];
118 pcdst[0] = pcsrc[0];
119 }
120 }
121 } else if (ch == 3) {
122 for (int dx = 0; dx < tabxsize; ++dx) {
123 uchar* pdst = dst.ptr(dx);
124 const uchar* psrc = src.ptr(tabx[dx]);
125 int dy3 = 0;
126 for (int dy = 0; dy < tabysize; ++dy, dy3 += 3) {
127 uchar* pcdst = pdst + dy3;
128 const uchar* pcsrc = psrc + taby[dy] * 3;
129 pcdst[0] = pcsrc[0];
130 pcdst[1] = pcsrc[1];
131 pcdst[2] = pcsrc[2];
132 }
133 }
134 }
135}
136
137void resize_nearest_32f(const Mat32f& src, Mat32f& dst) {
138 AlignedVector<int> tabx(dst.rows());

Callers 1

resize_cv_execMethod · 0.70

Calls 7

floorFunction · 0.50
saturateFunction · 0.50
rowsMethod · 0.45
colsMethod · 0.45
channelsMethod · 0.45
sizeMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected