| 1230 | |
| 1231 | template <typename T> |
| 1232 | void resize_opencv(const Mat<T>& src, Mat<T>& dst, InterpolationMode ip) { |
| 1233 | // fake area mode missing here |
| 1234 | int dwidth = dst.width(); |
| 1235 | int dheight = dst.height(); |
| 1236 | int swidth = src.width(); |
| 1237 | int sheight = src.height(); |
| 1238 | int xmin = 0, xmax = dwidth, width = dwidth * dst.channels(); |
| 1239 | double inv_scale_x = static_cast<double>(dwidth) / swidth; |
| 1240 | double inv_scale_y = static_cast<double>(dheight) / sheight; |
| 1241 | double scale_x = 1.0 / inv_scale_x; |
| 1242 | double scale_y = 1.0 / inv_scale_y; |
| 1243 | int dx, sx, dy, sy, k; |
| 1244 | float fx, fy; |
| 1245 | int cn = src.channels(); |
| 1246 | { |
| 1247 | int iscale_x = saturate_cast<int>(scale_x); |
| 1248 | int iscale_y = saturate_cast<int>(scale_y); |
| 1249 | |
| 1250 | bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON && |
| 1251 | std::abs(scale_y - iscale_y) < DBL_EPSILON; |
| 1252 | if (ip == IMode::INTER_LINEAR && is_area_fast && iscale_x == 2 && |
| 1253 | iscale_y == 2) { |
| 1254 | ip = IMode::INTER_AREA; |
| 1255 | } |
| 1256 | if (ip == IMode::INTER_AREA && scale_x >= 1 && scale_y >= 1) { |
| 1257 | if (is_area_fast) { |
| 1258 | int area = iscale_x * iscale_y; |
| 1259 | size_t srcstep = src.step(); |
| 1260 | AlignedVector<int> _ofs(area + dwidth * cn); |
| 1261 | int* ofs = _ofs.data(); |
| 1262 | int* xofs = ofs + area; |
| 1263 | ResizeAreaFastFunc<T> func = |
| 1264 | get_resize_area_fast_func<T>(); /// need change |
| 1265 | for (sy = 0, k = 0; sy < iscale_y; ++sy) |
| 1266 | for (sx = 0; sx < iscale_x; ++sx) |
| 1267 | ofs[k++] = static_cast<int>(sy * srcstep + sx * cn); |
| 1268 | for (dx = 0; dx < dwidth; ++dx) { |
| 1269 | int j = dx * cn; |
| 1270 | sx = iscale_x * j; |
| 1271 | for (k = 0; k < cn; ++k) |
| 1272 | xofs[j + k] = sx + k; |
| 1273 | } |
| 1274 | func(src, dst, ofs, xofs, iscale_x, iscale_y); |
| 1275 | return; |
| 1276 | } |
| 1277 | ResizeAreaFunc<T> func = get_resize_area_func<T>(); |
| 1278 | AlignedVector<DecimateAlpha> _xytab((swidth + sheight) * 2); |
| 1279 | DecimateAlpha *xtab = _xytab.data(), *ytab = xtab + swidth * 2; |
| 1280 | int xtab_size = compute_resize_area_tab(swidth, dwidth, cn, scale_x, xtab); |
| 1281 | int ytab_size = compute_resize_area_tab(sheight, dheight, 1, scale_y, ytab); |
| 1282 | AlignedVector<int> _tabofs(dheight + 1); |
| 1283 | int* tabofs = _tabofs.data(); |
| 1284 | for (k = 0, dy = 0; k < ytab_size; ++k) { |
| 1285 | if (k == 0 || ytab[k].di != ytab[k - 1].di) { |
| 1286 | megdnn_assert(ytab[k].di == dy); |
| 1287 | tabofs[dy++] = k; |
| 1288 | } |
| 1289 | } |
nothing calls this directly
no test coverage detected