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

Function resizeAreaFast_

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

Source from the content-addressed store, hash-verified

1542// resize Area Fast
1543template <typename T, typename WT, typename VecOp>
1544void resizeAreaFast_(
1545 const Mat<T>& src, Mat<T>& dst, const int* ofs, const int* xofs, int scale_x,
1546 int scale_y) {
1547 // Range range(0, dst.rows);
1548 int swidth = src.width();
1549 int sheight = src.height();
1550 int dwidth = dst.width();
1551 int dheight = dst.height();
1552 int cn = src.channels();
1553 int area = scale_x * scale_y;
1554 float scale = 1.f / (area);
1555 int dwidth1 = (swidth / scale_x) * cn;
1556 dwidth *= cn;
1557 swidth *= cn;
1558 int dy, dx, k = 0;
1559
1560 VecOp vop(scale_x, scale_y, src.channels(), (int)src.step());
1561
1562 for (dy = 0; dy < dheight; dy++) {
1563 T* D = (T*)(dst.ptr(dy));
1564 int sy0 = dy * scale_y;
1565 int w = sy0 + scale_y <= sheight ? dwidth1 : 0;
1566
1567 if (sy0 >= sheight) {
1568 for (dx = 0; dx < dwidth; dx++)
1569 D[dx] = 0;
1570 continue;
1571 }
1572
1573 dx = vop((const T*)(src.ptr(sy0)), D, w);
1574 for (; dx < w; dx++) {
1575 const T* S = (const T*)(src.ptr(sy0)) + xofs[dx];
1576 WT sum = 0;
1577 k = 0;
1578#if MEGCV_ENABLE_UNROLLED
1579 for (; k <= area - 4; k += 4)
1580 sum += S[ofs[k]] + S[ofs[k + 1]] + S[ofs[k + 2]] + S[ofs[k + 3]];
1581#endif
1582 for (; k < area; k++)
1583 sum += S[ofs[k]];
1584
1585 D[dx] = saturate_cast<T>(sum * scale);
1586 }
1587
1588 for (; dx < dwidth; dx++) {
1589 WT sum = 0;
1590 int count = 0, sx0 = xofs[dx];
1591 if (sx0 >= swidth)
1592 D[dx] = 0;
1593
1594 for (int sy = 0; sy < scale_y; sy++) {
1595 if (sy0 + sy >= sheight)
1596 break;
1597 const T* S = (const T*)(src.ptr(sy0 + sy)) + sx0;
1598 for (int sx = 0; sx < scale_x * cn; sx += cn) {
1599 if (sx0 + sx >= swidth)
1600 break;
1601 sum += S[sx];

Callers

nothing calls this directly

Calls 5

widthMethod · 0.45
heightMethod · 0.45
channelsMethod · 0.45
stepMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected