[Maintenance] Introduce factor and bit count constants for subpixels

Providing that tiny bit of additional readability.

Part of P0182, funded by Lmocinemod and [Anonymous].
This commit is contained in:
nmlgc 2022-02-12 12:33:23 +01:00
parent 70cbf4bbe1
commit 1fd9b6a0c1
2 changed files with 10 additions and 4 deletions

View File

@ -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<subpixel_t>(pixel_v * 16.0f);
return static_cast<subpixel_t>(pixel_v * SUBPIXEL_FACTOR);
}
inline unsigned char to_sp8(float pixel_v) {

View File

@ -1,2 +1,5 @@
PIXEL_NONE = -999
SUBPIXEL_NONE = (PIXEL_NONE shl 4)
SUBPIXEL_FACTOR = 16
SUBPIXEL_BITS = 4