| 1068 | // resize Area Fast |
| 1069 | template <typename T, typename WT, typename VecOp> |
| 1070 | void resizeAreaFast_( |
| 1071 | const Mat<T>& src, Mat<T>& dst, const int* ofs, const int* xofs, int scale_x, |
| 1072 | int scale_y) { |
| 1073 | // Range range(0, dst.rows); |
| 1074 | int swidth = src.width(); |
| 1075 | int sheight = src.height(); |
| 1076 | int dwidth = dst.width(); |
| 1077 | int dheight = dst.height(); |
| 1078 | int cn = src.channels(); |
| 1079 | int area = scale_x * scale_y; |
| 1080 | float scale = 1.f / (area); |
| 1081 | int dwidth1 = (swidth / scale_x) * cn; |
| 1082 | dwidth *= cn; |
| 1083 | swidth *= cn; |
| 1084 | int dy, dx, k = 0; |
| 1085 | |
| 1086 | VecOp vop(scale_x, scale_y, src.channels(), (int)src.step()); |
| 1087 | |
| 1088 | for (dy = 0; dy < dheight; dy++) { |
| 1089 | T* D = (T*)(dst.ptr(dy)); |
| 1090 | int sy0 = dy * scale_y; |
| 1091 | int w = sy0 + scale_y <= sheight ? dwidth1 : 0; |
| 1092 | |
| 1093 | if (sy0 >= sheight) { |
| 1094 | for (dx = 0; dx < dwidth; dx++) |
| 1095 | D[dx] = 0; |
| 1096 | continue; |
| 1097 | } |
| 1098 | |
| 1099 | dx = vop((const T*)(src.ptr(sy0)), D, w); |
| 1100 | for (; dx < w; dx++) { |
| 1101 | const T* S = (const T*)(src.ptr(sy0)) + xofs[dx]; |
| 1102 | WT sum = 0; |
| 1103 | k = 0; |
| 1104 | #if MEGCV_ENABLE_UNROLLED |
| 1105 | for (; k <= area - 4; k += 4) |
| 1106 | sum += S[ofs[k]] + S[ofs[k + 1]] + S[ofs[k + 2]] + S[ofs[k + 3]]; |
| 1107 | #endif |
| 1108 | for (; k < area; k++) |
| 1109 | sum += S[ofs[k]]; |
| 1110 | |
| 1111 | D[dx] = saturate_cast<T>(sum * scale); |
| 1112 | } |
| 1113 | |
| 1114 | for (; dx < dwidth; dx++) { |
| 1115 | WT sum = 0; |
| 1116 | int count = 0, sx0 = xofs[dx]; |
| 1117 | if (sx0 >= swidth) |
| 1118 | D[dx] = 0; |
| 1119 | |
| 1120 | for (int sy = 0; sy < scale_y; sy++) { |
| 1121 | if (sy0 + sy >= sheight) |
| 1122 | break; |
| 1123 | const T* S = (const T*)(src.ptr(sy0 + sy)) + sx0; |
| 1124 | for (int sx = 0; sx < scale_x * cn; sx += cn) { |
| 1125 | if (sx0 + sx >= swidth) |
| 1126 | break; |
| 1127 | sum += S[sx]; |