Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d32c27c2 authored by Hendrik Wagenaar's avatar Hendrik Wagenaar Committed by android-build-merger
Browse files

Merge "Remove the lookup distortion class" into oc-dev

am: 78145dd4

Change-Id: I358b9f7960cb4df5854b2d9c04eb6b7748a5d751
parents e7761772 78145dd4
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ sourceFiles = [
    "display_metrics.cpp",
    "distortion_renderer.cpp",
    "device_metrics.cpp",
    "lookup_radial_distortion.cpp",
    "polynomial_radial_distortion.cpp",
]

+0 −1
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
#include <cutils/properties.h>
#include <private/dvr/head_mount_metrics.h>
#include <private/dvr/identity_distortion.h>
#include <private/dvr/lookup_radial_distortion.h>
#include <private/dvr/polynomial_radial_distortion.h>
#include <private/dvr/types.h>
#include "include/private/dvr/display_metrics.h"
+0 −31
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_LOOKUP_RADIAL_DISTORTION_H_
#define ANDROID_DVR_LOOKUP_RADIAL_DISTORTION_H_

#include <vector>

#include <private/dvr/color_channel_distortion.h>

namespace android {
namespace dvr {

// LookupRadialDistortion implements a radial distortion based using using a
// vector of tan(angle) -> multipliers.  This can use measured data directly.
class LookupRadialDistortion : public ColorChannelDistortion {
 public:
  // lookup.x = tan(angle), lookup.y = distance from center multiplier.
  explicit LookupRadialDistortion(const vec2* lookup, size_t count);

  vec2 Distort(vec2 p) const override;
  vec2 DistortInverse(vec2 p) const override;

 private:
  float DistortionFactor(float r) const;
  float DistortRadius(float r) const;

  std::vector<vec2> lookup_;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_LOOKUP_RADIAL_DISTORTION_H_
+0 −47
Original line number Diff line number Diff line
#include "include/private/dvr/lookup_radial_distortion.h"

namespace android {
namespace dvr {

LookupRadialDistortion::LookupRadialDistortion(const vec2* lookup, size_t count)
    : lookup_(lookup, lookup + count) {}

float LookupRadialDistortion::DistortionFactor(float r) const {
  for (size_t i = 1; i < lookup_.size(); ++i) {
    if (lookup_[i].x() > r) {
      float t =
          (r - lookup_[i - 1].x()) / (lookup_[i].x() - lookup_[i - 1].x());
      return lookup_[i - 1].y() + t * (lookup_[i].y() - lookup_[i - 1].y());
    }
  }
  return lookup_.back().y();
}

float LookupRadialDistortion::DistortRadius(float r) const {
  return r * DistortionFactor(r);
}

vec2 LookupRadialDistortion::Distort(vec2 p) const {
  return p * DistortionFactor(p.norm());
}

vec2 LookupRadialDistortion::DistortInverse(vec2 p) const {
  // Secant method.
  const float radius = p.norm();
  float r0 = radius / 0.9f;
  float r1 = radius * 0.9f;
  float r2;
  float dr0 = radius - DistortRadius(r0);
  float dr1;
  while (fabsf(r1 - r0) > 0.0001f /** 0.1mm */) {
    dr1 = radius - DistortRadius(r1);
    r2 = r1 - dr1 * ((r1 - r0) / (dr1 - dr0));
    r0 = r1;
    r1 = r2;
    dr0 = dr1;
  }
  return (r1 / radius) * p;
}

}  // namespace dvr
}  // namespace android