mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
simplify vibrant
This commit is contained in:
parent
dc66936c08
commit
353dd8d067
1 changed files with 356 additions and 359 deletions
|
@ -504,12 +504,11 @@ module.exports = MMCQ.quantize
|
|||
Google - Palette support library in Android
|
||||
*/
|
||||
|
||||
(function() {
|
||||
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;
|
||||
|
||||
window.Swatch = Swatch = (function() {
|
||||
window.Swatch = Swatch = (function () {
|
||||
Swatch.prototype.hsl = void 0;
|
||||
|
||||
Swatch.prototype.rgb = void 0;
|
||||
|
@ -523,7 +522,7 @@ module.exports = MMCQ.quantize
|
|||
this.population = population;
|
||||
}
|
||||
|
||||
Swatch.prototype.getHsl = function() {
|
||||
Swatch.prototype.getHsl = function () {
|
||||
if (!this.hsl) {
|
||||
return this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
|
||||
} else {
|
||||
|
@ -531,19 +530,19 @@ module.exports = MMCQ.quantize
|
|||
}
|
||||
};
|
||||
|
||||
Swatch.prototype.getPopulation = function() {
|
||||
Swatch.prototype.getPopulation = function () {
|
||||
return this.population;
|
||||
};
|
||||
|
||||
Swatch.prototype.getRgb = function() {
|
||||
Swatch.prototype.getRgb = function () {
|
||||
return this.rgb;
|
||||
};
|
||||
|
||||
Swatch.prototype.getHex = function() {
|
||||
Swatch.prototype.getHex = function () {
|
||||
return "#" + ((1 << 24) + (this.rgb[0] << 16) + (this.rgb[1] << 8) + this.rgb[2]).toString(16).slice(1, 7);
|
||||
};
|
||||
|
||||
Swatch.prototype.getTitleTextColor = function() {
|
||||
Swatch.prototype.getTitleTextColor = function () {
|
||||
this._ensureTextColors();
|
||||
if (this.yiq < 200) {
|
||||
return "#fff";
|
||||
|
@ -552,7 +551,7 @@ module.exports = MMCQ.quantize
|
|||
}
|
||||
};
|
||||
|
||||
Swatch.prototype.getBodyTextColor = function() {
|
||||
Swatch.prototype.getBodyTextColor = function () {
|
||||
this._ensureTextColors();
|
||||
if (this.yiq < 150) {
|
||||
return "#fff";
|
||||
|
@ -561,7 +560,7 @@ module.exports = MMCQ.quantize
|
|||
}
|
||||
};
|
||||
|
||||
Swatch.prototype._ensureTextColors = function() {
|
||||
Swatch.prototype._ensureTextColors = function () {
|
||||
if (!this.yiq) {
|
||||
return this.yiq = (this.rgb[0] * 299 + this.rgb[1] * 587 + this.rgb[2] * 114) / 1000;
|
||||
}
|
||||
|
@ -571,7 +570,7 @@ module.exports = MMCQ.quantize
|
|||
|
||||
})();
|
||||
|
||||
window.Vibrant = Vibrant = (function() {
|
||||
window.Vibrant = Vibrant = (function () {
|
||||
Vibrant.prototype.quantize = require('quantize');
|
||||
|
||||
Vibrant.prototype._swatches = [];
|
||||
|
@ -648,8 +647,8 @@ module.exports = MMCQ.quantize
|
|||
i = i + quality;
|
||||
}
|
||||
cmap = this.quantize(allPixels, colorCount);
|
||||
this._swatches = cmap.vboxes.map((function(_this) {
|
||||
return function(vbox) {
|
||||
this._swatches = cmap.vboxes.map((function (_this) {
|
||||
return function (vbox) {
|
||||
return new Swatch(vbox.color, vbox.vbox.count());
|
||||
};
|
||||
})(this));
|
||||
|
@ -661,7 +660,7 @@ module.exports = MMCQ.quantize
|
|||
}
|
||||
}
|
||||
|
||||
Vibrant.prototype.generateVarationColors = function() {
|
||||
Vibrant.prototype.generateVarationColors = function () {
|
||||
this.VibrantSwatch = this.findColorVariation(this.TARGET_NORMAL_LUMA, this.MIN_NORMAL_LUMA, this.MAX_NORMAL_LUMA, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
||||
this.LightVibrantSwatch = this.findColorVariation(this.TARGET_LIGHT_LUMA, this.MIN_LIGHT_LUMA, 1, 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);
|
||||
|
@ -670,7 +669,7 @@ module.exports = MMCQ.quantize
|
|||
return this.DarkMutedSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||
};
|
||||
|
||||
Vibrant.prototype.generateEmptySwatches = function() {
|
||||
Vibrant.prototype.generateEmptySwatches = function () {
|
||||
var hsl;
|
||||
if (this.VibrantSwatch === void 0) {
|
||||
if (this.DarkVibrantSwatch !== void 0) {
|
||||
|
@ -688,7 +687,7 @@ module.exports = MMCQ.quantize
|
|||
}
|
||||
};
|
||||
|
||||
Vibrant.prototype.findMaxPopulation = function() {
|
||||
Vibrant.prototype.findMaxPopulation = function () {
|
||||
var j, len, population, ref, swatch;
|
||||
population = 0;
|
||||
ref = this._swatches;
|
||||
|
@ -699,7 +698,7 @@ module.exports = MMCQ.quantize
|
|||
return population;
|
||||
};
|
||||
|
||||
Vibrant.prototype.findColorVariation = function(targetLuma, minLuma, maxLuma, targetSaturation, minSaturation, maxSaturation) {
|
||||
Vibrant.prototype.findColorVariation = function (targetLuma, minLuma, maxLuma, targetSaturation, minSaturation, maxSaturation) {
|
||||
var j, len, luma, max, maxValue, ref, sat, swatch, value;
|
||||
max = void 0;
|
||||
maxValue = 0;
|
||||
|
@ -719,15 +718,15 @@ module.exports = MMCQ.quantize
|
|||
return max;
|
||||
};
|
||||
|
||||
Vibrant.prototype.createComparisonValue = function(saturation, targetSaturation, luma, targetLuma, population, maxPopulation) {
|
||||
Vibrant.prototype.createComparisonValue = function (saturation, targetSaturation, luma, targetLuma, population, maxPopulation) {
|
||||
return this.weightedMean(this.invertDiff(saturation, targetSaturation), this.WEIGHT_SATURATION, this.invertDiff(luma, targetLuma), this.WEIGHT_LUMA, population / maxPopulation, this.WEIGHT_POPULATION);
|
||||
};
|
||||
|
||||
Vibrant.prototype.invertDiff = function(value, targetValue) {
|
||||
Vibrant.prototype.invertDiff = function (value, targetValue) {
|
||||
return 1 - Math.abs(value - targetValue);
|
||||
};
|
||||
|
||||
Vibrant.prototype.weightedMean = function() {
|
||||
Vibrant.prototype.weightedMean = function () {
|
||||
var i, sum, sumWeight, value, values, weight;
|
||||
values = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
sum = 0;
|
||||
|
@ -743,7 +742,7 @@ module.exports = MMCQ.quantize
|
|||
return sum / sumWeight;
|
||||
};
|
||||
|
||||
Vibrant.prototype.swatches = function() {
|
||||
Vibrant.prototype.swatches = function () {
|
||||
return {
|
||||
Vibrant: this.VibrantSwatch,
|
||||
Muted: this.MutedSwatch,
|
||||
|
@ -754,11 +753,11 @@ module.exports = MMCQ.quantize
|
|||
};
|
||||
};
|
||||
|
||||
Vibrant.prototype.isAlreadySelected = function(swatch) {
|
||||
Vibrant.prototype.isAlreadySelected = function (swatch) {
|
||||
return this.VibrantSwatch === swatch || this.DarkVibrantSwatch === swatch || this.LightVibrantSwatch === swatch || this.MutedSwatch === swatch || this.DarkMutedSwatch === swatch || this.LightMutedSwatch === swatch;
|
||||
};
|
||||
|
||||
Vibrant.rgbToHsl = function(r, g, b) {
|
||||
Vibrant.rgbToHsl = function (r, g, b) {
|
||||
var d, h, l, max, min, s;
|
||||
r /= 255;
|
||||
g /= 255;
|
||||
|
@ -788,12 +787,12 @@ module.exports = MMCQ.quantize
|
|||
return [h, s, l];
|
||||
};
|
||||
|
||||
Vibrant.hslToRgb = function(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) {
|
||||
hue2rgb = function (p, q, t) {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
}
|
||||
|
@ -836,7 +835,7 @@ module.exports = MMCQ.quantize
|
|||
Stolen from https://github.com/lokesh/color-thief
|
||||
*/
|
||||
|
||||
window.CanvasImage = CanvasImage = (function() {
|
||||
window.CanvasImage = CanvasImage = (function () {
|
||||
function CanvasImage(image) {
|
||||
|
||||
this.canvas = document.createElement('canvas');
|
||||
|
@ -861,7 +860,7 @@ module.exports = MMCQ.quantize
|
|||
this.context.drawImage(image, 0, 0, originalWidth, originalHeight, 0, 0, this.width, this.height);
|
||||
}
|
||||
|
||||
CanvasImage.prototype.getPixelCount = function() {
|
||||
CanvasImage.prototype.getPixelCount = function () {
|
||||
return this.width * this.height;
|
||||
};
|
||||
|
||||
|
@ -869,7 +868,7 @@ module.exports = MMCQ.quantize
|
|||
return this.context.getImageData(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.removeCanvas = function() {
|
||||
CanvasImage.prototype.removeCanvas = function () {
|
||||
this.context = null;
|
||||
this.canvas = null;
|
||||
};
|
||||
|
@ -878,6 +877,4 @@ module.exports = MMCQ.quantize
|
|||
|
||||
})();
|
||||
|
||||
}).call(this);
|
||||
|
||||
},{"quantize":1}]},{},[2]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue