rext-image-editor
Version:
REXT is a client side image editor that uses GPU.
1 lines • 24.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.RextEditor=e():t.RextEditor=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{RextEditor:()=>m});var i=function(t,e,i){return t<e?e:t>i?i:t},r=function(t,e,i,r,n,o,a,s){void 0===n&&(n=0),void 0===o&&(o=.33),void 0===a&&(a=.66),void 0===s&&(s=1);var u,l,h,c,g,p,_,f,m,x,d,v,b,y,T,k,E,C=Math.pow(n,2),w=Math.pow(o,2),R=Math.pow(a,2),A=Math.pow(s,2),D=(p=(h=[n,o,a,s])[2]-h[3],g=(u=[C*n,w*o,R*a,A*s])[0]*((l=[C,w,R,A])[1]*p-h[1]*(f=l[2]-l[3])+(x=l[2]*h[3]-h[2]*l[3]))-l[0]*(u[1]*p-h[1]*(_=u[2]-u[3])+(d=u[2]*h[3]-h[2]*u[3]))+h[0]*(u[1]*f-l[1]*_+(v=u[2]*l[3]-l[2]*u[3]))-(u[1]*x-l[1]*d+h[1]*v),[((c=[t,e,i,r])[0]*(l[1]*p-h[1]*f+x)-l[0]*(c[1]*p-h[1]*(m=c[2]-c[3])+(b=c[2]*h[3]-h[2]*c[3]))+h[0]*(c[1]*f-l[1]*m+(y=c[2]*l[3]-l[2]*c[3]))-(c[1]*x-l[1]*b+h[1]*y))/g,(u[0]*(c[1]*p-h[1]*m+b)-c[0]*(u[1]*p-h[1]*_+d)+h[0]*(u[1]*m-c[1]*_+(T=u[2]*c[3]-c[2]*u[3]))-(u[1]*b-c[1]*d+h[1]*T))/g,(u[0]*(l[1]*m-c[1]*f+(k=l[2]*c[3]-c[2]*l[3]))-l[0]*(u[1]*m-c[1]*_+T)+c[0]*(u[1]*f-l[1]*_+v)-(u[1]*k-l[1]*T+c[1]*v))/g,(u[0]*(l[1]*(E=h[2]*c[3]-c[2]*h[3])-h[1]*k+c[1]*x)-l[0]*(u[1]*E-h[1]*T+c[1]*d)+h[0]*(u[1]*k-l[1]*T+c[1]*v)-c[0]*(u[1]*x-l[1]*d+h[1]*v))/g].map((function(t){return Math.round(1e3*t)/1e3})));return function(t){var e=D[3],i=t;return e+=D[2]*i,i*=t,e+=D[1]*i,i*=t,e+D[0]*i}},n=function(t){var e,r,n,o,a,s;return r=(e=t.z*t.y)*(1-Math.abs(t.x/60%2-1)),n=t.z-e,t.x<180?t.x<60?(o=t.z,a=r+n,s=n):t.x<120?(o=r+n,a=t.z,s=n):(o=n,a=t.z,s=r+n):t.x<240?(o=n,a=r+n,s=t.z):t.x<300?(o=r+n,a=n,s=e+n):(o=e+n,a=n,s=r+n),{x:o=i(o,0,1),y:a=i(a,0,1),z:s=i(s,0,1)}},o=function(t){return[t.x,t.y,t.z]},a={resolutionLimit:-1,editionResolutionLimit:-1},s={hdr:0,exposure:0,temperature:0,tint:0,brightness:0,saturation:0,contrast:0,sharpen:0,masking:0,sharpen_radius:0,radiance:0,highlights:0,shadows:0,whites:0,blacks:0,dehaze:0,bAndW:0,atmosferic_light:0,lightFill:0,lightColor:0,lightSat:1,darkFill:0,darkColor:0,darkSat:1,rotation:0,rotation_center:{x:0,y:0},scale:{x:1,y:1},translate:{x:0,y:0},size:{x:1,y:1},zoom:1},u={contrast:["generateLightning"],whites:["generateLightning"],highlights:["generateLightning"],shadows:["generateLightning"],blacks:["generateLightning"],radiance:["generateLightning","kernel_update"],hdr:["kernel_update"],temperature:["updateTemptint"],tint:["updateTemptint"],sharpen:["kernel_update"],sharpen_radius:["kernel_update"]},l=[[.6167426069865002,.017657981710823077],[.5838624982041293,.06447754787874993],[.5666570157784903,.1010769359975838],[.5600215017846518,.13012054359808795],[.5603460901328465,.15370282338343416],[.5651414015638195,.1734071109259789],[.5727157905223393,.19040417876076665],[.5819305919306469,.20554787970182647],[.5920253173976543,.219454396860673],[.6024964973113273,.23256361077001078],[.613014923688415,.2451851574423344],[.6233694681448863,.2575325541865392],[.633428991849502,.2697484189519574],[.6431164873163056,.2819231700046263],[.6523914777767198,.29410898225476145],[.6612380004437802,.30633028466830314],[.6696563786680246,.31859171532935343],[.6776575761390952,.330884185957384],[.6852593188363603,.34318952105568623],[.6924834326806721,.3554840067292358],[.6993540206164168,.36774109382812364],[.705896221219359,.37993343721079975],[.712135371070854,.3920344089104195],[.7180964477199883,.4040191918024166],[.7238037074478182,.41586553788423575],[.7292804578150028,.42755425869079605],[.7345489228275083,.43906950280216533],[.7396301709912545,.4503988656030025],[.7445440852278651,.4615333686006381],[.7493093597375261,.47246733915721345],[.7539435132044948,.4831982160881075],[.7584629107855697,.4937263019887011],[.7628827894765442,.5040544792219176],[.7672172829757861,.5141879031216875],[.7756812566990368,.5339005596070674],[.7756812566990368,.5339005596070674],[.7798336535847834,.5434985836882681],[.7839465092903851,.552938802301879],[.7880286368234596,.5622329533372938],[.7920877696863722,.5713931712543325],[.796130534601134,.5804317041849897],[.8001624136045166,.5893606423074715],[.8041876951180534,.5981916567442426],[.8082094136732589,.6069357478075997],[.8122292780585781,.6156030011340633],[.8162475877574743,.624202350096731],[.8202631376804659,.6327413428542148],[.8242731113661302,.6412259124772712],[.8282729630469863,.6496601487868902],[.8322562892583072,.6580460708395705],[.8362146910181553,.6663833994084263],[.8401376280395388,.6746693293369075],[.8440122669563406,.6828983022904387],[.8478233261635671,.691061781205187],[.8515529205921868,.6991480286361483],[.8578515274860328,.7143328511178657],[.8630349166004683,.7236145588845],[.8630349166004683,.7236145588845],[.8678866519883774,.7326305266929798],[.8724265417351438,.7413920824039555],[.8766746938112879,.7499106260961086],[.8806514255414362,.7581975699581189],[.8843771730729832,.7662642858505886],[.8878724008449614,.7741220599147951],[.8911575110568668,.7817820536219475],[.8942527531374216,.7892552706795768],[.8971781332133792,.7965525292390034],[.9025975721615955,.8106613818669473],[.9051296119968262,.8174934982533621],[.9051296119968262,.8174934982533621],[.9075675706910422,.8241906743465228],[.9099288798932852,.8307625342003426],[.912230184763394,.8372184337382709],[.914487253441016,.8435674571884941],[.9167148865142485,.8498184155292972],[.9189268264883301,.8559798466723794],[.9211356672547586,.862060017138353],[.9233527635598611,.8680669250033681],[.9278504028585166,.8798916280267886],[.9301466448383797,.8857241176152066],[.9324823592671754,.8915127453709542],[.9348613471976668,.8972642431099969],[.9348613471976668,.8972642431099969],[.9372856273504615,.9029851088748369],[.9397553455825536,.9086816143048344],[.9422686843563701,.9143598121965675],[.9448217722084058,.9200255441824128],[.947408593218177,.925684448465339],[.9500208964767429,.931341967556689],[.9552772279767501,.9426736878435626],[.9578927646784257,.9483578644262163],[.9604766194871308,.954060621455171],[.9630080085847714,.9597865363484674],[.965463369977889,.9655400352277332],[.965463369977889,.9655400352277332],[.9678162729662736,.9713253997462401],[.9700373276119754,.9771467737131783],[.9720940942080452,.9830081695063213],[.9739509927471266,.9889134742677088],[.97556921239073,.9948664558790756],[.9782396416593983,1]],h=function(){function t(){}return t.prototype.log=function(t){console.log(t)},t.prototype.warn=function(t){console.warn(t)},t.prototype.error=function(t){console.error(t)},t}(),c=function(t,e,i){var r=t.createShader(e);if(t.shaderSource(r,i),t.compileShader(r),t.getShaderParameter(r,t.COMPILE_STATUS))return r;throw console.warn(t.getError()),t.deleteShader(r),new Error("Unable to create a WebGL shader.")},g=function(t){var e=t.createTexture();return t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),e},p=function(){function t(t,e){this.gl=t,this.program=e,this.pointers={},this.atributes={},this.buffers={}}return t.prototype.getUniform=function(t){return this.pointers[t]||(this.pointers[t]=this.gl.getUniformLocation(this.program,t)),this.pointers[t]},t.prototype.getAttribute=function(t){return this.atributes[t]||(this.atributes[t]=this.gl.getAttribLocation(this.program,t)),this.atributes[t]},t.prototype.createBuffer=function(t){return this.buffers[t]=this.gl.createBuffer(),this.buffers[t]},t.prototype.getBuffer=function(t){return this.buffers[t]},t}(),_=function(){return(_=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},f={alpha:!1,antialias:!1},m=function(){function t(t){var e;this.params=(e=s,JSON.parse(JSON.stringify(e))),this.program=null,this.realImage=null,this.currentImage=null,this.context=null,this.config=a,this.onParamsChangeCallbacks=[],this.WIDTH=0,this.HEIGHT=0,this.log=new h,this.uniforms={kernel:[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],temptint:[1,1,1]},this.LIGHT_MATCH=new Array(256).fill(0).map((function(t,e){return e})),t&&this.setCanvas(t)}return t.prototype.setCanvas=function(t){this.config.width=t.width,this.config.height=t.height,this.canvas=t,this.gl=t.getContext("webgl",f)||t.getContext("experimental-webgl",f)},t.prototype.runCallback=function(t){switch(t){case"generateLightning":this.generateLightning();case"kernel_update":this.uniforms.kernel=function(t){var e=-t.sharpen,i=t.sharpen_radius,r=t.radiance,n=t.hdr;0!=r&&(e-=.5*r,i+=.5*r),0!=n&&(e-=.5*n,i+=.5*n);var o=e*Math.exp(-Math.pow(1/i,2)),a=e*Math.exp(-Math.pow(1.41/i,2)),s=e*Math.exp(-Math.pow(2/i,2)),u=e*Math.exp(-Math.pow(2.24/i,2)),l=e*Math.exp(-Math.pow(2.83/i,2)),h=1;return e<0&&(h+=4*Math.abs(l)+8*Math.abs(u)+4*Math.abs(s)+4*Math.abs(a)+4*Math.abs(o)),[l,u,s,u,l,u,a,o,a,u,s,o,h,o,s,u,a,o,a,u,l,u,s,u,l]}(this.params);case"updateTemptint":return void this.updateTemptint()}this.log.warn("No callback "+t+" exists")},t.prototype.onParamsChange=function(t){this.onParamsChangeCallbacks.push(t)},t.prototype.updateParams=function(t){var e=this,i=Object.keys(this.params).filter((function(i){return e.params[i]!==t[i]}));i.forEach((function(i){e._updateParam(i,t[i])})),this.getCallbacks(i).forEach((function(t){e.runCallback(t)})),this.update(),this.onParamsChangeCallbacks.forEach((function(t){if(t)try{t(e.params)}catch(t){}}))},t.prototype.getCallbacks=function(t){var e=new Set(t.filter((function(t){return null!=u[t]})).map((function(t){return u[t]})).reduce((function(t,e){return t.concat(e)}),[]));return Array.from(e)},t.prototype._updateParam=function(t,e){Object.keys(this.params).includes(t)?this.params[t]=e:this.log.error("Param "+t+" does not exists")},t.prototype.autoZoom=function(){var t=this.config.width/this.WIDTH,e=this.config.height/this.HEIGHT,i=Math.max(t,e);this.setZoom(i)},t.prototype.setZoom=function(t){this.updateParams(_(_({},this.params),{zoom:t})),this.update()},t.prototype.getWidth=function(){return this.WIDTH},t.prototype.getHeight=function(){return this.HEIGHT},t.prototype.setWidth=function(t){this.WIDTH=t},t.prototype.setHeight=function(t){this.HEIGHT=t},t.prototype.getCanvas=function(){return this.gl.canvas},t.prototype.get2dRotation=function(){return[Math.sin(this.params.rotation),Math.cos(this.params.rotation)]},t.prototype.get2dRotationCenter=function(){return[(this.params.rotation_center.x+1)*this.WIDTH/2,(this.params.rotation_center.y+1)*this.HEIGHT/2]},t.prototype.loadImage=function(t){var e=this;return new Promise((function(i,r){var n=new Image;n.onload=function(){null!=e.currentImage?(e.WIDTH=n.width,e.HEIGHT=n.height,e.fitCanvas(n.width,n.height),e.create(e.currentImage),i()):e.log.warn("Load Image called without image.")},n.onerror=function(t){e.log.error("Error while loading the image."),r(t)},e.currentImage=n,n.src=t,e.realImage=n}))},t.prototype.load=function(t,e){return i=this,r=void 0,o=function(){return function(t,e){var i,r,n,o,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(n=2&o[0]?r.return:o[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,o[1])).done)return n;switch(r=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((n=(n=a.trys).length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){a.label=o[1];break}if(6===o[0]&&a.label<n[1]){a.label=n[1],n=o;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(o);break}n[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],r=0}finally{i=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}(this,(function(i){switch(i.label){case 0:return this.log.log("Version 1.2.8"),void 0!==e&&(this.config=e),[4,this.loadImage(t)];case 1:return i.sent(),[2,this]}}))},new((n=void 0)||(n=Promise))((function(t,e){function a(t){try{u(o.next(t))}catch(t){e(t)}}function s(t){try{u(o.throw(t))}catch(t){e(t)}}function u(e){var i;e.done?t(e.value):(i=e.value,i instanceof n?i:new n((function(t){t(i)}))).then(a,s)}u((o=o.apply(i,r||[])).next())}));var i,r,n,o},t.prototype.setLog=function(t){this.log=t},t.prototype.updateTemptint=function(){this.uniforms.temptint=function(t){var e,i,r,n=t.temperature,o=t.tint;if(n<0){e=1;var a=l[Math.floor(100*(n+1))];i=a[0],r=a[1]}else e=.0438785/Math.pow(n+.150127,1.23675)+.543991,i=.0305003/Math.pow(n+.163976,1.23965)+.69136,r=1;-1==o&&(o=-.99);var s,u=1/(.2126*(s={x:e,y:i+=o,z:r}).x+.7152*s.y+.0722*s.z);return[e*u,i*u,r*u]}(this.params)},t.prototype.generateLightning=function(){this.LIGHT_MATCH=function(t){var e=r(t.blacks,t.shadows+.33,t.highlights+.66,t.whites+1,0,.33,.66,1),i=null;0!=t.radiance&&(i=r(0,.33-.11*t.radiance,.66+.11*t.radiance,1,0,.33,.66,1));for(var n=[],o=0;o<=255;o++){var a=o/255;0!=t.radiance&&(a=i(a)),(a=e(a))>1&&(a=1),a<0&&(a=0),n[o]=255*a}return n}(this.params)},t.prototype.blob=function(t,e){var i=this;return new Promise((function(r,n){if(null===i.realImage)return i.log.warn("Called to blob without loaded image"),n();i.create(i.realImage),i.getCanvas().toBlob((function(t){if(null===t)return i.log.error("Unable to generate the blob file"),n();r(t)}),t||"image/jpeg",e||1)}))},t.prototype.create=function(t,e){try{var i=c(this.gl,this.gl.VERTEX_SHADER,"attribute vec2 a_position;\nattribute vec2 a_texCoord;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\nuniform vec2 u_rotation;\nuniform vec2 u_rotation_center;\nuniform vec2 u_scale;\nuniform vec2 u_translate; \n\nvoid main() {\n\n vec2 scaled = a_position * vec2(u_scale);\n vec2 pos_r_t = scaled - u_rotation_center;\n vec2 pos_rotated = vec2(\n pos_r_t.x * u_rotation.y + pos_r_t.y * u_rotation.x,\n pos_r_t.y * u_rotation.y - pos_r_t.x * u_rotation.x);\n \n vec2 dist = (pos_rotated + u_rotation_center) / u_resolution;\n\n vec2 pos = vec2((dist + u_translate) * 2.0 - 1.0) * vec2(1, -1);\n gl_Position = vec4(pos, 0, 1);\n v_texCoord = a_texCoord;\n}\n"),r=c(this.gl,this.gl.FRAGMENT_SHADER,"/** * David Iglesias. All rights reserved */\nprecision mediump float;\nuniform sampler2D u_image;\nuniform vec2 u_textureSize;\nuniform float u_kernel[25];\nuniform float u_kernelWeight;\nuniform sampler2D u_lut;\nuniform float u_saturation;\nuniform float u_brightness;\nuniform float u_exposure;\nuniform float u_contrast;\nuniform float u_dehaze;\nuniform float u_atmosferic_light;\nuniform float u_masking;\nuniform vec3 u_temptint[3]; // RGB temptint, RGB lightFill, RGB darkFill\nuniform float u_bAndW;\nuniform float u_hdr;\nvarying vec2 v_texCoord;\nvoid main() {\n \n\tvec2 pixel_size = vec2(1.0, 1.0) / u_textureSize;\n \n\tvec3 center = texture2D(u_image, v_texCoord).rgb;\n\n /* 5x5 kernel filter */\n vec4 colorSum = texture2D(u_image, v_texCoord + pixel_size * vec2(-2, -2)) * u_kernel[0]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-1, -2)) * u_kernel[1]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(0, -2)) * u_kernel[2]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(1, -2)) * u_kernel[3]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(2, -2)) * u_kernel[4]\n\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-2, -1)) * u_kernel[5]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-1, -1)) * u_kernel[6]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(0, -1)) * u_kernel[7]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(1, -1)) * u_kernel[8]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(2, -1)) * u_kernel[9]\n\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-2, 0)) * u_kernel[10]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-1, 0)) * u_kernel[11]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(0, 0)) * u_kernel[12]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(1, 0)) * u_kernel[13]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(2, 0)) * u_kernel[14]\n\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-2, 1)) * u_kernel[15]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-1, 1)) * u_kernel[16]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(0, 1)) * u_kernel[17]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(1, 1)) * u_kernel[18]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(2, 1)) * u_kernel[19]\n\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-2, 2)) * u_kernel[20]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(-1, 2)) * u_kernel[21]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(0, 2)) * u_kernel[22]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(1, 2)) * u_kernel[23]\n\t\t + texture2D(u_image, v_texCoord + pixel_size * vec2(2, 2)) * u_kernel[24];\n\n\t/* Kernel filter mask */\n vec3 rgb_pix = mix(center, (colorSum.rgb / u_kernelWeight), u_masking);\n\t\n\t/**\n\t * RGB to saturation/value conversion, in order to keep hue constant \n\t * sv_pixel = (saturation, value)\n\t */\n float _max = max(rgb_pix.r, max(rgb_pix.g, rgb_pix.b));\n float _min = min(rgb_pix.r, min(rgb_pix.g, rgb_pix.b));\n vec2 sv_pixel = vec2(1.0 - _min / _max, _max);\n\n sv_pixel.y = clamp(texture2D(u_lut, vec2(sv_pixel.y, 0.0)).a, 0.0, 1.0);\n\n\t/* Add saturation */\n if (u_saturation != 0.0) {\n sv_pixel.x *= (1.0 + u_saturation);\n }\n\n sv_pixel.x = clamp(sv_pixel.x, 0.0, 1.0);\n\n\t/* Brightness */\n if (u_brightness != 0.0) {\n sv_pixel.y = pow(sv_pixel.y, 1.0 - u_brightness * 0.6);\n }\n\n\t/* HDR 'like' filter */\n if (u_hdr != 0.0) {\n sv_pixel.y = mix(sv_pixel.y, clamp(1.0 - pow(1.0 - pow(sv_pixel.y, 0.3), 0.42), 0.0, 1.0), u_hdr);\n }\n\n sv_pixel = clamp(sv_pixel, 0.0, 1.0);\n\t/* Return to RGB */\n if (sv_pixel.x > 0.0) {\n float k = -sv_pixel.x / (1.0 - _min / _max);\n rgb_pix = (_max - rgb_pix) * k + _max;\n rgb_pix *= sv_pixel.y / _max;\n } else {\n rgb_pix.r = rgb_pix.g = rgb_pix.b = sv_pixel.y;\n }\n\n\t/* Dehaze */\n if (u_dehaze != 0.0) {\n float t = 1.0 / 25.0;\n vec4 center = texture2D(u_image, v_texCoord);\n vec2 pixel_size = vec2(1.0, 1.0) / u_textureSize;\n float dark = 1.0;\n const int radius = 1;\n for (int ii = -radius; ii <= radius; ii++) {\n for (int jj = -radius; jj <= radius; jj++) {\n vec4 pix = texture2D(u_image, v_texCoord + pixel_size * vec2(ii, jj));\n float _min = min(pix.r, min(pix.g, pix.b));\n if (dark > _min) {\n dark = _min;\n }\n }\n }\n float darkPix = min(center.r, min(center.g, center.b));\n float diff = abs(darkPix - dark);\n float mask = pow(diff, 3.0);\n dark = mix(darkPix, dark, mask);\n float mm = max(1.0 - dark, 0.2);\n rgb_pix = mix(rgb_pix, ((rgb_pix - u_atmosferic_light) / mm + u_atmosferic_light), u_dehaze);\n }\n\n\t/* Exposure */\n rgb_pix += u_exposure;\n rgb_pix = clamp(rgb_pix, 0.0, 1.0);\n\n\t/* Contrast */\n float contrast = u_contrast + 1.0;\n rgb_pix = contrast * (rgb_pix - 0.5) + 0.5;\n\t\n\t/* Apply tint filter */\n rgb_pix *= u_temptint[0];\n float mono = dot(rgb_pix, vec3(0.2126, 0.7152, 0.0722));\n rgb_pix += mix(u_temptint[2], u_temptint[1], mono);\n\n\t/* Black&White filter */\n if (u_bAndW != 0.0) {\n rgb_pix = mix(rgb_pix, vec3(mono, mono, mono), u_bAndW);\n }\n\n gl_FragColor = vec4(rgb_pix, 1.0);\n\n}\n");this.program=function(t,e,i){var r=t.createProgram();if(t.attachShader(r,e),t.attachShader(r,i),t.linkProgram(r),t.getProgramParameter(r,t.LINK_STATUS))return r;throw console.warn(t.getError()),t.deleteProgram(r),new Error("Unable to create a WebGL Program.")}(this.gl,i,r)}catch(t){return this.log.error(t)}this.context=new p(this.gl,this.program),this.log.log("[IMAGE] width = "+this.WIDTH+", height = "+this.HEIGHT),this.log.log("[CANVAS] width = "+this.canvas.width+", height = "+this.canvas.height),this.setRectangle(this.context.createBuffer("ARRAY_BUFFER"),0,0,this.WIDTH,this.HEIGHT),this.setRectangle(this.context.createBuffer("TEXCOORD_BUFFER"),0,0,1,1),this.gl.activeTexture(this.gl.TEXTURE0),g(this.gl);try{this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t)}catch(t){return this.log.error(t)}this.gl.activeTexture(this.gl.TEXTURE1),g(this.gl),this.gl.viewport(0,0,this.WIDTH,this.HEIGHT),this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),e||this.update()},t.prototype.fitCanvas=function(t,e){this.canvas.width=t,this.canvas.height=e},t.prototype.update=function(){this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.ALPHA,256,1,0,this.gl.ALPHA,this.gl.UNSIGNED_BYTE,new Uint8Array(this.LIGHT_MATCH)),this.gl.useProgram(this.program),this.gl.enableVertexAttribArray(this.context.getAttribute("a_position")),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.context.getBuffer("ARRAY_BUFFER")),this.gl.vertexAttribPointer(this.context.getAttribute("a_position"),2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.context.getAttribute("a_texCoord")),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.context.getBuffer("TEXCOORD_BUFFER")),this.gl.vertexAttribPointer(this.context.getAttribute("a_texCoord"),2,this.gl.FLOAT,!1,0,0),this.gl.uniform2f(this.context.getUniform("u_resolution"),this.WIDTH,this.HEIGHT),this.gl.uniform2f(this.context.getUniform("u_textureSize"),this.WIDTH,this.HEIGHT),this.gl.uniform1f(this.context.getUniform("u_brightness"),this.params.brightness),this.gl.uniform1f(this.context.getUniform("u_contrast"),this.params.contrast),this.gl.uniform1f(this.context.getUniform("u_exposure"),this.params.exposure),this.gl.uniform1f(this.context.getUniform("u_contrast"),this.params.contrast),this.gl.uniform1f(this.context.getUniform("u_saturation"),this.params.saturation),this.gl.uniform1f(this.context.getUniform("u_masking"),this.params.masking),this.gl.uniform1f(this.context.getUniform("u_dehaze"),this.params.dehaze),this.gl.uniform1f(this.context.getUniform("u_atmosferic_light"),this.params.atmosferic_light),this.gl.uniform3fv(this.context.getUniform("u_temptint[0]"),this.uniforms.temptint.concat(o(n({x:360*this.params.lightColor,y:this.params.lightSat,z:this.params.lightFill}))).concat(o(n({x:360*this.params.darkColor,y:this.params.darkSat,z:this.params.darkFill})))),this.gl.uniform1f(this.context.getUniform("u_bAndW"),this.params.bAndW),this.gl.uniform1f(this.context.getUniform("u_hdr"),this.params.hdr),this.gl.uniform2fv(this.context.getUniform("u_rotation"),this.get2dRotation()),this.gl.uniform2fv(this.context.getUniform("u_rotation_center"),this.get2dRotationCenter()),this.gl.uniform2f(this.context.getUniform("u_scale"),this.params.scale.x,this.params.scale.y),this.gl.uniform2f(this.context.getUniform("u_translate"),this.params.translate.x,this.params.translate.y),this.gl.uniform1i(this.context.getUniform("u_lut"),1),this.gl.uniform1fv(this.context.getUniform("u_kernel[0]"),this.uniforms.kernel),this.gl.uniform1f(this.context.getUniform("u_kernelWeight"),this.uniforms.kernel.reduce((function(t,e){return t+e}))),this.applyCrop(),this.gl.drawArrays(this.gl.TRIANGLES,0,6)},t.prototype.applyCrop=function(){var t=this.WIDTH*this.params.size.x,e=this.HEIGHT*this.params.size.y,i=this.params.zoom*t,r=this.params.zoom*e;this.getCanvas().style.width=i+"px",this.getCanvas().style.height=r+"px",this.getCanvas().width=t,this.getCanvas().height=e},t.prototype.setRectangle=function(t,e,i,r,n){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t);var o=e,a=e+r,s=i,u=i+n;this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([o,s,a,s,o,u,o,u,a,s,a,u]),this.gl.STATIC_DRAW)},t}();return e})()}));