| 1947 | // resize Area Fast |
| 1948 | template <typename T, typename WT, typename VecOp> |
| 1949 | void resizeAreaFast_( |
| 1950 | const Mat<T>& src, Mat<T>& dst, const int* ofs, const int* xofs, int scale_x, |
| 1951 | int scale_y) { |
| 1952 | // Range range(0, dst.rows); |
| 1953 | int swidth = src.width(); |
| 1954 | int sheight = src.height(); |
| 1955 | int dwidth = dst.width(); |
| 1956 | int dheight = dst.height(); |
| 1957 | int cn = src.channels(); |
| 1958 | int area = scale_x * scale_y; |
| 1959 | float scale = 1.f / (area); |
| 1960 | int dwidth1 = (swidth / scale_x) * cn; |
| 1961 | dwidth *= cn; |
| 1962 | swidth *= cn; |
| 1963 | int dy, dx, k = 0; |
| 1964 | |
| 1965 | VecOp vop(scale_x, scale_y, src.channels(), (int)src.step()); |
| 1966 | |
| 1967 | for (dy = 0; dy < dheight; dy++) { |
| 1968 | T* D = (T*)(dst.ptr(dy)); |
| 1969 | int sy0 = dy * scale_y; |
| 1970 | int w = sy0 + scale_y <= sheight ? dwidth1 : 0; |
| 1971 | |
| 1972 | if (sy0 >= sheight) { |
| 1973 | for (dx = 0; dx < dwidth; dx++) |
| 1974 | D[dx] = 0; |
| 1975 | continue; |
| 1976 | } |
| 1977 | |
| 1978 | dx = vop((const T*)(src.ptr(sy0)), D, w); |
| 1979 | for (; dx < w; dx++) { |
| 1980 | const T* S = (const T*)(src.ptr(sy0)) + xofs[dx]; |
| 1981 | WT sum = 0; |
| 1982 | k = 0; |
| 1983 | #if MEGCV_ENABLE_UNROLLED |
| 1984 | for (; k <= area - 4; k += 4) |
| 1985 | sum += S[ofs[k]] + S[ofs[k + 1]] + S[ofs[k + 2]] + S[ofs[k + 3]]; |
| 1986 | #endif |
| 1987 | for (; k < area; k++) |
| 1988 | sum += S[ofs[k]]; |
| 1989 | |
| 1990 | D[dx] = saturate_cast<T>(sum * scale); |
| 1991 | } |
| 1992 | |
| 1993 | for (; dx < dwidth; dx++) { |
| 1994 | WT sum = 0; |
| 1995 | int count = 0, sx0 = xofs[dx]; |
| 1996 | if (sx0 >= swidth) |
| 1997 | D[dx] = 0; |
| 1998 | |
| 1999 | for (int sy = 0; sy < scale_y; sy++) { |
| 2000 | if (sy0 + sy >= sheight) |
| 2001 | break; |
| 2002 | const T* S = (const T*)(src.ptr(sy0 + sy)) + sx0; |
| 2003 | for (int sx = 0; sx < scale_x * cn; sx += cn) { |
| 2004 | if (sx0 + sx >= swidth) |
| 2005 | break; |
| 2006 | sum += S[sx]; |