image-color-grading 1.0.0 → 1.0.1
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/{processor.d.ts → index.d.cts} +65 -4
- package/dist/index.d.ts +161 -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.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};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}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)),v=t.createBuffer(),s=t.createBuffer();if(!v||!s)throw new Error("Failed to create buffers");t.bindBuffer(t.ARRAY_BUFFER,v),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,s),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:v,texCoordBuffer:s},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:v}=e;t.viewport(0,0,r,o);const s=[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=v[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,s[0],s[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,s[0],s[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,s[0],s[1])},g()),n.sharpen>.5&&f(l.sharpen,()=>{t.uniform2f(l.sharpen.uniforms.uTexel,s[0],s[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,s[0],s[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.defaultSettings=u;
|
|
@@ -1,8 +1,68 @@
|
|
|
1
|
-
|
|
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
|
+
|
|
2
62
|
/**
|
|
3
63
|
* 默认设置
|
|
4
64
|
*/
|
|
5
|
-
|
|
65
|
+
declare const defaultSettings: ColorGradingSettings;
|
|
6
66
|
/**
|
|
7
67
|
* 图像调色处理器
|
|
8
68
|
*
|
|
@@ -15,7 +75,7 @@ export declare const defaultSettings: ColorGradingSettings;
|
|
|
15
75
|
* const dataUrl = processor.toDataURL();
|
|
16
76
|
* ```
|
|
17
77
|
*/
|
|
18
|
-
|
|
78
|
+
declare class ImageColorGrading {
|
|
19
79
|
private canvas;
|
|
20
80
|
private resources;
|
|
21
81
|
private settings;
|
|
@@ -106,4 +166,5 @@ export declare class ImageColorGrading {
|
|
|
106
166
|
private disposeResources;
|
|
107
167
|
private drawFrame;
|
|
108
168
|
}
|
|
109
|
-
|
|
169
|
+
|
|
170
|
+
export { type ColorGradingSettings, type ExportOptions, ImageColorGrading, type PartialColorGradingSettings, defaultSettings };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,170 @@
|
|
|
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
|
+
*/
|
|
65
|
+
declare const defaultSettings: ColorGradingSettings;
|
|
66
|
+
/**
|
|
67
|
+
* 图像调色处理器
|
|
5
68
|
*
|
|
6
69
|
* @example
|
|
7
70
|
* ```ts
|
|
8
|
-
* import { ImageColorGrading, defaultSettings } from 'image-color-grading';
|
|
9
|
-
*
|
|
10
71
|
* const processor = new ImageColorGrading();
|
|
11
72
|
* await processor.loadImage('path/to/image.jpg');
|
|
12
|
-
* processor.setSettings({
|
|
13
|
-
*
|
|
14
|
-
* contrast: 10,
|
|
15
|
-
* saturation: 15
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
73
|
+
* processor.setSettings({ brightness: 20, contrast: 10 });
|
|
74
|
+
* processor.render();
|
|
18
75
|
* const dataUrl = processor.toDataURL();
|
|
19
76
|
* ```
|
|
20
77
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
78
|
+
declare class ImageColorGrading {
|
|
79
|
+
private canvas;
|
|
80
|
+
private resources;
|
|
81
|
+
private settings;
|
|
82
|
+
private imageLoaded;
|
|
83
|
+
/**
|
|
84
|
+
* 创建图像调色处理器
|
|
85
|
+
* @param canvas - 可选的 canvas 元素,不传则自动创建
|
|
86
|
+
*/
|
|
87
|
+
constructor(canvas?: HTMLCanvasElement);
|
|
88
|
+
/**
|
|
89
|
+
* 获取 canvas 元素
|
|
90
|
+
*/
|
|
91
|
+
getCanvas(): HTMLCanvasElement;
|
|
92
|
+
/**
|
|
93
|
+
* 获取当前设置
|
|
94
|
+
*/
|
|
95
|
+
getSettings(): ColorGradingSettings;
|
|
96
|
+
/**
|
|
97
|
+
* 设置调色参数
|
|
98
|
+
* @param newSettings - 部分或全部设置参数
|
|
99
|
+
*/
|
|
100
|
+
setSettings(newSettings: PartialColorGradingSettings): void;
|
|
101
|
+
/**
|
|
102
|
+
* 重置所有设置为默认值
|
|
103
|
+
*/
|
|
104
|
+
resetSettings(): void;
|
|
105
|
+
/**
|
|
106
|
+
* 从 URL 加载图像
|
|
107
|
+
* @param url - 图像 URL
|
|
108
|
+
* @returns Promise
|
|
109
|
+
*/
|
|
110
|
+
loadImage(url: string): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* 从 HTMLImageElement 加载图像
|
|
113
|
+
* @param image - 图像元素
|
|
114
|
+
*/
|
|
115
|
+
loadFromImage(image: HTMLImageElement): void;
|
|
116
|
+
/**
|
|
117
|
+
* 从 File 对象加载图像
|
|
118
|
+
* @param file - File 对象
|
|
119
|
+
* @returns Promise
|
|
120
|
+
*/
|
|
121
|
+
loadFromFile(file: File): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* 从 ImageData 加载图像
|
|
124
|
+
* @param imageData - ImageData 对象
|
|
125
|
+
*/
|
|
126
|
+
loadFromImageData(imageData: ImageData): void;
|
|
127
|
+
/**
|
|
128
|
+
* 渲染图像
|
|
129
|
+
*/
|
|
130
|
+
render(): void;
|
|
131
|
+
/**
|
|
132
|
+
* 导出为 Data URL
|
|
133
|
+
* @param options - 导出选项
|
|
134
|
+
* @returns Data URL 字符串
|
|
135
|
+
*/
|
|
136
|
+
toDataURL(options?: ExportOptions): string;
|
|
137
|
+
/**
|
|
138
|
+
* 导出为 Blob
|
|
139
|
+
* @param options - 导出选项
|
|
140
|
+
* @returns Promise<Blob>
|
|
141
|
+
*/
|
|
142
|
+
toBlob(options?: ExportOptions): Promise<Blob>;
|
|
143
|
+
/**
|
|
144
|
+
* 获取 ImageData
|
|
145
|
+
* @returns ImageData
|
|
146
|
+
*/
|
|
147
|
+
getImageData(): ImageData;
|
|
148
|
+
/**
|
|
149
|
+
* 获取图像尺寸
|
|
150
|
+
*/
|
|
151
|
+
getSize(): {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* 检查是否已加载图像
|
|
157
|
+
*/
|
|
158
|
+
isLoaded(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* 销毁资源
|
|
161
|
+
*/
|
|
162
|
+
dispose(): void;
|
|
163
|
+
private getWebGLContext;
|
|
164
|
+
private initFromImage;
|
|
165
|
+
private initResources;
|
|
166
|
+
private disposeResources;
|
|
167
|
+
private drawFrame;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { type ColorGradingSettings, type ExportOptions, ImageColorGrading, type PartialColorGradingSettings, defaultSettings };
|
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=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}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)),v=t.createBuffer(),s=t.createBuffer();if(!v||!s)throw new Error("Failed to create buffers");t.bindBuffer(t.ARRAY_BUFFER,v),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,s),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:v,texCoordBuffer:s},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:v}=e;t.viewport(0,0,r,o);const s=[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=v[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,s[0],s[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,s[0],s[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,s[0],s[1])},g()),n.sharpen>.5&&f(l.sharpen,()=>{t.uniform2f(l.sharpen.uniforms.uTexel,s[0],s[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,s[0],s[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{l as ImageColorGrading,u as defaultSettings};
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-color-grading",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "基于 WebGL 的高性能图像调色库,支持亮度、对比度、饱和度、色温等 22+ 种调色参数",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import":
|
|
12
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"files": [
|
|
@@ -17,8 +23,8 @@
|
|
|
17
23
|
"README.md"
|
|
18
24
|
],
|
|
19
25
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"dev": "
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
22
28
|
"prepublishOnly": "npm run build"
|
|
23
29
|
},
|
|
24
30
|
"keywords": [
|
|
@@ -42,6 +48,8 @@
|
|
|
42
48
|
"url": ""
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
51
|
+
"terser": "^5.0.0",
|
|
52
|
+
"tsup": "^8.0.0",
|
|
45
53
|
"typescript": "^5.0.0"
|
|
46
54
|
},
|
|
47
55
|
"engines": {
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,aAAa,GACd,MAAM,SAAS,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/processor.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAI3B,aAAa,EACd,MAAM,SAAS,CAAC;AAYjB;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,oBAsB7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,QAAQ,CAAgD;IAChE,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,MAAM,CAAC,EAAE,iBAAiB;IAItC;;OAEG;IACH,SAAS,IAAI,iBAAiB;IAI9B;;OAEG;IACH,WAAW,IAAI,oBAAoB;IAInC;;;OAGG;IACH,WAAW,CAAC,WAAW,EAAE,2BAA2B,GAAG,IAAI;IAO3D;;OAEG;IACH,aAAa,IAAI,IAAI;IAOrB;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAerC;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAI5C;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAevC;;;OAGG;IACH,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAoC7C;;OAEG;IACH,MAAM,IAAI,IAAI;IAQd;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM;IAM1C;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB9C;;;OAGG;IACH,YAAY,IAAI,SAAS;IAiBzB;;OAEG;IACH,OAAO,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAO5C;;OAEG;IACH,QAAQ,IAAI,OAAO;IAInB;;OAEG;IACH,OAAO,IAAI,IAAI;IAOf,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,aAAa;IA4ErB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,SAAS;CAuUlB"}
|