mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update vibrant
This commit is contained in:
parent
621d660be1
commit
fcbb3ccc58
3 changed files with 784 additions and 747 deletions
|
@ -16,12 +16,12 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"version": "1.1.91",
|
"version": "1.1.92",
|
||||||
"_release": "1.1.91",
|
"_release": "1.1.92",
|
||||||
"_resolution": {
|
"_resolution": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"tag": "1.1.91",
|
"tag": "1.1.92",
|
||||||
"commit": "f94b80f14bce6922acf1dbd749a60ad54e4abfd8"
|
"commit": "0a48f9a0b64a422c4466938b24aa983041a89f52"
|
||||||
},
|
},
|
||||||
"_source": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
|
"_source": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
|
||||||
"_target": "^1.1.51",
|
"_target": "^1.1.51",
|
||||||
|
|
|
@ -216,7 +216,7 @@
|
||||||
return connectUser;
|
return connectUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
var minServerVersion = '3.0.5994';
|
var minServerVersion = '3.0.6040';
|
||||||
self.minServerVersion = function (val) {
|
self.minServerVersion = function (val) {
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
define([], function () {
|
define([], function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* quantize.js Copyright 2008 Nick Rabinowitz
|
* quantize.js Copyright 2008 Nick Rabinowitz
|
||||||
* Ported to node.js by Olivier Lesnicki
|
* Ported to node.js by Olivier Lesnicki
|
||||||
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
|
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// fill out a couple protovis dependencies
|
// fill out a couple protovis dependencies
|
||||||
/*
|
/*
|
||||||
* Block below copied from Protovis: http://mbostock.github.com/protovis/
|
* Block below copied from Protovis: http://mbostock.github.com/protovis/
|
||||||
* Copyright 2010 Stanford Visualization Group
|
* Copyright 2010 Stanford Visualization Group
|
||||||
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
||||||
*/
|
*/
|
||||||
if (!pv) {
|
|
||||||
var pv = {
|
var pv = {
|
||||||
map: function(array, f) {
|
map: function (array, f) {
|
||||||
var o = {};
|
var o = {};
|
||||||
return f ? array.map(function(d, i) {
|
return f ? array.map(function (d, i) {
|
||||||
o.index = i;
|
o.index = i;
|
||||||
return f.call(o, d);
|
return f.call(o, d);
|
||||||
}) : array.slice();
|
}) : array.slice();
|
||||||
},
|
},
|
||||||
naturalOrder: function(a, b) {
|
naturalOrder: function (a, b) {
|
||||||
return (a < b) ? -1 : ((a > b) ? 1 : 0);
|
return (a < b) ? -1 : ((a > b) ? 1 : 0);
|
||||||
},
|
},
|
||||||
sum: function(array, f) {
|
sum: function (array, f) {
|
||||||
var o = {};
|
var o = {};
|
||||||
return array.reduce(f ? function(p, d, i) {
|
return array.reduce(f ? function (p, d, i) {
|
||||||
o.index = i;
|
o.index = i;
|
||||||
return p + f.call(o, d);
|
return p + f.call(o, d);
|
||||||
} : function(p, d) {
|
} : function (p, d) {
|
||||||
return p + d;
|
return p + d;
|
||||||
}, 0);
|
}, 0);
|
||||||
},
|
},
|
||||||
max: function(array, f) {
|
max: function (array, f) {
|
||||||
return Math.max.apply(null, f ? pv.map(array, f) : array);
|
return Math.max.apply(null, f ? pv.map(array, f) : array);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic Javascript port of the MMCQ (modified median cut quantization)
|
* Basic Javascript port of the MMCQ (modified median cut quantization)
|
||||||
* algorithm from the Leptonica library (http://www.leptonica.com/).
|
* algorithm from the Leptonica library (http://www.leptonica.com/).
|
||||||
* Returns a color map you can use to map original pixels to the reduced
|
* Returns a color map you can use to map original pixels to the reduced
|
||||||
|
@ -47,20 +47,20 @@ if (!pv) {
|
||||||
* @author Nick Rabinowitz
|
* @author Nick Rabinowitz
|
||||||
* @example
|
* @example
|
||||||
|
|
||||||
// array of pixels as [R,G,B] arrays
|
// array of pixels as [R,G,B] arrays
|
||||||
var myPixels = [[190,197,190], [202,204,200], [207,214,210], [211,214,211], [205,207,207]
|
var myPixels = [[190,197,190], [202,204,200], [207,214,210], [211,214,211], [205,207,207]
|
||||||
// etc
|
// etc
|
||||||
];
|
];
|
||||||
var maxColors = 4;
|
var maxColors = 4;
|
||||||
|
|
||||||
var cmap = MMCQ.quantize(myPixels, maxColors);
|
var cmap = MMCQ.quantize(myPixels, maxColors);
|
||||||
var newPalette = cmap.palette();
|
var newPalette = cmap.palette();
|
||||||
var newPixels = myPixels.map(function(p) {
|
var newPixels = myPixels.map(function(p) {
|
||||||
return cmap.map(p);
|
return cmap.map(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
*/
|
*/
|
||||||
var MMCQ = (function() {
|
var MMCQ = (function () {
|
||||||
// private constants
|
// private constants
|
||||||
var sigbits = 5,
|
var sigbits = 5,
|
||||||
rshift = 8 - sigbits,
|
rshift = 8 - sigbits,
|
||||||
|
@ -85,27 +85,35 @@ var MMCQ = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
push: function(o) {
|
push: function (o) {
|
||||||
contents.push(o);
|
contents.push(o);
|
||||||
sorted = false;
|
sorted = false;
|
||||||
},
|
},
|
||||||
peek: function(index) {
|
peek: function (index) {
|
||||||
if (!sorted) sort();
|
if (!sorted) {
|
||||||
if (index === undefined) index = contents.length - 1;
|
sort();
|
||||||
|
}
|
||||||
|
if (index === undefined) {
|
||||||
|
index = contents.length - 1;
|
||||||
|
}
|
||||||
return contents[index];
|
return contents[index];
|
||||||
},
|
},
|
||||||
pop: function() {
|
pop: function () {
|
||||||
if (!sorted) sort();
|
if (!sorted) {
|
||||||
|
sort();
|
||||||
|
}
|
||||||
return contents.pop();
|
return contents.pop();
|
||||||
},
|
},
|
||||||
size: function() {
|
size: function () {
|
||||||
return contents.length;
|
return contents.length;
|
||||||
},
|
},
|
||||||
map: function(f) {
|
map: function (f) {
|
||||||
return contents.map(f);
|
return contents.map(f);
|
||||||
},
|
},
|
||||||
debug: function() {
|
debug: function () {
|
||||||
if (!sorted) sort();
|
if (!sorted) {
|
||||||
|
sort();
|
||||||
|
}
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -124,14 +132,14 @@ var MMCQ = (function() {
|
||||||
vbox.histo = histo;
|
vbox.histo = histo;
|
||||||
}
|
}
|
||||||
VBox.prototype = {
|
VBox.prototype = {
|
||||||
volume: function(force) {
|
volume: function (force) {
|
||||||
var vbox = this;
|
var vbox = this;
|
||||||
if (!vbox._volume || force) {
|
if (!vbox._volume || force) {
|
||||||
vbox._volume = ((vbox.r2 - vbox.r1 + 1) * (vbox.g2 - vbox.g1 + 1) * (vbox.b2 - vbox.b1 + 1));
|
vbox._volume = ((vbox.r2 - vbox.r1 + 1) * (vbox.g2 - vbox.g1 + 1) * (vbox.b2 - vbox.b1 + 1));
|
||||||
}
|
}
|
||||||
return vbox._volume;
|
return vbox._volume;
|
||||||
},
|
},
|
||||||
count: function(force) {
|
count: function (force) {
|
||||||
var vbox = this,
|
var vbox = this,
|
||||||
histo = vbox.histo;
|
histo = vbox.histo;
|
||||||
if (!vbox._count_set || force) {
|
if (!vbox._count_set || force) {
|
||||||
|
@ -150,11 +158,11 @@ var MMCQ = (function() {
|
||||||
}
|
}
|
||||||
return vbox._count;
|
return vbox._count;
|
||||||
},
|
},
|
||||||
copy: function() {
|
copy: function () {
|
||||||
var vbox = this;
|
var vbox = this;
|
||||||
return new VBox(vbox.r1, vbox.r2, vbox.g1, vbox.g2, vbox.b1, vbox.b2, vbox.histo);
|
return new VBox(vbox.r1, vbox.r2, vbox.g1, vbox.g2, vbox.b1, vbox.b2, vbox.histo);
|
||||||
},
|
},
|
||||||
avg: function(force) {
|
avg: function (force) {
|
||||||
var vbox = this,
|
var vbox = this,
|
||||||
histo = vbox.histo;
|
histo = vbox.histo;
|
||||||
if (!vbox._avg || force) {
|
if (!vbox._avg || force) {
|
||||||
|
@ -178,15 +186,15 @@ var MMCQ = (function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ntot) {
|
if (ntot) {
|
||||||
vbox._avg = [~~(rsum / ntot), ~~ (gsum / ntot), ~~ (bsum / ntot)];
|
vbox._avg = [~~(rsum / ntot), ~~(gsum / ntot), ~~(bsum / ntot)];
|
||||||
} else {
|
} else {
|
||||||
//console.log('empty box');
|
//console.log('empty box');
|
||||||
vbox._avg = [~~(mult * (vbox.r1 + vbox.r2 + 1) / 2), ~~ (mult * (vbox.g1 + vbox.g2 + 1) / 2), ~~ (mult * (vbox.b1 + vbox.b2 + 1) / 2)];
|
vbox._avg = [~~(mult * (vbox.r1 + vbox.r2 + 1) / 2), ~~(mult * (vbox.g1 + vbox.g2 + 1) / 2), ~~(mult * (vbox.b1 + vbox.b2 + 1) / 2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vbox._avg;
|
return vbox._avg;
|
||||||
},
|
},
|
||||||
contains: function(pixel) {
|
contains: function (pixel) {
|
||||||
var vbox = this,
|
var vbox = this,
|
||||||
rval = pixel[0] >> rshift;
|
rval = pixel[0] >> rshift;
|
||||||
gval = pixel[1] >> rshift;
|
gval = pixel[1] >> rshift;
|
||||||
|
@ -200,41 +208,41 @@ var MMCQ = (function() {
|
||||||
// Color map
|
// Color map
|
||||||
|
|
||||||
function CMap() {
|
function CMap() {
|
||||||
this.vboxes = new PQueue(function(a, b) {
|
this.vboxes = new PQueue(function (a, b) {
|
||||||
return pv.naturalOrder(
|
return pv.naturalOrder(
|
||||||
a.vbox.count() * a.vbox.volume(),
|
a.vbox.count() * a.vbox.volume(),
|
||||||
b.vbox.count() * b.vbox.volume()
|
b.vbox.count() * b.vbox.volume()
|
||||||
)
|
);
|
||||||
});;
|
});
|
||||||
}
|
}
|
||||||
CMap.prototype = {
|
CMap.prototype = {
|
||||||
push: function(vbox) {
|
push: function (vbox) {
|
||||||
this.vboxes.push({
|
this.vboxes.push({
|
||||||
vbox: vbox,
|
vbox: vbox,
|
||||||
color: vbox.avg()
|
color: vbox.avg()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
palette: function() {
|
palette: function () {
|
||||||
return this.vboxes.map(function(vb) {
|
return this.vboxes.map(function (vb) {
|
||||||
return vb.color
|
return vb.color;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
size: function() {
|
size: function () {
|
||||||
return this.vboxes.size();
|
return this.vboxes.size();
|
||||||
},
|
},
|
||||||
map: function(color) {
|
map: function (color) {
|
||||||
var vboxes = this.vboxes;
|
var vboxes = this.vboxes;
|
||||||
for (var i = 0; i < vboxes.size(); i++) {
|
for (var i = 0; i < vboxes.size() ; i++) {
|
||||||
if (vboxes.peek(i).vbox.contains(color)) {
|
if (vboxes.peek(i).vbox.contains(color)) {
|
||||||
return vboxes.peek(i).color;
|
return vboxes.peek(i).color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.nearest(color);
|
return this.nearest(color);
|
||||||
},
|
},
|
||||||
nearest: function(color) {
|
nearest: function (color) {
|
||||||
var vboxes = this.vboxes,
|
var vboxes = this.vboxes,
|
||||||
d1, d2, pColor;
|
d1, d2, pColor;
|
||||||
for (var i = 0; i < vboxes.size(); i++) {
|
for (var i = 0; i < vboxes.size() ; i++) {
|
||||||
d2 = Math.sqrt(
|
d2 = Math.sqrt(
|
||||||
Math.pow(color[0] - vboxes.peek(i).color[0], 2) +
|
Math.pow(color[0] - vboxes.peek(i).color[0], 2) +
|
||||||
Math.pow(color[1] - vboxes.peek(i).color[1], 2) +
|
Math.pow(color[1] - vboxes.peek(i).color[1], 2) +
|
||||||
|
@ -247,24 +255,26 @@ var MMCQ = (function() {
|
||||||
}
|
}
|
||||||
return pColor;
|
return pColor;
|
||||||
},
|
},
|
||||||
forcebw: function() {
|
forcebw: function () {
|
||||||
// XXX: won't work yet
|
// XXX: won't work yet
|
||||||
var vboxes = this.vboxes;
|
var vboxes = this.vboxes;
|
||||||
vboxes.sort(function(a, b) {
|
vboxes.sort(function (a, b) {
|
||||||
return pv.naturalOrder(pv.sum(a.color), pv.sum(b.color))
|
return pv.naturalOrder(pv.sum(a.color), pv.sum(b.color));
|
||||||
});
|
});
|
||||||
|
|
||||||
// force darkest color to black if everything < 5
|
// force darkest color to black if everything < 5
|
||||||
var lowest = vboxes[0].color;
|
var lowest = vboxes[0].color;
|
||||||
if (lowest[0] < 5 && lowest[1] < 5 && lowest[2] < 5)
|
if (lowest[0] < 5 && lowest[1] < 5 && lowest[2] < 5) {
|
||||||
vboxes[0].color = [0, 0, 0];
|
vboxes[0].color = [0, 0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
// force lightest color to white if everything > 251
|
// force lightest color to white if everything > 251
|
||||||
var idx = vboxes.length - 1,
|
var idx = vboxes.length - 1,
|
||||||
highest = vboxes[idx].color;
|
highest = vboxes[idx].color;
|
||||||
if (highest[0] > 251 && highest[1] > 251 && highest[2] > 251)
|
if (highest[0] > 251 && highest[1] > 251 && highest[2] > 251) {
|
||||||
vboxes[idx].color = [255, 255, 255];
|
vboxes[idx].color = [255, 255, 255];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// histo (1-d array, giving the number of pixels in
|
// histo (1-d array, giving the number of pixels in
|
||||||
|
@ -274,7 +284,7 @@ var MMCQ = (function() {
|
||||||
var histosize = 1 << (3 * sigbits),
|
var histosize = 1 << (3 * sigbits),
|
||||||
histo = new Array(histosize),
|
histo = new Array(histosize),
|
||||||
index, rval, gval, bval;
|
index, rval, gval, bval;
|
||||||
pixels.forEach(function(pixel) {
|
pixels.forEach(function (pixel) {
|
||||||
rval = pixel[0] >> rshift;
|
rval = pixel[0] >> rshift;
|
||||||
gval = pixel[1] >> rshift;
|
gval = pixel[1] >> rshift;
|
||||||
bval = pixel[2] >> rshift;
|
bval = pixel[2] >> rshift;
|
||||||
|
@ -293,37 +303,54 @@ var MMCQ = (function() {
|
||||||
bmax = 0,
|
bmax = 0,
|
||||||
rval, gval, bval;
|
rval, gval, bval;
|
||||||
// find min/max
|
// find min/max
|
||||||
pixels.forEach(function(pixel) {
|
pixels.forEach(function (pixel) {
|
||||||
rval = pixel[0] >> rshift;
|
rval = pixel[0] >> rshift;
|
||||||
gval = pixel[1] >> rshift;
|
gval = pixel[1] >> rshift;
|
||||||
bval = pixel[2] >> rshift;
|
bval = pixel[2] >> rshift;
|
||||||
if (rval < rmin) rmin = rval;
|
if (rval < rmin) {
|
||||||
else if (rval > rmax) rmax = rval;
|
rmin = rval;
|
||||||
if (gval < gmin) gmin = gval;
|
}
|
||||||
else if (gval > gmax) gmax = gval;
|
else if (rval > rmax) {
|
||||||
if (bval < bmin) bmin = bval;
|
rmax = rval;
|
||||||
else if (bval > bmax) bmax = bval;
|
}
|
||||||
|
if (gval < gmin) {
|
||||||
|
gmin = gval;
|
||||||
|
}
|
||||||
|
else if (gval > gmax) {
|
||||||
|
gmax = gval;
|
||||||
|
}
|
||||||
|
if (bval < bmin) {
|
||||||
|
bmin = bval;
|
||||||
|
}
|
||||||
|
else if (bval > bmax) {
|
||||||
|
bmax = bval;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return new VBox(rmin, rmax, gmin, gmax, bmin, bmax, histo);
|
return new VBox(rmin, rmax, gmin, gmax, bmin, bmax, histo);
|
||||||
}
|
}
|
||||||
|
|
||||||
function medianCutApply(histo, vbox) {
|
function medianCutApply(histo, vbox) {
|
||||||
if (!vbox.count()) return;
|
|
||||||
|
var vBoxCount = vbox.count();
|
||||||
|
|
||||||
|
if (!vBoxCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var rw = vbox.r2 - vbox.r1 + 1,
|
var rw = vbox.r2 - vbox.r1 + 1,
|
||||||
gw = vbox.g2 - vbox.g1 + 1,
|
gw = vbox.g2 - vbox.g1 + 1,
|
||||||
bw = vbox.b2 - vbox.b1 + 1,
|
bw = vbox.b2 - vbox.b1 + 1,
|
||||||
maxw = pv.max([rw, gw, bw]);
|
maxw = pv.max([rw, gw, bw]);
|
||||||
// only one pixel, no split
|
// only one pixel, no split
|
||||||
if (vbox.count() == 1) {
|
if (vBoxCount === 1) {
|
||||||
return [vbox.copy()]
|
return [vbox.copy()];
|
||||||
}
|
}
|
||||||
/* Find the partial sum arrays along the selected axis. */
|
/* Find the partial sum arrays along the selected axis. */
|
||||||
var total = 0,
|
var total = 0,
|
||||||
partialsum = [],
|
partialsum = [],
|
||||||
lookaheadsum = [],
|
lookaheadsum = [],
|
||||||
i, j, k, sum, index;
|
i, j, k, sum, index;
|
||||||
if (maxw == rw) {
|
if (maxw === rw) {
|
||||||
for (i = vbox.r1; i <= vbox.r2; i++) {
|
for (i = vbox.r1; i <= vbox.r2; i++) {
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (j = vbox.g1; j <= vbox.g2; j++) {
|
for (j = vbox.g1; j <= vbox.g2; j++) {
|
||||||
|
@ -335,7 +362,7 @@ var MMCQ = (function() {
|
||||||
total += sum;
|
total += sum;
|
||||||
partialsum[i] = total;
|
partialsum[i] = total;
|
||||||
}
|
}
|
||||||
} else if (maxw == gw) {
|
} else if (maxw === gw) {
|
||||||
for (i = vbox.g1; i <= vbox.g2; i++) {
|
for (i = vbox.g1; i <= vbox.g2; i++) {
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (j = vbox.r1; j <= vbox.r2; j++) {
|
for (j = vbox.r1; j <= vbox.r2; j++) {
|
||||||
|
@ -360,8 +387,8 @@ var MMCQ = (function() {
|
||||||
partialsum[i] = total;
|
partialsum[i] = total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
partialsum.forEach(function(d, i) {
|
partialsum.forEach(function (d, i) {
|
||||||
lookaheadsum[i] = total - d
|
lookaheadsum[i] = total - d;
|
||||||
});
|
});
|
||||||
|
|
||||||
function doCut(color) {
|
function doCut(color) {
|
||||||
|
@ -374,25 +401,31 @@ var MMCQ = (function() {
|
||||||
vbox2 = vbox.copy();
|
vbox2 = vbox.copy();
|
||||||
left = i - vbox[dim1];
|
left = i - vbox[dim1];
|
||||||
right = vbox[dim2] - i;
|
right = vbox[dim2] - i;
|
||||||
if (left <= right)
|
if (left <= right) {
|
||||||
d2 = Math.min(vbox[dim2] - 1, ~~ (i + right / 2));
|
d2 = Math.min(vbox[dim2] - 1, ~~(i + right / 2));
|
||||||
else d2 = Math.max(vbox[dim1], ~~ (i - 1 - left / 2));
|
}
|
||||||
|
else {
|
||||||
|
d2 = Math.max(vbox[dim1], ~~(i - 1 - left / 2));
|
||||||
|
}
|
||||||
// avoid 0-count boxes
|
// avoid 0-count boxes
|
||||||
while (!partialsum[d2]) d2++;
|
while (!partialsum[d2]) {
|
||||||
|
d2++;
|
||||||
|
}
|
||||||
count2 = lookaheadsum[d2];
|
count2 = lookaheadsum[d2];
|
||||||
while (!count2 && partialsum[d2 - 1]) count2 = lookaheadsum[--d2];
|
while (!count2 && partialsum[d2 - 1]) {
|
||||||
|
count2 = lookaheadsum[--d2];
|
||||||
|
}
|
||||||
// set dimensions
|
// set dimensions
|
||||||
vbox1[dim2] = d2;
|
vbox1[dim2] = d2;
|
||||||
vbox2[dim1] = vbox1[dim2] + 1;
|
vbox2[dim1] = vbox1[dim2] + 1;
|
||||||
// console.log('vbox counts:', vbox.count(), vbox1.count(), vbox2.count());
|
|
||||||
return [vbox1, vbox2];
|
return [vbox1, vbox2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// determine the cut planes
|
// determine the cut planes
|
||||||
return maxw == rw ? doCut('r') :
|
return maxw === rw ? doCut('r') :
|
||||||
maxw == gw ? doCut('g') :
|
maxw === gw ? doCut('g') :
|
||||||
doCut('b');
|
doCut('b');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +443,8 @@ var MMCQ = (function() {
|
||||||
|
|
||||||
// check that we aren't below maxcolors already
|
// check that we aren't below maxcolors already
|
||||||
var nColors = 0;
|
var nColors = 0;
|
||||||
histo.forEach(function() {
|
histo.forEach(function () {
|
||||||
nColors++
|
nColors++;
|
||||||
});
|
});
|
||||||
if (nColors <= maxcolors) {
|
if (nColors <= maxcolors) {
|
||||||
// XXX: generate the new colors from the histo and return
|
// XXX: generate the new colors from the histo and return
|
||||||
|
@ -419,8 +452,8 @@ var MMCQ = (function() {
|
||||||
|
|
||||||
// get the beginning vbox from the colors
|
// get the beginning vbox from the colors
|
||||||
var vbox = vboxFromPixels(pixels, histo),
|
var vbox = vboxFromPixels(pixels, histo),
|
||||||
pq = new PQueue(function(a, b) {
|
pq = new PQueue(function (a, b) {
|
||||||
return pv.naturalOrder(a.count(), b.count())
|
return pv.naturalOrder(a.count(), b.count());
|
||||||
});
|
});
|
||||||
pq.push(vbox);
|
pq.push(vbox);
|
||||||
|
|
||||||
|
@ -451,7 +484,9 @@ var MMCQ = (function() {
|
||||||
lh.push(vbox2);
|
lh.push(vbox2);
|
||||||
ncolors++;
|
ncolors++;
|
||||||
}
|
}
|
||||||
if (ncolors >= target) return;
|
if (ncolors >= target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (niters++ > maxIterations) {
|
if (niters++ > maxIterations) {
|
||||||
// console.log("infinite loop; perhaps too few pixels!");
|
// console.log("infinite loop; perhaps too few pixels!");
|
||||||
return;
|
return;
|
||||||
|
@ -464,8 +499,8 @@ var MMCQ = (function() {
|
||||||
// console.log(pq.size(), pq.debug().length, pq.debug().slice());
|
// console.log(pq.size(), pq.debug().length, pq.debug().slice());
|
||||||
|
|
||||||
// Re-sort by the product of pixel occupancy times the size in color space.
|
// Re-sort by the product of pixel occupancy times the size in color space.
|
||||||
var pq2 = new PQueue(function(a, b) {
|
var pq2 = new PQueue(function (a, b) {
|
||||||
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume())
|
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume());
|
||||||
});
|
});
|
||||||
while (pq.size()) {
|
while (pq.size()) {
|
||||||
pq2.push(pq.pop());
|
pq2.push(pq.pop());
|
||||||
|
@ -485,8 +520,8 @@ var MMCQ = (function() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
quantize: quantize
|
quantize: quantize
|
||||||
}
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Vibrant.js
|
Vibrant.js
|
||||||
|
@ -500,11 +535,11 @@ var MMCQ = (function() {
|
||||||
Google - Palette support library in Android
|
Google - Palette support library in Android
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var CanvasImage, Swatch, Vibrant,
|
var CanvasImage, Swatch, Vibrant,
|
||||||
bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; },
|
bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; },
|
||||||
slice = [].slice;
|
slice = [].slice;
|
||||||
|
|
||||||
window.Swatch = Swatch = (function () {
|
window.Swatch = Swatch = (function () {
|
||||||
Swatch.prototype.hsl = void 0;
|
Swatch.prototype.hsl = void 0;
|
||||||
|
|
||||||
Swatch.prototype.rgb = void 0;
|
Swatch.prototype.rgb = void 0;
|
||||||
|
@ -520,10 +555,9 @@ window.Swatch = Swatch = (function () {
|
||||||
|
|
||||||
Swatch.prototype.getHsl = function () {
|
Swatch.prototype.getHsl = function () {
|
||||||
if (!this.hsl) {
|
if (!this.hsl) {
|
||||||
return this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
|
this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
|
||||||
} else {
|
|
||||||
return this.hsl;
|
|
||||||
}
|
}
|
||||||
|
return this.hsl;
|
||||||
};
|
};
|
||||||
|
|
||||||
Swatch.prototype.getPopulation = function () {
|
Swatch.prototype.getPopulation = function () {
|
||||||
|
@ -558,15 +592,16 @@ window.Swatch = Swatch = (function () {
|
||||||
|
|
||||||
Swatch.prototype._ensureTextColors = function () {
|
Swatch.prototype._ensureTextColors = function () {
|
||||||
if (!this.yiq) {
|
if (!this.yiq) {
|
||||||
return this.yiq = (this.rgb[0] * 299 + this.rgb[1] * 587 + this.rgb[2] * 114) / 1000;
|
this.yiq = (this.rgb[0] * 299 + this.rgb[1] * 587 + this.rgb[2] * 114) / 1000;
|
||||||
|
return this.yiq;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Swatch;
|
return Swatch;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
window.Vibrant = Vibrant = (function () {
|
window.Vibrant = Vibrant = (function () {
|
||||||
Vibrant.prototype.quantize = MMCQ.quantize;
|
Vibrant.prototype.quantize = MMCQ.quantize;
|
||||||
Vibrant.prototype._swatches = [];
|
Vibrant.prototype._swatches = [];
|
||||||
|
|
||||||
|
@ -661,7 +696,8 @@ window.Vibrant = Vibrant = (function () {
|
||||||
this.DarkVibrantSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
this.DarkVibrantSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
||||||
this.MutedSwatch = this.findColorVariation(this.TARGET_NORMAL_LUMA, this.MIN_NORMAL_LUMA, this.MAX_NORMAL_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
this.MutedSwatch = this.findColorVariation(this.TARGET_NORMAL_LUMA, this.MIN_NORMAL_LUMA, this.MAX_NORMAL_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||||
this.LightMutedSwatch = this.findColorVariation(this.TARGET_LIGHT_LUMA, this.MIN_LIGHT_LUMA, 1, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
this.LightMutedSwatch = this.findColorVariation(this.TARGET_LIGHT_LUMA, this.MIN_LIGHT_LUMA, 1, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||||
return this.DarkMutedSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
this.DarkMutedSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||||
|
return this.DarkMutedSwatch;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vibrant.prototype.generateEmptySwatches = function () {
|
Vibrant.prototype.generateEmptySwatches = function () {
|
||||||
|
@ -677,7 +713,8 @@ window.Vibrant = Vibrant = (function () {
|
||||||
if (this.VibrantSwatch !== void 0) {
|
if (this.VibrantSwatch !== void 0) {
|
||||||
hsl = this.VibrantSwatch.getHsl();
|
hsl = this.VibrantSwatch.getHsl();
|
||||||
hsl[2] = this.TARGET_DARK_LUMA;
|
hsl[2] = this.TARGET_DARK_LUMA;
|
||||||
return this.DarkVibrantSwatch = new Swatch(Vibrant.hslToRgb(hsl[0], hsl[1], hsl[2]), 0);
|
this.DarkVibrantSwatch = new Swatch(Vibrant.hslToRgb(hsl[0], hsl[1], hsl[2]), 0);
|
||||||
|
return this.DarkVibrantSwatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -819,7 +856,7 @@ window.Vibrant = Vibrant = (function () {
|
||||||
|
|
||||||
return Vibrant;
|
return Vibrant;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -830,7 +867,7 @@ window.Vibrant = Vibrant = (function () {
|
||||||
Stolen from https://github.com/lokesh/color-thief
|
Stolen from https://github.com/lokesh/color-thief
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.CanvasImage = CanvasImage = (function () {
|
window.CanvasImage = CanvasImage = (function () {
|
||||||
function CanvasImage(image) {
|
function CanvasImage(image) {
|
||||||
|
|
||||||
this.canvas = document.createElement('canvas');
|
this.canvas = document.createElement('canvas');
|
||||||
|
@ -870,6 +907,6 @@ window.CanvasImage = CanvasImage = (function () {
|
||||||
|
|
||||||
return CanvasImage;
|
return CanvasImage;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue