| 175 | } |
| 176 | |
| 177 | UndistortMapFast buildFastRectifyMap(const UndistortMap& map) { |
| 178 | UndistortMapFast fast; |
| 179 | if (!map.valid() || map.src_width <= 0 || map.src_height <= 0) { |
| 180 | return fast; // invalid -> caller treats as "do not rectify". |
| 181 | } |
| 182 | fast.out_width = map.out_width; |
| 183 | fast.out_height = map.out_height; |
| 184 | fast.src_width = map.src_width; |
| 185 | fast.src_height = map.src_height; |
| 186 | |
| 187 | const int sw = map.src_width; |
| 188 | const int sh = map.src_height; |
| 189 | const auto n = static_cast<size_t>(map.out_width) * static_cast<size_t>(map.out_height); |
| 190 | fast.src_p0.resize(n); |
| 191 | fast.frac_x.resize(n); |
| 192 | fast.frac_y.resize(n); |
| 193 | |
| 194 | for (size_t i = 0; i < n; ++i) { |
| 195 | const float fx = map.src_x[i]; |
| 196 | const float fy = map.src_y[i]; |
| 197 | if (!bilinearTapInBounds(fx, fy, sw, sh)) { |
| 198 | fast.src_p0[i] = -1; |
| 199 | fast.frac_x[i] = 0.0F; |
| 200 | fast.frac_y[i] = 0.0F; |
| 201 | continue; |
| 202 | } |
| 203 | const float x0f = std::floor(fx); |
| 204 | const float y0f = std::floor(fy); |
| 205 | const int x0 = static_cast<int>(x0f); |
| 206 | const int y0 = static_cast<int>(y0f); |
| 207 | fast.src_p0[i] = y0 * sw + x0; // linear pixel index; rectifyFrameFast scales by channels. |
| 208 | fast.frac_x[i] = fx - x0f; |
| 209 | fast.frac_y[i] = fy - y0f; |
| 210 | } |
| 211 | return fast; |
| 212 | } |
| 213 | |
| 214 | std::vector<float> undistortMapToNormalizedRG(const UndistortMap& map) { |
| 215 | std::vector<float> rg; |