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": {},
|
||||
"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",
|
||||
|
|
|
@ -216,7 +216,7 @@
|
|||
return connectUser;
|
||||
};
|
||||
|
||||
var minServerVersion = '3.0.5994';
|
||||
var minServerVersion = '3.0.6040';
|
||||
self.minServerVersion = function (val) {
|
||||
|
||||
if (val) {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* quantize.js Copyright 2008 Nick Rabinowitz
|
||||
* Ported to node.js by Olivier Lesnicki
|
||||
|
@ -11,7 +13,6 @@ define([], function () {
|
|||
* 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) {
|
||||
var o = {};
|
||||
|
@ -35,8 +36,7 @@ if (!pv) {
|
|||
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)
|
||||
|
@ -90,12 +90,18 @@ var MMCQ = (function() {
|
|||
sorted = false;
|
||||
},
|
||||
peek: function (index) {
|
||||
if (!sorted) sort();
|
||||
if (index === undefined) index = contents.length - 1;
|
||||
if (!sorted) {
|
||||
sort();
|
||||
}
|
||||
if (index === undefined) {
|
||||
index = contents.length - 1;
|
||||
}
|
||||
return contents[index];
|
||||
},
|
||||
pop: function () {
|
||||
if (!sorted) sort();
|
||||
if (!sorted) {
|
||||
sort();
|
||||
}
|
||||
return contents.pop();
|
||||
},
|
||||
size: function () {
|
||||
|
@ -105,7 +111,9 @@ var MMCQ = (function() {
|
|||
return contents.map(f);
|
||||
},
|
||||
debug: function () {
|
||||
if (!sorted) sort();
|
||||
if (!sorted) {
|
||||
sort();
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
};
|
||||
|
@ -204,8 +212,8 @@ var MMCQ = (function() {
|
|||
return pv.naturalOrder(
|
||||
a.vbox.count() * a.vbox.volume(),
|
||||
b.vbox.count() * b.vbox.volume()
|
||||
)
|
||||
});;
|
||||
);
|
||||
});
|
||||
}
|
||||
CMap.prototype = {
|
||||
push: function (vbox) {
|
||||
|
@ -216,7 +224,7 @@ var MMCQ = (function() {
|
|||
},
|
||||
palette: function () {
|
||||
return this.vboxes.map(function (vb) {
|
||||
return vb.color
|
||||
return vb.color;
|
||||
});
|
||||
},
|
||||
size: function () {
|
||||
|
@ -251,20 +259,22 @@ var MMCQ = (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))
|
||||
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
|
||||
|
@ -297,33 +307,50 @@ var MMCQ = (function() {
|
|||
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++) {
|
||||
|
@ -361,7 +388,7 @@ var MMCQ = (function() {
|
|||
}
|
||||
}
|
||||
partialsum.forEach(function (d, i) {
|
||||
lookaheadsum[i] = total - d
|
||||
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)
|
||||
if (left <= right) {
|
||||
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
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -411,7 +444,7 @@ var MMCQ = (function() {
|
|||
// check that we aren't below maxcolors already
|
||||
var nColors = 0;
|
||||
histo.forEach(function () {
|
||||
nColors++
|
||||
nColors++;
|
||||
});
|
||||
if (nColors <= maxcolors) {
|
||||
// XXX: generate the new colors from the histo and return
|
||||
|
@ -420,7 +453,7 @@ 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())
|
||||
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;
|
||||
|
@ -465,7 +500,7 @@ var MMCQ = (function() {
|
|||
|
||||
// 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())
|
||||
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume());
|
||||
});
|
||||
while (pq.size()) {
|
||||
pq2.push(pq.pop());
|
||||
|
@ -485,7 +520,7 @@ var MMCQ = (function() {
|
|||
|
||||
return {
|
||||
quantize: quantize
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/*
|
||||
|
@ -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,7 +592,8 @@ 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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue