colorjs/color-space

HSP out of bounds values and hue shifting

jtlapp opened this issue · 2 comments

The HSP conversion will take an RGB to HSP and back and produce an RGB byte > 255.

Also, shifting the brightness by a small amount can produce a rather large change in hue.

const cs = require('color-space');

console.log('HSP:');
let rgb1 = [ 0xb7, 0xc7, 0xff ];
let hsp = cs.rgb.hsp(rgb1);
let rgb2 = cs.hsp.rgb(hsp);
console.log(`     from RGB ${rgb1} to HSP ${round(hsp)}`);
console.log(`  back to RGB ${rgb2}`);
hsp[2] += 6;
let rgb3 = cs.hsp.rgb(hsp);
console.log(`  p+=6 to RGB ${rgb3}`);

function round(vals) {
    return [Math.round(vals[0]), Math.round(vals[1]), Math.round(vals[2])];
}

Yields:

HSP:
     from RGB 183,199,255 to HSP 227,28,202
  back to RGB 184,199,256
  p+=6 to RGB 189,205,263

Also, the HSP conversion is rounding most of its output values, which probably isn't appropriate. It makes conversion unnecessarily lossy.

See also #38.