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

Hue component of HCG color is wrong by 120° then converting from RGB or CMYK #73

Closed
alex-knyaz opened this issue Aug 19, 2019 · 2 comments
Labels

Comments

@alex-knyaz
Copy link

Steps to reproduce

Here we are converting from RGB to HCG and then back.
Note color components are very far apart.

var convert = require('color-convert')
convert.hcg.rgb.raw(convert.rgb.hcg.raw([250, 0, 255]))
[ 0, 255, 249.99999999999991 ]

Description

Then converting color to HCG from RGB or CMYK Hue component of the color appears to be offset by 120°.

Current behavior

var convert = require('color-convert')
convert.rgb.hcg.raw([250, 0, 255])
[ 178.8235294117647, 100, 0 ]

Expected behavior

var convert = require('color-convert')
convert.rgb.hcg.raw([250, 0, 255])
[ 298.8235294117647, 100, 0 ]

Cause?

https://github.com/Qix-/color-convert/blob/master/conversions.js#L668

4 is added twice.
This is most likely it, but I'm not 100% sure.

@Qix- Qix- added the bug label Aug 19, 2019
@Qix-
Copy link
Owner

Qix- commented Aug 19, 2019

Your diagnosis is correct, wonderful catch.

I tested this with the "official" implementation (the creator of the model has sadly abandoned the project - which is sad, because I actually really like this model) and your math is correct.

> hcg = require('./hcg')
{ rgb2hcg: [Function: rgb2hcg], hcg2rgb: [Function: hcg2rgb] }
> hcg.rgb2hcg([250, 0, 255])
[ 0.8300653594771242, 255, 0 ]
> 0.8300653594771242 * 360
298.8235294117647

Pushing a patch now.

@Qix- Qix- closed this as completed in 3359002 Aug 19, 2019
@Qix-
Copy link
Owner

Qix- commented Aug 19, 2019

Published as 2.0.1. Thanks again for a well-written bug report - highly appreciated.

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

No branches or pull requests

2 participants