| 2195 | |
| 2196 | template <typename T> |
| 2197 | void resize_opencv(const Mat<T>& src, Mat<T>& dst, InterpolationMode ip) { |
| 2198 | // fake area mode missing here |
| 2199 | int dwidth = dst.width(); |
| 2200 | int dheight = dst.height(); |
| 2201 | int swidth = src.width(); |
| 2202 | int sheight = src.height(); |
| 2203 | int xmin = 0, xmax = dwidth, width = dwidth * dst.channels(); |
| 2204 | double inv_scale_x = static_cast<double>(dwidth) / swidth; |
| 2205 | double inv_scale_y = static_cast<double>(dheight) / sheight; |
| 2206 | double scale_x = 1.0 / inv_scale_x; |
| 2207 | double scale_y = 1.0 / inv_scale_y; |
| 2208 | int dx, sx, dy, sy, k; |
| 2209 | float fx, fy; |
| 2210 | int cn = src.channels(); |
| 2211 | { |
| 2212 | int iscale_x = saturate_cast<int>(scale_x); |
| 2213 | int iscale_y = saturate_cast<int>(scale_y); |
| 2214 | |
| 2215 | bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON && |
| 2216 | std::abs(scale_y - iscale_y) < DBL_EPSILON; |
| 2217 | if (ip == IMode::INTER_LINEAR && is_area_fast && iscale_x == 2 && |
| 2218 | iscale_y == 2) { |
| 2219 | ip = IMode::INTER_AREA; |
| 2220 | } |
| 2221 | if (ip == IMode::INTER_AREA && scale_x >= 1 && scale_y >= 1) { |
| 2222 | if (is_area_fast) { |
| 2223 | int area = iscale_x * iscale_y; |
| 2224 | size_t srcstep = src.step(); |
| 2225 | AlignedVector<int> _ofs(area + dwidth * cn); |
| 2226 | int* ofs = _ofs.data(); |
| 2227 | int* xofs = ofs + area; |
| 2228 | ResizeAreaFastFunc<T> func = |
| 2229 | get_resize_area_fast_func<T>(); /// need change |
| 2230 | for (sy = 0, k = 0; sy < iscale_y; ++sy) |
| 2231 | for (sx = 0; sx < iscale_x; ++sx) |
| 2232 | ofs[k++] = static_cast<int>(sy * srcstep + sx * cn); |
| 2233 | for (dx = 0; dx < dwidth; ++dx) { |
| 2234 | int j = dx * cn; |
| 2235 | sx = iscale_x * j; |
| 2236 | for (k = 0; k < cn; ++k) |
| 2237 | xofs[j + k] = sx + k; |
| 2238 | } |
| 2239 | func(src, dst, ofs, xofs, iscale_x, iscale_y); |
| 2240 | return; |
| 2241 | } |
| 2242 | ResizeAreaFunc<T> func = get_resize_area_func<T>(); |
| 2243 | AlignedVector<DecimateAlpha> _xytab((swidth + sheight) * 2); |
| 2244 | DecimateAlpha *xtab = _xytab.data(), *ytab = xtab + swidth * 2; |
| 2245 | int xtab_size = compute_resize_area_tab(swidth, dwidth, cn, scale_x, xtab); |
| 2246 | int ytab_size = compute_resize_area_tab(sheight, dheight, 1, scale_y, ytab); |
| 2247 | AlignedVector<int> _tabofs(dheight + 1); |
| 2248 | int* tabofs = _tabofs.data(); |
| 2249 | for (k = 0, dy = 0; k < ytab_size; ++k) { |
| 2250 | if (k == 0 || ytab[k].di != ytab[k - 1].di) { |
| 2251 | megdnn_assert(ytab[k].di == dy); |
| 2252 | tabofs[dy++] = k; |
| 2253 | } |
| 2254 | } |
nothing calls this directly
no test coverage detected