image-color-grading 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +233 -0
- package/dist/index.d.ts +224 -14
- package/dist/index.js +1 -22
- package/package.json +14 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/processor.d.ts +0 -109
- package/dist/processor.d.ts.map +0 -1
- package/dist/processor.js +0 -527
- package/dist/processor.js.map +0 -1
- package/dist/shaders.d.ts +0 -27
- package/dist/shaders.d.ts.map +0 -1
- package/dist/shaders.js +0 -674
- package/dist/shaders.js.map +0 -1
- package/dist/types.d.ts +0 -97
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -50
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -176
- package/dist/utils.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e="\nprecision highp float;\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nvarying vec2 vUv;\nvoid main() {\n vUv = aTexCoord;\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n",n="\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform vec2 uTexel;\nuniform float uKernel[9];\nuniform float uAmount;\nvoid main(void) {\n vec4 c11 = texture2D(uTexture, vUv - uTexel);\n vec4 c12 = texture2D(uTexture, vec2(vUv.x, vUv.y - uTexel.y));\n vec4 c13 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y - uTexel.y));\n vec4 c21 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y));\n vec4 c22 = texture2D(uTexture, vUv);\n vec4 c23 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y));\n vec4 c31 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y + uTexel.y));\n vec4 c32 = texture2D(uTexture, vec2(vUv.x, vUv.y + uTexel.y));\n vec4 c33 = texture2D(uTexture, vUv + uTexel);\n vec4 color = c11 * uKernel[0] + c12 * uKernel[1] + c13 * uKernel[2] +\n c21 * uKernel[3] + c22 * uKernel[4] + c23 * uKernel[5] +\n c31 * uKernel[6] + c32 * uKernel[7] + c33 * uKernel[8];\n gl_FragColor = color * uAmount + (c22 * (1.0 - uAmount));\n}\n";function t(e,n,t){const r=e.createShader(n);return r?(e.shaderSource(r,t),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null}function r(e,n,r,o){const a=t(e,e.VERTEX_SHADER,n),i=t(e,e.FRAGMENT_SHADER,r);if(!a||!i)throw new Error("Shader compile failed.");const c=function(e,n,t){const r=e.createProgram();return r?(e.attachShader(r,n),e.attachShader(r,t),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(e.deleteProgram(r),null)):null}(e,a,i);if(!c)throw new Error("Program link failed.");const u={aPosition:e.getAttribLocation(c,"aPosition"),aTexCoord:e.getAttribLocation(c,"aTexCoord"),apos:e.getAttribLocation(c,"apos"),auv:e.getAttribLocation(c,"auv")},l={};return o.forEach(n=>{l[n]=e.getUniformLocation(c,n)}),{program:c,attribs:u,uniforms:l}}function o(e,n,t){const r=e.createTexture();if(!r)throw new Error("Unable to create texture");e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);const o=e.createFramebuffer();if(!o)throw new Error("Unable to create framebuffer");return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0),{framebuffer:o,texture:r}}var a=e=>Math.min(1,Math.max(0,e)),i=(e,n,t,r,o)=>{const a=1-e;return a*a*a*n+3*a*a*e*t+3*a*e*e*r+e*e*e*o},c=e=>{const n=Math.max(-100,Math.min(100,e))/100;return(e=>{const n=new Uint8Array(768);for(let t=0;t<256;t+=1){const r=i(t/255,0,e,.66,1),o=Math.round(255*a(r)),c=3*t;n[c]=o,n[c+1]=o,n[c+2]=o}return n})(a(.33-.35*n))},u={vibrance:0,saturation:0,temperature:0,tint:0,hue:0,brightness:0,exposure:0,contrast:0,blacks:0,whites:0,highlights:0,shadows:0,dehaze:0,bloom:0,glamour:0,clarity:0,sharpen:0,smooth:0,blur:0,vignette:0,grain:0},l={auto:{},blackAndWhite:{saturation:-100,contrast:20,exposure:10,clarity:10},pop:{highlights:50,shadows:-50,vibrance:50,saturation:20,exposure:20,clarity:20},vintage:{saturation:-20,contrast:10,temperature:15,grain:30,vignette:25},vivid:{vibrance:40,saturation:20,contrast:15,clarity:20},cinematic:{contrast:25,highlights:-20,shadows:15,temperature:-10,vignette:30}};function s(e){const{data:n,width:t,height:r}=e,o=new Array(256).fill(0);for(let e=0;e<n.length;e+=4)o[n[e]]+=1,o[n[e+1]]+=1,o[n[e+2]]+=1;const a=Math.round(t*r/1e3);let i=0;for(let e=0;e<256;e++)if(o[e]>a){i=e;break}let c=255;for(let e=255;e>=0;e--)if(o[e]>a){c=e;break}return i>100&&(i=100),c<155&&(c=155),{black:i,white:c}}function v(e){const{data:n,width:t,height:r}=e;let o=1,a=1;for(let e=0;e<n.length;e+=4){const t=n[e],r=n[e+1],i=n[e+2],c=Math.min(t,r,i),u=Math.max(t,r,i);a+=u/255;const l=u-c;l>0&&(o+=l/u)}return(o+a)/(t*r*2)}function m(e){return{levels:s(e),vibrance:v(e)}}exports.ImageColorGrading=class{constructor(e){this.resources=null,this.settings={...u},this.imageLoaded=!1,this.canvas=e||document.createElement("canvas")}getCanvas(){return this.canvas}getSettings(){return{...this.settings}}setSettings(e){this.settings={...this.settings,...e},this.resources&&this.render()}resetSettings(){this.settings={...u},this.resources&&this.render()}loadImage(e){return new Promise((n,t)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{this.initFromImage(r),n()},r.onerror=()=>{t(new Error(`Failed to load image: ${e}`))},r.src=e})}loadFromImage(e){this.initFromImage(e)}loadFromFile(e){return new Promise((n,t)=>{const r=URL.createObjectURL(e);this.loadImage(r).then(()=>{URL.revokeObjectURL(r),n()}).catch(e=>{URL.revokeObjectURL(r),t(e)})})}loadFromImageData(e){const{width:n,height:t,data:r}=e;this.canvas.width=n,this.canvas.height=t;const o=this.getWebGLContext();if(!o)throw new Error("WebGL not supported");this.disposeResources(),o.viewport(0,0,n,t),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1);const a=o.createTexture();if(!a)throw new Error("Failed to create texture");o.bindTexture(o.TEXTURE_2D,a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,n,t,0,o.RGBA,o.UNSIGNED_BYTE,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.initResources(o,n,t,a)}render(){this.resources&&this.drawFrame(this.resources,this.settings)}toDataURL(e){const n=e?.format||"image/png",t=e?.quality;return this.canvas.toDataURL(n,t)}toBlob(e){return new Promise((n,t)=>{const r=e?.format||"image/png",o=e?.quality;this.canvas.toBlob(e=>{e?n(e):t(new Error("Failed to create blob"))},r,o)})}getImageData(){const e=this.canvas.getContext("2d");if(e)return e.getImageData(0,0,this.canvas.width,this.canvas.height);const n=this.canvas.getContext("webgl");if(n){const e=new Uint8ClampedArray(this.canvas.width*this.canvas.height*4);return n.readPixels(0,0,this.canvas.width,this.canvas.height,n.RGBA,n.UNSIGNED_BYTE,e),new ImageData(e,this.canvas.width,this.canvas.height)}throw new Error("Cannot get ImageData")}getSize(){return{width:this.canvas.width,height:this.canvas.height}}isLoaded(){return this.imageLoaded}dispose(){this.disposeResources(),this.imageLoaded=!1}analyze(){if(!this.imageLoaded)throw new Error("No image loaded");const e={...this.settings};this.settings={...u},this.render();const n=m(this.getImageData());return this.settings=e,this.render(),n}autoFix(){if(!this.imageLoaded)throw new Error("No image loaded");this.settings={...u},this.render();const e=this.getImageData(),n=s(e),t=v(e),r={...u};if(r.whites=Math.round(255-n.white),r.blacks=Math.round(n.black),t<.7){const e=Math.round(100*(.7-t));r.vibrance=Math.min(e,50)}return this.settings=r,this.render(),r}applyPreset(e){if("auto"===e)return this.autoFix();const n=l[e],t={...u,...n};return this.settings=t,this.resources&&this.render(),t}getWebGLContext(){return this.canvas.getContext("webgl",{antialias:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0})}initFromImage(e){const n=e.naturalWidth||e.width,t=e.naturalHeight||e.height;this.canvas.width=n,this.canvas.height=t;const r=this.getWebGLContext();if(!r)throw new Error("WebGL not supported");this.disposeResources(),r.disable(r.DEPTH_TEST),r.viewport(0,0,n,t),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1);const o=r.createTexture();if(!o)throw new Error("Failed to create texture");r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),this.initResources(r,n,t,o)}initResources(t,a,i,u){const l=((e,n)=>{const t=e.createTexture();if(!t)throw new Error("Unable to create palette texture");return e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,0,e.RGB,256,1,0,e.RGB,e.UNSIGNED_BYTE,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t})(t,c(0)),s=t.createBuffer(),v=t.createBuffer();if(!s||!v)throw new Error("Failed to create buffers");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,v),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);const m={pass:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vUv);\n}\n",["uTexture"]),vibrance:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 col = texture2D(uTexture, vUv);\n vec3 color = col.rgb;\n float luminance = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;\n float mn = min(min(color.r, color.g), color.b);\n float mx = max(max(color.r, color.g), color.b);\n float sat = (1.0 - (mx - mn)) * (1.0 - mx) * luminance * 5.0;\n vec3 lightness = vec3((mn + mx) / 2.0);\n color = mix(color, mix(color, lightness, -uAmount), sat);\n gl_FragColor = vec4(\n mix(color, lightness, (1.0 - lightness) * (1.0 - uAmount) / 2.0 * abs(uAmount)),\n col.a\n );\n}\n",["uTexture","uAmount"]),saturation:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uMatrix[20];\nvoid main(void) {\n vec4 c = texture2D(uTexture, vUv);\n gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];\n gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];\n gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];\n gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];\n}\n",["uTexture","uMatrix[0]"]),temperature:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n color.r = clamp(color.r + uAmount, 0.0, 1.0);\n color.b = clamp(color.b - uAmount, 0.0, 1.0);\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),tint:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n color.g = clamp(color.g + uAmount, 0.0, 1.0);\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),hue:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uRotation;\nvec3 rgb2hsv(vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvoid main() {\n lowp vec4 base = texture2D(uTexture, vUv);\n vec3 hsv = rgb2hsv(base.rgb);\n hsv.x = fract(hsv.x + uRotation);\n gl_FragColor = vec4(hsv2rgb(hsv), base.a);\n}\n",["uTexture","uRotation"]),brightness:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float PI = 3.1415926535897932384626433832795;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n if (uAmount >= 0.0) {\n color.r = color.r + uAmount * sin(color.r * PI);\n color.g = color.g + uAmount * sin(color.g * PI);\n color.b = color.b + uAmount * sin(color.b * PI);\n } else {\n color.r = (1.0 + uAmount) * color.r;\n color.g = (1.0 + uAmount) * color.g;\n color.b = (1.0 + uAmount) * color.b;\n }\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),exposure:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat ramp(in float t) {\n t *= 2.0;\n if (t >= 1.0) {\n t -= 1.0;\n t = log(0.5) / log(0.5 * (1.0 - t) + 0.9332 * t);\n }\n return clamp(t, 0.001, 10.0);\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n vec3 base = col.rgb * matRGBtoROMM;\n float a = abs(uAmount) * col.a + epsilon;\n float v = pow(2.0, a * 2.0 + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (uAmount > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = pow(res, vec3(ramp(1.0 - (0.0 * col.a + 1.0) / 2.0)));\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),contrast:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uMatrix[20];\nvoid main(void) {\n vec4 c = texture2D(uTexture, vUv);\n gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];\n gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];\n gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];\n gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];\n}\n",["uTexture","uMatrix[0]"]),blacks:r(t,"\nprecision highp float;\nattribute vec2 apos;\nattribute vec2 auv;\nvarying vec2 uv;\nuniform vec4 transform;\nvoid main(void) {\n uv = auv;\n gl_Position = vec4(\n apos.x * transform.x + transform.z,\n apos.y * transform.y + transform.w,\n 0.0,\n 1.0\n );\n}\n","\nprecision highp float;\nvarying vec2 uv;\nuniform sampler2D uTexture;\nuniform sampler2D uPaletteMap;\nvoid main() {\n lowp vec4 base = texture2D(uTexture, uv.xy);\n float r = texture2D(uPaletteMap, vec2(base.r, 0.0)).r;\n float g = texture2D(uPaletteMap, vec2(base.g, 0.0)).g;\n float b = texture2D(uPaletteMap, vec2(base.b, 0.0)).b;\n gl_FragColor = vec4(r, g, b, base.a);\n}\n",["uTexture","uPaletteMap","transform"]),whites:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst vec3 RGB2Y = vec3(0.2126, 0.7152, 0.0722);\nvoid main() {\n vec4 base = texture2D(uTexture, vUv.xy);\n vec3 color = base.rgb;\n float lum = dot(color, RGB2Y);\n float whiteMask = smoothstep(0.5, 1.0, lum);\n color += uAmount * whiteMask;\n gl_FragColor = vec4(clamp(color, 0.0, 1.0), base.a);\n}\n",["uTexture","uAmount"]),highlights:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst float PI = 3.1415926535897932384626433832795;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat luma_romm(in vec3 color) {\n return dot(color, vec3(0.242655, 0.755158, 0.002187));\n}\nfloat luma(in vec3 color) {\n return dot(color, vec3(0.298839, 0.586811, 0.11435));\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nfloat gaussian(in float x) {\n return 1.0 - exp(-PI * 2.0 * x * x);\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n lowp vec3 map = col.rgb;\n vec3 base = col.rgb * matRGBtoROMM;\n float base_lum = luma(col.rgb);\n float map_lum = luma_romm(map * matRGBtoROMM);\n float exposure = mix(uAmount, 0.0, 1.0 - map_lum) * col.a;\n float a = abs(exposure) * col.a + epsilon;\n float v = pow(2.0, a + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),shadows:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst float PI = 3.1415926535897932384626433832795;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat luma_romm(in vec3 color) {\n return dot(color, vec3(0.242655, 0.755158, 0.002187));\n}\nfloat luma(in vec3 color) {\n return dot(color, vec3(0.298839, 0.586811, 0.11435));\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nfloat gaussian(in float x) {\n return 1.0 - exp(-PI * 2.0 * x * x);\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n lowp vec3 map = col.rgb;\n vec3 base = col.rgb * matRGBtoROMM;\n float base_lum = luma(col.rgb);\n float map_lum = luma_romm(map * matRGBtoROMM);\n float exposure = mix(0.0, uAmount, 1.0 - map_lum) * col.a;\n float a = abs(exposure) * col.a + epsilon;\n float v = pow(2.0, a + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),dehaze:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uSize;\n\nfloat hazeMap(vec2 coord) {\n vec3 color = vec3(1.0);\n vec2 stepSize = vec2(1.0 / uSize.x, 1.0 / uSize.y);\n for (int i = -1; i <= 1; ++i) {\n for (int j = -1; j <= 1; ++j) {\n vec2 offset = vec2(float(i), float(j)) * stepSize;\n vec2 uv = clamp(coord + offset, 0.0, 1.0);\n vec3 sample = texture2D(uTexture, uv).rgb;\n color = min(color, sample);\n }\n }\n return min(color.r, min(color.g, color.b));\n}\n\nvoid main() {\n vec4 base = texture2D(uTexture, vUv);\n float haze = hazeMap(vUv);\n float transmission = 1.0 - 0.95 * haze;\n const float A = 0.95;\n const float t0 = 0.1;\n float t = mix(1.0, max(t0, transmission), uAmount);\n vec3 J = (base.rgb - A) / t + A;\n gl_FragColor = vec4(J, base.a);\n}\n",["uTexture","uAmount","uSize"]),bloom:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\nuniform float uThreshold;\n\nvoid main() {\n vec4 sum = vec4(0.0);\n int j = -2;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = -1;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 0;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 1;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 2;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n sum /= 25.0;\n vec4 base = texture2D(uTexture, vUv);\n if (length(sum.rgb) > uThreshold) {\n base += sum * uAmount;\n }\n gl_FragColor = base;\n}\n",["uTexture","uAmount","uTexel","uThreshold"]),glamour:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\n\nfloat normpdf(in float x, in float sigma) {\n return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;\n}\n\nvec3 blurMap() {\n const int mSize = 11;\n const int kSize = (mSize - 1) / 2;\n float kernel[mSize];\n vec3 final_colour = vec3(0.0);\n float sigma = 7.0;\n float Z = 0.0;\n for (int j = 0; j <= kSize; ++j) {\n kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);\n }\n for (int j = 0; j < mSize; ++j) {\n Z += kernel[j];\n }\n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n final_colour += kernel[kSize + j] * kernel[kSize + i] *\n texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;\n }\n }\n return vec3(final_colour / (Z * Z));\n}\n\nfloat luma(vec3 color) {\n return dot(color, vec3(0.299, 0.587, 0.114));\n}\n\nvoid main() {\n vec4 base = texture2D(uTexture, vUv);\n vec3 color = blurMap();\n color = vec3(luma(color));\n color = vec3(\n (base.r <= 0.5) ? (2.0 * base.r * color.r) : (1.0 - 2.0 * (1.0 - base.r) * (1.0 - color.r)),\n (base.g <= 0.5) ? (2.0 * base.g * color.g) : (1.0 - 2.0 * (1.0 - base.g) * (1.0 - color.g)),\n (base.b <= 0.5) ? (2.0 * base.b * color.b) : (1.0 - 2.0 * (1.0 - base.b) * (1.0 - color.b))\n );\n gl_FragColor = mix(base, vec4(color, base.a), uAmount);\n}\n",["uTexture","uAmount","uTexel"]),clarity:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\n\nfloat Lum(vec3 c) {\n return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;\n}\nfloat BlendOverlayf(float base, float blend) {\n return (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)));\n}\nvec3 BlendOverlay(vec3 base, vec3 blend) {\n return vec3(BlendOverlayf(base.r, blend.r), BlendOverlayf(base.g, blend.g), BlendOverlayf(base.b, blend.b));\n}\nfloat BlendVividLightf(float base, float blend) {\n float BlendColorBurnf = (((2.0 * blend) == 0.0) ? (2.0 * blend) : max((1.0 - ((1.0 - base) / (2.0 * blend))), 0.0));\n float BlendColorDodgef = (((2.0 * (blend - 0.5)) == 1.0) ? (2.0 * (blend - 0.5)) : min(base / (1.0 - (2.0 * (blend - 0.5))), 1.0));\n return ((blend < 0.5) ? BlendColorBurnf : BlendColorDodgef);\n}\nvec3 BlendVividLight(vec3 base, vec3 blend) {\n return vec3(BlendVividLightf(base.r, blend.r), BlendVividLightf(base.g, blend.g), BlendVividLightf(base.b, blend.b));\n}\nfloat normpdf(in float x, in float sigma) {\n return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;\n}\nvec3 blurMap() {\n const int mSize = 11;\n const int kSize = (mSize - 1) / 2;\n float kernel[mSize];\n vec3 final_colour = vec3(0.0);\n float sigma = 7.0;\n float Z = 0.0;\n for (int j = 0; j <= kSize; ++j) {\n kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);\n }\n for (int j = 0; j < mSize; ++j) {\n Z += kernel[j];\n }\n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n final_colour += kernel[kSize + j] * kernel[kSize + i] *\n texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;\n }\n }\n return vec3(final_colour / (Z * Z));\n}\nvoid main() {\n vec4 base4 = texture2D(uTexture, vUv);\n vec3 blur = blurMap();\n vec3 base = base4.rgb;\n float intensity = (uAmount < 0.0) ? (uAmount / 2.0) : uAmount;\n float lum = Lum(base);\n vec3 col = vec3(lum);\n vec3 mask = vec3(1.0 - pow(lum, 1.8));\n vec3 layer = vec3(1.0 - Lum(blur));\n vec3 detail = clamp(BlendVividLight(col, layer), 0.0, 1.0);\n vec3 inverse = mix(1.0 - detail, detail, (intensity + 1.0) / 2.0);\n gl_FragColor = vec4(BlendOverlay(base, mix(vec3(0.5), inverse, mask)), base4.a);\n}\n",["uTexture","uAmount","uTexel"]),sharpen:r(t,e,n,["uTexture","uTexel","uKernel[0]","uAmount"]),smooth:r(t,e,n,["uTexture","uTexel","uKernel[0]","uAmount"]),blur:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform vec2 uSize;\nfloat random(vec3 scale, float seed) {\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\nvoid main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n for (int t = -30; t <= 30; t++) {\n float percent = (float(t) + offset - 0.5) / 30.0;\n float weight = 1.0 - abs(percent);\n vec4 sample = texture2D(uTexture, vUv + uSize * percent);\n sample.rgb *= sample.a;\n color += sample * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n gl_FragColor.rgb /= gl_FragColor.a + 0.00001;\n}\n",["uTexture","uSize"]),vignette:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform float uSize;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n float dist = distance(vUv, vec2(0.5, 0.5));\n float amt = clamp(uAmount, -1.0, 1.0);\n float edge = dist * (abs(amt) * 0.75 + uSize * 2.0);\n float vignette = smoothstep(0.8, uSize * 0.799, edge);\n if (amt < 0.0) {\n vignette = 1.0 + (1.0 - vignette) * (-amt);\n } else {\n vignette = mix(1.0, vignette, amt);\n }\n color.rgb *= vignette;\n gl_FragColor = color;\n}\n",["uTexture","uAmount","uSize"]),grain:r(t,e,"\nprecision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vUv;\nuniform vec2 uResolution;\nuniform float uAmount;\nuniform float uTime;\nconst float permTexUnit = 1.0 / 256.0;\nconst float permTexUnitHalf = 0.5 / 256.0;\nfloat grainsize = 1.8;\nfloat lumamount = 1.0;\n\nvec4 rnm(in vec2 tc) {\n float noise = sin(dot(tc + vec2(uTime, uTime), vec2(12.9898, 78.233))) * 43758.5453;\n float noiseR = fract(noise) * 2.0 - 1.0;\n float noiseG = fract(noise * 1.2154) * 2.0 - 1.0;\n float noiseB = fract(noise * 1.3453) * 2.0 - 1.0;\n float noiseA = fract(noise * 1.3647) * 2.0 - 1.0;\n return vec4(noiseR, noiseG, noiseB, noiseA);\n}\nfloat fade(in float t) {\n return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n}\nfloat pnoise3D(in vec3 p) {\n vec3 pi = permTexUnit * floor(p) + permTexUnitHalf;\n vec3 pf = fract(p);\n float perm00 = rnm(pi.xy).a;\n vec3 grad000 = rnm(vec2(perm00, pi.z)).rgb * 4.0 - 1.0;\n float n000 = dot(grad000, pf);\n vec3 grad001 = rnm(vec2(perm00, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n001 = dot(grad001, pf - vec3(0.0, 0.0, 1.0));\n float perm01 = rnm(pi.xy + vec2(0.0, permTexUnit)).a;\n vec3 grad010 = rnm(vec2(perm01, pi.z)).rgb * 4.0 - 1.0;\n float n010 = dot(grad010, pf - vec3(0.0, 1.0, 0.0));\n vec3 grad011 = rnm(vec2(perm01, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n011 = dot(grad011, pf - vec3(0.0, 1.0, 1.0));\n float perm10 = rnm(pi.xy + vec2(permTexUnit, 0.0)).a;\n vec3 grad100 = rnm(vec2(perm10, pi.z)).rgb * 4.0 - 1.0;\n float n100 = dot(grad100, pf - vec3(1.0, 0.0, 0.0));\n vec3 grad101 = rnm(vec2(perm10, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n101 = dot(grad101, pf - vec3(1.0, 0.0, 1.0));\n float perm11 = rnm(pi.xy + vec2(permTexUnit, permTexUnit)).a;\n vec3 grad110 = rnm(vec2(perm11, pi.z)).rgb * 4.0 - 1.0;\n float n110 = dot(grad110, pf - vec3(1.0, 1.0, 0.0));\n vec3 grad111 = rnm(vec2(perm11, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n111 = dot(grad111, pf - vec3(1.0, 1.0, 1.0));\n vec4 n_x = mix(vec4(n000, n001, n010, n011), vec4(n100, n101, n110, n111), fade(pf.x));\n vec2 n_xy = mix(n_x.xy, n_x.zw, fade(pf.y));\n float n_xyz = mix(n_xy.x, n_xy.y, fade(pf.z));\n return n_xyz;\n}\nvec2 coordRot(in vec2 tc, in float angle) {\n float aspect = uResolution.x / uResolution.y;\n float rotX = ((tc.x * 2.0 - 1.0) * aspect * cos(angle)) - ((tc.y * 2.0 - 1.0) * sin(angle));\n float rotY = ((tc.y * 2.0 - 1.0) * cos(angle)) + ((tc.x * 2.0 - 1.0) * aspect * sin(angle));\n rotX = ((rotX / aspect) * 0.5 + 0.5);\n rotY = rotY * 0.5 + 0.5;\n return vec2(rotX, rotY);\n}\nvoid main() {\n vec3 rotOffset = vec3(1.425, 3.892, 5.835);\n vec2 rotCoordsR = coordRot(vUv, uTime + rotOffset.x);\n vec3 noise = vec3(pnoise3D(vec3(rotCoordsR * vec2(uResolution.x / grainsize, uResolution.y / grainsize), 0.0)));\n vec4 tex = texture2D(uTexture, vUv);\n vec3 col = tex.rgb;\n vec3 lumcoeff = vec3(0.299, 0.587, 0.114);\n float luminance = mix(0.0, dot(col, lumcoeff), lumamount);\n float lum = smoothstep(0.2, 0.0, luminance);\n lum += luminance;\n noise = mix(noise, vec3(0.0), pow(lum, 4.0));\n col = col + noise * uAmount;\n gl_FragColor = vec4(col, tex.a);\n}\n",["uTexture","uResolution","uAmount","uTime"])},x=[o(t,a,i),o(t,a,i)];this.resources={gl:t,width:a,height:i,sourceTexture:u,blackPalette:l,quad:{positionBuffer:s,texCoordBuffer:v},programs:m,targets:x},this.imageLoaded=!0,this.render()}disposeResources(){if(!this.resources)return;const{gl:e,sourceTexture:n,blackPalette:t,quad:r,programs:o,targets:a}=this.resources;e.deleteTexture(n),e.deleteTexture(t),e.deleteBuffer(r.positionBuffer),e.deleteBuffer(r.texCoordBuffer),a.forEach(n=>{e.deleteFramebuffer(n.framebuffer),e.deleteTexture(n.texture)}),Object.values(o).forEach(n=>{e.deleteProgram(n.program)}),this.resources=null}drawFrame(e,n){const{gl:t,width:r,height:o,sourceTexture:a,blackPalette:i,quad:u,programs:l,targets:s}=e;t.viewport(0,0,r,o);const v=[1/r,1/o];let m=a,x=0;const f=(e,n,r)=>{t.useProgram(e.program),(e=>{t.bindBuffer(t.ARRAY_BUFFER,u.positionBuffer);const n=e.attribs.aPosition>=0?e.attribs.aPosition:e.attribs.apos;n>=0&&(t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0)),t.bindBuffer(t.ARRAY_BUFFER,u.texCoordBuffer);const r=e.attribs.aTexCoord>=0?e.attribs.aTexCoord:e.attribs.auv;r>=0&&(t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0))})(e),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,m);const o=e.uniforms.uTexture;o&&t.uniform1i(o,0),n(),t.bindFramebuffer(t.FRAMEBUFFER,r?r.framebuffer:null),t.drawArrays(t.TRIANGLE_STRIP,0,4),m=r?r.texture:m},g=()=>{const e=s[x%2];return x+=1,e};Math.abs(n.vibrance)>.5&&f(l.vibrance,()=>{t.uniform1f(l.vibrance.uniforms.uAmount,n.vibrance/100)},g()),Math.abs(n.saturation)>.5&&f(l.saturation,()=>{const e=(e=>{const n=1+Math.max(-100,Math.min(100,e))/100,t=.299,r=.587,o=.114,a=1-n;return new Float32Array([a*t+n,a*r,a*o,0,0,a*t,a*r+n,a*o,0,0,a*t,a*r,a*o+n,0,0,0,0,0,1,0])})(n.saturation);t.uniform1fv(l.saturation.uniforms["uMatrix[0]"],e)},g()),Math.abs(n.temperature)>.5&&f(l.temperature,()=>{t.uniform1f(l.temperature.uniforms.uAmount,n.temperature/500)},g()),Math.abs(n.tint)>.5&&f(l.tint,()=>{t.uniform1f(l.tint.uniforms.uAmount,n.tint/500)},g()),Math.abs(n.hue)>.5&&f(l.hue,()=>{t.uniform1f(l.hue.uniforms.uRotation,n.hue/200)},g()),f(l.brightness,()=>{t.uniform1f(l.brightness.uniforms.uAmount,n.brightness/200)},g()),Math.abs(n.exposure)>.5&&f(l.exposure,()=>{t.uniform1f(l.exposure.uniforms.uAmount,n.exposure/100)},g()),Math.abs(n.contrast)>.5&&f(l.contrast,()=>{const e=(e=>{const n=1+Math.max(-100,Math.min(100,e))/100,t=.5*(1-n);return new Float32Array([n,0,0,0,t,0,n,0,0,t,0,0,n,0,t,0,0,0,1,0])})(n.contrast);t.uniform1fv(l.contrast.uniforms["uMatrix[0]"],e)},g()),Math.abs(n.blacks)>.5&&(((e,n,t)=>{e.bindTexture(e.TEXTURE_2D,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,256,1,e.RGB,e.UNSIGNED_BYTE,t)})(t,i,c(n.blacks)),f(l.blacks,()=>{t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i),t.uniform1i(l.blacks.uniforms.uPaletteMap,1),t.uniform4f(l.blacks.uniforms.transform,1,1,0,0),t.activeTexture(t.TEXTURE0)},g())),Math.abs(n.whites)>.5&&f(l.whites,()=>{t.uniform1f(l.whites.uniforms.uAmount,n.whites/400)},g()),Math.abs(n.highlights)>.5&&f(l.highlights,()=>{t.uniform1f(l.highlights.uniforms.uAmount,n.highlights/100)},g()),Math.abs(n.shadows)>.5&&f(l.shadows,()=>{t.uniform1f(l.shadows.uniforms.uAmount,n.shadows/100)},g()),Math.abs(n.dehaze)>.5&&f(l.dehaze,()=>{t.uniform1f(l.dehaze.uniforms.uAmount,n.dehaze/100),t.uniform2f(l.dehaze.uniforms.uSize,r,o)},g()),n.bloom>.5&&f(l.bloom,()=>{t.uniform1f(l.bloom.uniforms.uAmount,n.bloom/100),t.uniform2f(l.bloom.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.bloom.uniforms.uThreshold,.5)},g()),n.glamour>.5&&f(l.glamour,()=>{t.uniform1f(l.glamour.uniforms.uAmount,n.glamour/100),t.uniform2f(l.glamour.uniforms.uTexel,v[0],v[1])},g()),Math.abs(n.clarity)>.5&&f(l.clarity,()=>{t.uniform1f(l.clarity.uniforms.uAmount,n.clarity/100),t.uniform2f(l.clarity.uniforms.uTexel,v[0],v[1])},g()),n.sharpen>.5&&f(l.sharpen,()=>{t.uniform2f(l.sharpen.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.sharpen.uniforms.uAmount,n.sharpen/100),t.uniform1fv(l.sharpen.uniforms["uKernel[0]"],new Float32Array([0,-1,0,-1,5,-1,0,-1,0]))},g()),n.smooth>.5&&f(l.smooth,()=>{t.uniform2f(l.smooth.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.smooth.uniforms.uAmount,n.smooth/100),t.uniform1fv(l.smooth.uniforms["uKernel[0]"],new Float32Array([1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9]))},g());const p=n.blur;f(l.blur,()=>{t.uniform2f(l.blur.uniforms.uSize,p/r,0)},g()),f(l.blur,()=>{t.uniform2f(l.blur.uniforms.uSize,0,p/o)},g()),f(l.vignette,()=>{t.uniform1f(l.vignette.uniforms.uAmount,n.vignette/100),t.uniform1f(l.vignette.uniforms.uSize,.25)},g()),f(l.grain,()=>{t.uniform2f(l.grain.uniforms.uResolution,r,o),t.uniform1f(l.grain.uniforms.uAmount,n.grain/800),t.uniform1f(l.grain.uniforms.uTime,0)},g()),f(l.pass,()=>{},null)}},exports.analyzeImage=m,exports.analyzeImageLevels=s,exports.analyzeImageVibrance=v,exports.defaultSettings=u,exports.presets=l;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 调色设置参数
|
|
3
|
+
*/
|
|
4
|
+
interface ColorGradingSettings {
|
|
5
|
+
/** 自然饱和度 (-100 ~ 100) */
|
|
6
|
+
vibrance: number;
|
|
7
|
+
/** 饱和度 (-100 ~ 100) */
|
|
8
|
+
saturation: number;
|
|
9
|
+
/** 色温 (-100 ~ 100) */
|
|
10
|
+
temperature: number;
|
|
11
|
+
/** 色调 (-100 ~ 100) */
|
|
12
|
+
tint: number;
|
|
13
|
+
/** 色相 (-100 ~ 100) */
|
|
14
|
+
hue: number;
|
|
15
|
+
/** 亮度 (-100 ~ 100) */
|
|
16
|
+
brightness: number;
|
|
17
|
+
/** 曝光度 (-100 ~ 100) */
|
|
18
|
+
exposure: number;
|
|
19
|
+
/** 对比度 (-100 ~ 100) */
|
|
20
|
+
contrast: number;
|
|
21
|
+
/** 黑色 (-100 ~ 100) */
|
|
22
|
+
blacks: number;
|
|
23
|
+
/** 白色 (-100 ~ 100) */
|
|
24
|
+
whites: number;
|
|
25
|
+
/** 高光 (-100 ~ 100) */
|
|
26
|
+
highlights: number;
|
|
27
|
+
/** 暗调 (-100 ~ 100) */
|
|
28
|
+
shadows: number;
|
|
29
|
+
/** 除雾化 (0 ~ 100) */
|
|
30
|
+
dehaze: number;
|
|
31
|
+
/** 泛光 (0 ~ 100) */
|
|
32
|
+
bloom: number;
|
|
33
|
+
/** 氛围美化 (0 ~ 100) */
|
|
34
|
+
glamour: number;
|
|
35
|
+
/** 清晰度 (-100 ~ 100) */
|
|
36
|
+
clarity: number;
|
|
37
|
+
/** 锐化 (0 ~ 100) */
|
|
38
|
+
sharpen: number;
|
|
39
|
+
/** 平滑 (0 ~ 100) */
|
|
40
|
+
smooth: number;
|
|
41
|
+
/** 模糊 (0 ~ 100) */
|
|
42
|
+
blur: number;
|
|
43
|
+
/** 暗角 (-100 ~ 100) */
|
|
44
|
+
vignette: number;
|
|
45
|
+
/** 颗粒 (0 ~ 100) */
|
|
46
|
+
grain: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 部分调色设置参数
|
|
50
|
+
*/
|
|
51
|
+
type PartialColorGradingSettings = Partial<ColorGradingSettings>;
|
|
52
|
+
/**
|
|
53
|
+
* 导出选项
|
|
54
|
+
*/
|
|
55
|
+
interface ExportOptions {
|
|
56
|
+
/** 导出格式 */
|
|
57
|
+
format?: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
58
|
+
/** JPEG/WebP 质量 (0-1) */
|
|
59
|
+
quality?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 图像色阶分析结果
|
|
63
|
+
*/
|
|
64
|
+
interface ImageLevels {
|
|
65
|
+
/** 最暗像素值 (0-255) */
|
|
66
|
+
black: number;
|
|
67
|
+
/** 最亮像素值 (0-255) */
|
|
68
|
+
white: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 图像分析结果
|
|
72
|
+
*/
|
|
73
|
+
interface ImageAnalysis {
|
|
74
|
+
/** 色阶信息 */
|
|
75
|
+
levels: ImageLevels;
|
|
76
|
+
/** 鲜艳度 (0-1) */
|
|
77
|
+
vibrance: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 预设滤镜类型
|
|
81
|
+
*/
|
|
82
|
+
type PresetType = 'auto' | 'blackAndWhite' | 'pop' | 'vintage' | 'vivid' | 'cinematic';
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 默认设置
|
|
86
|
+
*/
|
|
87
|
+
declare const defaultSettings: ColorGradingSettings;
|
|
88
|
+
/**
|
|
89
|
+
* 预设滤镜配置
|
|
90
|
+
*/
|
|
91
|
+
declare const presets: Record<PresetType, PartialColorGradingSettings>;
|
|
92
|
+
/**
|
|
93
|
+
* 分析图像获取黑白色阶信息
|
|
94
|
+
* 使用直方图分析,忽略极端少数的像素值
|
|
95
|
+
* @param imageData - ImageData 对象
|
|
96
|
+
* @returns {black, white} 分别表示有效的最暗和最亮的亮度值 (0-255)
|
|
97
|
+
*/
|
|
98
|
+
declare function analyzeImageLevels(imageData: ImageData): ImageLevels;
|
|
99
|
+
/**
|
|
100
|
+
* 分析图像的饱和度/鲜艳度
|
|
101
|
+
* 使用 HSV 色彩空间计算,返回 0-1 之间的值
|
|
102
|
+
* @param imageData - ImageData 对象
|
|
103
|
+
* @returns 鲜艳度值 (0-1)
|
|
104
|
+
*/
|
|
105
|
+
declare function analyzeImageVibrance(imageData: ImageData): number;
|
|
106
|
+
/**
|
|
107
|
+
* 分析图像
|
|
108
|
+
* @param imageData - ImageData 对象
|
|
109
|
+
* @returns 图像分析结果
|
|
110
|
+
*/
|
|
111
|
+
declare function analyzeImage(imageData: ImageData): ImageAnalysis;
|
|
112
|
+
/**
|
|
113
|
+
* 图像调色处理器
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const processor = new ImageColorGrading();
|
|
118
|
+
* await processor.loadImage('path/to/image.jpg');
|
|
119
|
+
* processor.setSettings({ brightness: 20, contrast: 10 });
|
|
120
|
+
* processor.render();
|
|
121
|
+
* const dataUrl = processor.toDataURL();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare class ImageColorGrading {
|
|
125
|
+
private canvas;
|
|
126
|
+
private resources;
|
|
127
|
+
private settings;
|
|
128
|
+
private imageLoaded;
|
|
129
|
+
/**
|
|
130
|
+
* 创建图像调色处理器
|
|
131
|
+
* @param canvas - 可选的 canvas 元素,不传则自动创建
|
|
132
|
+
*/
|
|
133
|
+
constructor(canvas?: HTMLCanvasElement);
|
|
134
|
+
/**
|
|
135
|
+
* 获取 canvas 元素
|
|
136
|
+
*/
|
|
137
|
+
getCanvas(): HTMLCanvasElement;
|
|
138
|
+
/**
|
|
139
|
+
* 获取当前设置
|
|
140
|
+
*/
|
|
141
|
+
getSettings(): ColorGradingSettings;
|
|
142
|
+
/**
|
|
143
|
+
* 设置调色参数
|
|
144
|
+
* @param newSettings - 部分或全部设置参数
|
|
145
|
+
*/
|
|
146
|
+
setSettings(newSettings: PartialColorGradingSettings): void;
|
|
147
|
+
/**
|
|
148
|
+
* 重置所有设置为默认值
|
|
149
|
+
*/
|
|
150
|
+
resetSettings(): void;
|
|
151
|
+
/**
|
|
152
|
+
* 从 URL 加载图像
|
|
153
|
+
* @param url - 图像 URL
|
|
154
|
+
* @returns Promise
|
|
155
|
+
*/
|
|
156
|
+
loadImage(url: string): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* 从 HTMLImageElement 加载图像
|
|
159
|
+
* @param image - 图像元素
|
|
160
|
+
*/
|
|
161
|
+
loadFromImage(image: HTMLImageElement): void;
|
|
162
|
+
/**
|
|
163
|
+
* 从 File 对象加载图像
|
|
164
|
+
* @param file - File 对象
|
|
165
|
+
* @returns Promise
|
|
166
|
+
*/
|
|
167
|
+
loadFromFile(file: File): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* 从 ImageData 加载图像
|
|
170
|
+
* @param imageData - ImageData 对象
|
|
171
|
+
*/
|
|
172
|
+
loadFromImageData(imageData: ImageData): void;
|
|
173
|
+
/**
|
|
174
|
+
* 渲染图像
|
|
175
|
+
*/
|
|
176
|
+
render(): void;
|
|
177
|
+
/**
|
|
178
|
+
* 导出为 Data URL
|
|
179
|
+
* @param options - 导出选项
|
|
180
|
+
* @returns Data URL 字符串
|
|
181
|
+
*/
|
|
182
|
+
toDataURL(options?: ExportOptions): string;
|
|
183
|
+
/**
|
|
184
|
+
* 导出为 Blob
|
|
185
|
+
* @param options - 导出选项
|
|
186
|
+
* @returns Promise<Blob>
|
|
187
|
+
*/
|
|
188
|
+
toBlob(options?: ExportOptions): Promise<Blob>;
|
|
189
|
+
/**
|
|
190
|
+
* 获取 ImageData
|
|
191
|
+
* @returns ImageData
|
|
192
|
+
*/
|
|
193
|
+
getImageData(): ImageData;
|
|
194
|
+
/**
|
|
195
|
+
* 获取图像尺寸
|
|
196
|
+
*/
|
|
197
|
+
getSize(): {
|
|
198
|
+
width: number;
|
|
199
|
+
height: number;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 检查是否已加载图像
|
|
203
|
+
*/
|
|
204
|
+
isLoaded(): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* 销毁资源
|
|
207
|
+
*/
|
|
208
|
+
dispose(): void;
|
|
209
|
+
/**
|
|
210
|
+
* 分析当前加载的图像
|
|
211
|
+
* @returns 图像分析结果
|
|
212
|
+
*/
|
|
213
|
+
analyze(): ImageAnalysis;
|
|
214
|
+
/**
|
|
215
|
+
* 自动修复图像
|
|
216
|
+
* 分析图像并自动调整色阶和鲜艳度
|
|
217
|
+
* @returns 应用的设置
|
|
218
|
+
*/
|
|
219
|
+
autoFix(): ColorGradingSettings;
|
|
220
|
+
/**
|
|
221
|
+
* 应用预设滤镜
|
|
222
|
+
* @param preset - 预设类型
|
|
223
|
+
* @returns 应用的设置
|
|
224
|
+
*/
|
|
225
|
+
applyPreset(preset: PresetType): ColorGradingSettings;
|
|
226
|
+
private getWebGLContext;
|
|
227
|
+
private initFromImage;
|
|
228
|
+
private initResources;
|
|
229
|
+
private disposeResources;
|
|
230
|
+
private drawFrame;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, presets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,233 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
* 调色设置参数
|
|
3
|
+
*/
|
|
4
|
+
interface ColorGradingSettings {
|
|
5
|
+
/** 自然饱和度 (-100 ~ 100) */
|
|
6
|
+
vibrance: number;
|
|
7
|
+
/** 饱和度 (-100 ~ 100) */
|
|
8
|
+
saturation: number;
|
|
9
|
+
/** 色温 (-100 ~ 100) */
|
|
10
|
+
temperature: number;
|
|
11
|
+
/** 色调 (-100 ~ 100) */
|
|
12
|
+
tint: number;
|
|
13
|
+
/** 色相 (-100 ~ 100) */
|
|
14
|
+
hue: number;
|
|
15
|
+
/** 亮度 (-100 ~ 100) */
|
|
16
|
+
brightness: number;
|
|
17
|
+
/** 曝光度 (-100 ~ 100) */
|
|
18
|
+
exposure: number;
|
|
19
|
+
/** 对比度 (-100 ~ 100) */
|
|
20
|
+
contrast: number;
|
|
21
|
+
/** 黑色 (-100 ~ 100) */
|
|
22
|
+
blacks: number;
|
|
23
|
+
/** 白色 (-100 ~ 100) */
|
|
24
|
+
whites: number;
|
|
25
|
+
/** 高光 (-100 ~ 100) */
|
|
26
|
+
highlights: number;
|
|
27
|
+
/** 暗调 (-100 ~ 100) */
|
|
28
|
+
shadows: number;
|
|
29
|
+
/** 除雾化 (0 ~ 100) */
|
|
30
|
+
dehaze: number;
|
|
31
|
+
/** 泛光 (0 ~ 100) */
|
|
32
|
+
bloom: number;
|
|
33
|
+
/** 氛围美化 (0 ~ 100) */
|
|
34
|
+
glamour: number;
|
|
35
|
+
/** 清晰度 (-100 ~ 100) */
|
|
36
|
+
clarity: number;
|
|
37
|
+
/** 锐化 (0 ~ 100) */
|
|
38
|
+
sharpen: number;
|
|
39
|
+
/** 平滑 (0 ~ 100) */
|
|
40
|
+
smooth: number;
|
|
41
|
+
/** 模糊 (0 ~ 100) */
|
|
42
|
+
blur: number;
|
|
43
|
+
/** 暗角 (-100 ~ 100) */
|
|
44
|
+
vignette: number;
|
|
45
|
+
/** 颗粒 (0 ~ 100) */
|
|
46
|
+
grain: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 部分调色设置参数
|
|
50
|
+
*/
|
|
51
|
+
type PartialColorGradingSettings = Partial<ColorGradingSettings>;
|
|
52
|
+
/**
|
|
53
|
+
* 导出选项
|
|
54
|
+
*/
|
|
55
|
+
interface ExportOptions {
|
|
56
|
+
/** 导出格式 */
|
|
57
|
+
format?: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
58
|
+
/** JPEG/WebP 质量 (0-1) */
|
|
59
|
+
quality?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 图像色阶分析结果
|
|
63
|
+
*/
|
|
64
|
+
interface ImageLevels {
|
|
65
|
+
/** 最暗像素值 (0-255) */
|
|
66
|
+
black: number;
|
|
67
|
+
/** 最亮像素值 (0-255) */
|
|
68
|
+
white: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 图像分析结果
|
|
72
|
+
*/
|
|
73
|
+
interface ImageAnalysis {
|
|
74
|
+
/** 色阶信息 */
|
|
75
|
+
levels: ImageLevels;
|
|
76
|
+
/** 鲜艳度 (0-1) */
|
|
77
|
+
vibrance: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 预设滤镜类型
|
|
81
|
+
*/
|
|
82
|
+
type PresetType = 'auto' | 'blackAndWhite' | 'pop' | 'vintage' | 'vivid' | 'cinematic';
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 默认设置
|
|
86
|
+
*/
|
|
87
|
+
declare const defaultSettings: ColorGradingSettings;
|
|
88
|
+
/**
|
|
89
|
+
* 预设滤镜配置
|
|
90
|
+
*/
|
|
91
|
+
declare const presets: Record<PresetType, PartialColorGradingSettings>;
|
|
92
|
+
/**
|
|
93
|
+
* 分析图像获取黑白色阶信息
|
|
94
|
+
* 使用直方图分析,忽略极端少数的像素值
|
|
95
|
+
* @param imageData - ImageData 对象
|
|
96
|
+
* @returns {black, white} 分别表示有效的最暗和最亮的亮度值 (0-255)
|
|
97
|
+
*/
|
|
98
|
+
declare function analyzeImageLevels(imageData: ImageData): ImageLevels;
|
|
99
|
+
/**
|
|
100
|
+
* 分析图像的饱和度/鲜艳度
|
|
101
|
+
* 使用 HSV 色彩空间计算,返回 0-1 之间的值
|
|
102
|
+
* @param imageData - ImageData 对象
|
|
103
|
+
* @returns 鲜艳度值 (0-1)
|
|
104
|
+
*/
|
|
105
|
+
declare function analyzeImageVibrance(imageData: ImageData): number;
|
|
106
|
+
/**
|
|
107
|
+
* 分析图像
|
|
108
|
+
* @param imageData - ImageData 对象
|
|
109
|
+
* @returns 图像分析结果
|
|
110
|
+
*/
|
|
111
|
+
declare function analyzeImage(imageData: ImageData): ImageAnalysis;
|
|
112
|
+
/**
|
|
113
|
+
* 图像调色处理器
|
|
5
114
|
*
|
|
6
115
|
* @example
|
|
7
116
|
* ```ts
|
|
8
|
-
* import { ImageColorGrading, defaultSettings } from 'image-color-grading';
|
|
9
|
-
*
|
|
10
117
|
* const processor = new ImageColorGrading();
|
|
11
118
|
* await processor.loadImage('path/to/image.jpg');
|
|
12
|
-
* processor.setSettings({
|
|
13
|
-
*
|
|
14
|
-
* contrast: 10,
|
|
15
|
-
* saturation: 15
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
119
|
+
* processor.setSettings({ brightness: 20, contrast: 10 });
|
|
120
|
+
* processor.render();
|
|
18
121
|
* const dataUrl = processor.toDataURL();
|
|
19
122
|
* ```
|
|
20
123
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
124
|
+
declare class ImageColorGrading {
|
|
125
|
+
private canvas;
|
|
126
|
+
private resources;
|
|
127
|
+
private settings;
|
|
128
|
+
private imageLoaded;
|
|
129
|
+
/**
|
|
130
|
+
* 创建图像调色处理器
|
|
131
|
+
* @param canvas - 可选的 canvas 元素,不传则自动创建
|
|
132
|
+
*/
|
|
133
|
+
constructor(canvas?: HTMLCanvasElement);
|
|
134
|
+
/**
|
|
135
|
+
* 获取 canvas 元素
|
|
136
|
+
*/
|
|
137
|
+
getCanvas(): HTMLCanvasElement;
|
|
138
|
+
/**
|
|
139
|
+
* 获取当前设置
|
|
140
|
+
*/
|
|
141
|
+
getSettings(): ColorGradingSettings;
|
|
142
|
+
/**
|
|
143
|
+
* 设置调色参数
|
|
144
|
+
* @param newSettings - 部分或全部设置参数
|
|
145
|
+
*/
|
|
146
|
+
setSettings(newSettings: PartialColorGradingSettings): void;
|
|
147
|
+
/**
|
|
148
|
+
* 重置所有设置为默认值
|
|
149
|
+
*/
|
|
150
|
+
resetSettings(): void;
|
|
151
|
+
/**
|
|
152
|
+
* 从 URL 加载图像
|
|
153
|
+
* @param url - 图像 URL
|
|
154
|
+
* @returns Promise
|
|
155
|
+
*/
|
|
156
|
+
loadImage(url: string): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* 从 HTMLImageElement 加载图像
|
|
159
|
+
* @param image - 图像元素
|
|
160
|
+
*/
|
|
161
|
+
loadFromImage(image: HTMLImageElement): void;
|
|
162
|
+
/**
|
|
163
|
+
* 从 File 对象加载图像
|
|
164
|
+
* @param file - File 对象
|
|
165
|
+
* @returns Promise
|
|
166
|
+
*/
|
|
167
|
+
loadFromFile(file: File): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* 从 ImageData 加载图像
|
|
170
|
+
* @param imageData - ImageData 对象
|
|
171
|
+
*/
|
|
172
|
+
loadFromImageData(imageData: ImageData): void;
|
|
173
|
+
/**
|
|
174
|
+
* 渲染图像
|
|
175
|
+
*/
|
|
176
|
+
render(): void;
|
|
177
|
+
/**
|
|
178
|
+
* 导出为 Data URL
|
|
179
|
+
* @param options - 导出选项
|
|
180
|
+
* @returns Data URL 字符串
|
|
181
|
+
*/
|
|
182
|
+
toDataURL(options?: ExportOptions): string;
|
|
183
|
+
/**
|
|
184
|
+
* 导出为 Blob
|
|
185
|
+
* @param options - 导出选项
|
|
186
|
+
* @returns Promise<Blob>
|
|
187
|
+
*/
|
|
188
|
+
toBlob(options?: ExportOptions): Promise<Blob>;
|
|
189
|
+
/**
|
|
190
|
+
* 获取 ImageData
|
|
191
|
+
* @returns ImageData
|
|
192
|
+
*/
|
|
193
|
+
getImageData(): ImageData;
|
|
194
|
+
/**
|
|
195
|
+
* 获取图像尺寸
|
|
196
|
+
*/
|
|
197
|
+
getSize(): {
|
|
198
|
+
width: number;
|
|
199
|
+
height: number;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 检查是否已加载图像
|
|
203
|
+
*/
|
|
204
|
+
isLoaded(): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* 销毁资源
|
|
207
|
+
*/
|
|
208
|
+
dispose(): void;
|
|
209
|
+
/**
|
|
210
|
+
* 分析当前加载的图像
|
|
211
|
+
* @returns 图像分析结果
|
|
212
|
+
*/
|
|
213
|
+
analyze(): ImageAnalysis;
|
|
214
|
+
/**
|
|
215
|
+
* 自动修复图像
|
|
216
|
+
* 分析图像并自动调整色阶和鲜艳度
|
|
217
|
+
* @returns 应用的设置
|
|
218
|
+
*/
|
|
219
|
+
autoFix(): ColorGradingSettings;
|
|
220
|
+
/**
|
|
221
|
+
* 应用预设滤镜
|
|
222
|
+
* @param preset - 预设类型
|
|
223
|
+
* @returns 应用的设置
|
|
224
|
+
*/
|
|
225
|
+
applyPreset(preset: PresetType): ColorGradingSettings;
|
|
226
|
+
private getWebGLContext;
|
|
227
|
+
private initFromImage;
|
|
228
|
+
private initResources;
|
|
229
|
+
private disposeResources;
|
|
230
|
+
private drawFrame;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { type ColorGradingSettings, type ExportOptions, type ImageAnalysis, ImageColorGrading, type ImageLevels, type PartialColorGradingSettings, type PresetType, analyzeImage, analyzeImageLevels, analyzeImageVibrance, defaultSettings, presets };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module image-color-grading
|
|
3
|
-
*
|
|
4
|
-
* 基于 WebGL 的高性能图像调色库
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { ImageColorGrading, defaultSettings } from 'image-color-grading';
|
|
9
|
-
*
|
|
10
|
-
* const processor = new ImageColorGrading();
|
|
11
|
-
* await processor.loadImage('path/to/image.jpg');
|
|
12
|
-
* processor.setSettings({
|
|
13
|
-
* brightness: 20,
|
|
14
|
-
* contrast: 10,
|
|
15
|
-
* saturation: 15
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* const dataUrl = processor.toDataURL();
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export { ImageColorGrading, defaultSettings } from './processor';
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
var e="\nprecision highp float;\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nvarying vec2 vUv;\nvoid main() {\n vUv = aTexCoord;\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n",n="\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform vec2 uTexel;\nuniform float uKernel[9];\nuniform float uAmount;\nvoid main(void) {\n vec4 c11 = texture2D(uTexture, vUv - uTexel);\n vec4 c12 = texture2D(uTexture, vec2(vUv.x, vUv.y - uTexel.y));\n vec4 c13 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y - uTexel.y));\n vec4 c21 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y));\n vec4 c22 = texture2D(uTexture, vUv);\n vec4 c23 = texture2D(uTexture, vec2(vUv.x + uTexel.x, vUv.y));\n vec4 c31 = texture2D(uTexture, vec2(vUv.x - uTexel.x, vUv.y + uTexel.y));\n vec4 c32 = texture2D(uTexture, vec2(vUv.x, vUv.y + uTexel.y));\n vec4 c33 = texture2D(uTexture, vUv + uTexel);\n vec4 color = c11 * uKernel[0] + c12 * uKernel[1] + c13 * uKernel[2] +\n c21 * uKernel[3] + c22 * uKernel[4] + c23 * uKernel[5] +\n c31 * uKernel[6] + c32 * uKernel[7] + c33 * uKernel[8];\n gl_FragColor = color * uAmount + (c22 * (1.0 - uAmount));\n}\n";function t(e,n,t){const r=e.createShader(n);return r?(e.shaderSource(r,t),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null}function r(e,n,r,o){const a=t(e,e.VERTEX_SHADER,n),i=t(e,e.FRAGMENT_SHADER,r);if(!a||!i)throw new Error("Shader compile failed.");const c=function(e,n,t){const r=e.createProgram();return r?(e.attachShader(r,n),e.attachShader(r,t),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(e.deleteProgram(r),null)):null}(e,a,i);if(!c)throw new Error("Program link failed.");const u={aPosition:e.getAttribLocation(c,"aPosition"),aTexCoord:e.getAttribLocation(c,"aTexCoord"),apos:e.getAttribLocation(c,"apos"),auv:e.getAttribLocation(c,"auv")},l={};return o.forEach(n=>{l[n]=e.getUniformLocation(c,n)}),{program:c,attribs:u,uniforms:l}}function o(e,n,t){const r=e.createTexture();if(!r)throw new Error("Unable to create texture");e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);const o=e.createFramebuffer();if(!o)throw new Error("Unable to create framebuffer");return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0),{framebuffer:o,texture:r}}var a=e=>Math.min(1,Math.max(0,e)),i=(e,n,t,r,o)=>{const a=1-e;return a*a*a*n+3*a*a*e*t+3*a*e*e*r+e*e*e*o},c=e=>{const n=Math.max(-100,Math.min(100,e))/100;return(e=>{const n=new Uint8Array(768);for(let t=0;t<256;t+=1){const r=i(t/255,0,e,.66,1),o=Math.round(255*a(r)),c=3*t;n[c]=o,n[c+1]=o,n[c+2]=o}return n})(a(.33-.35*n))},u={vibrance:0,saturation:0,temperature:0,tint:0,hue:0,brightness:0,exposure:0,contrast:0,blacks:0,whites:0,highlights:0,shadows:0,dehaze:0,bloom:0,glamour:0,clarity:0,sharpen:0,smooth:0,blur:0,vignette:0,grain:0},l={auto:{},blackAndWhite:{saturation:-100,contrast:20,exposure:10,clarity:10},pop:{highlights:50,shadows:-50,vibrance:50,saturation:20,exposure:20,clarity:20},vintage:{saturation:-20,contrast:10,temperature:15,grain:30,vignette:25},vivid:{vibrance:40,saturation:20,contrast:15,clarity:20},cinematic:{contrast:25,highlights:-20,shadows:15,temperature:-10,vignette:30}};function s(e){const{data:n,width:t,height:r}=e,o=new Array(256).fill(0);for(let e=0;e<n.length;e+=4)o[n[e]]+=1,o[n[e+1]]+=1,o[n[e+2]]+=1;const a=Math.round(t*r/1e3);let i=0;for(let e=0;e<256;e++)if(o[e]>a){i=e;break}let c=255;for(let e=255;e>=0;e--)if(o[e]>a){c=e;break}return i>100&&(i=100),c<155&&(c=155),{black:i,white:c}}function v(e){const{data:n,width:t,height:r}=e;let o=1,a=1;for(let e=0;e<n.length;e+=4){const t=n[e],r=n[e+1],i=n[e+2],c=Math.min(t,r,i),u=Math.max(t,r,i);a+=u/255;const l=u-c;l>0&&(o+=l/u)}return(o+a)/(t*r*2)}function m(e){return{levels:s(e),vibrance:v(e)}}var x=class{constructor(e){this.resources=null,this.settings={...u},this.imageLoaded=!1,this.canvas=e||document.createElement("canvas")}getCanvas(){return this.canvas}getSettings(){return{...this.settings}}setSettings(e){this.settings={...this.settings,...e},this.resources&&this.render()}resetSettings(){this.settings={...u},this.resources&&this.render()}loadImage(e){return new Promise((n,t)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{this.initFromImage(r),n()},r.onerror=()=>{t(new Error(`Failed to load image: ${e}`))},r.src=e})}loadFromImage(e){this.initFromImage(e)}loadFromFile(e){return new Promise((n,t)=>{const r=URL.createObjectURL(e);this.loadImage(r).then(()=>{URL.revokeObjectURL(r),n()}).catch(e=>{URL.revokeObjectURL(r),t(e)})})}loadFromImageData(e){const{width:n,height:t,data:r}=e;this.canvas.width=n,this.canvas.height=t;const o=this.getWebGLContext();if(!o)throw new Error("WebGL not supported");this.disposeResources(),o.viewport(0,0,n,t),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1);const a=o.createTexture();if(!a)throw new Error("Failed to create texture");o.bindTexture(o.TEXTURE_2D,a),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,n,t,0,o.RGBA,o.UNSIGNED_BYTE,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.initResources(o,n,t,a)}render(){this.resources&&this.drawFrame(this.resources,this.settings)}toDataURL(e){const n=e?.format||"image/png",t=e?.quality;return this.canvas.toDataURL(n,t)}toBlob(e){return new Promise((n,t)=>{const r=e?.format||"image/png",o=e?.quality;this.canvas.toBlob(e=>{e?n(e):t(new Error("Failed to create blob"))},r,o)})}getImageData(){const e=this.canvas.getContext("2d");if(e)return e.getImageData(0,0,this.canvas.width,this.canvas.height);const n=this.canvas.getContext("webgl");if(n){const e=new Uint8ClampedArray(this.canvas.width*this.canvas.height*4);return n.readPixels(0,0,this.canvas.width,this.canvas.height,n.RGBA,n.UNSIGNED_BYTE,e),new ImageData(e,this.canvas.width,this.canvas.height)}throw new Error("Cannot get ImageData")}getSize(){return{width:this.canvas.width,height:this.canvas.height}}isLoaded(){return this.imageLoaded}dispose(){this.disposeResources(),this.imageLoaded=!1}analyze(){if(!this.imageLoaded)throw new Error("No image loaded");const e={...this.settings};this.settings={...u},this.render();const n=m(this.getImageData());return this.settings=e,this.render(),n}autoFix(){if(!this.imageLoaded)throw new Error("No image loaded");this.settings={...u},this.render();const e=this.getImageData(),n=s(e),t=v(e),r={...u};if(r.whites=Math.round(255-n.white),r.blacks=Math.round(n.black),t<.7){const e=Math.round(100*(.7-t));r.vibrance=Math.min(e,50)}return this.settings=r,this.render(),r}applyPreset(e){if("auto"===e)return this.autoFix();const n=l[e],t={...u,...n};return this.settings=t,this.resources&&this.render(),t}getWebGLContext(){return this.canvas.getContext("webgl",{antialias:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0})}initFromImage(e){const n=e.naturalWidth||e.width,t=e.naturalHeight||e.height;this.canvas.width=n,this.canvas.height=t;const r=this.getWebGLContext();if(!r)throw new Error("WebGL not supported");this.disposeResources(),r.disable(r.DEPTH_TEST),r.viewport(0,0,n,t),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1);const o=r.createTexture();if(!o)throw new Error("Failed to create texture");r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),this.initResources(r,n,t,o)}initResources(t,a,i,u){const l=((e,n)=>{const t=e.createTexture();if(!t)throw new Error("Unable to create palette texture");return e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,0,e.RGB,256,1,0,e.RGB,e.UNSIGNED_BYTE,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t})(t,c(0)),s=t.createBuffer(),v=t.createBuffer();if(!s||!v)throw new Error("Failed to create buffers");t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,v),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),t.STATIC_DRAW);const m={pass:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nvoid main() {\n gl_FragColor = texture2D(uTexture, vUv);\n}\n",["uTexture"]),vibrance:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 col = texture2D(uTexture, vUv);\n vec3 color = col.rgb;\n float luminance = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;\n float mn = min(min(color.r, color.g), color.b);\n float mx = max(max(color.r, color.g), color.b);\n float sat = (1.0 - (mx - mn)) * (1.0 - mx) * luminance * 5.0;\n vec3 lightness = vec3((mn + mx) / 2.0);\n color = mix(color, mix(color, lightness, -uAmount), sat);\n gl_FragColor = vec4(\n mix(color, lightness, (1.0 - lightness) * (1.0 - uAmount) / 2.0 * abs(uAmount)),\n col.a\n );\n}\n",["uTexture","uAmount"]),saturation:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uMatrix[20];\nvoid main(void) {\n vec4 c = texture2D(uTexture, vUv);\n gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];\n gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];\n gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];\n gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];\n}\n",["uTexture","uMatrix[0]"]),temperature:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n color.r = clamp(color.r + uAmount, 0.0, 1.0);\n color.b = clamp(color.b - uAmount, 0.0, 1.0);\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),tint:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n color.g = clamp(color.g + uAmount, 0.0, 1.0);\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),hue:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uRotation;\nvec3 rgb2hsv(vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvoid main() {\n lowp vec4 base = texture2D(uTexture, vUv);\n vec3 hsv = rgb2hsv(base.rgb);\n hsv.x = fract(hsv.x + uRotation);\n gl_FragColor = vec4(hsv2rgb(hsv), base.a);\n}\n",["uTexture","uRotation"]),brightness:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float PI = 3.1415926535897932384626433832795;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n if (uAmount >= 0.0) {\n color.r = color.r + uAmount * sin(color.r * PI);\n color.g = color.g + uAmount * sin(color.g * PI);\n color.b = color.b + uAmount * sin(color.b * PI);\n } else {\n color.r = (1.0 + uAmount) * color.r;\n color.g = (1.0 + uAmount) * color.g;\n color.b = (1.0 + uAmount) * color.b;\n }\n gl_FragColor = color;\n}\n",["uTexture","uAmount"]),exposure:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat ramp(in float t) {\n t *= 2.0;\n if (t >= 1.0) {\n t -= 1.0;\n t = log(0.5) / log(0.5 * (1.0 - t) + 0.9332 * t);\n }\n return clamp(t, 0.001, 10.0);\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n vec3 base = col.rgb * matRGBtoROMM;\n float a = abs(uAmount) * col.a + epsilon;\n float v = pow(2.0, a * 2.0 + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (uAmount > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = pow(res, vec3(ramp(1.0 - (0.0 * col.a + 1.0) / 2.0)));\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),contrast:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uMatrix[20];\nvoid main(void) {\n vec4 c = texture2D(uTexture, vUv);\n gl_FragColor.r = uMatrix[0] * c.r + uMatrix[1] * c.g + uMatrix[2] * c.b + uMatrix[3] * c.a + uMatrix[4];\n gl_FragColor.g = uMatrix[5] * c.r + uMatrix[6] * c.g + uMatrix[7] * c.b + uMatrix[8] * c.a + uMatrix[9];\n gl_FragColor.b = uMatrix[10] * c.r + uMatrix[11] * c.g + uMatrix[12] * c.b + uMatrix[13] * c.a + uMatrix[14];\n gl_FragColor.a = uMatrix[15] * c.r + uMatrix[16] * c.g + uMatrix[17] * c.b + uMatrix[18] * c.a + uMatrix[19];\n}\n",["uTexture","uMatrix[0]"]),blacks:r(t,"\nprecision highp float;\nattribute vec2 apos;\nattribute vec2 auv;\nvarying vec2 uv;\nuniform vec4 transform;\nvoid main(void) {\n uv = auv;\n gl_Position = vec4(\n apos.x * transform.x + transform.z,\n apos.y * transform.y + transform.w,\n 0.0,\n 1.0\n );\n}\n","\nprecision highp float;\nvarying vec2 uv;\nuniform sampler2D uTexture;\nuniform sampler2D uPaletteMap;\nvoid main() {\n lowp vec4 base = texture2D(uTexture, uv.xy);\n float r = texture2D(uPaletteMap, vec2(base.r, 0.0)).r;\n float g = texture2D(uPaletteMap, vec2(base.g, 0.0)).g;\n float b = texture2D(uPaletteMap, vec2(base.b, 0.0)).b;\n gl_FragColor = vec4(r, g, b, base.a);\n}\n",["uTexture","uPaletteMap","transform"]),whites:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst vec3 RGB2Y = vec3(0.2126, 0.7152, 0.0722);\nvoid main() {\n vec4 base = texture2D(uTexture, vUv.xy);\n vec3 color = base.rgb;\n float lum = dot(color, RGB2Y);\n float whiteMask = smoothstep(0.5, 1.0, lum);\n color += uAmount * whiteMask;\n gl_FragColor = vec4(clamp(color, 0.0, 1.0), base.a);\n}\n",["uTexture","uAmount"]),highlights:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst float PI = 3.1415926535897932384626433832795;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat luma_romm(in vec3 color) {\n return dot(color, vec3(0.242655, 0.755158, 0.002187));\n}\nfloat luma(in vec3 color) {\n return dot(color, vec3(0.298839, 0.586811, 0.11435));\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nfloat gaussian(in float x) {\n return 1.0 - exp(-PI * 2.0 * x * x);\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n lowp vec3 map = col.rgb;\n vec3 base = col.rgb * matRGBtoROMM;\n float base_lum = luma(col.rgb);\n float map_lum = luma_romm(map * matRGBtoROMM);\n float exposure = mix(uAmount, 0.0, 1.0 - map_lum) * col.a;\n float a = abs(exposure) * col.a + epsilon;\n float v = pow(2.0, a + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),shadows:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nconst float epsilon = 0.000001;\nconst float mx = 1.0 - epsilon;\nconst float PI = 3.1415926535897932384626433832795;\nconst mat3 matRGBtoROMM = mat3(\n 0.5293459296226501, 0.3300727903842926, 0.14058130979537964,\n 0.09837432950735092, 0.8734610080718994, 0.028164653107523918,\n 0.01688321679830551, 0.11767247319221497, 0.8654443025588989\n);\nconst mat3 matROMMtoRGB = mat3(\n 2.0340757369995117, -0.727334201335907, -0.3067416846752167,\n -0.22881317138671875, 1.2317301034927368, -0.0029169507324695587,\n -0.008569774217903614, -0.1532866358757019, 1.1618564128875732\n);\nfloat luma_romm(in vec3 color) {\n return dot(color, vec3(0.242655, 0.755158, 0.002187));\n}\nfloat luma(in vec3 color) {\n return dot(color, vec3(0.298839, 0.586811, 0.11435));\n}\nvec3 rgb2hsv(in vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\nvec3 hsv2rgb(in vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\nvec3 setHue(in vec3 res, in vec3 base) {\n vec3 hsv = rgb2hsv(base);\n vec3 res_hsv = rgb2hsv(res);\n return hsv2rgb(vec3(hsv.x, res_hsv.y, res_hsv.z));\n}\nfloat gaussian(in float x) {\n return 1.0 - exp(-PI * 2.0 * x * x);\n}\nvoid main() {\n lowp vec4 col = texture2D(uTexture, vUv);\n lowp vec3 map = col.rgb;\n vec3 base = col.rgb * matRGBtoROMM;\n float base_lum = luma(col.rgb);\n float map_lum = luma_romm(map * matRGBtoROMM);\n float exposure = mix(0.0, uAmount, 1.0 - map_lum) * col.a;\n float a = abs(exposure) * col.a + epsilon;\n float v = pow(2.0, a + 1.0) - 2.0;\n float m = mx - exp(-v);\n vec3 res = (exposure > 0.0) ? (1.0 - exp(-v * base)) / m : log(1.0 - base * m) / -v;\n res = mix(base, res, min(a * 100.0, 1.0));\n res = setHue(res, base);\n res = res * matROMMtoRGB;\n gl_FragColor = vec4(res, col.a);\n}\n",["uTexture","uAmount"]),dehaze:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uSize;\n\nfloat hazeMap(vec2 coord) {\n vec3 color = vec3(1.0);\n vec2 stepSize = vec2(1.0 / uSize.x, 1.0 / uSize.y);\n for (int i = -1; i <= 1; ++i) {\n for (int j = -1; j <= 1; ++j) {\n vec2 offset = vec2(float(i), float(j)) * stepSize;\n vec2 uv = clamp(coord + offset, 0.0, 1.0);\n vec3 sample = texture2D(uTexture, uv).rgb;\n color = min(color, sample);\n }\n }\n return min(color.r, min(color.g, color.b));\n}\n\nvoid main() {\n vec4 base = texture2D(uTexture, vUv);\n float haze = hazeMap(vUv);\n float transmission = 1.0 - 0.95 * haze;\n const float A = 0.95;\n const float t0 = 0.1;\n float t = mix(1.0, max(t0, transmission), uAmount);\n vec3 J = (base.rgb - A) / t + A;\n gl_FragColor = vec4(J, base.a);\n}\n",["uTexture","uAmount","uSize"]),bloom:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\nuniform float uThreshold;\n\nvoid main() {\n vec4 sum = vec4(0.0);\n int j = -2;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = -1;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 0;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 1;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n j = 2;\n for (int i = -2; i <= 2; i++) sum += texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel);\n sum /= 25.0;\n vec4 base = texture2D(uTexture, vUv);\n if (length(sum.rgb) > uThreshold) {\n base += sum * uAmount;\n }\n gl_FragColor = base;\n}\n",["uTexture","uAmount","uTexel","uThreshold"]),glamour:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\n\nfloat normpdf(in float x, in float sigma) {\n return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;\n}\n\nvec3 blurMap() {\n const int mSize = 11;\n const int kSize = (mSize - 1) / 2;\n float kernel[mSize];\n vec3 final_colour = vec3(0.0);\n float sigma = 7.0;\n float Z = 0.0;\n for (int j = 0; j <= kSize; ++j) {\n kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);\n }\n for (int j = 0; j < mSize; ++j) {\n Z += kernel[j];\n }\n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n final_colour += kernel[kSize + j] * kernel[kSize + i] *\n texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;\n }\n }\n return vec3(final_colour / (Z * Z));\n}\n\nfloat luma(vec3 color) {\n return dot(color, vec3(0.299, 0.587, 0.114));\n}\n\nvoid main() {\n vec4 base = texture2D(uTexture, vUv);\n vec3 color = blurMap();\n color = vec3(luma(color));\n color = vec3(\n (base.r <= 0.5) ? (2.0 * base.r * color.r) : (1.0 - 2.0 * (1.0 - base.r) * (1.0 - color.r)),\n (base.g <= 0.5) ? (2.0 * base.g * color.g) : (1.0 - 2.0 * (1.0 - base.g) * (1.0 - color.g)),\n (base.b <= 0.5) ? (2.0 * base.b * color.b) : (1.0 - 2.0 * (1.0 - base.b) * (1.0 - color.b))\n );\n gl_FragColor = mix(base, vec4(color, base.a), uAmount);\n}\n",["uTexture","uAmount","uTexel"]),clarity:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform vec2 uTexel;\n\nfloat Lum(vec3 c) {\n return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;\n}\nfloat BlendOverlayf(float base, float blend) {\n return (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)));\n}\nvec3 BlendOverlay(vec3 base, vec3 blend) {\n return vec3(BlendOverlayf(base.r, blend.r), BlendOverlayf(base.g, blend.g), BlendOverlayf(base.b, blend.b));\n}\nfloat BlendVividLightf(float base, float blend) {\n float BlendColorBurnf = (((2.0 * blend) == 0.0) ? (2.0 * blend) : max((1.0 - ((1.0 - base) / (2.0 * blend))), 0.0));\n float BlendColorDodgef = (((2.0 * (blend - 0.5)) == 1.0) ? (2.0 * (blend - 0.5)) : min(base / (1.0 - (2.0 * (blend - 0.5))), 1.0));\n return ((blend < 0.5) ? BlendColorBurnf : BlendColorDodgef);\n}\nvec3 BlendVividLight(vec3 base, vec3 blend) {\n return vec3(BlendVividLightf(base.r, blend.r), BlendVividLightf(base.g, blend.g), BlendVividLightf(base.b, blend.b));\n}\nfloat normpdf(in float x, in float sigma) {\n return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;\n}\nvec3 blurMap() {\n const int mSize = 11;\n const int kSize = (mSize - 1) / 2;\n float kernel[mSize];\n vec3 final_colour = vec3(0.0);\n float sigma = 7.0;\n float Z = 0.0;\n for (int j = 0; j <= kSize; ++j) {\n kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);\n }\n for (int j = 0; j < mSize; ++j) {\n Z += kernel[j];\n }\n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n final_colour += kernel[kSize + j] * kernel[kSize + i] *\n texture2D(uTexture, vUv + vec2(float(i), float(j)) * uTexel).rgb;\n }\n }\n return vec3(final_colour / (Z * Z));\n}\nvoid main() {\n vec4 base4 = texture2D(uTexture, vUv);\n vec3 blur = blurMap();\n vec3 base = base4.rgb;\n float intensity = (uAmount < 0.0) ? (uAmount / 2.0) : uAmount;\n float lum = Lum(base);\n vec3 col = vec3(lum);\n vec3 mask = vec3(1.0 - pow(lum, 1.8));\n vec3 layer = vec3(1.0 - Lum(blur));\n vec3 detail = clamp(BlendVividLight(col, layer), 0.0, 1.0);\n vec3 inverse = mix(1.0 - detail, detail, (intensity + 1.0) / 2.0);\n gl_FragColor = vec4(BlendOverlay(base, mix(vec3(0.5), inverse, mask)), base4.a);\n}\n",["uTexture","uAmount","uTexel"]),sharpen:r(t,e,n,["uTexture","uTexel","uKernel[0]","uAmount"]),smooth:r(t,e,n,["uTexture","uTexel","uKernel[0]","uAmount"]),blur:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform vec2 uSize;\nfloat random(vec3 scale, float seed) {\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\nvoid main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n for (int t = -30; t <= 30; t++) {\n float percent = (float(t) + offset - 0.5) / 30.0;\n float weight = 1.0 - abs(percent);\n vec4 sample = texture2D(uTexture, vUv + uSize * percent);\n sample.rgb *= sample.a;\n color += sample * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n gl_FragColor.rgb /= gl_FragColor.a + 0.00001;\n}\n",["uTexture","uSize"]),vignette:r(t,e,"\nprecision highp float;\nvarying vec2 vUv;\nuniform sampler2D uTexture;\nuniform float uAmount;\nuniform float uSize;\nvoid main() {\n vec4 color = texture2D(uTexture, vUv);\n float dist = distance(vUv, vec2(0.5, 0.5));\n float amt = clamp(uAmount, -1.0, 1.0);\n float edge = dist * (abs(amt) * 0.75 + uSize * 2.0);\n float vignette = smoothstep(0.8, uSize * 0.799, edge);\n if (amt < 0.0) {\n vignette = 1.0 + (1.0 - vignette) * (-amt);\n } else {\n vignette = mix(1.0, vignette, amt);\n }\n color.rgb *= vignette;\n gl_FragColor = color;\n}\n",["uTexture","uAmount","uSize"]),grain:r(t,e,"\nprecision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vUv;\nuniform vec2 uResolution;\nuniform float uAmount;\nuniform float uTime;\nconst float permTexUnit = 1.0 / 256.0;\nconst float permTexUnitHalf = 0.5 / 256.0;\nfloat grainsize = 1.8;\nfloat lumamount = 1.0;\n\nvec4 rnm(in vec2 tc) {\n float noise = sin(dot(tc + vec2(uTime, uTime), vec2(12.9898, 78.233))) * 43758.5453;\n float noiseR = fract(noise) * 2.0 - 1.0;\n float noiseG = fract(noise * 1.2154) * 2.0 - 1.0;\n float noiseB = fract(noise * 1.3453) * 2.0 - 1.0;\n float noiseA = fract(noise * 1.3647) * 2.0 - 1.0;\n return vec4(noiseR, noiseG, noiseB, noiseA);\n}\nfloat fade(in float t) {\n return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n}\nfloat pnoise3D(in vec3 p) {\n vec3 pi = permTexUnit * floor(p) + permTexUnitHalf;\n vec3 pf = fract(p);\n float perm00 = rnm(pi.xy).a;\n vec3 grad000 = rnm(vec2(perm00, pi.z)).rgb * 4.0 - 1.0;\n float n000 = dot(grad000, pf);\n vec3 grad001 = rnm(vec2(perm00, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n001 = dot(grad001, pf - vec3(0.0, 0.0, 1.0));\n float perm01 = rnm(pi.xy + vec2(0.0, permTexUnit)).a;\n vec3 grad010 = rnm(vec2(perm01, pi.z)).rgb * 4.0 - 1.0;\n float n010 = dot(grad010, pf - vec3(0.0, 1.0, 0.0));\n vec3 grad011 = rnm(vec2(perm01, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n011 = dot(grad011, pf - vec3(0.0, 1.0, 1.0));\n float perm10 = rnm(pi.xy + vec2(permTexUnit, 0.0)).a;\n vec3 grad100 = rnm(vec2(perm10, pi.z)).rgb * 4.0 - 1.0;\n float n100 = dot(grad100, pf - vec3(1.0, 0.0, 0.0));\n vec3 grad101 = rnm(vec2(perm10, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n101 = dot(grad101, pf - vec3(1.0, 0.0, 1.0));\n float perm11 = rnm(pi.xy + vec2(permTexUnit, permTexUnit)).a;\n vec3 grad110 = rnm(vec2(perm11, pi.z)).rgb * 4.0 - 1.0;\n float n110 = dot(grad110, pf - vec3(1.0, 1.0, 0.0));\n vec3 grad111 = rnm(vec2(perm11, pi.z + permTexUnit)).rgb * 4.0 - 1.0;\n float n111 = dot(grad111, pf - vec3(1.0, 1.0, 1.0));\n vec4 n_x = mix(vec4(n000, n001, n010, n011), vec4(n100, n101, n110, n111), fade(pf.x));\n vec2 n_xy = mix(n_x.xy, n_x.zw, fade(pf.y));\n float n_xyz = mix(n_xy.x, n_xy.y, fade(pf.z));\n return n_xyz;\n}\nvec2 coordRot(in vec2 tc, in float angle) {\n float aspect = uResolution.x / uResolution.y;\n float rotX = ((tc.x * 2.0 - 1.0) * aspect * cos(angle)) - ((tc.y * 2.0 - 1.0) * sin(angle));\n float rotY = ((tc.y * 2.0 - 1.0) * cos(angle)) + ((tc.x * 2.0 - 1.0) * aspect * sin(angle));\n rotX = ((rotX / aspect) * 0.5 + 0.5);\n rotY = rotY * 0.5 + 0.5;\n return vec2(rotX, rotY);\n}\nvoid main() {\n vec3 rotOffset = vec3(1.425, 3.892, 5.835);\n vec2 rotCoordsR = coordRot(vUv, uTime + rotOffset.x);\n vec3 noise = vec3(pnoise3D(vec3(rotCoordsR * vec2(uResolution.x / grainsize, uResolution.y / grainsize), 0.0)));\n vec4 tex = texture2D(uTexture, vUv);\n vec3 col = tex.rgb;\n vec3 lumcoeff = vec3(0.299, 0.587, 0.114);\n float luminance = mix(0.0, dot(col, lumcoeff), lumamount);\n float lum = smoothstep(0.2, 0.0, luminance);\n lum += luminance;\n noise = mix(noise, vec3(0.0), pow(lum, 4.0));\n col = col + noise * uAmount;\n gl_FragColor = vec4(col, tex.a);\n}\n",["uTexture","uResolution","uAmount","uTime"])},x=[o(t,a,i),o(t,a,i)];this.resources={gl:t,width:a,height:i,sourceTexture:u,blackPalette:l,quad:{positionBuffer:s,texCoordBuffer:v},programs:m,targets:x},this.imageLoaded=!0,this.render()}disposeResources(){if(!this.resources)return;const{gl:e,sourceTexture:n,blackPalette:t,quad:r,programs:o,targets:a}=this.resources;e.deleteTexture(n),e.deleteTexture(t),e.deleteBuffer(r.positionBuffer),e.deleteBuffer(r.texCoordBuffer),a.forEach(n=>{e.deleteFramebuffer(n.framebuffer),e.deleteTexture(n.texture)}),Object.values(o).forEach(n=>{e.deleteProgram(n.program)}),this.resources=null}drawFrame(e,n){const{gl:t,width:r,height:o,sourceTexture:a,blackPalette:i,quad:u,programs:l,targets:s}=e;t.viewport(0,0,r,o);const v=[1/r,1/o];let m=a,x=0;const f=(e,n,r)=>{t.useProgram(e.program),(e=>{t.bindBuffer(t.ARRAY_BUFFER,u.positionBuffer);const n=e.attribs.aPosition>=0?e.attribs.aPosition:e.attribs.apos;n>=0&&(t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0)),t.bindBuffer(t.ARRAY_BUFFER,u.texCoordBuffer);const r=e.attribs.aTexCoord>=0?e.attribs.aTexCoord:e.attribs.auv;r>=0&&(t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0))})(e),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,m);const o=e.uniforms.uTexture;o&&t.uniform1i(o,0),n(),t.bindFramebuffer(t.FRAMEBUFFER,r?r.framebuffer:null),t.drawArrays(t.TRIANGLE_STRIP,0,4),m=r?r.texture:m},g=()=>{const e=s[x%2];return x+=1,e};Math.abs(n.vibrance)>.5&&f(l.vibrance,()=>{t.uniform1f(l.vibrance.uniforms.uAmount,n.vibrance/100)},g()),Math.abs(n.saturation)>.5&&f(l.saturation,()=>{const e=(e=>{const n=1+Math.max(-100,Math.min(100,e))/100,t=.299,r=.587,o=.114,a=1-n;return new Float32Array([a*t+n,a*r,a*o,0,0,a*t,a*r+n,a*o,0,0,a*t,a*r,a*o+n,0,0,0,0,0,1,0])})(n.saturation);t.uniform1fv(l.saturation.uniforms["uMatrix[0]"],e)},g()),Math.abs(n.temperature)>.5&&f(l.temperature,()=>{t.uniform1f(l.temperature.uniforms.uAmount,n.temperature/500)},g()),Math.abs(n.tint)>.5&&f(l.tint,()=>{t.uniform1f(l.tint.uniforms.uAmount,n.tint/500)},g()),Math.abs(n.hue)>.5&&f(l.hue,()=>{t.uniform1f(l.hue.uniforms.uRotation,n.hue/200)},g()),f(l.brightness,()=>{t.uniform1f(l.brightness.uniforms.uAmount,n.brightness/200)},g()),Math.abs(n.exposure)>.5&&f(l.exposure,()=>{t.uniform1f(l.exposure.uniforms.uAmount,n.exposure/100)},g()),Math.abs(n.contrast)>.5&&f(l.contrast,()=>{const e=(e=>{const n=1+Math.max(-100,Math.min(100,e))/100,t=.5*(1-n);return new Float32Array([n,0,0,0,t,0,n,0,0,t,0,0,n,0,t,0,0,0,1,0])})(n.contrast);t.uniform1fv(l.contrast.uniforms["uMatrix[0]"],e)},g()),Math.abs(n.blacks)>.5&&(((e,n,t)=>{e.bindTexture(e.TEXTURE_2D,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,256,1,e.RGB,e.UNSIGNED_BYTE,t)})(t,i,c(n.blacks)),f(l.blacks,()=>{t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i),t.uniform1i(l.blacks.uniforms.uPaletteMap,1),t.uniform4f(l.blacks.uniforms.transform,1,1,0,0),t.activeTexture(t.TEXTURE0)},g())),Math.abs(n.whites)>.5&&f(l.whites,()=>{t.uniform1f(l.whites.uniforms.uAmount,n.whites/400)},g()),Math.abs(n.highlights)>.5&&f(l.highlights,()=>{t.uniform1f(l.highlights.uniforms.uAmount,n.highlights/100)},g()),Math.abs(n.shadows)>.5&&f(l.shadows,()=>{t.uniform1f(l.shadows.uniforms.uAmount,n.shadows/100)},g()),Math.abs(n.dehaze)>.5&&f(l.dehaze,()=>{t.uniform1f(l.dehaze.uniforms.uAmount,n.dehaze/100),t.uniform2f(l.dehaze.uniforms.uSize,r,o)},g()),n.bloom>.5&&f(l.bloom,()=>{t.uniform1f(l.bloom.uniforms.uAmount,n.bloom/100),t.uniform2f(l.bloom.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.bloom.uniforms.uThreshold,.5)},g()),n.glamour>.5&&f(l.glamour,()=>{t.uniform1f(l.glamour.uniforms.uAmount,n.glamour/100),t.uniform2f(l.glamour.uniforms.uTexel,v[0],v[1])},g()),Math.abs(n.clarity)>.5&&f(l.clarity,()=>{t.uniform1f(l.clarity.uniforms.uAmount,n.clarity/100),t.uniform2f(l.clarity.uniforms.uTexel,v[0],v[1])},g()),n.sharpen>.5&&f(l.sharpen,()=>{t.uniform2f(l.sharpen.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.sharpen.uniforms.uAmount,n.sharpen/100),t.uniform1fv(l.sharpen.uniforms["uKernel[0]"],new Float32Array([0,-1,0,-1,5,-1,0,-1,0]))},g()),n.smooth>.5&&f(l.smooth,()=>{t.uniform2f(l.smooth.uniforms.uTexel,v[0],v[1]),t.uniform1f(l.smooth.uniforms.uAmount,n.smooth/100),t.uniform1fv(l.smooth.uniforms["uKernel[0]"],new Float32Array([1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9]))},g());const p=n.blur;f(l.blur,()=>{t.uniform2f(l.blur.uniforms.uSize,p/r,0)},g()),f(l.blur,()=>{t.uniform2f(l.blur.uniforms.uSize,0,p/o)},g()),f(l.vignette,()=>{t.uniform1f(l.vignette.uniforms.uAmount,n.vignette/100),t.uniform1f(l.vignette.uniforms.uSize,.25)},g()),f(l.grain,()=>{t.uniform2f(l.grain.uniforms.uResolution,r,o),t.uniform1f(l.grain.uniforms.uAmount,n.grain/800),t.uniform1f(l.grain.uniforms.uTime,0)},g()),f(l.pass,()=>{},null)}};export{x as ImageColorGrading,m as analyzeImage,s as analyzeImageLevels,v as analyzeImageVibrance,u as defaultSettings,l as presets};
|