diff --git a/th01/math/subpixel.hpp b/th01/math/subpixel.hpp index f2d152a6..2ee9e54d 100644 --- a/th01/math/subpixel.hpp +++ b/th01/math/subpixel.hpp @@ -8,48 +8,50 @@ typedef int subpixel_t; #define TO_SP(v) \ (v << 4) -inline subpixel_t to_sp(float screen_v) { - return static_cast(screen_v * 16.0f); +inline subpixel_t to_sp(float pixel_v) { + return static_cast(pixel_v * 16.0f); } -template class SubpixelBase { +template class SubpixelBase { public: + typedef SubpixelBase SelfType; + // Code generation will require direct access to v, if performing // arithmetic with a local variable... - T v; + SubpixelType v; - subpixel_t operator -(const SubpixelBase &other) { + SubpixelType operator -(const SelfType &other) { return (this->v - other.v); } - void operator +=(float screen_v) { - this->v += static_cast(to_sp(screen_v)); + void operator +=(float pixel_v) { + this->v += static_cast(to_sp(pixel_v)); } - void operator -=(float screen_v) { - this->v -= static_cast(to_sp(screen_v)); + void operator -=(float pixel_v) { + this->v -= static_cast(to_sp(pixel_v)); } // No overloads of `operator =()`, since the class needs to be trivially // copyable. - void set(float screen_v) { - v = static_cast(to_sp(screen_v)); + void set(float pixel_v) { + v = static_cast(to_sp(pixel_v)); } - void set(const T &screen_v) { - v = TO_SP(screen_v); + void set(const PixelType &pixel_v) { + v = static_cast(TO_SP(pixel_v)); } - T to_pixel() const { - return v >> 4; + PixelType to_pixel() const { + return static_cast(v >> 4); } - operator T() const { + operator SubpixelType() const { return v; } - static T None() { - return to_sp(PIXEL_NONE); + static SubpixelType None() { + return static_cast(TO_SP(PIXEL_NONE)); } }; @@ -63,9 +65,9 @@ template struct SPPointBase { }; // 16-bit (Q12.4) -typedef SubpixelBase Subpixel; +typedef SubpixelBase Subpixel; typedef SPPointBase SPPoint; // 8-bit (Q4.4) -typedef SubpixelBase SubpixelLength8; -typedef SubpixelBase Subpixel8; +typedef SubpixelBase SubpixelLength8; +typedef SubpixelBase Subpixel8; typedef SPPointBase SPPoint8;