Fri, 27 Jun 2025 22:30:17 +0200
optimize asc_col_itof()
src/ascension/datatypes.h | file | annotate | diff | comparison | revisions |
--- a/src/ascension/datatypes.h Thu Jun 26 21:43:22 2025 +0200 +++ b/src/ascension/datatypes.h Fri Jun 27 22:30:17 2025 +0200 @@ -164,13 +164,13 @@ static inline asc_col4f asc_col_itof(asc_col4i c) { // dividing by 256 is much more performant - // TODO: this loses optimized rendering for zero-color / alpha - return (asc_col4f) { - (c.red+1.f) / 256.f, - (c.green+1.f) / 256.f, - (c.blue+1.f) / 256.f, - (c.alpha+1.f) / 256.f, - }; + // because it compiles to multiplication instead of division + const float f = 256.f / 255.f; + const float red = c.red * f / 256.f; + const float green = c.green * f / 256.f; + const float blue = c.blue * f / 256.f; + const float alpha = c.alpha * f / 256.f; + return (asc_col4f) {red, green, blue, alpha}; } static inline SDL_Color asc_col_sdl(asc_col4i col) {