node-vibrant
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
var Image, NodeImage, | ||
var Image, Jimp, JimpImage, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -7,11 +7,39 @@ hasProp = {}.hasOwnProperty; | ||
module["export"] = NodeImage = (function(superClass) { | ||
extend(NodeImage, superClass); | ||
Jimp = require('jimp'); | ||
function NodeImage() { | ||
return NodeImage.__super__.constructor.apply(this, arguments); | ||
JimpImage = (function(superClass) { | ||
extend(JimpImage, superClass); | ||
function JimpImage(path, cb) { | ||
new Jimp(path, (function(_this) { | ||
return function(err, image) { | ||
if (err != null) { | ||
return typeof cb === "function" ? cb(err) : void 0; | ||
} | ||
_this.img = image; | ||
return typeof cb === "function" ? cb(null, _this) : void 0; | ||
}; | ||
})(this)); | ||
} | ||
return NodeImage; | ||
JimpImage.prototype.clear = function() {}; | ||
JimpImage.prototype.update = function(imageData) {}; | ||
JimpImage.prototype.getPixelCount = function() { | ||
return this.img.bitmap.width * this.img.bitmap.height; | ||
}; | ||
JimpImage.prototype.getImageData = function() { | ||
return { | ||
data: this.img.bitmap.data | ||
}; | ||
}; | ||
JimpImage.prototype.removeCanvas = function() {}; | ||
return JimpImage; | ||
})(Image); | ||
module.exports = JimpImage; |
@@ -0,2 +1,6 @@ | ||
var Swatch, util; | ||
util = require('./util'); | ||
/* | ||
@@ -8,3 +12,2 @@ From Vibrant.js by Jari Zwarts | ||
*/ | ||
var Swatch; | ||
@@ -27,3 +30,3 @@ module.exports = Swatch = (function() { | ||
if (!this.hsl) { | ||
return this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]); | ||
return this.hsl = util.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]); | ||
} else { | ||
@@ -30,0 +33,0 @@ return this.hsl; |
@@ -13,3 +13,3 @@ | ||
*/ | ||
var Image, Swatch, Vibrant, | ||
var Image, Swatch, Vibrant, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -22,2 +22,4 @@ slice = [].slice; | ||
_ = require('underscore'); | ||
module.exports = Vibrant = (function() { | ||
@@ -70,12 +72,32 @@ Vibrant.prototype.quantize = require('quantize'); | ||
function Vibrant(sourceImage, colorCount, quality) { | ||
function Vibrant(sourceImage, opts1) { | ||
this.sourceImage = sourceImage; | ||
this.opts = opts1 != null ? opts1 : { | ||
colorCount: 64, | ||
quality: 5 | ||
}; | ||
this.swatches = bind(this.swatches, this); | ||
var a, allPixels, b, cmap, g, i, image, imageData, offset, pixelCount, pixels, r; | ||
if (typeof colorCount === 'undefined') { | ||
colorCount = 64; | ||
} | ||
if (typeof quality === 'undefined') { | ||
quality = 5; | ||
} | ||
image = new Image(sourceImage); | ||
} | ||
Vibrant.prototype.getSwatches = function(cb) { | ||
var image; | ||
return image = new Image(this.sourceImage, (function(_this) { | ||
return function(err, image) { | ||
var error; | ||
if (err != null) { | ||
return cb(err); | ||
} | ||
try { | ||
_this._process(image, _this.opts); | ||
return cb(null, _this.swatches()); | ||
} catch (_error) { | ||
error = _error; | ||
return cb(error); | ||
} | ||
}; | ||
})(this)); | ||
}; | ||
Vibrant.prototype._process = function(image, opts) { | ||
var a, allPixels, b, cmap, g, i, imageData, offset, pixelCount, pixels, r; | ||
imageData = image.getImageData(); | ||
@@ -97,5 +119,5 @@ pixels = imageData.data; | ||
} | ||
i = i + quality; | ||
i = i + opts.quality; | ||
} | ||
cmap = this.quantize(allPixels, colorCount); | ||
cmap = this.quantize(allPixels, opts.colorCount); | ||
this._swatches = cmap.vboxes.map((function(_this) { | ||
@@ -109,4 +131,4 @@ return function(vbox) { | ||
this.generateEmptySwatches(); | ||
image.removeCanvas(); | ||
} | ||
return image.removeCanvas(); | ||
}; | ||
@@ -210,69 +232,4 @@ Vibrant.prototype.generateVarationColors = function() { | ||
Vibrant.rgbToHsl = function(r, g, b) { | ||
var d, h, l, max, min, s; | ||
r /= 255; | ||
g /= 255; | ||
b /= 255; | ||
max = Math.max(r, g, b); | ||
min = Math.min(r, g, b); | ||
h = void 0; | ||
s = void 0; | ||
l = (max + min) / 2; | ||
if (max === min) { | ||
h = s = 0; | ||
} else { | ||
d = max - min; | ||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min); | ||
switch (max) { | ||
case r: | ||
h = (g - b) / d + (g < b ? 6 : 0); | ||
break; | ||
case g: | ||
h = (b - r) / d + 2; | ||
break; | ||
case b: | ||
h = (r - g) / d + 4; | ||
} | ||
h /= 6; | ||
} | ||
return [h, s, l]; | ||
}; | ||
Vibrant.hslToRgb = function(h, s, l) { | ||
var b, g, hue2rgb, p, q, r; | ||
r = void 0; | ||
g = void 0; | ||
b = void 0; | ||
hue2rgb = function(p, q, t) { | ||
if (t < 0) { | ||
t += 1; | ||
} | ||
if (t > 1) { | ||
t -= 1; | ||
} | ||
if (t < 1 / 6) { | ||
return p + (q - p) * 6 * t; | ||
} | ||
if (t < 1 / 2) { | ||
return q; | ||
} | ||
if (t < 2 / 3) { | ||
return p + (q - p) * (2 / 3 - t) * 6; | ||
} | ||
return p; | ||
}; | ||
if (s === 0) { | ||
r = g = b = l; | ||
} else { | ||
q = l < 0.5 ? l * (1 + s) : l + s - (l * s); | ||
p = 2 * l - q; | ||
r = hue2rgb(p, q, h + 1 / 3); | ||
g = hue2rgb(p, q, h); | ||
b = hue2rgb(p, q, h - (1 / 3)); | ||
} | ||
return [r * 255, g * 255, b * 255]; | ||
}; | ||
return Vibrant; | ||
})(); |
{ | ||
"name": "node-vibrant", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Node.js port of vibrant.js. Get color variations from an image. Basically a JS port of Android's Palette", | ||
@@ -5,0 +5,0 @@ "main": "lib/vibrant.js", |
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
473291
22
389