| 1171 | |
| 1172 | template <typename T> |
| 1173 | void resize_opencv(const Mat<T>& src, Mat<T>& dst, InterpolationMode ip) { |
| 1174 | // fake area mode missing here |
| 1175 | int dwidth = dst.width(); |
| 1176 | int dheight = dst.height(); |
| 1177 | int swidth = src.width(); |
| 1178 | int sheight = src.height(); |
| 1179 | int xmin = 0, xmax = dwidth, width = dwidth * dst.channels(); |
| 1180 | double inv_scale_x = static_cast<double>(dwidth) / swidth; |
| 1181 | double inv_scale_y = static_cast<double>(dheight) / sheight; |
| 1182 | double scale_x = 1.0 / inv_scale_x; |
| 1183 | double scale_y = 1.0 / inv_scale_y; |
| 1184 | int dx, sx, dy, sy, k; |
| 1185 | float fx, fy; |
| 1186 | int cn = src.channels(); |
| 1187 | { |
| 1188 | int iscale_x = saturate_cast<int>(scale_x); |
| 1189 | int iscale_y = saturate_cast<int>(scale_y); |
| 1190 | |
| 1191 | bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON && |
| 1192 | std::abs(scale_y - iscale_y) < DBL_EPSILON; |
| 1193 | if (ip == IMode::INTER_LINEAR && is_area_fast && iscale_x == 2 && |
| 1194 | iscale_y == 2) { |
| 1195 | ip = IMode::INTER_AREA; |
| 1196 | } |
| 1197 | if (ip == IMode::INTER_AREA && scale_x >= 1 && scale_y >= 1) { |
| 1198 | if (is_area_fast) { |
| 1199 | int area = iscale_x * iscale_y; |
| 1200 | size_t srcstep = src.step(); |
| 1201 | AlignedVector<int> _ofs(area + dwidth * cn); |
| 1202 | int* ofs = _ofs.data(); |
| 1203 | int* xofs = ofs + area; |
| 1204 | ResizeAreaFastFunc<T> func = |
| 1205 | get_resize_area_fast_func<T>(); /// need change |
| 1206 | for (sy = 0, k = 0; sy < iscale_y; ++sy) |
| 1207 | for (sx = 0; sx < iscale_x; ++sx) |
| 1208 | ofs[k++] = static_cast<int>(sy * srcstep + sx * cn); |
| 1209 | for (dx = 0; dx < dwidth; ++dx) { |
| 1210 | int j = dx * cn; |
| 1211 | sx = iscale_x * j; |
| 1212 | for (k = 0; k < cn; ++k) |
| 1213 | xofs[j + k] = sx + k; |
| 1214 | } |
| 1215 | func(src, dst, ofs, xofs, iscale_x, iscale_y); |
| 1216 | return; |
| 1217 | } |
| 1218 | ResizeAreaFunc<T> func = get_resize_area_func<T>(); |
| 1219 | AlignedVector<DecimateAlpha> _xytab((swidth + sheight) * 2); |
| 1220 | DecimateAlpha *xtab = _xytab.data(), *ytab = xtab + swidth * 2; |
| 1221 | int xtab_size = compute_resize_area_tab(swidth, dwidth, cn, scale_x, xtab); |
| 1222 | int ytab_size = compute_resize_area_tab(sheight, dheight, 1, scale_y, ytab); |
| 1223 | AlignedVector<int> _tabofs(dheight + 1); |
| 1224 | int* tabofs = _tabofs.data(); |
| 1225 | for (k = 0, dy = 0; k < ytab_size; ++k) { |
| 1226 | if (k == 0 || ytab[k].di != ytab[k - 1].di) { |
| 1227 | megdnn_assert(ytab[k].di == dy); |
| 1228 | tabofs[dy++] = k; |
| 1229 | } |
| 1230 | } |
nothing calls this directly
no test coverage detected