Skip to content

Commit

Permalink
Use 4 largest bits for rgb->ansi256 gray check
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack authored and Qix- committed Feb 28, 2021
1 parent 674f803 commit 3808cc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ convert.rgb.ansi256 = function (args) {

// We use the extended greyscale palette here, with the exception of
// black and white. normal palette only has 4 greyscale shades.
if (r === g && g === b) {
if (r >> 4 === g >> 4 && g >> 4 === b >> 4) {
if (r < 8) {
return 16;
}
Expand Down
3 changes: 3 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,6 @@ assert.deepStrictEqual(convert.rgb.gray([0, 0, 0]), [0]);
assert.deepStrictEqual(convert.rgb.gray([128, 128, 128]), [50]);
assert.deepStrictEqual(convert.rgb.gray([255, 255, 255]), [100]);
assert.deepStrictEqual(convert.rgb.gray([0, 128, 255]), [50]);

// https://github.com/Qix-/color-convert/issues/74
assert.deepStrictEqual(convert.rgb.ansi256(40, 38, 41), 235);

0 comments on commit 3808cc7

Please sign in to comment.