nyancat

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.inz.fi/nyancat
Log | Files | Refs | README

commit 2abf293ba0c01cd37dac3c93e34258f6cda3f977
parent ad27f9f67f3dc20c756d9c99c05b14fcf48bc84a
Author: Santtu Lakkala <inz@inz.fi>
Date:   Mon, 20 Jul 2020 14:39:00 +0300

Fix 256 color output

Diffstat:
Mnyancat.c | 20+++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/nyancat.c b/nyancat.c @@ -258,16 +258,22 @@ static inline int _index256(uint32_t col) uint8_t r = col >> 16; uint8_t g = (col >> 8) & 255; uint8_t b = col & 255; - uint8_t cr = r < 28 ? 0 : (r - 28) * 5 / 228 + 1; - uint8_t cb = b < 28 ? 0 : (b - 28) * 5 / 228 + 1; - uint8_t cg = g < 28 ? 0 : (g - 28) * 5 / 228 + 1; - uint8_t gs = ((uint16_t)r + g + b) / 3 * 32 / 256; + uint8_t cr = r < 35 ? 0 : (r - 35) / 40; + uint8_t cb = b < 35 ? 0 : (b - 35) / 40; + uint8_t cg = g < 35 ? 0 : (g - 35) / 40; - if (absd(cr * 40 + !!cr * 55, r) + absd(cg * 40 + !!cg * 55, g) + absd(cb + 40 + !!cb * 55, b) < - absd(gs, r) + absd(gs, g) + absd(gs, b)) + uint8_t gs = (0xee - ((uint16_t)r + g + b) / 3) / 10; + + if (gs > 23 || + absd(cr * 40 + !!cr * 55, r) + + absd(cg * 40 + !!cg * 55, g) + + absd(cb + 40 + !!cb * 55, b) <= + absd(0xee - 10 * gs, r) + + absd(0xee - 10 * gs, g) + + absd(0xee - 10 * gs, b)) return cr * 36 + cg * 6 + cb + 16; - return g + 232; + return 255 - gs; } static void _lc_colorize(struct lolcat *lc, const char *u8_char, size_t len)