Coder Social home page Coder Social logo

colorjs / color-space Goto Github PK

View Code? Open in Web Editor NEW
319.0 319.0 23.0 571 KB

Math & data behind color spaces and color conversions.

Home Page: http://colorjs.github.io/color-space

License: The Unlicense

JavaScript 93.94% HTML 6.06%
color colorjs

color-space's People

Contributors

artoria2e5 avatar bluej100 avatar chrisgervang avatar dy avatar harthur avatar hunmar avatar ianstormtaylor avatar jlhwung avatar klamping avatar moox avatar munter avatar piamancini avatar zubb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

color-space's Issues

Query regarding TSL color space implementation

Hi

I'm trying to implement the TSL colour space in Python. I've referred to your implementation and the Wikipedia source for this. In your implementation, you do not follow the Wikipedia format entirely as it mentions that the R, G, and B values need to be gamma corrected. And even your implementation of Tint values is different. Can you shed some light on this?

HSP out of bounds values and hue shifting

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.

Documentation about RGB conversion: is it sRGB? D65/2?

Hi guys, I would like to know more about the rgb conversion... what does it use right now?
Does it consider any profile?

I need a conversion from sRGB (RGB D65/2) to LAB D50/2.

I also checked that when using the transformation from RGB to XYZ, it's possible to specify the parameters for the conversion... It's the RGB profile?

HSI out of bounds values and hue shifting

The HSI conversion will take valid intensity values and convert them to RGB bytes > 255.

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

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

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

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

Yields:

HSI:
     from RGB 183,199,255 to HSI 228,14,212
  back to RGB 183,199,255
  i+=6 to RGB 188,205,262

Hex

is there any plan to add hex, to convert from rgb or hsl.
hex.hsl
hex.rgb

HuSL deprecated, use HSLuv instead

Hi there,
Some time ago HuSL was deprecated and replaced by HSLuv. Although they are functionally the same, only hsluv is actively maintained.

Could we consider swapping these packages?

TypeError: space.lab.lch is not a function

The readme suggests that space.lab.lch is a function:

color-space/README.md

Lines 13 to 16 in 9687f77

import space from 'color-space';
//convert lab to lch
var result = space.lab.lch([80,50,60]);

However, running this throws TypeError: space.lab.lch is not a function.

Should this be space.lab.lchab instead?

eslint

Add checker with loose rules

PMS

Pantone color system may have legal issues using it in open-source. Thought here it would require some neural network to calc the formula.

Failure to convert XYZ to RGB and back

I have an issue converting an XYZ value to RGB and back, it seems that for some values this works, but for others not. I checked the xyz.max value and all my X/Y/Z values are within range, so that should not be the issue.

This conversion matches (after rounding):

const startXYZ = [47.854955042890886, 29.320696241557958, 21.87902240817543]
const _rgb = colorSpace.xyz.rgb(startXYZ);
const endXYZ = colorSpace.rgb.xyz(_rgb) // => [ 47.854955042890005, 29.320696241558192, 21.879022408175473 ]

However, the following conversion is a mismatch (and quite some other value):

const startXYZ = [ 20, 87, 79 ]
const _rgb = colorSpace.xyz.rgb(startXYZ);
const endXYZ = colorSpace.rgb.xyz(_rgb) // => [ 47.82670703075629, 76.3441771137228, 75.47904959927504 ]

I have been fiddling with the color-convert library as well, but that seems to have the same result (https://github.com/Qix-/color-convert/issues/81). Is this a bug in the conversion algorithm?

main in Package.json

In package.json your current main is configured to ./index.js

when we use webpack and require("color-space"); it uses this index.js. this index requires your husl.js. in your husl.js it has another require("husl"); the issue here is that in our configuration this resolves to itself since it checks the current folder first. it builds successfully but throws errors during runtime because _conv is undefined.

I ended up changing my requires to require("color-space/dist/color-space"); so that webpack finds your compiled version which fixed our issues.

What do you think of changing your main: to dist/color-space.js? so that people can use require("color-space") ?

OSAUCS

It seems trivial to implement one-side transformation, but hardly possible backwise. It takes some neural network / system of equasions with studied coefficients.

Typescript declarations

I am interested in using color-space in a typescript project. To this end I have created type declarations for the library (https://github.com/sbliven/chromanaut/blob/master/color-space.d.ts). I would like to make these available to other projects. This can be done in a few ways depending on the desired integration with the javascript color-space package.

  1. Include index.d.ts in the package directory. This has the benefit of keeping the type definitions and the javascript in the same repository, so the versions should always match. However, it would require that new pull requests modify the index.d.ts file to reflect any changes to the javascript API.

  2. Type declarations can be included in the DefinitelyTyped repository. This makes the process independent of the maintainers here, but runs a greater risk that the type information will be out of date.

Both methods are widely used. I'm happy to help maintain the declarations regardless of which approach is preferred by the community here.

Add HCG tests

Please, wait. I will add support for HCG tests. How to it run?
Okay. Try describe:

hcg[0, 0.5, 1] == rgb[255, 128, 128]
hcg[0, 0.5, 0] == rgb[128, 0, 0]
hcg[0, 0.5, 0.5] == rgb[192, 64, 64]
hcg[0, 1, 0] == rgb[255, 0, 0]
hcg[0, 0, 0] == rgb[0, 0, 0]
hcg[0, 0, 1] == rgb[255, 255, 255]
hcg[0, 0.5, 1] == rgb[128, 128, 128]

If not working, try 127 number.

Conversion errors HWB -> RGB -> HWB

  it('breaks', () => {
    const rgb = colorSpace.hwb.rgb([219, 31, 84]);
    const hwb = colorSpace.rgb.hwb(rgb);
    expect(hwb).toEqual([219, 31, 84]);
    // actual value is [0, 26.956521739130434, 73.04347826086956]
  });

RGBA support

Is there a specific reason RGBA is not one of the supported color spaces? I saw the color-rgba and color-alpha modules which seem to handle this well, unfortunately it is not available in color-space.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.