Qix-/color-convert

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

alex-knyaz posted onGitHub

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.


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.

posted by Qix- over 5 years ago

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

posted by Qix- over 5 years ago

Fund this Issue

$0.00
Funded

Pull requests