diff --git a/th01/math/subpixel.hpp b/th01/math/subpixel.hpp index c0363cbd..468a3987 100644 --- a/th01/math/subpixel.hpp +++ b/th01/math/subpixel.hpp @@ -7,18 +7,21 @@ typedef int subpixel_t; +static const subpixel_t SUBPIXEL_FACTOR = 16; +static const char SUBPIXEL_BITS = 4; + #define TO_SP(v) \ - (v << 4) + (v << SUBPIXEL_BITS) #define TO_PIXEL(v) \ - (v >> 4) + (v >> SUBPIXEL_BITS) // In-place conversion to a pixel. Ugly, and should not exist. #define TO_PIXEL_INPLACE(v) \ - (v >>= 4) + (v >>= SUBPIXEL_BITS) inline subpixel_t to_sp(float pixel_v) { - return static_cast(pixel_v * 16.0f); + return static_cast(pixel_v * SUBPIXEL_FACTOR); } inline unsigned char to_sp8(float pixel_v) { diff --git a/th01/math/subpixel.inc b/th01/math/subpixel.inc index c51c152f..e11a5ca1 100644 --- a/th01/math/subpixel.inc +++ b/th01/math/subpixel.inc @@ -1,2 +1,5 @@ PIXEL_NONE = -999 SUBPIXEL_NONE = (PIXEL_NONE shl 4) + +SUBPIXEL_FACTOR = 16 +SUBPIXEL_BITS = 4