mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-04-18 17:51:12 +08:00
8 lines
26 KiB
JavaScript
8 lines
26 KiB
JavaScript
|
/*Copyrights for code authored by Yahoo Inc. is licensed under the following terms:
|
||
|
MIT License
|
||
|
Copyright 2017 Yahoo Inc.
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
*/
|
||
|
!function(e,t,r,i){"use strict";function n(){return C.isValid()}function o(){return C.isValid()}function a(){var e={getUserMedia:!0};return C.isValid(e)}function s(e){var t=!1;if(w.isArray(e)&&e.length){if(w.each(e,function(e,r){w.isSupported.videoCodecs[r]&&(t=!0)}),!t)return!1}else if(w.isString(e)&&e.length&&!w.isSupported.videoCodecs[e])return!1;return C.isValid({getUserMedia:!0})}function d(){function e(e,t,r){var i,n;for(u=e,m=t,g=r,f=new Array(h),i=0;h>i;i++)f[i]=new Array(4),n=f[i],n[0]=n[1]=n[2]=(i<<k+8)/h|0,D[i]=F/h|0,G[i]=0}function t(){for(var e=[],t=new Array(h),r=0;h>r;r++)t[f[r][3]]=r;for(var i=0,n=0;h>n;n++){var o=t[n];e[i++]=f[o][0],e[i++]=f[o][1],e[i++]=f[o][2]}return e}function r(){var e,t,r,i,n,o,a,s;for(a=0,s=0,e=0;h>e;e++){for(n=f[e],r=e,i=n[1],t=e+1;h>t;t++)o=f[t],o[1]<i&&(r=t,i=o[1]);if(o=f[r],e!=r&&(t=o[0],o[0]=n[0],n[0]=t,t=o[1],o[1]=n[1],n[1]=t,t=o[2],o[2]=n[2],n[2]=t,t=o[3],o[3]=n[3],n[3]=t),i!=a){for(P[a]=s+e>>1,t=a+1;i>t;t++)P[t]=e;a=i,s=e}}for(P[a]=s+C>>1,t=a+1;256>t;t++)P[t]=C}function i(){var e,t,r,i,n,o,a,f,h,C,x,F,W,O;for(y>m&&(g=1),l=30+(g-1)/3,F=u,W=0,O=m,x=m/(3*g),C=x/S|0,f=V,o=T,a=o>>U,1>=a&&(a=0),e=0;a>e;e++)N[e]=f*((a*a-e*e)*z/(a*a));for(h=y>m?3:m%p!==0?3*p:m%v!==0?3*v:m%b!==0?3*b:3*w,e=0;x>e;)if(r=(255&F[W+0])<<k,i=(255&F[W+1])<<k,n=(255&F[W+2])<<k,t=c(r,i,n),d(f,t,r,i,n),0!==a&&s(a,t,r,i,n),W+=h,W>=O&&(W-=m),e++,0===C&&(C=1),e%C===0)for(f-=f/l,o-=o/I,a=o>>U,1>=a&&(a=0),t=0;a>t;t++)N[t]=f*((a*a-t*t)*z/(a*a))}function n(e,t,r){var i,n,o,a,s,d,c;for(s=1e3,c=-1,i=P[t],n=i-1;h>i||n>=0;)h>i&&(d=f[i],o=d[1]-t,o>=s?i=h:(i++,0>o&&(o=-o),a=d[0]-e,0>a&&(a=-a),o+=a,s>o&&(a=d[2]-r,0>a&&(a=-a),o+=a,s>o&&(s=o,c=d[3])))),n>=0&&(d=f[n],o=t-d[1],o>=s?n=-1:(n--,0>o&&(o=-o),a=d[0]-e,0>a&&(a=-a),o+=a,s>o&&(a=d[2]-r,0>a&&(a=-a),o+=a,s>o&&(s=o,c=d[3]))));return c}function o(){return i(),a(),r(),t()}function a(){var e;for(e=0;h>e;e++)f[e][0]>>=k,f[e][1]>>=k,f[e][2]>>=k,f[e][3]=e}function s(e,t,r,i,n){var o,a,s,d,c,l,u;for(s=t-e,-1>s&&(s=-1),d=t+e,d>h&&(d=h),o=t+1,a=t-1,l=1;d>o||a>s;){if(c=N[l++],d>o){u=f[o++];try{u[0]-=c*(u[0]-r)/B|0,u[1]-=c*(u[1]-i)/B|0,u[2]-=c*(u[2]-n)/B|0}catch(m){}}if(a>s){u=f[a--];try{u[0]-=c*(u[0]-r)/B|0,u[1]-=c*(u[1]-i)/B|0,u[2]-=c*(u[2]-n)/B|0}catch(m){}}}}function d(e,t,r,i,n){var o=f[t],a=e/V;o[0]-=a*(o[0]-r)|0,o[1]-=a*(o[1]-i)|0,o[2]-=a*(o[2]-n)|0}function c(e,t,r){var i,n,o,a,s,d,c,l,u,m;for(l=~(1<<31),u=l,d=-1,c=d,i=0;h>i;i++)m=f[i],n=m[0]-e,0>n&&(n=-n),o=m[1]-t,0>o&&(o=-o),n+=o,o=m[2]-r,0>o&&(o=-o),n+=o,l>n&&(l=n,d=i),a=n-(G[i]>>x-k),u>a&&(u=a,c=i),s=D[i]>>O,D[i]-=s,G[i]+=s<<W;return D[d]+=E,G[d]-=M,c}var l,u,m,g,f,h=256,p=499,v=491,b=487,w=503,y=3*w,C=h-1,k=4,S=100,x=16,F=1<<x,W=10,O=10,E=F>>O,M=F<<W-O,A=h>>3,U=6,R=1<<U,T=A*R,I=30,j=10,V=1<<j,H=8,z=1<<H,L=j+H,B=1<<L,P=[],G=[],D=[],N=[];e.apply(this,arguments);var q={};return q.map=n,q.process=o,q}function c(){var e=this;try{e.onmessage=function(e){var t,i=e.data||{};i.gifshot&&(t=r.run(i),postMessage(t))}}catch(t){}var r={dataToRGB:function(e,t,r){for(var i=t*r*4,n=0,o=[];i>n;)o.push(e[n++]),o.push(e[n++]),o.push(e[n++]),n++;return o},componentizedPaletteToArray:function(e){e=e||[];for(var t=[],r=0;r<e.length;r+=3){var i=e[r],n=e[r+1],o=e[r+2];t.push(i<<16|n<<8|o)}return t},processFrameWithQuantizer:function(e,t,r,i){for(var n=this.dataToRGB(e,t,r),o=new d(n,n.length,i),a=o.process(),s=new Uint32Array(this.componentizedPaletteToArray(a)),c=t*r,l=new Uint8Array(c),u=0,m=0;c>m;m++){var g=n[u++],f=n[u++],h=n[u++];l[m]=o.map(g,f,h)}return{pixels:l,palette:s}},run:function(e){e=e||{};var t=e,r=t.height,i=(t.palette,t.sampleInterval),n=t.width,o=e.data;return this.processFrameWithQuantizer(o,n,r,i)}};return r}function l(e,t,r,n){function o(e){var t=e.length;if(2>t||t>256||t&t-1)throw"Invalid code/color length, must be power of 2 and 2 .. 256.";return t}function a(e,t,r,n){function o(r){for(;g>=r;)e[t++]=255&f,f>>=8,g-=8,t===s+256&&(e[s]=255,s=t++)}function a(e){f|=e<<g,g+=m,o(8)}e[t++]=r;var s=t++,d=1<<r,c=d-1,l=d+1,u=l+1,m=r+1,g=0,f=0,h=n[0]&c,p={};a(d);for(var v=1,b=n.length;b>v;++v){var w=n[v]&c,y=h<<8|w,C=p[y];if(C===i){f
|