Qix- / color-convert

Plain color conversion functions in JavaScript
MIT License
744 stars 96 forks source link

Fix ansi256 to rgb conversions for values < 16. #109

Open jwalton opened 7 months ago

jwalton commented 7 months ago

The first 16 colors (0-15) of ANSI 256 are the same colors as ANSI 16 colors. This PR fixes it so convert.ansi256.rgb returns sensible values for these lower colors. Prior to this change:

console.log(convert.ansi256.rgb(0)); // Prints [-51, -153, -204]

Negative r, g, b values are clearly nonsense. After this change:

console.log(convert.ansi256.rgb(0)); // Prints [0, 0, 0]