color-space
Advanced tools
Comparing version 1.2.1 to 1.3.0
39
cmy.js
@@ -6,3 +6,3 @@ /** | ||
module.exports = { | ||
var cmy = module.exports = { | ||
name: 'cmy', | ||
@@ -12,18 +12,33 @@ min: [0,0,0], | ||
channel: ['cyan', 'magenta', 'yellow'], | ||
alias: ['CMY'] | ||
}; | ||
rgb: function(cmy) { | ||
var c = cmy[0] / 100, | ||
m = cmy[1] / 100, | ||
y = cmy[2] / 100; | ||
return [ | ||
(1 - c) * 255, | ||
(1 - m) * 255, | ||
(1 - y) * 255 | ||
]; | ||
} | ||
/** | ||
* CMY to RGB | ||
* | ||
* @param {Array} cmy Channels | ||
* | ||
* @return {Array} RGB channels | ||
*/ | ||
cmy.rgb = function(cmy) { | ||
var c = cmy[0] / 100, | ||
m = cmy[1] / 100, | ||
y = cmy[2] / 100; | ||
return [ | ||
(1 - c) * 255, | ||
(1 - m) * 255, | ||
(1 - y) * 255 | ||
]; | ||
}; | ||
//extend rgb | ||
/** | ||
* RGB to CMY | ||
* | ||
* @param {Array} rgb channels | ||
* | ||
* @return {Array} CMY channels | ||
*/ | ||
rgb.cmy = function(rgb) { | ||
@@ -30,0 +45,0 @@ var r = rgb[0] / 255, |
@@ -12,2 +12,3 @@ /** | ||
channel: ['cyan', 'magenta', 'yellow', 'black'], | ||
alias: ['CMYK'], | ||
@@ -14,0 +15,0 @@ rgb: function(cmyk) { |
@@ -12,2 +12,3 @@ /** | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HSL'], | ||
@@ -14,0 +15,0 @@ rgb: function(hsl) { |
@@ -13,3 +13,3 @@ /** | ||
channel: ['hue', 'saturation', 'value'], | ||
alias: ['hsb'], | ||
alias: ['HSB', 'HSV'], | ||
@@ -16,0 +16,0 @@ rgb: function(hsv) { |
@@ -18,2 +18,3 @@ /** | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HuSL'], | ||
@@ -20,0 +21,0 @@ lchuv: _husl._conv.husl.lch, |
@@ -17,2 +17,3 @@ /** | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HuSLp'], | ||
@@ -19,0 +20,0 @@ lchuv: _husl._conv.huslp.lch, |
@@ -15,2 +15,3 @@ /** | ||
channel: ['hue', 'whiteness', 'blackness'], | ||
alias: ['HWB'], | ||
@@ -17,0 +18,0 @@ // http://dev.w3.org/csswg/css-color/#hwb-to-rgb |
14
index.js
@@ -14,2 +14,3 @@ /** | ||
hsv: require('./hsv'), | ||
hsi: require('./hsi'), | ||
hwb: require('./hwb'), | ||
@@ -20,2 +21,4 @@ cmyk: require('./cmyk'), | ||
xyy: require('./xyy'), | ||
yiq: require('./yiq'), | ||
yuv: require('./yuv'), | ||
lab: require('./lab'), | ||
@@ -38,3 +41,3 @@ labh: require('./labh'), | ||
toSpace = spaces[toSpaceName]; | ||
if (!fromSpace[toSpaceName]) fromSpace[toSpaceName] = getConvertor(fromSpace, toSpace); | ||
if (!fromSpace[toSpaceName]) fromSpace[toSpaceName] = getConvertor(fromSpaceName, toSpaceName); | ||
} | ||
@@ -45,7 +48,8 @@ } | ||
/** return converter through xyz/rgb space */ | ||
function getConvertor(fromSpace, toSpace){ | ||
var toSpaceName = toSpace.name; | ||
function getConvertor(fromSpaceName, toSpaceName){ | ||
var fromSpace = spaces[fromSpaceName]; | ||
var toSpace = spaces[toSpaceName]; | ||
//create straight converter | ||
if (fromSpace === toSpace) { | ||
if (fromSpaceName === toSpaceName) { | ||
return function (a) { | ||
@@ -68,4 +72,2 @@ return a; | ||
} | ||
throw Error('Can’t add convertor from ' + fromSpace.name + ' to ' + toSpaceName); | ||
} | ||
@@ -72,0 +74,0 @@ |
@@ -14,3 +14,3 @@ /** | ||
channel: ['lightness', 'a', 'b'], | ||
alias: ['cielab'], | ||
alias: ['LAB', 'cielab'], | ||
@@ -17,0 +17,0 @@ xyz: function(lab) { |
@@ -17,3 +17,3 @@ /** | ||
channel: ['lightness', 'a', 'b'], | ||
alias: ['hunter-lab', 'hlab'], | ||
alias: ['LABh', 'hunter-lab', 'hlab'], | ||
@@ -20,0 +20,0 @@ //maths are taken from EasyRGB |
@@ -17,3 +17,3 @@ /** | ||
channel: ['lightness', 'chroma', 'hue'], | ||
alias: ['cielch', 'lch'], | ||
alias: ['LCHab', 'cielch', 'LCH', 'HLC'], | ||
@@ -20,0 +20,0 @@ xyz: function(arg) { |
@@ -14,3 +14,3 @@ /** | ||
channel: ['lightness', 'chroma', 'hue'], | ||
alias: ['cielchuv'], | ||
alias: ['LCHuv', 'cielchuv'], | ||
min: [0,0,0], | ||
@@ -17,0 +17,0 @@ max: [100,100,360], |
@@ -18,3 +18,3 @@ /** | ||
channel: ['lightness', 'u', 'v'], | ||
alias: ['cieluv'], | ||
alias: ['LUV', 'cieluv'], | ||
@@ -21,0 +21,0 @@ xyz: function(arg, i, o){ |
{ | ||
"name": "color-space", | ||
"description": "Color space conversions and data", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"author": "Deema Yvanow <dfcreative@gmail.com>", | ||
@@ -35,6 +35,6 @@ "keywords": [ | ||
"dependencies": { | ||
"husl": ">=5.0" | ||
"husl": ">=5.0", | ||
"mumath": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"mumath": "~0.x", | ||
"mocha": "*", | ||
@@ -41,0 +41,0 @@ "browserify": "~6.x", |
@@ -5,33 +5,8 @@ # Color-space [![Build Status](https://travis-ci.org/dfcreative/color-space.svg?branch=master)](https://travis-ci.org/dfcreative/color-space) [![Code Climate](https://codeclimate.com/github/dfcreative/color-space/badges/gpa.svg)](https://codeclimate.com/github/dfcreative/color-space) [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) | ||
Conversions and data for the following color spaces: | ||
Conversions and data for color spaces. [Demo](http://dfcreative.github.io/color-space). | ||
* [x] RGB | ||
* [x] HSl | ||
* [x] HSV (HSB) | ||
* [x] [HWB](http://dev.w3.org/csswg/css-color/#the-hwb-notation) | ||
* [x] CMYK | ||
* [x] CMY | ||
* [x] [XYZ](http://en.wikipedia.org/wiki/CIE_1931_color_space) | ||
* [x] XYY (YXY) | ||
* [x] [LAB](http://en.wikipedia.org/wiki/Lab_color_space) | ||
* [x] LCH<sub>ab</sub> | ||
* [x] [LUV](http://en.wikipedia.org/wiki/CIELUV) | ||
* [x] [LCH<sub>uv</sub>](http://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation) | ||
* [x] [H<sub>u</sub>SL](http://www.boronine.com/husl/) | ||
* [x] [H<sub>u</sub>SL<sub>p</sub>](http://www.boronine.com/husl/) | ||
* [x] [LAB<sub>Hunter</sub>](http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab) | ||
* [ ] [LMS](http://en.wikipedia.org/wiki/LMS_color_space). | ||
* [ ] [YUV]() | ||
* [ ] [YIQ]() | ||
* [ ] [CIE CAM]() | ||
* [ ] [cubehelix](http://bl.ocks.org/mbostock/11415064) | ||
* [ ] gray | ||
* [ ] [Other spaces](#contribute) | ||
#### [Demo & tests](https://cdn.rawgit.com/dfcreative/color-space/master/test/index.html) | ||
## Usage | ||
`$ npm install --save color-space` | ||
[![NPM](https://nodei.co/npm/color-space.png?mini=true)](https://nodei.co/npm/color-space/) | ||
@@ -70,3 +45,47 @@ ```js | ||
## Spaces | ||
* [x] [RGB](https://en.wikipedia.org/wiki/CIE_1931_color_space#Experimental_results:_the_CIE_RGB_color_space) | ||
* [x] [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) | ||
* [x] [HSV, HSB](https://en.wikipedia.org/wiki/HSL_and_HSV) | ||
* [x] [HWB](http://dev.w3.org/csswg/css-color/#the-hwb-notation) | ||
* [x] [HSI](https://en.wikipedia.org/wiki/HSL_and_HSV) | ||
* [x] [CMYK](https://en.wikipedia.org/wiki/CMYK_color_model) | ||
* [x] [CMY](https://en.wikipedia.org/wiki/CMYK_color_model) | ||
* [x] [XYZ](http://en.wikipedia.org/wiki/CIE_1931_color_space) | ||
* [x] [XYY (YXY)](https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space) | ||
* [x] [LAB](http://en.wikipedia.org/wiki/Lab_color_space) | ||
* [x] [LCH<sub>ab</sub>](https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC) | ||
* [x] [LUV](http://en.wikipedia.org/wiki/CIELUV) | ||
* [x] [LCH<sub>uv</sub>](http://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation) | ||
* [x] [H<sub>u</sub>SL](http://www.boronine.com/husl/) | ||
* [x] [H<sub>u</sub>SL<sub>p</sub>](http://www.boronine.com/husl/) | ||
* [x] [LAB<sub>Hunter</sub>](http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab) | ||
* [x] [YUV](https://en.wikipedia.org/?title=YUV) | ||
* [x] [YIQ](https://en.wikipedia.org/?title=YIQ) | ||
* [ ] [YDbDr](https://en.wikipedia.org/wiki/YDbDr) | ||
* [ ] [YPbPr](https://en.wikipedia.org/wiki/YPbPr) | ||
* [ ] [YCbCr](https://en.wikipedia.org/wiki/YCbCr) | ||
* [ ] [YCgCo](https://en.wikipedia.org/wiki/YCgCo) | ||
* [ ] [XvYCC](https://en.wikipedia.org/wiki/XvYCC) | ||
* [ ] [UVW](https://en.wikipedia.org/wiki/CIE_1964_color_space) | ||
* [ ] [Munsell](https://en.wikipedia.org/wiki/Munsell_color_system) | ||
* [ ] [NCS](https://en.wikipedia.org/wiki/Natural_Color_System) | ||
* [ ] [PMS](https://en.wikipedia.org/wiki/Pantone) | ||
* [ ] [RAL](https://en.wikipedia.org/wiki/RAL_colour_standard) | ||
* [ ] [TSL](https://en.wikipedia.org/wiki/TSL_color_space) | ||
* [ ] [RG](https://en.wikipedia.org/wiki/RG_color_space) | ||
* [ ] [Coloroid](https://en.wikipedia.org/wiki/Coloroid) | ||
* [ ] [HKS](https://en.wikipedia.org/wiki/HKS_(colour_system)) | ||
* [ ] [LMS](http://en.wikipedia.org/wiki/LMS_color_space). | ||
* [ ] [cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) | ||
* [ ] [gray](http://dev.w3.org/csswg/css-color/#grays) | ||
* [ ] [CIECAM](https://en.wikipedia.org/wiki/CIECAM02) | ||
* [ ] [ITU](http://www.jentronics.com/color.html) | ||
* [ ] [REC709](http://www.jentronics.com/color.html) | ||
* [ ] [SMTPE](http://www.jentronics.com/color.html) | ||
* [ ] [NTSC](http://www.jentronics.com/color.html) | ||
* [ ] [GREY](http://www.jentronics.com/color.html) | ||
## Contribute | ||
@@ -84,4 +103,1 @@ | ||
* [colorspaces.js](https://github.com/boronine/colorspaces.js) | ||
[![NPM](https://nodei.co/npm/color-space.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/color-space/) |
@@ -11,3 +11,4 @@ /** | ||
max: [255,255,255], | ||
channel: ['red', 'green', 'blue'] | ||
channel: ['red', 'green', 'blue'], | ||
alias: ['RGB'] | ||
}; |
@@ -13,3 +13,3 @@ /** | ||
channel: ['x','y','Y'], | ||
alias: ['Yxy', 'xyY', 'yxy'], | ||
alias: ['xyY', 'Yxy', 'yxy'], | ||
@@ -19,3 +19,3 @@ // https://github.com/boronine/colorspaces.js/blob/master/colorspaces.js#L128 | ||
var X, Y, Z, x, y; | ||
x = arg[0], y = arg[1], Y = arg[2]; | ||
x = arg[0]; y = arg[1]; Y = arg[2]; | ||
if (y === 0) { | ||
@@ -34,3 +34,3 @@ return [0, 0, 0]; | ||
var sum, X, Y, Z; | ||
X = arg[0], Y = arg[1], Z = arg[2]; | ||
X = arg[0]; Y = arg[1]; Z = arg[2]; | ||
sum = X + Y + Z; | ||
@@ -37,0 +37,0 @@ if (sum === 0) { |
12
xyz.js
@@ -13,4 +13,4 @@ /** | ||
max: [96,100,109], | ||
channel: ['lightness','u','v'], | ||
alias: ['ciexyz'], | ||
channel: ['X','Y','Z'], | ||
alias: ['XYZ', 'ciexyz'], | ||
@@ -93,3 +93,9 @@ //whitepoint with observer/illuminant | ||
//extend rgb | ||
/** | ||
* RGB to XYZ | ||
* | ||
* @param {Array} rgb RGB channels | ||
* | ||
* @return {Array} XYZ channels | ||
*/ | ||
rgb.xyz = function(rgb) { | ||
@@ -96,0 +102,0 @@ var r = rgb[0] / 255, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78823
6
31
2362
101
2
+ Addedmumath@^1.0.2
+ Addedmumath@1.0.2(transitive)