Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSP out of bounds values and hue shifting #39

Open
jtlapp opened this issue Nov 9, 2017 · 2 comments
Open

HSP out of bounds values and hue shifting #39

jtlapp opened this issue Nov 9, 2017 · 2 comments

Comments

@jtlapp
Copy link

jtlapp commented Nov 9, 2017

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.

@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

FYI @hunmar

@jtlapp
Copy link
Author

jtlapp commented Nov 9, 2017

See also #38.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant