| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef INTERPOLATOR_H |
| 17 |
#define INTERPOLATOR_H |
| 18 |
|
| 19 |
#include <stddef.h> |
| 20 |
#include <memory> |
| 21 |
|
| 22 |
#include <cutils/compiler.h> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
namespace android { |
| 26 |
namespace uirenderer { |
| 27 |
|
| 28 |
class Interpolator { |
| 29 |
public: |
| 30 |
virtual ~Interpolator() {} |
| 31 |
|
| 32 |
virtual float interpolate(float input) = 0; |
| 33 |
|
| 34 |
static Interpolator* createDefaultInterpolator(); |
| 35 |
|
| 36 |
protected: |
| 37 |
Interpolator() {} |
| 38 |
}; |
| 39 |
|
| 40 |
class AccelerateDecelerateInterpolator : public Interpolator { |
| 41 |
public: |
| 42 |
virtual float interpolate(float input) override; |
| 43 |
}; |
| 44 |
|
| 45 |
class AccelerateInterpolator : public Interpolator { |
| 46 |
public: |
| 47 |
explicit AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor * 2) {} |
| 48 |
virtual float interpolate(float input) override; |
| 49 |
|
| 50 |
private: |
| 51 |
const float mFactor; |
| 52 |
const float mDoubleFactor; |
| 53 |
}; |
| 54 |
|
| 55 |
class AnticipateInterpolator : public Interpolator { |
| 56 |
public: |
| 57 |
explicit AnticipateInterpolator(float tension) : mTension(tension) {} |
| 58 |
virtual float interpolate(float input) override; |
| 59 |
|
| 60 |
private: |
| 61 |
const float mTension; |
| 62 |
}; |
| 63 |
|
| 64 |
class AnticipateOvershootInterpolator : public Interpolator { |
| 65 |
public: |
| 66 |
explicit AnticipateOvershootInterpolator(float tension) : mTension(tension) {} |
| 67 |
virtual float interpolate(float input) override; |
| 68 |
|
| 69 |
private: |
| 70 |
const float mTension; |
| 71 |
}; |
| 72 |
|
| 73 |
class BounceInterpolator : public Interpolator { |
| 74 |
public: |
| 75 |
virtual float interpolate(float input) override; |
| 76 |
}; |
| 77 |
|
| 78 |
class CycleInterpolator : public Interpolator { |
| 79 |
public: |
| 80 |
explicit CycleInterpolator(float cycles) : mCycles(cycles) {} |
| 81 |
virtual float interpolate(float input) override; |
| 82 |
|
| 83 |
private: |
| 84 |
const float mCycles; |
| 85 |
}; |
| 86 |
|
| 87 |
class DecelerateInterpolator : public Interpolator { |
| 88 |
public: |
| 89 |
explicit DecelerateInterpolator(float factor) : mFactor(factor) {} |
| 90 |
virtual float interpolate(float input) override; |
| 91 |
|
| 92 |
private: |
| 93 |
const float mFactor; |
| 94 |
}; |
| 95 |
|
| 96 |
class LinearInterpolator : public Interpolator { |
| 97 |
public: |
| 98 |
virtual float interpolate(float input) override { return input; } |
| 99 |
}; |
| 100 |
|
| 101 |
class OvershootInterpolator : public Interpolator { |
| 102 |
public: |
| 103 |
explicit OvershootInterpolator(float tension) : mTension(tension) {} |
| 104 |
virtual float interpolate(float input) override; |
| 105 |
|
| 106 |
private: |
| 107 |
const float mTension; |
| 108 |
}; |
| 109 |
|
| 110 |
class PathInterpolator : public Interpolator { |
| 111 |
public: |
| 112 |
explicit PathInterpolator(std::vector<float>&& x, std::vector<float>&& y) : mX(x), mY(y) {} |
| 113 |
virtual float interpolate(float input) override; |
| 114 |
|
| 115 |
private: |
| 116 |
std::vector<float> mX; |
| 117 |
std::vector<float> mY; |
| 118 |
}; |
| 119 |
|
| 120 |
class LUTInterpolator : public Interpolator { |
| 121 |
public: |
| 122 |
LUTInterpolator(float* values, size_t size); |
| 123 |
~LUTInterpolator(); |
| 124 |
|
| 125 |
virtual float interpolate(float input) override; |
| 126 |
|
| 127 |
private: |
| 128 |
std::unique_ptr<float[]> mValues; |
| 129 |
size_t mSize; |
| 130 |
}; |
| 131 |
|
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
#endif |