29struct ApplyIntrinsicsFunction {
30 ApplyIntrinsicsFunction(
const CameraIntrinsics& intrinsics,
35 double normalized_x, normalized_y;
36 intrinsics.ImageSpaceToNormalized(
x,
y, &normalized_x, &normalized_y);
37 intrinsics.ApplyIntrinsics(normalized_x, normalized_y, warp_x, warp_y);
41struct InvertIntrinsicsFunction {
42 InvertIntrinsicsFunction(
const CameraIntrinsics& intrinsics,
47 double normalized_x, normalized_y;
48 intrinsics.InvertIntrinsics(
x,
y, &normalized_x, &normalized_y);
49 intrinsics.NormalizedToImageSpace(
50 normalized_x, normalized_y, warp_x, warp_y);
59template <
typename WarpFunction>
60void LookupWarpGrid::Compute(
const CameraIntrinsics& intrinsics,
66 const double aspx = (double)
w / intrinsics.image_width();
67 const double aspy = (double)h / intrinsics.image_height();
71 double src_x = (
x - 0.5 *
overscan *
w) / aspx,
73 double warp_x, warp_y;
74 WarpFunction(intrinsics, src_x, src_y, &warp_x, &warp_y);
75 warp_x = warp_x * aspx + 0.5 *
overscan *
w;
76 warp_y = warp_y * aspy + 0.5 *
overscan * h;
77 int ix = int(warp_x), iy = int(warp_y);
78 int fx =
round((warp_x - ix) * 256), fy =
round((warp_y - iy) * 256);
99 Offset offset = {(short)(ix -
x),
103 offset_[
y *
width +
x] = offset;
108template <
typename WarpFunction>
117 if (offset_ == NULL) {
128template <
typename PixelType>
133 PixelType* output_buffer) {
136 Offset offset = offset_[
y *
width +
x];
137 const int pixel_index =
138 ((
y + offset.iy) *
width + (
x + offset.ix)) * channels;
139 const PixelType* s = &input_buffer[pixel_index];
140 for (
int i = 0; i < channels; i++) {
141 output_buffer[(
y *
width +
x) * channels + i] =
142 ((s[i] * (256 - offset.fx) + s[channels + i] * offset.fx) *
144 (s[
width * channels + i] * (256 - offset.fx) +
145 s[
width * channels + channels + i] * offset.fx) *
155template <
typename PixelType>
161 PixelType* output_buffer) {
164 distort_.
Update<InvertIntrinsicsFunction>(*
this, width, height, overscan);
165 distort_.
Apply<PixelType>(
166 input_buffer, width, height, channels, output_buffer);
169template <
typename PixelType>
175 PixelType* output_buffer) {
178 undistort_.
Update<ApplyIntrinsicsFunction>(*
this, width, height, overscan);
180 undistort_.
Apply<PixelType>(
181 input_buffer, width, height, channels, output_buffer);
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void DistortBuffer(const PixelType *input_buffer, int width, int height, double overscan, int channels, PixelType *output_buffer)
void UndistortBuffer(const PixelType *input_buffer, int width, int height, double overscan, int channels, PixelType *output_buffer)
void Apply(const PixelType *input_buffer, int width, int height, int channels, PixelType *output_buffer)
void Update(const CameraIntrinsics &intrinsics, int width, int height, double overscan)
#define assert(assertion)
void parallel_for(const Index first, const Index last, const Function &f)