1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update vibrant

This commit is contained in:
Luke Pulverenti 2016-10-22 15:21:57 -04:00
parent 621d660be1
commit fcbb3ccc58
3 changed files with 784 additions and 747 deletions

View file

@ -16,12 +16,12 @@
},
"devDependencies": {},
"ignore": [],
"version": "1.1.91",
"_release": "1.1.91",
"version": "1.1.92",
"_release": "1.1.92",
"_resolution": {
"type": "version",
"tag": "1.1.91",
"commit": "f94b80f14bce6922acf1dbd749a60ad54e4abfd8"
"tag": "1.1.92",
"commit": "0a48f9a0b64a422c4466938b24aa983041a89f52"
},
"_source": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
"_target": "^1.1.51",

View file

@ -216,7 +216,7 @@
return connectUser;
};
var minServerVersion = '3.0.5994';
var minServerVersion = '3.0.6040';
self.minServerVersion = function (val) {
if (val) {

View file

@ -1,44 +1,44 @@
define([], function () {
'use strict';
/*
* quantize.js Copyright 2008 Nick Rabinowitz
* Ported to node.js by Olivier Lesnicki
* 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/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
*/
if (!pv) {
var pv = {
map: function(array, f) {
map: function (array, f) {
var o = {};
return f ? array.map(function(d, i) {
return f ? array.map(function (d, i) {
o.index = i;
return f.call(o, d);
}) : array.slice();
},
naturalOrder: function(a, b) {
naturalOrder: function (a, b) {
return (a < b) ? -1 : ((a > b) ? 1 : 0);
},
sum: function(array, f) {
sum: function (array, f) {
var o = {};
return array.reduce(f ? function(p, d, i) {
return array.reduce(f ? function (p, d, i) {
o.index = i;
return p + f.call(o, d);
} : function(p, d) {
} : function (p, d) {
return p + d;
}, 0);
},
max: function(array, f) {
max: function (array, f) {
return Math.max.apply(null, f ? pv.map(array, f) : array);
}
}
}
};
/**
/**
* Basic Javascript port of the MMCQ (modified median cut quantization)
* algorithm from the Leptonica library (http://www.leptonica.com/).
* Returns a color map you can use to map original pixels to the reduced
@ -47,20 +47,20 @@ if (!pv) {
* @author Nick Rabinowitz
* @example
// 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]
// 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]
// etc
];
var maxColors = 4;
var maxColors = 4;
var cmap = MMCQ.quantize(myPixels, maxColors);
var newPalette = cmap.palette();
var newPixels = myPixels.map(function(p) {
var cmap = MMCQ.quantize(myPixels, maxColors);
var newPalette = cmap.palette();
var newPixels = myPixels.map(function(p) {
return cmap.map(p);
});
});
*/
var MMCQ = (function() {
var MMCQ = (function () {
// private constants
var sigbits = 5,
rshift = 8 - sigbits,
@ -85,27 +85,35 @@ var MMCQ = (function() {
}
return {
push: function(o) {
push: function (o) {
contents.push(o);
sorted = false;
},
peek: function(index) {
if (!sorted) sort();
if (index === undefined) index = contents.length - 1;
peek: function (index) {
if (!sorted) {
sort();
}
if (index === undefined) {
index = contents.length - 1;
}
return contents[index];
},
pop: function() {
if (!sorted) sort();
pop: function () {
if (!sorted) {
sort();
}
return contents.pop();
},
size: function() {
size: function () {
return contents.length;
},
map: function(f) {
map: function (f) {
return contents.map(f);
},
debug: function() {
if (!sorted) sort();
debug: function () {
if (!sorted) {
sort();
}
return contents;
}
};
@ -124,14 +132,14 @@ var MMCQ = (function() {
vbox.histo = histo;
}
VBox.prototype = {
volume: function(force) {
volume: function (force) {
var vbox = this;
if (!vbox._volume || force) {
vbox._volume = ((vbox.r2 - vbox.r1 + 1) * (vbox.g2 - vbox.g1 + 1) * (vbox.b2 - vbox.b1 + 1));
}
return vbox._volume;
},
count: function(force) {
count: function (force) {
var vbox = this,
histo = vbox.histo;
if (!vbox._count_set || force) {
@ -150,11 +158,11 @@ var MMCQ = (function() {
}
return vbox._count;
},
copy: function() {
copy: function () {
var vbox = this;
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,
histo = vbox.histo;
if (!vbox._avg || force) {
@ -178,15 +186,15 @@ var MMCQ = (function() {
}
}
if (ntot) {
vbox._avg = [~~(rsum / ntot), ~~ (gsum / ntot), ~~ (bsum / ntot)];
vbox._avg = [~~(rsum / ntot), ~~(gsum / ntot), ~~(bsum / ntot)];
} else {
//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;
},
contains: function(pixel) {
contains: function (pixel) {
var vbox = this,
rval = pixel[0] >> rshift;
gval = pixel[1] >> rshift;
@ -200,41 +208,41 @@ var MMCQ = (function() {
// Color map
function CMap() {
this.vboxes = new PQueue(function(a, b) {
this.vboxes = new PQueue(function (a, b) {
return pv.naturalOrder(
a.vbox.count() * a.vbox.volume(),
b.vbox.count() * b.vbox.volume()
)
});;
);
});
}
CMap.prototype = {
push: function(vbox) {
push: function (vbox) {
this.vboxes.push({
vbox: vbox,
color: vbox.avg()
});
},
palette: function() {
return this.vboxes.map(function(vb) {
return vb.color
palette: function () {
return this.vboxes.map(function (vb) {
return vb.color;
});
},
size: function() {
size: function () {
return this.vboxes.size();
},
map: function(color) {
map: function (color) {
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)) {
return vboxes.peek(i).color;
}
}
return this.nearest(color);
},
nearest: function(color) {
nearest: function (color) {
var vboxes = this.vboxes,
d1, d2, pColor;
for (var i = 0; i < vboxes.size(); i++) {
for (var i = 0; i < vboxes.size() ; i++) {
d2 = Math.sqrt(
Math.pow(color[0] - vboxes.peek(i).color[0], 2) +
Math.pow(color[1] - vboxes.peek(i).color[1], 2) +
@ -247,24 +255,26 @@ var MMCQ = (function() {
}
return pColor;
},
forcebw: function() {
forcebw: function () {
// XXX: won't work yet
var vboxes = this.vboxes;
vboxes.sort(function(a, b) {
return pv.naturalOrder(pv.sum(a.color), pv.sum(b.color))
vboxes.sort(function (a, b) {
return pv.naturalOrder(pv.sum(a.color), pv.sum(b.color));
});
// force darkest color to black if everything < 5
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];
}
// force lightest color to white if everything > 251
var idx = vboxes.length - 1,
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];
}
}
};
// histo (1-d array, giving the number of pixels in
@ -274,7 +284,7 @@ var MMCQ = (function() {
var histosize = 1 << (3 * sigbits),
histo = new Array(histosize),
index, rval, gval, bval;
pixels.forEach(function(pixel) {
pixels.forEach(function (pixel) {
rval = pixel[0] >> rshift;
gval = pixel[1] >> rshift;
bval = pixel[2] >> rshift;
@ -293,37 +303,54 @@ var MMCQ = (function() {
bmax = 0,
rval, gval, bval;
// find min/max
pixels.forEach(function(pixel) {
pixels.forEach(function (pixel) {
rval = pixel[0] >> rshift;
gval = pixel[1] >> rshift;
bval = pixel[2] >> rshift;
if (rval < rmin) rmin = rval;
else if (rval > rmax) rmax = rval;
if (gval < gmin) gmin = gval;
else if (gval > gmax) gmax = gval;
if (bval < bmin) bmin = bval;
else if (bval > bmax) bmax = bval;
if (rval < rmin) {
rmin = rval;
}
else if (rval > rmax) {
rmax = rval;
}
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);
}
function medianCutApply(histo, vbox) {
if (!vbox.count()) return;
var vBoxCount = vbox.count();
if (!vBoxCount) {
return;
}
var rw = vbox.r2 - vbox.r1 + 1,
gw = vbox.g2 - vbox.g1 + 1,
bw = vbox.b2 - vbox.b1 + 1,
maxw = pv.max([rw, gw, bw]);
// only one pixel, no split
if (vbox.count() == 1) {
return [vbox.copy()]
if (vBoxCount === 1) {
return [vbox.copy()];
}
/* Find the partial sum arrays along the selected axis. */
var total = 0,
partialsum = [],
lookaheadsum = [],
i, j, k, sum, index;
if (maxw == rw) {
if (maxw === rw) {
for (i = vbox.r1; i <= vbox.r2; i++) {
sum = 0;
for (j = vbox.g1; j <= vbox.g2; j++) {
@ -335,7 +362,7 @@ var MMCQ = (function() {
total += sum;
partialsum[i] = total;
}
} else if (maxw == gw) {
} else if (maxw === gw) {
for (i = vbox.g1; i <= vbox.g2; i++) {
sum = 0;
for (j = vbox.r1; j <= vbox.r2; j++) {
@ -360,8 +387,8 @@ var MMCQ = (function() {
partialsum[i] = total;
}
}
partialsum.forEach(function(d, i) {
lookaheadsum[i] = total - d
partialsum.forEach(function (d, i) {
lookaheadsum[i] = total - d;
});
function doCut(color) {
@ -374,25 +401,31 @@ var MMCQ = (function() {
vbox2 = vbox.copy();
left = i - vbox[dim1];
right = vbox[dim2] - i;
if (left <= right)
d2 = Math.min(vbox[dim2] - 1, ~~ (i + right / 2));
else d2 = Math.max(vbox[dim1], ~~ (i - 1 - left / 2));
if (left <= right) {
d2 = Math.min(vbox[dim2] - 1, ~~(i + right / 2));
}
else {
d2 = Math.max(vbox[dim1], ~~(i - 1 - left / 2));
}
// avoid 0-count boxes
while (!partialsum[d2]) d2++;
while (!partialsum[d2]) {
d2++;
}
count2 = lookaheadsum[d2];
while (!count2 && partialsum[d2 - 1]) count2 = lookaheadsum[--d2];
while (!count2 && partialsum[d2 - 1]) {
count2 = lookaheadsum[--d2];
}
// set dimensions
vbox1[dim2] = d2;
vbox2[dim1] = vbox1[dim2] + 1;
// console.log('vbox counts:', vbox.count(), vbox1.count(), vbox2.count());
return [vbox1, vbox2];
}
}
}
// determine the cut planes
return maxw == rw ? doCut('r') :
maxw == gw ? doCut('g') :
return maxw === rw ? doCut('r') :
maxw === gw ? doCut('g') :
doCut('b');
}
@ -410,8 +443,8 @@ var MMCQ = (function() {
// check that we aren't below maxcolors already
var nColors = 0;
histo.forEach(function() {
nColors++
histo.forEach(function () {
nColors++;
});
if (nColors <= maxcolors) {
// XXX: generate the new colors from the histo and return
@ -419,8 +452,8 @@ var MMCQ = (function() {
// get the beginning vbox from the colors
var vbox = vboxFromPixels(pixels, histo),
pq = new PQueue(function(a, b) {
return pv.naturalOrder(a.count(), b.count())
pq = new PQueue(function (a, b) {
return pv.naturalOrder(a.count(), b.count());
});
pq.push(vbox);
@ -451,7 +484,9 @@ var MMCQ = (function() {
lh.push(vbox2);
ncolors++;
}
if (ncolors >= target) return;
if (ncolors >= target) {
return;
}
if (niters++ > maxIterations) {
// console.log("infinite loop; perhaps too few pixels!");
return;
@ -464,8 +499,8 @@ var MMCQ = (function() {
// console.log(pq.size(), pq.debug().length, pq.debug().slice());
// Re-sort by the product of pixel occupancy times the size in color space.
var pq2 = new PQueue(function(a, b) {
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume())
var pq2 = new PQueue(function (a, b) {
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume());
});
while (pq.size()) {
pq2.push(pq.pop());
@ -485,8 +520,8 @@ var MMCQ = (function() {
return {
quantize: quantize
}
})();
};
})();
/*
Vibrant.js
@ -500,11 +535,11 @@ var MMCQ = (function() {
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); }; },
slice = [].slice;
window.Swatch = Swatch = (function () {
window.Swatch = Swatch = (function () {
Swatch.prototype.hsl = void 0;
Swatch.prototype.rgb = void 0;
@ -520,10 +555,9 @@ window.Swatch = Swatch = (function () {
Swatch.prototype.getHsl = function () {
if (!this.hsl) {
return this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
} else {
return this.hsl;
this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
}
return this.hsl;
};
Swatch.prototype.getPopulation = function () {
@ -558,15 +592,16 @@ window.Swatch = Swatch = (function () {
Swatch.prototype._ensureTextColors = function () {
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;
})();
})();
window.Vibrant = Vibrant = (function () {
window.Vibrant = Vibrant = (function () {
Vibrant.prototype.quantize = MMCQ.quantize;
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.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);
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 () {
@ -677,7 +713,8 @@ window.Vibrant = Vibrant = (function () {
if (this.VibrantSwatch !== void 0) {
hsl = this.VibrantSwatch.getHsl();
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;
})();
})();
/*
@ -830,7 +867,7 @@ window.Vibrant = Vibrant = (function () {
Stolen from https://github.com/lokesh/color-thief
*/
window.CanvasImage = CanvasImage = (function () {
window.CanvasImage = CanvasImage = (function () {
function CanvasImage(image) {
this.canvas = document.createElement('canvas');
@ -870,6 +907,6 @@ window.CanvasImage = CanvasImage = (function () {
return CanvasImage;
})();
})();
});