You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1001 lines
172 KiB
1001 lines
172 KiB
7 months ago
|
// ==========================================================
|
||
|
// MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
|
||
|
// License: Creative Commons Attribution-NonCommercial 4.0
|
||
|
// Authors: Sarka Sochorova and Ondrej Jamriska
|
||
|
// ==========================================================
|
||
|
//
|
||
|
// BASIC USAGE
|
||
|
//
|
||
|
// var rgb = mixbox.lerp(rgb1, rgb2, t);
|
||
|
//
|
||
|
// MULTI-COLOR MIXING
|
||
|
//
|
||
|
// var z1 = mixbox.rgbToLatent(rgb1);
|
||
|
// var z2 = mixbox.rgbToLatent(rgb2);
|
||
|
// var z3 = mixbox.rgbToLatent(rgb3);
|
||
|
//
|
||
|
// var zMix = new Array(mixbox.LATENT_SIZE);
|
||
|
//
|
||
|
// for (var i = 0; i < zMix.length; i++) { // mix:
|
||
|
// zMix[i] = (0.3*z1[i] + // 30% of rgb1
|
||
|
// 0.6*z2[i] + // 60% of rgb2
|
||
|
// 0.1*z3[i]); // 10% of rgb3
|
||
|
// }
|
||
|
//
|
||
|
// var rgbMix = mixbox.latentToRgb(zMix);
|
||
|
//
|
||
|
// PIGMENT COLORS
|
||
|
//
|
||
|
// Cadmium Yellow 254, 236, 0
|
||
|
// Hansa Yellow 252, 211, 0
|
||
|
// Cadmium Orange 255, 105, 0
|
||
|
// Cadmium Red 255, 39, 2
|
||
|
// Quinacridone Magenta 128, 2, 46
|
||
|
// Cobalt Violet 78, 0, 66
|
||
|
// Ultramarine Blue 25, 0, 89
|
||
|
// Cobalt Blue 0, 33, 133
|
||
|
// Phthalo Blue 13, 27, 68
|
||
|
// Phthalo Green 0, 60, 50
|
||
|
// Permanent Green 7, 109, 22
|
||
|
// Sap Green 107, 148, 4
|
||
|
// Burnt Sienna 123, 72, 0
|
||
|
//
|
||
|
// LICENSING
|
||
|
//
|
||
|
// If you want to obtain commercial license, please
|
||
|
// contact us at: [email protected]
|
||
|
//
|
||
|
|
||
|
(function (global, factory) {
|
||
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||
|
(global = global || self, factory(global.mixbox = {}));
|
||
|
}(this, (function (exports) { 'use strict';
|
||
|
|
||
|
function lerp(color1, color2, t) {
|
||
|
color1 = unpackColor(color1);
|
||
|
color2 = unpackColor(color2);
|
||
|
|
||
|
if (color1 !== undefined && color2 !== undefined) {
|
||
|
var latent1 = unpackedRgbToLatent(color1);
|
||
|
var latent2 = unpackedRgbToLatent(color2);
|
||
|
|
||
|
var colorMix = latentToRgb(lerpLatent(latent1, latent2, t));
|
||
|
|
||
|
if (color1.length === 3 && color2.length === 3) return colorMix;
|
||
|
|
||
|
var alpha1 = color1.length > 3 ? color1[3] : 255;
|
||
|
var alpha2 = color2.length > 3 ? color2[3] : 255;
|
||
|
colorMix[3] = (((1.0-t)*alpha1 + t*alpha2)+0.5) | 0;
|
||
|
|
||
|
return colorMix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function lerpFloat(color1, color2, t) {
|
||
|
color1 = unpackFloatColor(color1);
|
||
|
color2 = unpackFloatColor(color2);
|
||
|
|
||
|
if (color1 !== undefined && color2 !== undefined) {
|
||
|
var latent1 = unpackedFloatRgbToLatent(color1);
|
||
|
var latent2 = unpackedFloatRgbToLatent(color2);
|
||
|
|
||
|
var colorMix = latentToFloatRgb(lerpLatent(latent1, latent2, t));
|
||
|
|
||
|
if (color1.length === 3 && color2.length === 3) return colorMix;
|
||
|
|
||
|
var alpha1 = color1.length > 3 ? color1[3] : 1.0;
|
||
|
var alpha2 = color2.length > 3 ? color2[3] : 1.0;
|
||
|
colorMix[3] = (1.0-t)*alpha1 + t*alpha2;
|
||
|
|
||
|
return colorMix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function lerpLinearFloat(color1, color2, t) {
|
||
|
color1 = unpackLinearFloatColor(color1);
|
||
|
color2 = unpackLinearFloatColor(color2);
|
||
|
|
||
|
if (color1 !== undefined && color2 !== undefined) {
|
||
|
var latent1 = unpackedLinearFloatRgbToLatent(color1);
|
||
|
var latent2 = unpackedLinearFloatRgbToLatent(color2);
|
||
|
|
||
|
var colorMix = latentToLinearFloatRgb(lerpLatent(latent1, latent2, t));
|
||
|
|
||
|
if (color1.length === 3 && color2.length === 3) return colorMix;
|
||
|
|
||
|
var alpha1 = color1.length > 3 ? color1[3] : 1.0;
|
||
|
var alpha2 = color2.length > 3 ? color2[3] : 1.0;
|
||
|
colorMix[3] = (1.0-t)*alpha1 + t*alpha2;
|
||
|
|
||
|
return colorMix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function rgbArray(r, g, b) {
|
||
|
var rgb = [r, g, b];
|
||
|
rgb.toString = function() {
|
||
|
return this.length > 3 ? "rgba(" + this[0] + "," + this[1] + "," + this[2] + "," + (this[3]/255.0) + ")" :
|
||
|
"rgb(" + this[0] + "," + this[1] + "," + this[2] + ")";
|
||
|
}
|
||
|
return rgb;
|
||
|
}
|
||
|
|
||
|
function rgbToLatent(r, g, b) {
|
||
|
var rgb = unpackColor((g === undefined && b === undefined) ? (r) : [r, g, b]);
|
||
|
if (rgb !== undefined) return unpackedRgbToLatent(rgb);
|
||
|
}
|
||
|
|
||
|
function latentToRgb(latent) {
|
||
|
if (Array.isArray(latent) && latent.length === 7) {
|
||
|
var rgb = evalPolynomial(latent[0], latent[1], latent[2], latent[3]);
|
||
|
return rgbArray((clamp01(rgb[0] + latent[4])*255.0 + 0.5) | 0,
|
||
|
(clamp01(rgb[1] + latent[5])*255.0 + 0.5) | 0,
|
||
|
(clamp01(rgb[2] + latent[6])*255.0 + 0.5) | 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function floatRgbToLatent(r, g, b) {
|
||
|
var rgb = unpackFloatColor((g === undefined && b === undefined) ? r : [r, g, b]);
|
||
|
if (rgb !== undefined) return unpackedFloatRgbToLatent(rgb);
|
||
|
}
|
||
|
|
||
|
function latentToFloatRgb(latent) {
|
||
|
if (Array.isArray(latent) && latent.length === 7) {
|
||
|
var rgb = evalPolynomial(latent[0], latent[1], latent[2], latent[3]);
|
||
|
return [
|
||
|
clamp01(rgb[0] + latent[4]),
|
||
|
clamp01(rgb[1] + latent[5]),
|
||
|
clamp01(rgb[2] + latent[6])
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function linearFloatRgbToLatent(r, g, b) {
|
||
|
var rgb = unpackLinearFloatColor((g === undefined && b === undefined) ? r : [r, g, b]);
|
||
|
if (rgb !== undefined) return unpackedLinearFloatRgbToLatent(rgb);
|
||
|
}
|
||
|
|
||
|
function latentToLinearFloatRgb(latent) {
|
||
|
var rgb = latentToFloatRgb(latent);
|
||
|
if (rgb !== undefined) return [
|
||
|
srgbToLinear(rgb[0]),
|
||
|
srgbToLinear(rgb[1]),
|
||
|
srgbToLinear(rgb[2])
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function clamp(x, xmin, xmax) {
|
||
|
return Math.min(Math.max(x, xmin), xmax);
|
||
|
}
|
||
|
|
||
|
function clamp01(x) {
|
||
|
return Math.min(Math.max(x, 0.0), 1.0);
|
||
|
}
|
||
|
|
||
|
function srgbToLinear(x) {
|
||
|
return (x >= 0.04045) ? Math.pow((x + 0.055) / 1.055, 2.4) : x/12.92;
|
||
|
}
|
||
|
|
||
|
function linearToSrgb(x) {
|
||
|
return (x >= 0.0031308) ? 1.055*Math.pow(x, 1.0/2.4) - 0.055 : 12.92*x;
|
||
|
}
|
||
|
|
||
|
function lerpLatent(latent1, latent2, t) {
|
||
|
var latentMix = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
|
||
|
|
||
|
for (var i = 0; i < 7; i++) {
|
||
|
latentMix[i] = (1.0-t)*latent1[i] + t*latent2[i];
|
||
|
}
|
||
|
|
||
|
return latentMix;
|
||
|
}
|
||
|
|
||
|
function unpackColor(color) {
|
||
|
if (Array.isArray(color) && color.length >= 3) {
|
||
|
return color;
|
||
|
}
|
||
|
if (typeof color === 'string') {
|
||
|
return parseColorString(color);
|
||
|
}
|
||
|
if (typeof color === 'object') {
|
||
|
if (typeof color.getHexString === 'function') {
|
||
|
return parseColorString(color.getHexString());
|
||
|
}
|
||
|
if (!isNaN(color.r) && !isNaN(color.g) && !isNaN(color.b)) {
|
||
|
if (isNaN(color.a)) { return [color.r, color.g, color.b]; }
|
||
|
return [color.r, color.g, color.b, color.a];
|
||
|
}
|
||
|
return parseColorString(color.toString());
|
||
|
}
|
||
|
if (typeof color === 'number' && isFinite(color) && Math.floor(color) === color && color >= 0) {
|
||
|
return [ (color >>> 16) & 255, (color >>> 8) & 255, color & 255 ];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function unpackFloatColor(color) {
|
||
|
if (Array.isArray(color) && color.length >= 3) {
|
||
|
return color;
|
||
|
}
|
||
|
if (typeof color === 'object' && !isNaN(color.r) && !isNaN(color.g) && !isNaN(color.b)) {
|
||
|
if (isNaN(color.a)) { return [color.r, color.g, color.b]; }
|
||
|
return [color.r, color.g, color.b, color.a];
|
||
|
}
|
||
|
if (color = unpackColor(color)) {
|
||
|
for (var i = 0; i < color.length; i++) { color[i] /= 255.0; }
|
||
|
return color;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function unpackLinearFloatColor(color) {
|
||
|
if (Array.isArray(color) && color.length >= 3) {
|
||
|
return color;
|
||
|
}
|
||
|
if (typeof color === 'object' && !isNaN(color.r) && !isNaN(color.g) && !isNaN(color.b)) {
|
||
|
if (isNaN(color.a)) { return [color.r, color.g, color.b]; }
|
||
|
return [color.r, color.g, color.b, color.a];
|
||
|
}
|
||
|
if (color = unpackColor(color)) {
|
||
|
for (var i = 0; i < 3; i++) { color[i] = srgbToLinear(color[i] / 255.0); }
|
||
|
if (color.length > 3) { color[3] /= 255.0; }
|
||
|
return color;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function unpackedRgbToLatent(rgb) {
|
||
|
return unpackedFloatRgbToLatent([
|
||
|
rgb[0] / 255.0,
|
||
|
rgb[1] / 255.0,
|
||
|
rgb[2] / 255.0
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
function unpackedFloatRgbToLatent(rgb) {
|
||
|
var r = clamp01(rgb[0]);
|
||
|
var g = clamp01(rgb[1]);
|
||
|
var b = clamp01(rgb[2]);
|
||
|
|
||
|
var x = r * 63.0;
|
||
|
var y = g * 63.0;
|
||
|
var z = b * 63.0;
|
||
|
|
||
|
var ix = x | 0;
|
||
|
var iy = y | 0;
|
||
|
var iz = z | 0;
|
||
|
|
||
|
var tx = x - ix;
|
||
|
var ty = y - iy;
|
||
|
var tz = z - iz;
|
||
|
|
||
|
var xyz = ix + iy*64 + iz*64*64;
|
||
|
|
||
|
var c0 = 0.0;
|
||
|
var c1 = 0.0;
|
||
|
var c2 = 0.0;
|
||
|
|
||
|
var w = 0.0;
|
||
|
w = (1.0-tx)*(1.0-ty)*(1.0-tz); c0 += w*lut[xyz+ 192]; c1 += w*lut[xyz+262336]; c2 += w*lut[xyz+524480];
|
||
|
w = ( tx)*(1.0-ty)*(1.0-tz); c0 += w*lut[xyz+ 193]; c1 += w*lut[xyz+262337]; c2 += w*lut[xyz+524481];
|
||
|
w = (1.0-tx)*( ty)*(1.0-tz); c0 += w*lut[xyz+ 256]; c1 += w*lut[xyz+262400]; c2 += w*lut[xyz+524544];
|
||
|
w = ( tx)*( ty)*(1.0-tz); c0 += w*lut[xyz+ 257]; c1 += w*lut[xyz+262401]; c2 += w*lut[xyz+524545];
|
||
|
w = (1.0-tx)*(1.0-ty)*( tz); c0 += w*lut[xyz+4288]; c1 += w*lut[xyz+266432]; c2 += w*lut[xyz+528576];
|
||
|
w = ( tx)*(1.0-ty)*( tz); c0 += w*lut[xyz+4289]; c1 += w*lut[xyz+266433]; c2 += w*lut[xyz+528577];
|
||
|
w = (1.0-tx)*( ty)*( tz); c0 += w*lut[xyz+4352]; c1 += w*lut[xyz+266496]; c2 += w*lut[xyz+528640];
|
||
|
w = ( tx)*( ty)*( tz); c0 += w*lut[xyz+4353]; c1 += w*lut[xyz+266497]; c2 += w*lut[xyz+528641];
|
||
|
|
||
|
c0 /= 255.0;
|
||
|
c1 /= 255.0;
|
||
|
c2 /= 255.0;
|
||
|
|
||
|
var c3 = 1.0 - (c0 + c1 + c2);
|
||
|
|
||
|
var c00 = c0 * c0;
|
||
|
var c11 = c1 * c1;
|
||
|
var c22 = c2 * c2;
|
||
|
var c33 = c3 * c3;
|
||
|
var c01 = c0 * c1;
|
||
|
var c02 = c0 * c2;
|
||
|
var c12 = c1 * c2;
|
||
|
|
||
|
var rmix = 0.0;
|
||
|
var gmix = 0.0;
|
||
|
var bmix = 0.0;
|
||
|
|
||
|
var w = 0.0;
|
||
|
w = c0*c00; rmix += +0.07717053*w; gmix += +0.02826978*w; bmix += +0.24832992*w;
|
||
|
w = c1*c11; rmix += +0.95912302*w; gmix += +0.80256528*w; bmix += +0.03561839*w;
|
||
|
w = c2*c22; rmix += +0.74683774*w; gmix += +0.04868586*w; bmix += +0.00000000*w;
|
||
|
w = c3*c33; rmix += +0.99518138*w; gmix += +0.99978149*w; bmix += +0.99704802*w;
|
||
|
w = c00*c1; rmix += +0.04819146*w; gmix += +0.83363781*w; bmix += +0.32515377*w;
|
||
|
w = c01*c1; rmix += -0.68146950*w; gmix += +1.46107803*w; bmix += +1.06980936*w;
|
||
|
w = c00*c2; rmix += +0.27058419*w; gmix += -0.15324870*w; bmix += +1.98735057*w;
|
||
|
w = c02*c2; rmix += +0.80478189*w; gmix += +0.67093710*w; bmix += +0.18424500*w;
|
||
|
w = c00*c3; rmix += -0.35031003*w; gmix += +1.37855826*w; bmix += +3.68865000*w;
|
||
|
w = c0*c33; rmix += +1.05128046*w; gmix += +1.97815239*w; bmix += +2.82989073*w;
|
||
|
w = c11*c2; rmix += +3.21607125*w; gmix += +0.81270228*w; bmix += +1.03384539*w;
|
||
|
w = c1*c22; rmix += +2.78893374*w; gmix += +0.41565549*w; bmix += -0.04487295*w;
|
||
|
w = c11*c3; rmix += +3.02162577*w; gmix += +2.55374103*w; bmix += +0.32766114*w;
|
||
|
w = c1*c33; rmix += +2.95124691*w; gmix += +2.81201112*w; bmix += +1.17578442*w;
|
||
|
w = c22*c3; rmix += +2.82677043*w; gmix += +0.79933038*w; bmix += +1.81715262*w;
|
||
|
w = c2*c33; rmix += +2.99691099*w; gmix += +1.22593053*w; bmix += +1.80653661*w;
|
||
|
w = c01*c2; rmix += +1.87394106*w; gmix += +2.05027182*w; bmix += -0.29835996*w;
|
||
|
w = c01*c3; rmix += +2.56609566*w; gmix += +7.03428198*w; bmix += +0.62575374*w;
|
||
|
w = c02*c3; rmix += +4.08329484*w; gmix += -1.40408358*w; bmix += +2.14995522*w;
|
||
|
w = c12*c3; rmix += +6.00078678*w; gmix += +2.55552042*w; bmix += +1.90739502*w;
|
||
|
|
||
|
return [
|
||
|
c0,
|
||
|
c1,
|
||
|
c2,
|
||
|
c3,
|
||
|
r - rmix,
|
||
|
g - gmix,
|
||
|
b - bmix,
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function unpackedLinearFloatRgbToLatent(rgb) {
|
||
|
return unpackedFloatRgbToLatent([
|
||
|
linearToSrgb(rgb[0]),
|
||
|
linearToSrgb(rgb[1]),
|
||
|
linearToSrgb(rgb[2])
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
function evalPolynomial(c0, c1, c2, c3) {
|
||
|
var r = 0.0;
|
||
|
var g = 0.0;
|
||
|
var b = 0.0;
|
||
|
|
||
|
var c00 = c0 * c0;
|
||
|
var c11 = c1 * c1;
|
||
|
var c22 = c2 * c2;
|
||
|
var c33 = c3 * c3;
|
||
|
var c01 = c0 * c1;
|
||
|
var c02 = c0 * c2;
|
||
|
var c12 = c1 * c2;
|
||
|
|
||
|
var w = 0.0;
|
||
|
w = c0*c00; r += +0.07717053*w; g += +0.02826978*w; b += +0.24832992*w;
|
||
|
w = c1*c11; r += +0.95912302*w; g += +0.80256528*w; b += +0.03561839*w;
|
||
|
w = c2*c22; r += +0.74683774*w; g += +0.04868586*w; b += +0.00000000*w;
|
||
|
w = c3*c33; r += +0.99518138*w; g += +0.99978149*w; b += +0.99704802*w;
|
||
|
w = c00*c1; r += +0.04819146*w; g += +0.83363781*w; b += +0.32515377*w;
|
||
|
w = c01*c1; r += -0.68146950*w; g += +1.46107803*w; b += +1.06980936*w;
|
||
|
w = c00*c2; r += +0.27058419*w; g += -0.15324870*w; b += +1.98735057*w;
|
||
|
w = c02*c2; r += +0.80478189*w; g += +0.67093710*w; b += +0.18424500*w;
|
||
|
w = c00*c3; r += -0.35031003*w; g += +1.37855826*w; b += +3.68865000*w;
|
||
|
w = c0*c33; r += +1.05128046*w; g += +1.97815239*w; b += +2.82989073*w;
|
||
|
w = c11*c2; r += +3.21607125*w; g += +0.81270228*w; b += +1.03384539*w;
|
||
|
w = c1*c22; r += +2.78893374*w; g += +0.41565549*w; b += -0.04487295*w;
|
||
|
w = c11*c3; r += +3.02162577*w; g += +2.55374103*w; b += +0.32766114*w;
|
||
|
w = c1*c33; r += +2.95124691*w; g += +2.81201112*w; b += +1.17578442*w;
|
||
|
w = c22*c3; r += +2.82677043*w; g += +0.79933038*w; b += +1.81715262*w;
|
||
|
w = c2*c33; r += +2.99691099*w; g += +1.22593053*w; b += +1.80653661*w;
|
||
|
w = c01*c2; r += +1.87394106*w; g += +2.05027182*w; b += -0.29835996*w;
|
||
|
w = c01*c3; r += +2.56609566*w; g += +7.03428198*w; b += +0.62575374*w;
|
||
|
w = c02*c3; r += +4.08329484*w; g += -1.40408358*w; b += +2.14995522*w;
|
||
|
w = c12*c3; r += +6.00078678*w; g += +2.55552042*w; b += +1.90739502*w;
|
||
|
|
||
|
return [r, g, b];
|
||
|
}
|
||
|
|
||
|
function hexToUint8(str) {
|
||
|
if (str.length === 1) { str = str + str; }
|
||
|
return parseInt("0x" + str, 16);
|
||
|
}
|
||
|
|
||
|
function strToUint8(str) {
|
||
|
var value = (str.charAt(str.length - 1) === '%') ? ((Number(str.slice(0, -1)) / 100.0) * 255.0) : Number(str);
|
||
|
return clamp(Math.round(value), 0, 255);
|
||
|
}
|
||
|
|
||
|
var numRegex = /[+\-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:\d[eE][+\-]?\d+)?%?/;
|
||
|
var rgbRegex = new RegExp('^rgb\\(('+numRegex.source+'),('+numRegex.source+'),('+numRegex.source+')\\)$','i');
|
||
|
var rgbaRegex = new RegExp('^rgba\\(('+numRegex.source+'),('+numRegex.source+'),('+numRegex.source+'),('+numRegex.source+')\\)$','i');
|
||
|
var hex3Regex = /^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i;
|
||
|
var hex4Regex = /^#?([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])$/i;
|
||
|
var hex6Regex = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
||
|
var hex8Regex = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
||
|
|
||
|
function parseColorString(string) {
|
||
|
string = string.replace(/\s/g, '');
|
||
|
|
||
|
var matches;
|
||
|
if (matches = rgbRegex.exec(string)) { return [ strToUint8(matches[1]), strToUint8(matches[2]), strToUint8(matches[3]) ]; }
|
||
|
if (matches = rgbaRegex.exec(string)) { return [ strToUint8(matches[1]), strToUint8(matches[2]), strToUint8(matches[3]), clamp(Number(matches[4]) * 255.0, 0, 255) ]; }
|
||
|
if (matches = hex6Regex.exec(string)) { return [ hexToUint8(matches[1]), hexToUint8(matches[2]), hexToUint8(matches[3]) ]; }
|
||
|
if (matches = hex3Regex.exec(string)) { return [ hexToUint8(matches[1]), hexToUint8(matches[2]), hexToUint8(matches[3]) ]; }
|
||
|
if (matches = hex8Regex.exec(string)) { return [ hexToUint8(matches[1]), hexToUint8(matches[2]), hexToUint8(matches[3]), hexToUint8(matches[4]) ]; }
|
||
|
if (matches = hex4Regex.exec(string)) { return [ hexToUint8(matches[1]), hexToUint8(matches[2]), hexToUint8(matches[3]), hexToUint8(matches[4]) ]; }
|
||
|
|
||
|
var namedColors = {
|
||
|
aliceblue : [ 240, 248, 255 ],
|
||
|
antiquewhite : [ 250, 235, 215 ],
|
||
|
aqua : [ 0, 255, 255 ],
|
||
|
aquamarine : [ 127, 255, 212 ],
|
||
|
azure : [ 240, 255, 255 ],
|
||
|
beige : [ 245, 245, 220 ],
|
||
|
bisque : [ 255, 228, 196 ],
|
||
|
black : [ 0, 0, 0 ],
|
||
|
blanchedalmond : [ 255, 235, 205 ],
|
||
|
blue : [ 0, 0, 255 ],
|
||
|
blueviolet : [ 138, 43, 226 ],
|
||
|
brown : [ 165, 42, 42 ],
|
||
|
burlywood : [ 222, 184, 135 ],
|
||
|
cadetblue : [ 95, 158, 160 ],
|
||
|
chartreuse : [ 127, 255, 0 ],
|
||
|
chocolate : [ 210, 105, 30 ],
|
||
|
coral : [ 255, 127, 80 ],
|
||
|
cornflowerblue : [ 100, 149, 237 ],
|
||
|
cornsilk : [ 255, 248, 220 ],
|
||
|
crimson : [ 220, 20, 60 ],
|
||
|
cyan : [ 0, 255, 255 ],
|
||
|
darkblue : [ 0, 0, 139 ],
|
||
|
darkcyan : [ 0, 139, 139 ],
|
||
|
darkgoldenrod : [ 184, 134, 11 ],
|
||
|
darkgray : [ 169, 169, 169 ],
|
||
|
darkgreen : [ 0, 100, 0 ],
|
||
|
darkgrey : [ 169, 169, 169 ],
|
||
|
darkkhaki : [ 189, 183, 107 ],
|
||
|
darkmagenta : [ 139, 0, 139 ],
|
||
|
darkolivegreen : [ 85, 107, 47 ],
|
||
|
darkorange : [ 255, 140, 0 ],
|
||
|
darkorchid : [ 153, 50, 204 ],
|
||
|
darkred : [ 139, 0, 0 ],
|
||
|
darksalmon : [ 233, 150, 122 ],
|
||
|
darkseagreen : [ 143, 188, 143 ],
|
||
|
darkslateblue : [ 72, 61, 139 ],
|
||
|
darkslategray : [ 47, 79, 79 ],
|
||
|
darkslategrey : [ 47, 79, 79 ],
|
||
|
darkturquoise : [ 0, 206, 209 ],
|
||
|
darkviolet : [ 148, 0, 211 ],
|
||
|
deeppink : [ 255, 20, 147 ],
|
||
|
deepskyblue : [ 0, 191, 255 ],
|
||
|
dimgray : [ 105, 105, 105 ],
|
||
|
dimgrey : [ 105, 105, 105 ],
|
||
|
dodgerblue : [ 30, 144, 255 ],
|
||
|
firebrick : [ 178, 34, 34 ],
|
||
|
floralwhite : [ 255, 250, 240 ],
|
||
|
forestgreen : [ 34, 139, 34 ],
|
||
|
fuchsia : [ 255, 0, 255 ],
|
||
|
gainsboro : [ 220, 220, 220 ],
|
||
|
ghostwhite : [ 248, 248, 255 ],
|
||
|
gold : [ 255, 215, 0 ],
|
||
|
goldenrod : [ 218, 165, 32 ],
|
||
|
gray : [ 128, 128, 128 ],
|
||
|
green : [ 0, 128, 0 ],
|
||
|
greenyellow : [ 173, 255, 47 ],
|
||
|
grey : [ 128, 128, 128 ],
|
||
|
honeydew : [ 240, 255, 240 ],
|
||
|
hotpink : [ 255, 105, 180 ],
|
||
|
indianred : [ 205, 92, 92 ],
|
||
|
indigo : [ 75, 0, 130 ],
|
||
|
ivory : [ 255, 255, 240 ],
|
||
|
khaki : [ 240, 230, 140 ],
|
||
|
lavender : [ 230, 230, 250 ],
|
||
|
lavenderblush : [ 255, 240, 245 ],
|
||
|
lawngreen : [ 124, 252, 0 ],
|
||
|
lemonchiffon : [ 255, 250, 205 ],
|
||
|
lightblue : [ 173, 216, 230 ],
|
||
|
lightcoral : [ 240, 128, 128 ],
|
||
|
lightcyan : [ 224, 255, 255 ],
|
||
|
lightgoldenrodyellow : [ 250, 250, 210 ],
|
||
|
lightgray : [ 211, 211, 211 ],
|
||
|
lightgreen : [ 144, 238, 144 ],
|
||
|
lightgrey : [ 211, 211, 211 ],
|
||
|
lightpink : [ 255, 182, 193 ],
|
||
|
lightsalmon : [ 255, 160, 122 ],
|
||
|
lightseagreen : [ 32, 178, 170 ],
|
||
|
lightskyblue : [ 135, 206, 250 ],
|
||
|
lightslategray : [ 119, 136, 153 ],
|
||
|
lightslategrey : [ 119, 136, 153 ],
|
||
|
lightsteelblue : [ 176, 196, 222 ],
|
||
|
lightyellow : [ 255, 255, 224 ],
|
||
|
lime : [ 0, 255, 0 ],
|
||
|
limegreen : [ 50, 205, 50 ],
|
||
|
linen : [ 250, 240, 230 ],
|
||
|
magenta : [ 255, 0, 255 ],
|
||
|
maroon : [ 128, 0, 0 ],
|
||
|
mediumaquamarine : [ 102, 205, 170 ],
|
||
|
mediumblue : [ 0, 0, 205 ],
|
||
|
mediumorchid : [ 186, 85, 211 ],
|
||
|
mediumpurple : [ 147, 112, 219 ],
|
||
|
mediumseagreen : [ 60, 179, 113 ],
|
||
|
mediumslateblue : [ 123, 104, 238 ],
|
||
|
mediumspringgreen : [ 0, 250, 154 ],
|
||
|
mediumturquoise : [ 72, 209, 204 ],
|
||
|
mediumvioletred : [ 199, 21, 133 ],
|
||
|
midnightblue : [ 25, 25, 112 ],
|
||
|
mintcream : [ 245, 255, 250 ],
|
||
|
mistyrose : [ 255, 228, 225 ],
|
||
|
moccasin : [ 255, 228, 181 ],
|
||
|
navajowhite : [ 255, 222, 173 ],
|
||
|
navy : [ 0, 0, 128 ],
|
||
|
oldlace : [ 253, 245, 230 ],
|
||
|
olive : [ 128, 128, 0 ],
|
||
|
olivedrab : [ 107, 142, 35 ],
|
||
|
orange : [ 255, 165, 0 ],
|
||
|
orangered : [ 255, 69, 0 ],
|
||
|
orchid : [ 218, 112, 214 ],
|
||
|
palegoldenrod : [ 238, 232, 170 ],
|
||
|
palegreen : [ 152, 251, 152 ],
|
||
|
paleturquoise : [ 175, 238, 238 ],
|
||
|
palevioletred : [ 219, 112, 147 ],
|
||
|
papayawhip : [ 255, 239, 213 ],
|
||
|
peachpuff : [ 255, 218, 185 ],
|
||
|
peru : [ 205, 133, 63 ],
|
||
|
pink : [ 255, 192, 203 ],
|
||
|
plum : [ 221, 160, 221 ],
|
||
|
powderblue : [ 176, 224, 230 ],
|
||
|
purple : [ 128, 0, 128 ],
|
||
|
red : [ 255, 0, 0 ],
|
||
|
rosybrown : [ 188, 143, 143 ],
|
||
|
royalblue : [ 65, 105, 225 ],
|
||
|
saddlebrown : [ 139, 69, 19 ],
|
||
|
salmon : [ 250, 128, 114 ],
|
||
|
sandybrown : [ 244, 164, 96 ],
|
||
|
seagreen : [ 46, 139, 87 ],
|
||
|
seashell : [ 255, 245, 238 ],
|
||
|
sienna : [ 160, 82, 45 ],
|
||
|
silver : [ 192, 192, 192 ],
|
||
|
skyblue : [ 135, 206, 235 ],
|
||
|
slateblue : [ 106, 90, 205 ],
|
||
|
slategray : [ 112, 128, 144 ],
|
||
|
slategrey : [ 112, 128, 144 ],
|
||
|
snow : [ 255, 250, 250 ],
|
||
|
springgreen : [ 0, 255, 127 ],
|
||
|
steelblue : [ 70, 130, 180 ],
|
||
|
tan : [ 210, 180, 140 ],
|
||
|
teal : [ 0, 128, 128 ],
|
||
|
thistle : [ 216, 191, 216 ],
|
||
|
tomato : [ 255, 99, 71 ],
|
||
|
turquoise : [ 64, 224, 208 ],
|
||
|
violet : [ 238, 130, 238 ],
|
||
|
wheat : [ 245, 222, 179 ],
|
||
|
white : [ 255, 255, 255 ],
|
||
|
whitesmoke : [ 245, 245, 245 ],
|
||
|
yellow : [ 255, 255, 0 ],
|
||
|
yellowgreen : [ 154, 205, 50 ],
|
||
|
};
|
||
|
|
||
|
var name = string.toLowerCase();
|
||
|
if (namedColors.hasOwnProperty(name)) return namedColors[name];
|
||
|
}
|
||
|
|
||
|
function glsl() {
|
||
|
return "#ifndef MIXBOX_INCLUDED\n" +
|
||
|
"#define MIXBOX_INCLUDED\n" +
|
||
|
"\n" +
|
||
|
"#ifndef MIXBOX_LUT\n" +
|
||
|
" #if __VERSION__ <= 120\n" +
|
||
|
" #define MIXBOX_LUT(UV) texture2D(mixbox_lut, UV)\n" +
|
||
|
" #else\n" +
|
||
|
" #define MIXBOX_LUT(UV) textureLod(mixbox_lut, UV, 0.0)\n" +
|
||
|
" #endif\n" +
|
||
|
"#endif\n" +
|
||
|
"\n" +
|
||
|
"#define mixbox_latent mat3\n" +
|
||
|
"\n" +
|
||
|
"vec3 mixbox_eval_polynomial(vec3 c)\n" +
|
||
|
"{\n" +
|
||
|
" float c0 = c[0];\n" +
|
||
|
" float c1 = c[1];\n" +
|
||
|
" float c2 = c[2];\n" +
|
||
|
" float c3 = 1.0 - (c0 + c1 + c2);\n" +
|
||
|
"\n" +
|
||
|
" float c00 = c0 * c0;\n" +
|
||
|
" float c11 = c1 * c1;\n" +
|
||
|
" float c22 = c2 * c2;\n" +
|
||
|
" float c01 = c0 * c1;\n" +
|
||
|
" float c02 = c0 * c2;\n" +
|
||
|
" float c12 = c1 * c2;\n" +
|
||
|
" float c33 = c3 * c3;\n" +
|
||
|
"\n" +
|
||
|
" return (c0*c00) * vec3(+0.07717053, +0.02826978, +0.24832992) +\n" +
|
||
|
" (c1*c11) * vec3(+0.95912302, +0.80256528, +0.03561839) +\n" +
|
||
|
" (c2*c22) * vec3(+0.74683774, +0.04868586, +0.00000000) +\n" +
|
||
|
" (c3*c33) * vec3(+0.99518138, +0.99978149, +0.99704802) +\n" +
|
||
|
" (c00*c1) * vec3(+0.04819146, +0.83363781, +0.32515377) +\n" +
|
||
|
" (c01*c1) * vec3(-0.68146950, +1.46107803, +1.06980936) +\n" +
|
||
|
" (c00*c2) * vec3(+0.27058419, -0.15324870, +1.98735057) +\n" +
|
||
|
" (c02*c2) * vec3(+0.80478189, +0.67093710, +0.18424500) +\n" +
|
||
|
" (c00*c3) * vec3(-0.35031003, +1.37855826, +3.68865000) +\n" +
|
||
|
" (c0*c33) * vec3(+1.05128046, +1.97815239, +2.82989073) +\n" +
|
||
|
" (c11*c2) * vec3(+3.21607125, +0.81270228, +1.03384539) +\n" +
|
||
|
" (c1*c22) * vec3(+2.78893374, +0.41565549, -0.04487295) +\n" +
|
||
|
" (c11*c3) * vec3(+3.02162577, +2.55374103, +0.32766114) +\n" +
|
||
|
" (c1*c33) * vec3(+2.95124691, +2.81201112, +1.17578442) +\n" +
|
||
|
" (c22*c3) * vec3(+2.82677043, +0.79933038, +1.81715262) +\n" +
|
||
|
" (c2*c33) * vec3(+2.99691099, +1.22593053, +1.80653661) +\n" +
|
||
|
" (c01*c2) * vec3(+1.87394106, +2.05027182, -0.29835996) +\n" +
|
||
|
" (c01*c3) * vec3(+2.56609566, +7.03428198, +0.62575374) +\n" +
|
||
|
" (c02*c3) * vec3(+4.08329484, -1.40408358, +2.14995522) +\n" +
|
||
|
" (c12*c3) * vec3(+6.00078678, +2.55552042, +1.90739502);\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"float mixbox_srgb_to_linear(float x)\n" +
|
||
|
"{\n" +
|
||
|
" return (x >= 0.04045) ? pow((x + 0.055) / 1.055, 2.4) : x/12.92;\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"float mixbox_linear_to_srgb(float x)\n" +
|
||
|
"{\n" +
|
||
|
" return (x >= 0.0031308) ? 1.055*pow(x, 1.0/2.4) - 0.055 : 12.92*x;\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"vec3 mixbox_srgb_to_linear(vec3 rgb)\n" +
|
||
|
"{\n" +
|
||
|
" return vec3(mixbox_srgb_to_linear(rgb.r),\n" +
|
||
|
" mixbox_srgb_to_linear(rgb.g),\n" +
|
||
|
" mixbox_srgb_to_linear(rgb.b));\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"vec3 mixbox_linear_to_srgb(vec3 rgb)\n" +
|
||
|
"{\n" +
|
||
|
" return vec3(mixbox_linear_to_srgb(rgb.r),\n" +
|
||
|
" mixbox_linear_to_srgb(rgb.g),\n" +
|
||
|
" mixbox_linear_to_srgb(rgb.b));\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"mixbox_latent mixbox_rgb_to_latent(vec3 rgb)\n" +
|
||
|
"{\n" +
|
||
|
"#ifdef MIXBOX_COLORSPACE_LINEAR\n" +
|
||
|
" rgb = mixbox_linear_to_srgb(clamp(rgb, 0.0, 1.0));\n" +
|
||
|
"#else\n" +
|
||
|
" rgb = clamp(rgb, 0.0, 1.0);\n" +
|
||
|
"#endif\n" +
|
||
|
"\n" +
|
||
|
" float x = rgb.r * 63.0;\n" +
|
||
|
" float y = rgb.g * 63.0;\n" +
|
||
|
" float z = rgb.b * 63.0;\n" +
|
||
|
"\n" +
|
||
|
" float iz = floor(z);\n" +
|
||
|
"\n" +
|
||
|
" float x0 = mod(iz, 8.0) * 64.0;\n" +
|
||
|
" float y0 = floor(iz / 8.0) * 64.0;\n" +
|
||
|
"\n" +
|
||
|
" float x1 = mod(iz + 1.0, 8.0) * 64.0;\n" +
|
||
|
" float y1 = floor((iz + 1.0) / 8.0) * 64.0;\n" +
|
||
|
"\n" +
|
||
|
" vec2 uv0 = vec2(x0 + x + 0.5, y0 + y + 0.5) / 512.0;\n" +
|
||
|
" vec2 uv1 = vec2(x1 + x + 0.5, y1 + y + 0.5) / 512.0;\n" +
|
||
|
"\n" +
|
||
|
" if (MIXBOX_LUT(vec2(0.5, 0.5) / 512.0).b < 0.1)\n" +
|
||
|
" {\n" +
|
||
|
" uv0.y = 1.0 - uv0.y;\n" +
|
||
|
" uv1.y = 1.0 - uv1.y;\n" +
|
||
|
" }\n" +
|
||
|
"\n" +
|
||
|
" vec3 c = mix(MIXBOX_LUT(uv0).rgb, MIXBOX_LUT(uv1).rgb, z - iz);\n" +
|
||
|
"\n" +
|
||
|
" return mixbox_latent(c, rgb - mixbox_eval_polynomial(c), vec3(0.0));\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"vec3 mixbox_latent_to_rgb(mixbox_latent latent)\n" +
|
||
|
"{\n" +
|
||
|
" vec3 rgb = clamp(mixbox_eval_polynomial(latent[0]) + latent[1], 0.0, 1.0);\n" +
|
||
|
"\n" +
|
||
|
"#ifdef MIXBOX_COLORSPACE_LINEAR\n" +
|
||
|
" return mixbox_srgb_to_linear(rgb);\n" +
|
||
|
"#else\n" +
|
||
|
" return rgb;\n" +
|
||
|
"#endif\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"vec3 mixbox_lerp(vec3 color1, vec3 color2, float t)\n" +
|
||
|
"{\n" +
|
||
|
" return mixbox_latent_to_rgb((1.0-t)*mixbox_rgb_to_latent(color1) + t*mixbox_rgb_to_latent(color2));\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"vec4 mixbox_lerp(vec4 color1, vec4 color2, float t)\n" +
|
||
|
"{\n" +
|
||
|
" return vec4(mixbox_lerp(color1.rgb, color2.rgb, t), mix(color1.a, color2.a, t));\n" +
|
||
|
"}\n" +
|
||
|
"\n" +
|
||
|
"#endif\n";
|
||
|
}
|
||
|
|
||
|
var texture;
|
||
|
|
||
|
function lutTexture(gl) {
|
||
|
if (!texture) {
|
||
|
var pixels = new Uint8Array(512 * 512 * 4);
|
||
|
|
||
|
for(var b = 0; b < 64; b++)
|
||
|
for(var g = 0; g < 64; g++)
|
||
|
for(var r = 0; r < 64; r++)
|
||
|
{
|
||
|
var x = (b % 8)*64 + r;
|
||
|
var y = ((b / 8) | 0)*64 + g;
|
||
|
var xyz = r + g*64 + b*64*64;
|
||
|
pixels[(x + y*512)*4 + 0] = lut[xyz+ 192];
|
||
|
pixels[(x + y*512)*4 + 1] = lut[xyz+262336];
|
||
|
pixels[(x + y*512)*4 + 2] = lut[xyz+524480];
|
||
|
pixels[(x + y*512)*4 + 3] = 255;
|
||
|
}
|
||
|
|
||
|
var textureState = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
||
|
|
||
|
texture = gl.createTexture();
|
||
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 512, 512, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||
|
|
||
|
gl.bindTexture(gl.TEXTURE_2D, textureState);
|
||
|
}
|
||
|
|
||
|
return texture;
|
||
|
}
|
||
|
|
||
|
function decompress(input) {
|
||
|
var output = new Uint8Array(64*64*64*3 + 4353);
|
||
|
|
||
|
var inPos = 0;
|
||
|
var outPos = 0;
|
||
|
var numBits = 0;
|
||
|
var codeBuffer = 0;
|
||
|
|
||
|
var fastBits = 9;
|
||
|
var fastMask = ((1 << fastBits) - 1);
|
||
|
|
||
|
var distExtra = [
|
||
|
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
||
|
10, 10, 11, 11, 12, 12, 13, 13
|
||
|
];
|
||
|
|
||
|
var lenghtBase = [
|
||
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
|
||
|
15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
|
||
|
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||
|
];
|
||
|
|
||
|
var lengthExtra = [
|
||
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4,
|
||
|
4, 4, 4, 5, 5, 5, 5, 0, 0, 0
|
||
|
];
|
||
|
|
||
|
var distBase = [
|
||
|
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||
|
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193,
|
||
|
12289, 16385, 24577, 0, 0
|
||
|
];
|
||
|
|
||
|
var lengthDezigzag = [
|
||
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2,
|
||
|
14,
|
||
|
1, 15
|
||
|
];
|
||
|
|
||
|
function Huffman(sizeListArray, sizeListOffset, sizeListCount) {
|
||
|
this.fast = new Uint16Array(1 << fastBits);
|
||
|
this.firstCode = new Uint16Array(16);
|
||
|
this.firstSymbol = new Uint16Array(16);
|
||
|
this.maxCode = new Int32Array(17);
|
||
|
this.size = new Uint8Array(288);
|
||
|
this.value = new Uint16Array(288);
|
||
|
|
||
|
var i = 0;
|
||
|
var k = 0;
|
||
|
var nextCode = new Int32Array(16);
|
||
|
var sizes = new Int32Array(17);
|
||
|
|
||
|
for (i = 0; i < this.fast.length; i++) this.fast[i] = 0xffff;
|
||
|
for (i = 0; i < sizeListCount; i++) { ++sizes[sizeListArray[i + sizeListOffset]]; }
|
||
|
|
||
|
sizes[0] = 0;
|
||
|
var code = 0;
|
||
|
for (i = 1; i < 16; i++) {
|
||
|
nextCode[i] = code;
|
||
|
this.firstCode[i] = code;
|
||
|
this.firstSymbol[i] = k;
|
||
|
code = (code + sizes[i]);
|
||
|
this.maxCode[i] = code << (16 - i);
|
||
|
code <<= 1;
|
||
|
k += sizes[i];
|
||
|
}
|
||
|
this.maxCode[16] = 0x10000;
|
||
|
|
||
|
for (i = 0; i < sizeListCount; i++) {
|
||
|
var s = sizeListArray[i + sizeListOffset];
|
||
|
if (s !== 0) {
|
||
|
var c = nextCode[s] - this.firstCode[s] + this.firstSymbol[s];
|
||
|
this.size[c] = s;
|
||
|
this.value[c] = i;
|
||
|
if (s <= fastBits) {
|
||
|
var j = bitReverse(nextCode[s], s);
|
||
|
while (j < (1 << fastBits)) {
|
||
|
this.fast[j] = c;
|
||
|
j += (1 << s);
|
||
|
}
|
||
|
}
|
||
|
nextCode[s] += 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var distance;
|
||
|
var length;
|
||
|
|
||
|
function bitReverse16(n) {
|
||
|
n = ((n & 0xAAAA) >>> 1) | ((n & 0x5555) << 1);
|
||
|
n = ((n & 0xCCCC) >>> 2) | ((n & 0x3333) << 2);
|
||
|
n = ((n & 0xF0F0) >>> 4) | ((n & 0x0F0F) << 4);
|
||
|
n = ((n & 0xFF00) >>> 8) | ((n & 0x00FF) << 8);
|
||
|
return n;
|
||
|
}
|
||
|
|
||
|
function bitReverse(v, bits) {
|
||
|
return bitReverse16(v) >>> (16 - bits);
|
||
|
}
|
||
|
|
||
|
function get8() {
|
||
|
return inPos >= input.length ? 0 : input[inPos++];
|
||
|
}
|
||
|
|
||
|
function fillBits() {
|
||
|
do {
|
||
|
codeBuffer |= (get8() << numBits);
|
||
|
numBits += 8;
|
||
|
} while (numBits <= 24);
|
||
|
}
|
||
|
|
||
|
function receive(n) {
|
||
|
if (numBits < n) fillBits();
|
||
|
var k = (codeBuffer & ((1 << n) - 1));
|
||
|
codeBuffer >>>= n;
|
||
|
numBits -= n;
|
||
|
return k;
|
||
|
}
|
||
|
|
||
|
function huffmanDecode(z) {
|
||
|
var s;
|
||
|
if (numBits < 16) fillBits();
|
||
|
var b = z.fast[codeBuffer & fastMask];
|
||
|
if (b < 0xffff) {
|
||
|
s = z.size[b];
|
||
|
codeBuffer >>>= s;
|
||
|
numBits -= s;
|
||
|
return z.value[b];
|
||
|
}
|
||
|
|
||
|
var k = bitReverse(codeBuffer, 16);
|
||
|
for (s = fastBits + 1;; ++s)
|
||
|
if (k < z.maxCode[s])
|
||
|
break;
|
||
|
if (s === 16) return -1;
|
||
|
|
||
|
b = (k >>> (16 - s)) - z.firstCode[s] + z.firstSymbol[s];
|
||
|
codeBuffer >>>= s;
|
||
|
numBits -= s;
|
||
|
return z.value[b];
|
||
|
}
|
||
|
|
||
|
function parseHuffmanBlock() {
|
||
|
for (;;) {
|
||
|
var z = huffmanDecode(length);
|
||
|
if (z < 256) {
|
||
|
output[outPos++] = z;
|
||
|
}
|
||
|
else {
|
||
|
if (z === 256) return;
|
||
|
z -= 257;
|
||
|
var len = lenghtBase[z];
|
||
|
if (lengthExtra[z] !== 0) len += receive(lengthExtra[z]);
|
||
|
z = huffmanDecode(distance);
|
||
|
var dist = distBase[z];
|
||
|
if (distExtra[z] !== 0) dist += receive(distExtra[z]);
|
||
|
dist = outPos - dist;
|
||
|
for (var i = 0; i < len; i++, dist++) { output[outPos++] = output[dist]; }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function computeHuffmanCodes() {
|
||
|
var lenCodes = new Uint8Array(286 + 32 + 137);
|
||
|
var codeLengthSizes = new Uint8Array(19);
|
||
|
|
||
|
var hlit = receive(5) + 257;
|
||
|
var hdist = receive(5) + 1;
|
||
|
var hclen = receive(4) + 4;
|
||
|
|
||
|
for (var i = 0; i < hclen; i++) { codeLengthSizes[lengthDezigzag[i]] = receive(3); }
|
||
|
|
||
|
var codeLength = new Huffman(codeLengthSizes,0,codeLengthSizes.length);
|
||
|
|
||
|
var n = 0;
|
||
|
while (n < hlit + hdist) {
|
||
|
var c = huffmanDecode(codeLength);
|
||
|
|
||
|
if (c < 16) { lenCodes[n++] = c; }
|
||
|
else if (c === 16) {
|
||
|
c = receive(2) + 3;
|
||
|
for (var i = 0; i < c; i++) lenCodes[n + i] = lenCodes[n - 1];
|
||
|
n += c;
|
||
|
}
|
||
|
else if (c === 17) {
|
||
|
c = receive(3) + 3;
|
||
|
for (var i = 0; i < c; i++) lenCodes[n + i] = 0;
|
||
|
n += c;
|
||
|
}
|
||
|
else {
|
||
|
c = receive(7) + 11;
|
||
|
for (var i = 0; i < c; i++) lenCodes[n + i] = 0;
|
||
|
n += c;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
length = new Huffman(lenCodes, 0, hlit);
|
||
|
distance = new Huffman(lenCodes, hlit, hdist);
|
||
|
}
|
||
|
|
||
|
function decodeChar(c) {
|
||
|
return c >= 92 ? c-36 : c-35;
|
||
|
}
|
||
|
|
||
|
function decodeBase85(input) {
|
||
|
var output = new Uint8Array((input.length * 4) / 5);
|
||
|
var inPos = 0;
|
||
|
var outPos = 0;
|
||
|
|
||
|
while (input.charCodeAt(inPos)) {
|
||
|
var block = decodeChar(input.charCodeAt(inPos + 0)) +
|
||
|
85*(decodeChar(input.charCodeAt(inPos + 1)) +
|
||
|
85*(decodeChar(input.charCodeAt(inPos + 2)) +
|
||
|
85*(decodeChar(input.charCodeAt(inPos + 3)) +
|
||
|
85*decodeChar(input.charCodeAt(inPos + 4)))));
|
||
|
|
||
|
output[outPos + 0] = (block & 0xFF);
|
||
|
output[outPos + 1] = ((block >>> 8) & 0xFF);
|
||
|
output[outPos + 2] = ((block >>> 16) & 0xFF);
|
||
|
output[outPos + 3] = ((block >>> 24) & 0xFF);
|
||
|
|
||
|
inPos += 5;
|
||
|
outPos += 4;
|
||
|
}
|
||
|
|
||
|
return output;
|
||
|
}
|
||
|
|
||
|
input = decodeBase85(input);
|
||
|
|
||
|
var final = false;
|
||
|
do {
|
||
|
final = receive(1) !== 0;
|
||
|
var type = receive(2);
|
||
|
computeHuffmanCodes();
|
||
|
parseHuffmanBlock();
|
||
|
} while (!final);
|
||
|
|
||
|
for (var i = 0; i < output.length; i++) {
|
||
|
output[i] = ((i & 63) ? output[i - 1] : 127) + (output[i] - 127);
|
||
|
}
|
||
|
|
||
|
return output;
|
||
|
}
|
||
|
|
||
|
var lut = decompress("#$6cTLFMX$M:PgZQ0uX#c3Hv3j%J:58NctbqUCrcZ#^pc.=#G_)_C0K)6PdZZKP0X+Aa=(<R9Y`tOclFQdG&Hp;1LfTE9n^:6S&uK`Z'hu@%prNaF=3@u6La8:AucRJe9n*3M-?=VkLSQ^d/[email protected]/_glJU1%aU;#cA@E@IUc3lI^L*sWK_>i0V9/QuO-^mL`JLUJeIfW7ZB#F+q-M>)n/f_1tB_s)ew2HO[e.0^o0?E$(-_.`Ij#hBlY-^hjMZl*uMf6]jE31glP(x^K4T9hiBQi4p;(wguxYlHI^$:u3[D^L4r&`uif7UBV=dDJ%D-SkSvcri,<vqi+E-g)e(ItZpoIaY>->']48?P3kFDd-;XcL0-+iia2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hK:`I?t`=lSnbNF,QB^Lq_%kcX,i/:fWAlfLUDF`%`_PA-ECS751Xi&+HbCV2;rs^*Gml_YcImD2E+xkC?b1o<xP>s1'&Kb$c_1QDr'Oi]YbHuH-p.Za?,I0.P[$vaI85aphaNqBk[+i0qdr>'AwF7)J.]tTjpku(n-0uwmesBDpIuk%e1XA;*4[R'V/'>uX-6Kmr5nVC@rSoJpt)qA4+OE%`Z&8cD]^'e`,DuY)d0CtdDJ`uD1FZVO=aK7Y/te';h.mr4IucuDx:D1)i86?,YBr3EHr),dLf#T:Clf>n&BW$n%KXRKFkXR-]KlApAcK.)Y%R?pcPnEvrj`TSM&Lo^pGUFRdmjgqjub$c$DWXW=Yl(N8]X7vmnJigq:Q0TsM87H_Z+.)*FrIAkFiTL,%7?m#pt.DI;mCB:5f@_E`<1(69-7h[t'9lFd'Qe-cr9HG-WhQg8i5L_l/eYsvOv;t*MQ[I%tS4f@2dG_HgYTbc]Wf7&XX-wW6`9$.L;EMlUiA?7v^3Yj1TUhx4mj,9tXmpGKS::J:-Ev[U+0XXuH0o6c]Vd'vC(,kUHP=M97QX`/8`',v-uR9VO
|
||
|
|
||
|
exports.LATENT_SIZE = 7;
|
||
|
|
||
|
exports.lerp = lerp;
|
||
|
exports.lerpFloat = lerpFloat;
|
||
|
exports.lerpLinearFloat = lerpLinearFloat;
|
||
|
|
||
|
exports.rgbToLatent = rgbToLatent;
|
||
|
exports.latentToRgb = latentToRgb;
|
||
|
|
||
|
exports.floatRgbToLatent = floatRgbToLatent;
|
||
|
exports.latentToFloatRgb = latentToFloatRgb;
|
||
|
|
||
|
exports.linearFloatRgbToLatent = linearFloatRgbToLatent;
|
||
|
exports.latentToLinearFloatRgb = latentToLinearFloatRgb;
|
||
|
|
||
|
exports.glsl = glsl;
|
||
|
exports.lutTexture = lutTexture;
|
||
|
|
||
|
})));
|