color-space
Advanced tools
Comparing version 1.3.1 to 1.4.1
/** | ||
* Cubehelix https://www.mrao.cubehelix.ac.uk/~dag/CUBEHELIX/ | ||
* Cubehelix http://astron-soc.in/bulletin/11June/289392011.pdf | ||
* | ||
@@ -7,20 +7,67 @@ * @module color-space/cubehelix | ||
var rgb = require('./rgb'); | ||
var clamp = require('mumath/between'); | ||
var cubehelix = module.exports = { | ||
name: 'cubehelix', | ||
channel: ['start', 'rotation', 'hue', 'gamma'], | ||
min: [0, -10, 0, 0], | ||
max: [3, 10, 2, 2], | ||
name: 'cubehelix', | ||
channel: ['fraction'], | ||
min: [0], | ||
max: [1] | ||
}; | ||
rgb: function(ch){ | ||
//TODO | ||
} | ||
/** Default options for space */ | ||
var defaults = cubehelix.defaults = { | ||
//0..3 | ||
start: 0, | ||
//-10..10 | ||
rotation: 0.5, | ||
//0..1+ | ||
hue: 1, | ||
//0..2 | ||
gamma: 1 | ||
}; | ||
//extend rgb | ||
rgb.cubehelix = function(rgb){ | ||
var x = rgb[0], y = rgb[1], z = rgb[2]; | ||
//TODO | ||
/** | ||
* cubehelix to RGB | ||
* | ||
* @param {Array} cubehelix RGB values | ||
* | ||
* @return {Array} cubehelix values | ||
*/ | ||
cubehelix.rgb = function(fraction, options) { | ||
options = options || {}; | ||
var start = options.start !== undefined ? options.start : defaults.start; | ||
var rotation = options.rotation !== undefined ? options.rotation : defaults.rotation; | ||
var gamma = options.gamma !== undefined ? options.gamma : defaults.gamma; | ||
var hue = options.hue !== undefined ? options.hue : defaults.hue; | ||
var angle = 2 * Math.PI * (start/3 + 1.0 + rotation * fraction); | ||
fraction = Math.pow(fraction, gamma); | ||
var amp = hue * fraction * (1-fraction)/2.0; | ||
var r = fraction + amp*(-0.14861*Math.cos(angle)+1.78277*Math.sin(angle)); | ||
var g = fraction + amp*(-0.29227*Math.cos(angle)-0.90649*Math.sin(angle)); | ||
var b = fraction + amp*(+1.97294*Math.cos(angle)); | ||
r = clamp(r, 0, 1); | ||
g = clamp(g, 0, 1); | ||
b = clamp(b, 0, 1); | ||
return [r * 255, g * 255, b * 255]; | ||
}; | ||
/** | ||
* RGB to cubehelix | ||
* | ||
* @param {Array} cubehelix cubehelix values | ||
* | ||
* @return {Array} RGB values | ||
*/ | ||
rgb.cubehelix = function(rgb) { | ||
//TODO - there’re no backwise conversion yet | ||
}; |
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.colorSpace=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/** | ||
* @module color-space/cmy | ||
*/ | ||
var rgb = require('./rgb'); | ||
var cmy = module.exports = { | ||
name: 'cmy', | ||
min: [0,0,0], | ||
max: [100,100,100], | ||
channel: ['cyan', 'magenta', 'yellow'], | ||
alias: ['CMY'] | ||
}; | ||
/** | ||
* 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 | ||
]; | ||
}; | ||
/** | ||
* RGB to CMY | ||
* | ||
* @param {Array} rgb channels | ||
* | ||
* @return {Array} CMY channels | ||
*/ | ||
rgb.cmy = function(rgb) { | ||
var r = rgb[0] / 255, | ||
g = rgb[1] / 255, | ||
b = rgb[2] / 255; | ||
return [ | ||
(1-r) * 100 || 0, | ||
(1-g) * 100 || 0, | ||
(1-b) * 100 || 0 | ||
]; | ||
}; | ||
},{"./rgb":19}],2:[function(require,module,exports){ | ||
/** | ||
* @module color-space/cmyk | ||
@@ -13,2 +66,3 @@ */ | ||
channel: ['cyan', 'magenta', 'yellow', 'black'], | ||
alias: ['CMYK'], | ||
@@ -43,4 +97,7 @@ rgb: function(cmyk) { | ||
}; | ||
},{"./rgb":13}],2:[function(require,module,exports){ | ||
},{"./rgb":19}],3:[function(require,module,exports){ | ||
/** | ||
* http://www.cse.usf.edu/~mshreve/rgb-to-hsi | ||
* http://web.archive.org/web/20130124054245/http://web2.clarkson.edu/class/image_process/RGB_to_HSI.pdf | ||
* | ||
* @module color-space/hsl | ||
@@ -51,2 +108,87 @@ */ | ||
var loop = require('mumath/loop'); | ||
var clamp = require('mumath/between'); | ||
var hsi = module.exports = { | ||
name: 'hsi', | ||
min: [0,0,0], | ||
max: [360,100,255], | ||
channel: ['hue', 'saturation', 'intensity'], | ||
alias: ['HSI'] | ||
}; | ||
/** | ||
* HSI to RGB | ||
* | ||
* @param {Array} hsi Channel values | ||
* | ||
* @return {Array} RGB channel values | ||
*/ | ||
hsi.rgb = function (hsi) { | ||
var h = loop(hsi[0], 0, 360) * Math.PI / 180; | ||
var s = clamp(hsi[1], 0, 100) / 100; | ||
var i = clamp(hsi[2], 0, 255) / 255; | ||
var pi3 = Math.PI / 3; | ||
var r, g, b; | ||
if (h < (2 * pi3) ) { | ||
b = i * ( 1 - s ); | ||
r = i * (1 + ( s * Math.cos(h) / Math.cos(pi3 - h) )); | ||
g = i * (1 + ( s * ( 1 - Math.cos(h) / Math.cos(pi3 - h) ))); | ||
} | ||
else if (h < (4 * pi3) ) { | ||
h = h - 2 * pi3; | ||
r = i * ( 1 - s ); | ||
g = i * (1 + ( s * Math.cos(h) / Math.cos(pi3 - h) )); | ||
b = i * (1 + ( s * ( 1 - Math.cos(h) / Math.cos(pi3 - h) ))); | ||
} | ||
else { | ||
h = h - 4 * pi3; | ||
g = i * ( 1 - s ); | ||
b = i * (1 + ( s * Math.cos(h) / Math.cos(pi3 - h) )); | ||
r = i * (1 + ( s * ( 1 - Math.cos(h) / Math.cos(pi3 - h) ))); | ||
} | ||
return [r * 255, g * 255, b * 255]; | ||
}; | ||
/** | ||
* RGB to HSI | ||
* | ||
* @param {Array} rgb Channel values | ||
* | ||
* @return {Array} HSI channel values | ||
*/ | ||
rgb.hsi = function (rgb) { | ||
var sum = rgb[0] + rgb[1] + rgb[2]; | ||
var r = rgb[0] / sum; | ||
var g = rgb[1] / sum; | ||
var b = rgb[2] / sum; | ||
var h = Math.acos( | ||
( 0.5 * ((r - g) + (r - b)) ) / | ||
Math.sqrt( (r - g)*(r - g) + (r - b)*(g - b) ) | ||
); | ||
if (b > g) { | ||
h = 2 * Math.PI - h; | ||
} | ||
var s = 1 - 3 * Math.min(r, g, b); | ||
var i = sum / 3; | ||
return [h * 180 / Math.PI, s * 100, i]; | ||
}; | ||
},{"./rgb":19,"mumath/between":16,"mumath/loop":17}],4:[function(require,module,exports){ | ||
/** | ||
* @module color-space/hsl | ||
*/ | ||
var rgb = require('./rgb'); | ||
module.exports = { | ||
@@ -57,2 +199,3 @@ name: 'hsl', | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HSL'], | ||
@@ -81,4 +224,8 @@ rgb: function(hsl) { | ||
t3 = h + 1 / 3 * - (i - 1); | ||
if (t3 < 0) t3++; | ||
else if (t3 > 1) t3--; | ||
if (t3 < 0) { | ||
t3++; | ||
} | ||
else if (t3 > 1) { | ||
t3--; | ||
} | ||
@@ -131,4 +278,5 @@ if (6 * t3 < 1) { | ||
if (h < 0) | ||
if (h < 0) { | ||
h += 360; | ||
} | ||
@@ -149,3 +297,3 @@ l = (min + max) / 2; | ||
}; | ||
},{"./rgb":13}],3:[function(require,module,exports){ | ||
},{"./rgb":19}],5:[function(require,module,exports){ | ||
/** | ||
@@ -163,14 +311,14 @@ * @module color-space/hsv | ||
channel: ['hue', 'saturation', 'value'], | ||
alias: ['hsb'], | ||
alias: ['HSV', 'HSB'], | ||
rgb: function(hsv) { | ||
var h = hsv[0] / 60, | ||
s = hsv[1] / 100, | ||
v = hsv[2] / 100, | ||
hi = Math.floor(h) % 6; | ||
s = hsv[1] / 100, | ||
v = hsv[2] / 100, | ||
hi = Math.floor(h) % 6; | ||
var f = h - Math.floor(h), | ||
p = 255 * v * (1 - s), | ||
q = 255 * v * (1 - (s * f)), | ||
t = 255 * v * (1 - (s * (1 - f))); | ||
p = 255 * v * (1 - s), | ||
q = 255 * v * (1 - (s * f)), | ||
t = 255 * v * (1 - (s * (1 - f))); | ||
v *= 255; | ||
@@ -214,8 +362,8 @@ | ||
var r = rgb[0], | ||
g = rgb[1], | ||
b = rgb[2], | ||
min = Math.min(r, g, b), | ||
max = Math.max(r, g, b), | ||
delta = max - min, | ||
h, s, v; | ||
g = rgb[1], | ||
b = rgb[2], | ||
min = Math.min(r, g, b), | ||
max = Math.max(r, g, b), | ||
delta = max - min, | ||
h, s, v; | ||
@@ -226,3 +374,3 @@ if (max === 0) { | ||
else { | ||
s = (delta/max * 1000)/10; | ||
s = (delta/max * 100); | ||
} | ||
@@ -269,3 +417,3 @@ | ||
}; | ||
},{"./hsl":2,"./rgb":13}],4:[function(require,module,exports){ | ||
},{"./hsl":4,"./rgb":19}],6:[function(require,module,exports){ | ||
/** | ||
@@ -288,2 +436,3 @@ * A uniform wrapper for husl. | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HuSL'], | ||
@@ -307,3 +456,3 @@ lchuv: _husl._conv.husl.lch, | ||
}; | ||
},{"./lchuv":10,"./xyz":15,"husl":12}],5:[function(require,module,exports){ | ||
},{"./lchuv":13,"./xyz":21,"husl":15}],7:[function(require,module,exports){ | ||
/** | ||
@@ -325,2 +474,3 @@ * A uniform wrapper for huslp. | ||
channel: ['hue', 'saturation', 'lightness'], | ||
alias: ['HuSLp'], | ||
@@ -339,3 +489,3 @@ lchuv: _husl._conv.huslp.lch, | ||
xyz.huslp = function(arg){return _husl._conv.lch.huslp(xyz.lchuv(arg));}; | ||
},{"./lchuv":10,"./xyz":15,"husl":12}],6:[function(require,module,exports){ | ||
},{"./lchuv":13,"./xyz":21,"husl":15}],8:[function(require,module,exports){ | ||
/** | ||
@@ -355,2 +505,3 @@ * @module color-space/hwb | ||
channel: ['hue', 'whiteness', 'blackness'], | ||
alias: ['HWB'], | ||
@@ -451,17 +602,11 @@ // http://dev.w3.org/csswg/css-color/#hwb-to-rgb | ||
}; | ||
},{"./hsl":2,"./hsv":3,"./rgb":13}],7:[function(require,module,exports){ | ||
},{"./hsl":4,"./hsv":5,"./rgb":19}],9:[function(require,module,exports){ | ||
/** | ||
* Color space data and conversions | ||
* | ||
* @module color-space | ||
* | ||
* @todo to-source method, preparing the code for webworker | ||
* @todo implement all side spaces from http://en.wikipedia.org/wiki/Category:Color_space yuv, yiq etc. | ||
* @todo here are additional spaces http://www.jentronics.com/color.html ITU, REC709, SMTPE, NTSC, GREY | ||
* | ||
* @todo implement asm-js way to convert spaces (promises to be times faster) | ||
* | ||
*/ | ||
var addConvertor = require('./util/add-convertor'); | ||
/** Exported spaces */ | ||
@@ -472,6 +617,12 @@ var spaces = { | ||
hsv: require('./hsv'), | ||
hsi: require('./hsi'), | ||
hwb: require('./hwb'), | ||
cmyk: require('./cmyk'), | ||
cmy: require('./cmy'), | ||
xyz: require('./xyz'), | ||
xyy: require('./xyy'), | ||
yiq: require('./yiq'), | ||
yuv: require('./yuv'), | ||
lab: require('./lab'), | ||
labh: require('./labh'), | ||
lchab: require('./lchab'), | ||
@@ -491,6 +642,4 @@ luv: require('./luv'), | ||
for (var toSpaceName in spaces) { | ||
if (toSpaceName !== fromSpaceName) { | ||
toSpace = spaces[toSpaceName]; | ||
addConvertor(fromSpace, toSpace); | ||
} | ||
toSpace = spaces[toSpaceName]; | ||
if (!fromSpace[toSpaceName]) fromSpace[toSpaceName] = getConvertor(fromSpaceName, toSpaceName); | ||
} | ||
@@ -500,4 +649,31 @@ } | ||
/** return converter through xyz/rgb space */ | ||
function getConvertor(fromSpaceName, toSpaceName){ | ||
var fromSpace = spaces[fromSpaceName]; | ||
var toSpace = spaces[toSpaceName]; | ||
//create straight converter | ||
if (fromSpaceName === toSpaceName) { | ||
return function (a) { | ||
return a; | ||
}; | ||
} | ||
//create xyz converter, if available | ||
else if (fromSpace.xyz && spaces.xyz[toSpaceName]) { | ||
return function(arg){ | ||
return spaces.xyz[toSpaceName](fromSpace.xyz(arg)); | ||
}; | ||
} | ||
//create rgb converter | ||
else if (fromSpace.rgb && spaces.rgb[toSpaceName]) { | ||
return function(arg){ | ||
return spaces.rgb[toSpaceName](fromSpace.rgb(arg)); | ||
}; | ||
} | ||
} | ||
module.exports = spaces; | ||
},{"./cmyk":1,"./hsl":2,"./hsv":3,"./husl":4,"./huslp":5,"./hwb":6,"./lab":8,"./lchab":9,"./lchuv":10,"./luv":11,"./rgb":13,"./util/add-convertor":14,"./xyz":15}],8:[function(require,module,exports){ | ||
},{"./cmy":1,"./cmyk":2,"./hsi":3,"./hsl":4,"./hsv":5,"./husl":6,"./huslp":7,"./hwb":8,"./lab":10,"./labh":11,"./lchab":12,"./lchuv":13,"./luv":14,"./rgb":19,"./xyy":20,"./xyz":21,"./yiq":22,"./yuv":23}],10:[function(require,module,exports){ | ||
/** | ||
@@ -516,3 +692,3 @@ * CIE LAB space model | ||
channel: ['lightness', 'a', 'b'], | ||
alias: ['cielab'], | ||
alias: ['LAB', 'cielab'], | ||
@@ -563,4 +739,48 @@ xyz: function(lab) { | ||
}; | ||
},{"./xyz":15}],9:[function(require,module,exports){ | ||
},{"./xyz":21}],11:[function(require,module,exports){ | ||
/** | ||
* Hunter-lab space. | ||
* | ||
* @module color-space/labh | ||
*/ | ||
var xyz = require('./xyz'); | ||
module.exports = { | ||
name: 'labh', | ||
//mins/maxes are taken from colormine | ||
//FIXME: check whether mins/maxes correct | ||
min: [0,-128,-128], | ||
max: [100,128,128], | ||
channel: ['lightness', 'a', 'b'], | ||
alias: ['LABh', 'hunter-lab', 'hlab'], | ||
//maths are taken from EasyRGB | ||
xyz: function(lab) { | ||
var l = lab[0], a = lab[1], b = lab[2]; | ||
var _y = l / 10; | ||
var _x = a / 17.5 * l / 10; | ||
var _z = b / 7 * l / 10; | ||
var y = _y * _y; | ||
var x = ( _x + y ) / 1.02; | ||
var z = -( _z - y ) / 0.847; | ||
return [x,y,z]; | ||
} | ||
}; | ||
//extend xyz | ||
xyz.labh = function(xyz){ | ||
var x = xyz[0], y = xyz[1], z = xyz[2]; | ||
var l = 10 * Math.sqrt( y ); | ||
var a = y === 0 ? 0 : 17.5 * ((( 1.02 * x ) - y ) / Math.sqrt( y ) ); | ||
var b = y === 0 ? 0 : 7 * ( ( y - ( 0.847 * z ) ) / Math.sqrt( y ) ); | ||
return [l, a, b]; | ||
}; | ||
},{"./xyz":21}],12:[function(require,module,exports){ | ||
/** | ||
* Cylindrical LAB | ||
@@ -581,3 +801,3 @@ * | ||
channel: ['lightness', 'chroma', 'hue'], | ||
alias: ['cielch', 'lch'], | ||
alias: ['LCHab', 'cielch', 'LCH', 'HLC'], | ||
@@ -621,3 +841,3 @@ xyz: function(arg) { | ||
}; | ||
},{"./lab":8,"./xyz":15}],10:[function(require,module,exports){ | ||
},{"./lab":10,"./xyz":21}],13:[function(require,module,exports){ | ||
/** | ||
@@ -636,3 +856,3 @@ * Cylindrical CIE LUV | ||
channel: ['lightness', 'chroma', 'hue'], | ||
alias: ['cielchuv'], | ||
alias: ['LCHuv', 'cielchuv'], | ||
min: [0,0,0], | ||
@@ -655,3 +875,3 @@ max: [100,100,360], | ||
return luv.xyz(lchuv.luv(arg)); | ||
}, | ||
} | ||
}; | ||
@@ -675,3 +895,3 @@ | ||
}; | ||
},{"./luv":11,"./xyz":15}],11:[function(require,module,exports){ | ||
},{"./luv":14,"./xyz":21}],14:[function(require,module,exports){ | ||
/** | ||
@@ -694,3 +914,3 @@ * CIE LUV (C'est la vie) | ||
channel: ['lightness', 'u', 'v'], | ||
alias: ['cieluv'], | ||
alias: ['LUV', 'cieluv'], | ||
@@ -777,3 +997,3 @@ xyz: function(arg, i, o){ | ||
}; | ||
},{"./xyz":15}],12:[function(require,module,exports){ | ||
},{"./xyz":21}],15:[function(require,module,exports){ | ||
// Generated by CoffeeScript 1.8.0 | ||
@@ -1213,4 +1433,88 @@ (function() { | ||
},{}],13:[function(require,module,exports){ | ||
},{}],16:[function(require,module,exports){ | ||
/** | ||
* Clamper. | ||
* Detects proper clamp min/max. | ||
* | ||
* @param {number} a Current value to cut off | ||
* @param {number} min One side limit | ||
* @param {number} max Other side limit | ||
* | ||
* @return {number} Clamped value | ||
*/ | ||
module.exports = require('./wrap')(function(a, min, max){ | ||
return max > min ? Math.max(Math.min(a,max),min) : Math.max(Math.min(a,min),max); | ||
}); | ||
},{"./wrap":18}],17:[function(require,module,exports){ | ||
/** | ||
* @module mumath/loop | ||
* | ||
* Looping function for any framesize | ||
*/ | ||
module.exports = require('./wrap')(function (value, left, right) { | ||
//detect single-arg case, like mod-loop | ||
if (right === undefined) { | ||
right = left; | ||
left = 0; | ||
} | ||
//swap frame order | ||
if (left > right) { | ||
var tmp = right; | ||
right = left; | ||
left = tmp; | ||
} | ||
var frame = right - left; | ||
value = ((value + left) % frame) - left; | ||
if (value < left) value += frame; | ||
if (value > right) value -= frame; | ||
return value; | ||
}); | ||
},{"./wrap":18}],18:[function(require,module,exports){ | ||
/** | ||
* Get fn wrapped with array/object attrs recognition | ||
* | ||
* @return {Function} Target function | ||
*/ | ||
module.exports = function(fn){ | ||
return function(a){ | ||
var args = arguments; | ||
if (a instanceof Array) { | ||
var result = new Array(a.length), slice; | ||
for (var i = 0; i < a.length; i++){ | ||
slice = []; | ||
for (var j = 0, l = args.length, val; j < l; j++){ | ||
val = args[j] instanceof Array ? args[j][i] : args[j]; | ||
val = val; | ||
slice.push(val); | ||
} | ||
result[i] = fn.apply(this, slice); | ||
} | ||
return result; | ||
} | ||
else if (typeof a === 'object') { | ||
var result = {}, slice; | ||
for (var i in a){ | ||
slice = []; | ||
for (var j = 0, l = args.length, val; j < l; j++){ | ||
val = typeof args[j] === 'object' ? args[j][i] : args[j]; | ||
val = val; | ||
slice.push(val); | ||
} | ||
result[i] = fn.apply(this, slice); | ||
} | ||
return result; | ||
} | ||
else { | ||
return fn.apply(this, args); | ||
} | ||
}; | ||
}; | ||
},{}],19:[function(require,module,exports){ | ||
/** | ||
* RGB space. | ||
@@ -1225,53 +1529,45 @@ * | ||
max: [255,255,255], | ||
channel: ['red', 'green', 'blue'] | ||
channel: ['red', 'green', 'blue'], | ||
alias: ['RGB'] | ||
}; | ||
},{}],14:[function(require,module,exports){ | ||
},{}],20:[function(require,module,exports){ | ||
/** | ||
* Add a convertor from one to another space via XYZ or RGB space as a medium. | ||
* Additional xyY space. | ||
* | ||
* @module color-space/add-convertor | ||
* @module color-space/xyy | ||
*/ | ||
var xyz = require('./xyz'); | ||
var xyz = require('../xyz'); | ||
var rgb = require('../rgb'); | ||
module.exports = { | ||
name: 'xyy', | ||
min: [0,0,0], | ||
max: [1,1,100], | ||
channel: ['x','y','Y'], | ||
alias: ['xyY', 'Yxy', 'yxy'], | ||
module.exports = addConvertor; | ||
/** | ||
* Add convertor from space A to space B. | ||
* So space A will be able to transform to B. | ||
*/ | ||
function addConvertor(fromSpace, toSpace){ | ||
if (!fromSpace[toSpace.name]) { | ||
fromSpace[toSpace.name] = getConvertor(fromSpace, toSpace); | ||
// https://github.com/boronine/colorspaces.js/blob/master/colorspaces.js#L128 | ||
xyz: function(arg) { | ||
var X, Y, Z, x, y; | ||
x = arg[0]; y = arg[1]; Y = arg[2]; | ||
if (y === 0) { | ||
return [0, 0, 0]; | ||
} | ||
X = x * Y / y; | ||
Z = (1 - x - y) * Y / y; | ||
return [X, Y, Z]; | ||
} | ||
}; | ||
return fromSpace; | ||
} | ||
/** return converter through xyz/rgb space */ | ||
function getConvertor(fromSpace, toSpace){ | ||
var toSpaceName = toSpace.name; | ||
//create xyz converter, if available | ||
if (fromSpace.xyz && xyz[toSpaceName]) { | ||
return function(arg){ | ||
return xyz[toSpaceName](fromSpace.xyz(arg)); | ||
}; | ||
//extend xyz | ||
xyz.xyy = function(arg) { | ||
var sum, X, Y, Z; | ||
X = arg[0]; Y = arg[1]; Z = arg[2]; | ||
sum = X + Y + Z; | ||
if (sum === 0) { | ||
return [0, 0, Y]; | ||
} | ||
//create rgb converter | ||
else if (fromSpace.rgb && rgb[toSpaceName]) { | ||
return function(arg){ | ||
return rgb[toSpaceName](fromSpace.rgb(arg)); | ||
}; | ||
} | ||
else throw Error('Can’t add convertor from ' + fromSpace.name + ' to ' + toSpaceName); | ||
return fromSpace[toSpaceName]; | ||
} | ||
},{"../rgb":13,"../xyz":15}],15:[function(require,module,exports){ | ||
return [X / sum, Y / sum, Y]; | ||
}; | ||
},{"./xyz":21}],21:[function(require,module,exports){ | ||
/** | ||
@@ -1289,4 +1585,4 @@ * CIE XYZ | ||
max: [96,100,109], | ||
channel: ['lightness','u','v'], | ||
alias: ['ciexyz'], | ||
channel: ['X','Y','Z'], | ||
alias: ['XYZ', 'ciexyz'], | ||
@@ -1369,3 +1665,9 @@ //whitepoint with observer/illuminant | ||
//extend rgb | ||
/** | ||
* RGB to XYZ | ||
* | ||
* @param {Array} rgb RGB channels | ||
* | ||
* @return {Array} XYZ channels | ||
*/ | ||
rgb.xyz = function(rgb) { | ||
@@ -1387,3 +1689,100 @@ var r = rgb[0] / 255, | ||
}; | ||
},{"./rgb":13}]},{},[7])(7) | ||
},{"./rgb":19}],22:[function(require,module,exports){ | ||
/** | ||
* YIQ https://en.wikipedia.org/?title=YIQ | ||
* | ||
* @module color-space/yiq | ||
*/ | ||
var rgb = require('./rgb'); | ||
var yiq = module.exports = { | ||
name: 'yiq', | ||
min: [0,-0.5957,-0.5226], | ||
max: [1, 0.5957, 0.5226], | ||
channel: ['Y','I','Q'], | ||
alias: ['YIQ'] | ||
}; | ||
yiq.rgb = function(yiq) { | ||
var y = yiq[0], | ||
i = yiq[1], | ||
q = yiq[2], | ||
r, g, b; | ||
r = (y * 1) + (i * 0.956) + (q * 0.621); | ||
g = (y * 1) + (i * -0.272) + (q * -0.647); | ||
b = (y * 1) + (i * -1.108) + (q * 1.705); | ||
r = Math.min(Math.max(0, r), 1); | ||
g = Math.min(Math.max(0, g), 1); | ||
b = Math.min(Math.max(0, b), 1); | ||
return [r * 255, g * 255, b * 255]; | ||
}; | ||
//extend rgb | ||
rgb.yiq = function(rgb) { | ||
var r = rgb[0] / 255, | ||
g = rgb[1] / 255, | ||
b = rgb[2] / 255; | ||
var y = (r * 0.299) + (g * 0.587) + (b * 0.114); | ||
var i = 0, q = 0; | ||
if (r !== g || g !== b) { | ||
i = (r * 0.596) + (g * -0.275) + (b * -0.321); | ||
q = (r * 0.212) + (g * -0.528) + (b * 0.311); | ||
} | ||
return [y, i, q]; | ||
}; | ||
},{"./rgb":19}],23:[function(require,module,exports){ | ||
/** | ||
* YUV https://en.wikipedia.org/?title=YUV | ||
* | ||
* @module color-space/yuv | ||
*/ | ||
var rgb = require('./rgb'); | ||
var yuv = module.exports = { | ||
name: 'yuv', | ||
min: [0,-0.5,-0.5], | ||
max: [1, 0.5, 0.5], | ||
channel: ['Y','U','V'], | ||
alias: ['YUV'], | ||
rgb: function(yuv) { | ||
var y = yuv[0], | ||
u = yuv[1], | ||
v = yuv[2], | ||
r, g, b; | ||
r = (y * 1) + (u * 0) + (v * 1.13983); | ||
g = (y * 1) + (u * -0.39465) + (v * -0.58060); | ||
b = (y * 1) + (u * 2.02311) + (v * 0); | ||
r = Math.min(Math.max(0, r), 1); | ||
g = Math.min(Math.max(0, g), 1); | ||
b = Math.min(Math.max(0, b), 1); | ||
return [r * 255, g * 255, b * 255]; | ||
} | ||
}; | ||
//extend rgb | ||
rgb.yuv = function(rgb) { | ||
var r = rgb[0] / 255, | ||
g = rgb[1] / 255, | ||
b = rgb[2] / 255; | ||
var y = (r * 0.299) + (g * 0.587) + (b * 0.114); | ||
var u = (r * -0.14713) + (g * -0.28886) + (b * 0.436); | ||
var v = (r * 0.615) + (g * -0.51499) + (b * -0.10001); | ||
return [y, u, v]; | ||
}; | ||
},{"./rgb":19}]},{},[9])(9) | ||
}); |
@@ -28,3 +28,4 @@ /** | ||
husl: require('./husl'), | ||
huslp: require('./huslp') | ||
huslp: require('./huslp'), | ||
cubehelix: require('./cubehelix') | ||
}; | ||
@@ -31,0 +32,0 @@ |
{ | ||
"name": "color-space", | ||
"description": "Color space conversions and data", | ||
"version": "1.3.1", | ||
"version": "1.4.1", | ||
"author": "Deema Yvanow <dfcreative@gmail.com>", | ||
@@ -36,11 +36,9 @@ "keywords": [ | ||
"husl": ">=5.0", | ||
"mumath": "^1.0.2" | ||
"mumath": "^1.0.2", | ||
"queried": "^1.4.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"browserify": "~6.x", | ||
"assert": "~1.x", | ||
"closurecompiler": "~1.x", | ||
"require-stub": "~1.x", | ||
"query-relative": "~1.x" | ||
"browserify": "^6.x", | ||
"closurecompiler": "^1.x" | ||
}, | ||
@@ -51,4 +49,4 @@ "scripts": { | ||
"min": "ccjs dist/color-space.js --language_in=ECMASCRIPT5 > dist/color-space.min.js && cat dist/color-space.min.js | gzip-size | pretty-bytes", | ||
"build-test": "browserify -r ./util/add-space:../util/add-space -r ./index:../index -r ./xyy:../xyy -r ./labh:../labh -r ./cmy:../cmy -r husl -r assert -r mumath -r query-relative > test/test.bundle.js" | ||
"build-test": "browserify -r ./index:../index -r husl -r assert -r mumath -r queried -d > test/bundle.js" | ||
} | ||
} |
@@ -79,3 +79,3 @@ # 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) | ||
* [ ] [LMS](http://en.wikipedia.org/wiki/LMS_color_space). | ||
* [ ] [cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) | ||
* [x] [cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) | ||
* [ ] [gray](http://dev.w3.org/csswg/css-color/#grays) | ||
@@ -82,0 +82,0 @@ * [ ] [CIECAM](https://en.wikipedia.org/wiki/CIECAM02) |
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
87666
3
2746
3
+ Addedqueried@^1.4.1
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-flatten@2.1.2(transitive)
+ Addedarray-unique@0.1.1(transitive)
+ Addedarrayify-compact@0.1.1(transitive)
+ Addedget-doc@1.0.4(transitive)
+ Addedget-uid@1.0.1(transitive)
+ Addedhas-dom@1.0.1(transitive)
+ Addedmutype@0.3.9(transitive)
+ Addedparenthesis@1.3.0(transitive)
+ Addedqueried@1.4.5(transitive)
+ Addedsliced@0.0.5(transitive)