| 135 | } |
| 136 | |
| 137 | void resize_nearest_32f(const Mat32f& src, Mat32f& dst) { |
| 138 | AlignedVector<int> tabx(dst.rows()); |
| 139 | AlignedVector<int> taby(dst.cols()); |
| 140 | const double fx = static_cast<double>(dst.rows()) / src.rows(); |
| 141 | const double fy = static_cast<double>(dst.cols()) / src.cols(); |
| 142 | const double ifx = 1.0f / fx; |
| 143 | const double ify = 1.0f / fy; |
| 144 | const size_t ch = src.channels(); |
| 145 | for (size_t dx = 0; dx < tabx.size(); ++dx) { |
| 146 | double rx = dx * ifx; |
| 147 | int sx = static_cast<int>(floor(rx)); |
| 148 | sx = megcv::saturate(sx, 0, static_cast<int>(src.rows())); |
| 149 | tabx[dx] = sx; |
| 150 | } |
| 151 | for (size_t dy = 0; dy < taby.size(); ++dy) { |
| 152 | double ry = dy * ify; |
| 153 | int sy = static_cast<int>(floor(ry)); |
| 154 | sy = megcv::saturate(sy, 0, static_cast<int>(src.cols())); |
| 155 | taby[dy] = sy; |
| 156 | } |
| 157 | // taby[taby.size() - 1] = src.cols() - 1; |
| 158 | size_t tabxsize = tabx.size(); |
| 159 | size_t tabysize = taby.size(); |
| 160 | if (ch == 1) { |
| 161 | for (size_t dx = 0; dx < tabxsize; ++dx) { |
| 162 | float* pdst = dst.ptr(dx); |
| 163 | const float* psrc = src.ptr(tabx[dx]); |
| 164 | size_t dy = 0; |
| 165 | for (; dy < tabysize; dy++) { |
| 166 | const float* pcsrc = psrc + taby[dy]; |
| 167 | pdst[dy] = pcsrc[0]; |
| 168 | } |
| 169 | } |
| 170 | } else if (ch == 3) { |
| 171 | for (size_t dx = 0; dx < tabxsize; ++dx) { |
| 172 | float* pdst = dst.ptr(dx); |
| 173 | const float* psrc = src.ptr(tabx[dx]); |
| 174 | size_t dy3 = 0; |
| 175 | for (size_t dy = 0; dy < tabysize; ++dy, dy3 += 3) { |
| 176 | float* pcdst = pdst + dy3; |
| 177 | const float* pcsrc = psrc + taby[dy] * 3; |
| 178 | pcdst[0] = pcsrc[0]; |
| 179 | pcdst[1] = pcsrc[1]; |
| 180 | pcdst[2] = pcsrc[2]; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // linear 32f |
| 187 | void build_tabs_linear_32f( |