diff --git a/source/plutovg-utils.h b/source/plutovg-utils.h index 7e657e1..0847b38 100644 --- a/source/plutovg-utils.h +++ b/source/plutovg-utils.h @@ -17,7 +17,6 @@ #define plutovg_min(a, b) ((a) < (b) ? (a) : (b)) #define plutovg_max(a, b) ((a) > (b) ? (a) : (b)) #define plutovg_clamp(v, lo, hi) ((v) < (lo) ? (lo) : (hi) < (v) ? (hi) : (v)) -#define plutovg_div255(x) (((x) + ((x) >> 8) + 0x80) >> 8) #define plutovg_alpha(c) (((c) >> 24) & 0xff) #define plutovg_red(c) (((c) >> 16) & 0xff) @@ -53,6 +52,11 @@ #define plutovg_array_clear(array) ((array).size = 0) #define plutovg_array_destroy(array) free((array).data) +static inline uint32_t plutovg_div255(uint32_t x) +{ + return (((x) + ((x) >> 8) + 0x80) >> 8); +} + static inline uint32_t plutovg_premultiply_argb(uint32_t color) { uint32_t a = plutovg_alpha(color); @@ -60,9 +64,9 @@ static inline uint32_t plutovg_premultiply_argb(uint32_t color) uint32_t g = plutovg_green(color); uint32_t b = plutovg_blue(color); if(a != 255) { - r = (r * a) / 255; - g = (g * a) / 255; - b = (b * a) / 255; + r = plutovg_div255(r * a); + g = plutovg_div255(g * a); + b = plutovg_div255(b * a); } return (a << 24) | (r << 16) | (g << 8) | (b);