Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-space

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-space - npm Package Compare versions

Comparing version 0.0.4 to 0.1.1

test/index.html

276

index.js

@@ -0,1 +1,10 @@

//TODO: save hue on setting sat = 0;
var options = {
illuminant: 'D65',
observer: '2'
};
var rgb = {

@@ -137,2 +146,10 @@ hsl: function(rgb) {

luv: function(args){
return xyz.luv(rgb.xyz(args));
},
lchuv: function(args){
return luv.lchuv(rgb.luv(args));
},
min: [0,0,0],

@@ -203,2 +220,20 @@ max: [255,255,255],

xyz: function(arg) {
return rgb.xyz(hsl.rgb(arg));
},
lab: function(arg) {
return rgb.lab(hsl.rgb(arg));
},
lch: function(arg) {
return rgb.lch(hsl.rgb(arg));
},
luv: function(arg) {
return rgb.luv(hsl.rgb(arg));
},
min: [0,0,0],

@@ -261,2 +296,22 @@ max: [360,100,100],

xyz: function(arg) {
return rgb.xyz(hsv.rgb(arg));
},
lab: function(arg) {
return rgb.lab(hsv.rgb(arg));
},
lch: function(arg) {
return rgb.lch(hsv.rgb(arg));
},
luv: function(arg) {
return rgb.luv(hsv.rgb(arg));
},
min: [0,0,0],

@@ -278,2 +333,4 @@ max: [360,100,100],

var r, g, b;
// wh + bl cant be > 1

@@ -319,2 +376,20 @@ if (ratio > 1) {

xyz: function(args) {
return rgb.xyz(hwb.rgb(args));
},
lab: function(arg) {
return rgb.lab(hwb.rgb(arg));
},
lch: function(arg) {
return rgb.lch(hwb.rgb(arg));
},
luv: function(arg) {
return rgb.luv(hwb.rgb(arg));
},
min: [0,0,0],

@@ -352,2 +427,20 @@ max: [360,100,100],

xyz: function(arg) {
return rgb.xyz(cmyk.rgb(arg));
},
lab: function(arg) {
return rgb.lab(cmyk.rgb(arg));
},
lch: function(arg) {
return rgb.lch(cmyk.rgb(arg));
},
luv: function(arg) {
return rgb.luv(cmyk.rgb(arg));
},
min: [0,0,0,0],

@@ -359,4 +452,4 @@ max: [100,100,100,100],

//TODO: add illuminant info?
var xyz = {
//TODO: fix this maths so to return 255,255,255 in rgb
rgb: function(xyz) {

@@ -368,7 +461,8 @@ var x = xyz[0] / 100,

r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
// assume sRGB
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
r = (x * 3.2404542) + (y * -1.5371385) + (z * -0.4985314);
g = (x * -0.9692660) + (y * 1.8760108) + (z * 0.0415560);
b = (x * 0.0556434) + (y * -0.2040259) + (z * 1.0572252);
// assume sRGB
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)

@@ -390,2 +484,18 @@ : r = (r * 12.92);

hsl: function(arg) {
return rgb.hsl(xyz.rgb(arg));
},
hsv: function(arg) {
return rgb.hsv(xyz.rgb(arg));
},
hwb: function(arg) {
return rgb.hwb(xyz.rgb(arg));
},
cmyk: function(arg) {
return rgb.cmyk(xyz.rgb(arg));
},
lab: function(xyz) {

@@ -416,6 +526,65 @@ var x = xyz[0],

//http://www.brucelindbloom.com/index.html?Equations.html
luv: function(arg, i) {
var _u, _v, l, u, v, x, y, z, yn, un, vn;
//get constants
var e = 0.008856451679035631; //(6/29)^3
var k = 903.2962962962961; //(29/3)^3
//get illuminant
i = i || options.illuminant;
yn = xyz.illuminant[i][1];
un = luv.illuminant[i][1]/100;
vn = luv.illuminant[i][2]/100;
x = arg[0]/100, y = arg[1]/100, z = arg[2]/100;
_u = (4 * x) / (x + (15 * y) + (3 * z));
_v = (9 * y) / (x + (15 * y) + (3 * z));
var yr = y/yn;
l = yr <= e ? k * yr : 116 * Math.pow(yr, .333333333) - 16;
u = 13 * l * (_u - un);
v = 13 * l * (_v - vn);
return [l, u, v];
},
//TODO
cam: function(xyz){
var x = xyz[0], y = xyz[1], z = xyz[2];
//Mcat02
var m =[[0.7328, 0.4296, -0.1624], [-0.7036, 1.6975, 0.0061], [0.0030, 0.0136, 0.9834]];
//get lms
var L = x*m[0][0] + y*m[0][1] + z*m[0][2];
var M = x*m[1][0] + y*m[1][1] + z*m[1][2];
var S = x*m[2][0] + y*m[2][1] + z*m[2][2];
//calc lc, mc, sc
//FIXME: choose proper d
var d = 0.85;
var Lwr = 100, Mwr = 100, Swr = 100;
var Lc = (Lwr*D/Lw + 1 - D) * L;
var Mc = (Mwr*D/Mw + 1 - D) * M;
var Sc = (Swr*D/Sw + 1 - D) * S;
},
min: [0,0,0],
max: [100,100,100],
channel: ['x','y','z'],
alias: ['ciexyz']
max: [96,100,109],
channel: ['lightness','u','v'],
alias: ['ciexyz'],
//Xn, Yn, Zn
illuminant: {
A:[109.85, 100, 35.58],
C: [98.07, 100, 118.23],
E: [100,100,100],
D65: [95.04, 100, 108.88]
}
};

@@ -461,2 +630,6 @@

luv: function(arg) {
},
rgb: function(args) {

@@ -466,2 +639,19 @@ return xyz.rgb(lab.xyz(args));

hsl: function(arg) {
return rgb.hsl(lab.rgb(arg));
},
hsv: function(arg) {
return rgb.hsv(lab.rgb(arg));
},
hwb: function(arg) {
return rgb.hwb(lab.rgb(arg));
},
cmyk: function(arg) {
return rgb.cmyk(lab.rgb(arg));
},
min: [0,-100,-100],

@@ -474,2 +664,3 @@ max: [100,100,100],

//cylindrical lab
var lch = {

@@ -496,18 +687,54 @@ lab: function(lch) {

hsl: function(arg) {
return rgb.hsl(lch.rgb(arg));
},
hsv: function(arg) {
return rgb.hsv(lch.rgb(arg));
},
hwb: function(arg) {
return rgb.hwb(lch.rgb(arg));
},
cmyk: function(arg) {
return rgb.cmyk(lch.rgb(arg));
},
luv: function(){
},
min: [0,0,0],
max: [100,100,360],
channel: ['lightness', 'chroma', 'hue'],
alias: ['cielch']
alias: ['cielch', 'lchab']
};
//TODO
var xyy = {
alias: ['ciexyy']
};
var luv = {
xyz: function(luv){
},
//TODO
var luv = {
alias: ['cieluv']
lchuv: function(luv){
var C = Math.sqrt();
},
min: [0,-100,-100],
max: [100,100,100],
channel: ['lightness', 'u', 'v'],
alias: ['cieluv'],
//Yn, un,vn: http://www.optique-ingenieur.org/en/courses/OPI_ang_M07_C02/co/Contenu_08.html
illuminant: {
A:[100, 255.97, 524.29],
C: [100, 200.89, 460.89],
E: [100,100,100],
D65: [100, 197, 468.34]
}
};

@@ -517,3 +744,7 @@

//TODO
//cylindrical luv
var lchuv = {
luv: function(){
},
alias: ['cielchuv']

@@ -523,4 +754,14 @@ };

//TODO
var xyy = {
alias: ['ciexyy']
};
//CIECAM02 http://en.wikipedia.org/wiki/CIECAM02
var cam = {
alias: ['ciecam']

@@ -548,2 +789,3 @@ };

module.exports = {
options: options,
rgb: rgb,

@@ -556,3 +798,5 @@ hsl: hsl,

lab: lab,
lch: lch
lch: lch,
luv: luv,
// lchuv: lchuv
};

19

package.json
{
"name": "color-space",
"description": "Math & data behind color spaces and conversions between",
"version": "0.0.4",
"description": "Math & data behind color spaces and color conversions.",
"version": "0.1.1",
"author": "Deema Ywanow <dfcreative@gmail.com>",

@@ -12,3 +12,9 @@ "repository": {

"devDependencies": {
"mumath": "~0.2.3"
"mumath": "~0.x",
"mocha": "*",
"browserify": "~6.x",
"assert": "~1.x",
"closurecompiler": "~1.x",
"require-stub": "~1.x",
"query-relative": "~1.x"
},

@@ -23,2 +29,4 @@ "keywords": [

"lch",
"luv",
"cie",
"husl",

@@ -33,4 +41,7 @@ "color-convert",

"scripts": {
"test": "node test/basic.js"
"test": "mocha",
"build": "browserify --standalone color ./index.js > dist/color.js",
"min": "ccjs dist/color.js --language_in=ECMASCRIPT5 > dist/color.min.js && cat dist/color.min.js | gzip-size | pretty-bytes",
"build-test": "browserify -r assert -r mumath -r query-relative -r ./index.js:../index > test/test.bundle.js"
}
}
# color-space [![Build Status](https://travis-ci.org/dfcreative/color-space.svg?branch=master)](https://travis-ci.org/dfcreative/color-space)
Math and data behind color spaces and color conversions.
Math and data behind color spaces and color conversions. [Converter & tests](https://rawgit.com/dfcreative/color-space/master/test/index.html).

@@ -8,3 +8,2 @@ [![NPM](https://nodei.co/npm/color-space.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/color-space/)

## Use

@@ -14,3 +13,3 @@

Use [browserify](https://github.com/substack/node-browserify) for browser use.
Use [browserify](https://github.com/substack/node-browserify) to use in browser.

@@ -52,2 +51,3 @@ ```js

* lab (cielab)
* luv (cieluv)
* lch (cielch)

@@ -60,16 +60,2 @@

## Color-convert differences
Color-space was initially a fork of [color-convert](https://github.com/harthur/color-convert), but then it was separated into a standalone module with changes:
* No keyword "space": actually, it is not a space, it is a different kind of knowledge. Also extra bytes are saved.
* No wrapper code: you have a natural wrapper already — [harthur/color](https://github.com/harthur/color) or a faster fork [dfcreative/color](https://github.com/dfcreative/color).
* `conversions.js` are placed to index.js for better use.
* [pending] CIE spaces.
* [pending] HUSL spaces (great thanks to Alexei Boronine for his [HUSL](https://github.com/boronine/husl)).
* Minimums, maximums, channel names and aliases info.
* Better structured, easier exported (esp. for webworkers).
* No result rounding — she can always do it herself.
* Unlicensed.
# Contribute

@@ -76,0 +62,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc