00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkInterpolator_DEFINED
00018 #define SkInterpolator_DEFINED
00019
00020 #include "SkScalar.h"
00021
00022 class SkInterpolatorBase : SkNoncopyable {
00023 public:
00024 enum Result {
00025 kNormal_Result,
00026 kFreezeStart_Result,
00027 kFreezeEnd_Result
00028 };
00029 protected:
00030 SkInterpolatorBase();
00031 ~SkInterpolatorBase();
00032 public:
00033 void reset(int elemCount, int frameCount);
00034
00045 bool getDuration(SkMSec* startTime, SkMSec* endTime) const;
00046
00047
00052 void setMirror(bool mirror) {
00053 fFlags = SkToU8((fFlags & ~kMirror) | (int)mirror);
00054 }
00055
00059 void setRepeatCount(SkScalar repeatCount) { fRepeat = repeatCount; }
00060
00065 void setReset(bool reset) {
00066 fFlags = SkToU8((fFlags & ~kReset) | (int)reset);
00067 }
00068
00069 Result timeToT(SkMSec time, SkScalar* T, int* index, SkBool* exact) const;
00070
00071 protected:
00072 enum Flags {
00073 kMirror = 1,
00074 kReset = 2,
00075 kHasBlend = 4
00076 };
00077 static SkScalar ComputeRelativeT(SkMSec time, SkMSec prevTime,
00078 SkMSec nextTime, const SkScalar blend[4] = NULL);
00079 int16_t fFrameCount;
00080 uint8_t fElemCount;
00081 uint8_t fFlags;
00082 SkScalar fRepeat;
00083 struct SkTimeCode {
00084 SkMSec fTime;
00085 SkScalar fBlend[4];
00086 };
00087 SkTimeCode* fTimes;
00088 void* fStorage;
00089 #ifdef SK_DEBUG
00090 SkTimeCode(* fTimesArray)[10];
00091 #endif
00092 };
00093
00094 class SkInterpolator : public SkInterpolatorBase {
00095 public:
00096 SkInterpolator();
00097 SkInterpolator(int elemCount, int frameCount);
00098 void reset(int elemCount, int frameCount);
00099
00111 bool setKeyFrame(int index, SkMSec time, const SkScalar values[],
00112 const SkScalar blend[4] = NULL);
00113
00121 Result timeToValues(SkMSec time, SkScalar values[] = NULL) const;
00122
00123 SkDEBUGCODE(static void UnitTest();)
00124 private:
00125 SkScalar* fValues;
00126 #ifdef SK_DEBUG
00127 SkScalar(* fScalarsArray)[10];
00128 #endif
00129 typedef SkInterpolatorBase INHERITED;
00130 };
00131
00135 SkScalar SkUnitCubicInterp(SkScalar value, SkScalar bx, SkScalar by,
00136 SkScalar cx, SkScalar cy);
00137
00138 #endif
00139