diff --git a/src/common/tvgMath.cpp b/src/common/tvgMath.cpp index d22232ee..0254cce9 100644 --- a/src/common/tvgMath.cpp +++ b/src/common/tvgMath.cpp @@ -132,4 +132,12 @@ Point operator*(const Point& pt, const Matrix& m) auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13; auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23; return {tx, ty}; -} \ No newline at end of file +} + +uint8_t mathLerp(const uint8_t &start, const uint8_t &end, float t) +{ + auto result = static_cast(start + (end - start) * t); + if (result > 255) result = 255; + else if (result < 0) result = 0; + return static_cast(result); +} diff --git a/src/common/tvgMath.h b/src/common/tvgMath.h index 556ed410..df39e3b9 100644 --- a/src/common/tvgMath.h +++ b/src/common/tvgMath.h @@ -259,5 +259,6 @@ static inline T mathLerp(const T &start, const T &end, float t) return static_cast(start + (end - start) * t); } +uint8_t mathLerp(const uint8_t &start, const uint8_t &end, float t); #endif //_TVG_MATH_H_