clipoox-render 0.4.7 → 0.4.8
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/package.json +2 -2
- package/scripts/render-local.mjs +2367 -1534
- package/shared/photocraft/LICENSE.txt +206 -0
- package/shared/photocraft/clipoox_photo.js +396 -0
- package/shared/photocraft/clipoox_photo_bg.wasm +0 -0
- package/web/assets/{FxEmbed-B-D-tbgP.js → FxEmbed-adbxHEBi.js} +1 -1
- package/web/assets/ImageStudio-CMxiT1jp.js +3 -0
- package/web/assets/ImageStudio-De_DCTrz.css +1 -0
- package/web/assets/{MotionEmbed-eB-zRpv9.js → MotionEmbed-CDUIyjk0.js} +1 -1
- package/web/assets/{PluginStore-D6UvvVXA.js → PluginStore-By_pdOOg.js} +2 -2
- package/web/assets/ShotComposer-DcwWZ-eP.css +1 -0
- package/web/assets/ShotComposer-XIbJ4nNm.js +287 -0
- package/web/assets/{TemplateEmbed-DZNaQAJ-.js → TemplateEmbed-a01nKECT.js} +1 -1
- package/web/assets/{TimelinePlugins-zhB9Uqav.js → TimelinePlugins-CqLMVjuh.js} +4 -4
- package/web/assets/TimelineShotFx-QmkyCg31.js +2 -0
- package/web/assets/{TransitionEmbed-r_B0toRr.js → TransitionEmbed-Cbwlxfl2.js} +1 -1
- package/web/assets/{Whiteboard-f6owS-ne.js → Whiteboard-ChYqIr3v.js} +1 -1
- package/web/assets/{aerial-DIj143Yz.js → aerial-CZeCeacv.js} +2 -2
- package/web/assets/{agentTools-CoNs1wCQ.js → agentTools-DW2ETnxE.js} +2 -2
- package/web/assets/{aiInbetween-ZFNHEXdI.js → aiInbetween-De98iM4m.js} +2 -2
- package/web/assets/analyzerRun-D5-g-Vxe.js +1 -0
- package/web/assets/{analyzerSandbox-C2rd6s8U.js → analyzerSandbox-E3CdovIk.js} +1 -1
- package/web/assets/{api-DJC95K48.js → api-CZoVJ9Fy.js} +87 -87
- package/web/assets/auraTrack-ClhHuqlf.js +1 -0
- package/web/assets/{breakthrough-DiHiElqL.js → breakthrough-DTpiUIZd.js} +2 -2
- package/web/assets/{cameraPresets-DfKERP1j.js → cameraPresets-DD0WmxiI.js} +1 -1
- package/web/assets/{cameraTracker-DFjnZ7tw.js → cameraTracker-Df9jWmz6.js} +2 -2
- package/web/assets/{captionLayout-CAuhUiW9.js → captionLayout-eiu9QPJu.js} +1 -1
- package/web/assets/{clientExport-DyqpYM6h.js → clientExport-BXegTdNc.js} +1 -1
- package/web/assets/{clientJobs-BqkjV5Ld.js → clientJobs-eB-lNyin.js} +2 -2
- package/web/assets/clipoox_photo_bg-BQ0aVNY0.wasm +0 -0
- package/web/assets/depthEstimate-CfwX-tXP.js +1 -0
- package/web/assets/{directorTools-CLn4xt6m.js → directorTools-ABbI8m0e.js} +1 -1
- package/web/assets/distortFrames-DMnZ8OYh.js +2 -0
- package/web/assets/distortGL-DQu0Df2c.js +18 -0
- package/web/assets/{domino-BDKBYrNQ.js → domino-trmDBvfH.js} +1 -1
- package/web/assets/{editTools-BqKU-ucA.js → editTools-DEFo9Ahv.js} +1 -1
- package/web/assets/{engine-B2YPWQZ2.js → engine-Y-GotDIy.js} +1 -1
- package/web/assets/exportGlb-BeLpJKJT.js +2 -0
- package/web/assets/{faceTracker-DsmLlUZ1.js → faceTracker-BeSFnLM8.js} +1 -1
- package/web/assets/{fightDirector-BIVLGhAP.js → fightDirector-Dfz3vu5-.js} +1 -1
- package/web/assets/{fightDrama-B_jDQ-cW.js → fightDrama-CNVn69s0.js} +2 -2
- package/web/assets/{focusTool-mWs2Eikj.js → focusTool-Dd2UDkiO.js} +1 -1
- package/web/assets/{frameSink-DWkHUnvV.js → frameSink-Rj02YES5.js} +3 -3
- package/web/assets/{glTransitionSources.generated-BJuEUz3E.js → glTransitionSources.generated-Cs8lVRqs.js} +438 -2
- package/web/assets/{gpuCompose-Fi0sIUI9.js → gpuCompose-DkkKH1Ab.js} +1 -1
- package/web/assets/gpuExport-DwrXpVGF.js +199 -0
- package/web/assets/{handMatte-CvFkZKTL.js → handMatte-B5sUeqKi.js} +1 -1
- package/web/assets/{handTracker-CF1hqh09.js → handTracker-CQV-D7va.js} +2 -2
- package/web/assets/i18n-ClNt3LKg.js +3 -0
- package/web/assets/{index-EegUntr6.js → index-D2u6mD-8.js} +1 -1
- package/web/assets/layer-worker-DP0N05Ua.js +5 -0
- package/web/assets/library-cb43ZEmy.js +1 -0
- package/web/assets/{lottieLayer-Dp_vGTy8.js → lottieLayer-DEw0c3to.js} +4 -4
- package/web/assets/main-C_XcvNyC.js +311 -0
- package/web/assets/{main-B_MAOvi6.css → main-DlzdW5C4.css} +1 -1
- package/web/assets/{mapBake-CEmw-e9Y.js → mapBake-BUWz0cSx.js} +1 -1
- package/web/assets/{maskTrack-CADMBJDf.js → maskTrack-GYpJyKFw.js} +1 -1
- package/web/assets/matteFixRun-BCVsuSxf.js +1 -0
- package/web/assets/{objectLocate-DWsEG8eK.js → objectLocate-CjIlo_u0.js} +1 -1
- package/web/assets/{objectSegmenter-oGv8YQbI.js → objectSegmenter-C4T9qgUL.js} +1 -1
- package/web/assets/{objectTrack.worker-B6RVfsq4.js → objectTrack.worker-BVvsDmR0.js} +1161 -770
- package/web/assets/{pathTracer-DxqKEvC7.js → pathTracer-DgL1_83l.js} +2 -2
- package/web/assets/{pendingMatte-Taa0BlLI.js → pendingMatte-DPTe6xoZ.js} +2 -2
- package/web/assets/peopleMatte-C1hruEM6.js +1 -0
- package/web/assets/{personAi-BebqXrqD.js → personAi-Cjg9KKeH.js} +2 -2
- package/web/assets/{personHq-Cyq9HWnW.js → personHq-CBP8v_cw.js} +2 -2
- package/web/assets/photo.worker-DK_ulTzR.js +1 -0
- package/web/assets/photoRun-lZ2BdSEk.js +2 -0
- package/web/assets/photoTools-DmUh69Qk.js +1 -0
- package/web/assets/plateCamera-DLqlXhMp.js +1 -0
- package/web/assets/{plateCameraMatch-1_DuZ0LV.js → plateCameraMatch-4VUlUMi-.js} +2 -2
- package/web/assets/{plateFollow-Ztxwpq5v.js → plateFollow-D2rjnmZA.js} +2 -2
- package/web/assets/plateMatte-0tTG7oeO.js +2 -0
- package/web/assets/{pluginAutomation-D73Az7HS.js → pluginAutomation-ClFdpcCR.js} +1 -1
- package/web/assets/popTools-B38V4wub.js +1 -0
- package/web/assets/{poseTracker-b1h08oRY.js → poseTracker-qtuytI-L.js} +1 -1
- package/web/assets/{productTools-CoJ_Fnfc.js → productTools-DlC5vWjx.js} +2 -2
- package/web/assets/remote-CpkPQOQH.js +989 -0
- package/web/assets/{rigTrack-B9r9wrdV.js → rigTrack-BbKqZGs7.js} +1 -1
- package/web/assets/{rotoMaskStore-RmW40Pcn.js → rotoMaskStore-BZBJLcCp.js} +1 -1
- package/web/assets/{rotoMatte-DisQplSv.js → rotoMatte-BI-vjjrv.js} +1 -1
- package/web/assets/rotoscope-DuNcCxQy.js +1 -0
- package/web/assets/{sceneTrack-DyVxpl7i.js → sceneTrack-CO4fTjft.js} +1 -1
- package/web/assets/sceneTrack-_n6WKKQv.js +1 -0
- package/web/assets/{sceneTrack.worker-DKVLLgf9.js → sceneTrack.worker-f2d-WOzw.js} +1207 -816
- package/web/assets/{shot-worker-DM5PUQ6g.js → shot-worker-BSmfIXHO.js} +1 -1
- package/web/assets/{shotFxAgent-CsW0MAiG.js → shotFxAgent-L2GG88W3.js} +1 -1
- package/web/assets/{skin-CXvqtCZI.js → skin-CirUiqcr.js} +1 -1
- package/web/assets/{spark.module-B341moK0.js → spark.module-3Q8DniuL.js} +1 -1
- package/web/assets/{spellDuel-KCMEFHLA.js → spellDuel-2CDLbiLQ.js} +2 -2
- package/web/assets/{store-xR02oY0m.js → store-D3Y663py.js} +1 -1
- package/web/assets/{surfaceLight-DBfJxggM.js → surfaceLight--HQj7xhO.js} +1 -1
- package/web/assets/{surfacePin-i-X1Dz68.js → surfacePin-BCmgw-40.js} +2 -2
- package/web/assets/{textAnimators-CeMuG34D.js → textAnimators-C4eMnVRD.js} +1 -1
- package/web/assets/{thumb-DzNl15MN.js → thumb-M9B_goj-.js} +1 -1
- package/web/assets/{timeline3d-D0Ws4lcp.js → timeline3d-BcW68fQr.js} +2 -2
- package/web/assets/{timeline3dExport-BO--SpAn.js → timeline3dExport-DgnorHLm.js} +1 -1
- package/web/assets/timelineComp-Ciu9JCWJ.js +1 -0
- package/web/assets/timelineOps-f1WsVbgS.js +526 -0
- package/web/assets/{timelineProps-Cm_Irino.js → timelineProps-CE1R11Hx.js} +1 -1
- package/web/assets/{timelineText-DjPW2-dd.js → timelineText-Cppd4KB7.js} +1 -1
- package/web/assets/{titleArt-BSu80bfN.js → titleArt-D0YI5xT2.js} +3 -3
- package/web/assets/{titleFrameBudget-BW-N1-cw.js → titleFrameBudget-h4nOQ5u9.js} +1382 -991
- package/web/assets/titleFrames-DnCzi_AI.js +1 -0
- package/web/assets/{tool-Bboi3NDg.js → tool-tp6gat1J.js} +1 -1
- package/web/assets/{tools-kgYkohv8.js → tools-C07G9KUM.js} +1 -1
- package/web/assets/{toonTools-Bxz_HSqT.js → toonTools-Cazx2CL7.js} +2 -2
- package/web/assets/{trackAnchor-DK9cEMCf.js → trackAnchor-DoqFDcJB.js} +1 -1
- package/web/assets/{userFonts-DSkZHfmh.js → userFonts-BlVEJfDk.js} +1 -1
- package/web/assets/{vfxAlpha-B0rNpKZN.js → vfxAlpha-Bp6VgIGN.js} +1 -1
- package/web/assets/vfxBackground-BFq44Srn.js +2 -0
- package/web/assets/{videoExport-Cu0vw-dL.js → videoExport-Cz02XKtX.js} +1 -1
- package/web/assets/{views-CmulxRJP.js → views-CNF3Afse.js} +1 -1
- package/web/assets/{weaponDuel-DuuMMfzY.js → weaponDuel-ChqBQo_b.js} +1 -1
- package/web/assets/{windowFrames-BP2oDn-n.js → windowFrames-dBMXwGek.js} +1 -1
- package/web/layer-worker.html +3 -3
- package/web/shot-worker.html +24 -24
- package/web/assets/ShotComposer-CoxtWL6A.js +0 -287
- package/web/assets/ShotComposer-deLi4grZ.css +0 -1
- package/web/assets/TimelineShotFx-muTN__gf.js +0 -2
- package/web/assets/analyzerRun-BswbLsRF.js +0 -1
- package/web/assets/auraTrack-C9diszRB.js +0 -1
- package/web/assets/depthEstimate-HrGq0Ffx.js +0 -1
- package/web/assets/distortFrames-D-DK2HlN.js +0 -2
- package/web/assets/distortGL-waTJhiOf.js +0 -12
- package/web/assets/exportGlb-Cm07JQXt.js +0 -2
- package/web/assets/gpuExport-Dlf6YjLs.js +0 -198
- package/web/assets/i18n-C9zFX25m.js +0 -3
- package/web/assets/layer-worker-Drj-NLVj.js +0 -5
- package/web/assets/library-BhH-xsMR.js +0 -1
- package/web/assets/main-DAk1Tv1E.js +0 -309
- package/web/assets/matteFixRun-BHD3Qnta.js +0 -1
- package/web/assets/plateCamera-D1A1iEpf.js +0 -1
- package/web/assets/plateMatte-CWT1ymGj.js +0 -2
- package/web/assets/remote-kxNNhmis.js +0 -974
- package/web/assets/rotoscope-Z8bn-jRs.js +0 -1
- package/web/assets/sceneTrack-BKknn180.js +0 -1
- package/web/assets/timelineComp-D8PHGHgQ.js +0 -1
- package/web/assets/timelineOps-CEGk2t4h.js +0 -525
- package/web/assets/titleFrames-BHFaInux.js +0 -1
- package/web/assets/vfxBackground-CBTDl1xA.js +0 -2
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-DnCzi_AI.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/titleArt-D0YI5xT2.js","assets/textAnimators-C4eMnVRD.js","assets/lottieLayer-DEw0c3to.js","assets/rigTrack-BbKqZGs7.js","assets/i18n-ClNt3LKg.js","assets/index-CKtv7gGE.js","assets/api-CZoVJ9Fy.js","assets/frameSink-Rj02YES5.js","assets/timeline3dExport-DgnorHLm.js","assets/timeline3d-BcW68fQr.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-BI-vjjrv.js","assets/store-D3Y663py.js","assets/captionLayout-eiu9QPJu.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{b_ as ao,U as Ht,eE as Go,eC as uo,cG as Uo,au as qo,eX as jo,iO as $o,iJ as Ho,_ as Lt,id as oo,aq as Vo,iP as eo,aR as Yo,aP as mo,hV as Wo,hW as Ko,iQ as po,ea as Qo,eO as xo,cd as to,cf as Zo,fr as Jo,eY as Vt,eW as ei,W as io,eu as vo,ew as ho,ev as go,cO as Yt,ey as ti,eU as oi,dH as Eo,iR as ii,ce as ri,eQ as ai,fk as ni,eP as si,hP as ci,ee as Kt,iS as fi,eo as bo,em as li,hN as ui,iT as mi,iU as pi,iV as di,b2 as xi,aQ as vi,iW as hi,iX as gi,iY as Ei,bH as bi,aG as ko,iZ as Ti,h as Po,i_ as wi,i$ as yi,e2 as Ri,e3 as _i,ai as Fi,j0 as Ai,ep as Mi,eq as Si,er as Di,ek as Ui,es as ki,j1 as Pi,j2 as Bi,f5 as Ni,cq as Li,hZ as Ii,j3 as Ci,hT as Xi,et as To,j4 as Oi,V as zi,X as Gi,a0 as wo,j5 as yo,Y as Ro,an as qi,j6 as ji,e5 as $i,a2 as Hi,a3 as Vi,j7 as Yi,a4 as Wi,e4 as Ki,a5 as Qi,ab as Zi,aa as Ji,a8 as er,a6 as St,j8 as ro,ez as tr,j9 as or,e6 as ir,ja as rr,jb as ar}from"./titleFrameBudget-h4nOQ5u9.js";import{h as no,j as nr,G as sr,z as cr,L as fr,e as lr,d as ur,l as mr,c as pr}from"./glTransitionSources.generated-Cs8lVRqs.js";import{b as dr,e as xr,a as vr}from"./timelineComp-Ciu9JCWJ.js";import{g as so,l as ot,f as It,p as Ct,s as _o,w as Ot,r as hr,a as Xt,t as gr,n as Er,b as Fo,c as Bo,d as br}from"./gpuCompose-DkkKH1Ab.js";import{t as Tr}from"./motionBlur-uAm030t9.js";import{c as wr,f as yr}from"./distortGL-DQu0Df2c.js";import{c as co,V as Rr,a as _r,I as Fr,A as Ar,U as Mr,b as Sr}from"./id3-arvEpAg7.js";import{S as Ao,B as Dr,O as Ur,M as kr,a as Pr,C as Br,A as Nr}from"./output-p-Q7qous.js";import"./api-CZoVJ9Fy.js";import"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";const Lr=p=>p.kind==="image"&&!!p.title?.text&&!p.url&&!oo(p)&&!Uo(p),Wt=p=>ui(p)||Lr(p),zt=48e3,No=192e3,Ir=4,Lo=(p,E)=>E?.name==="AbortError"||p>=Ir?null:Math.min(2**(p-1),4);async function Cr(p,E){for(let y=1;;y++){let e;try{e=await fetch(p,{signal:E})}catch(q){const h=E?.aborted?null:Lo(y,q);if(h===null)throw q;await new Promise(N=>setTimeout(N,h*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Io=()=>_r("aac",{numberOfChannels:2,sampleRate:zt,bitrate:No}).catch(()=>!1),Oa=async(p,E)=>await co("avc",{width:p,height:E}).catch(()=>!1)&&Io();async function za(p){try{const{width:E,height:y,fps:e}=ao(p);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:E,height:y,bitrate:no(null,{width:E,height:y,fps:e},so),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const Ga=(p,E)=>co("hevc",{width:p,height:E}).catch(()=>!1);async function qa(p,E){try{const{width:y,height:e,fps:q}=ao(p),h=E?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:h?"hvc1.1.6.L153.B0":"avc1.640034",width:y,height:e,bitrate:no(E,{width:y,height:e,fps:q},so),framerate:q,hardwareAcceleration:"prefer-hardware"})).supported?!1:await co(h?"hevc":"avc",{width:y,height:e})&&await Io()}catch{return!1}}class Xr{frames=new Map;async push(E,y,e){let q=this.frames.get(y);q||(q=[],this.frames.set(y,q)),q.push(e)}}async function Mo(p,E,y,e,q,h,N){const M=E.get(y.url);if(!M)return null;if(ko(y)&&!y._still){const C=`${y.id}
|
|
3
|
+
remap
|
|
4
|
+
${h}`,L=Math.round((e-h)*q);let X=p.get(C);if(!X){const te=M.samplesAtTimestamps(Ti(y,h-y.start,Math.max(1,Math.round(N*q)),q))[Symbol.asyncIterator]();X={iterator:te,peek:null,current:null,ts0:0,idx:0,next:async()=>{const oe=await te.next();return oe.done?null:oe.value}},p.set(C,X)}for(;(X.idx??0)<=L;){const te=await X.iterator.next();if(X.idx=(X.idx??0)+1,te.done)break;te.value&&te.value!==X.current&&(X.current?.close(),X.current=te.value)}return X.current}const V=!!(y._still||y.freeze),ie=V?1:y.playbackRate||1,se=!V&&Po(y),me=se?wi(y,h,N).start:(y.inPoint||0)+(V?0:(h-y.start)*ie),de=`${y.id}
|
|
5
|
+
${V?"still":h}`;let d=p.get(de);if(!d){if(!V)for(const[L,X]of p)L!==de&&L.startsWith(`${y.id}
|
|
6
|
+
`)&&!L.endsWith(`
|
|
7
|
+
still`)&&!L.includes(`
|
|
8
|
+
remap
|
|
9
|
+
`)&&(X.current?.close(),X.peek?.close(),p.delete(L),await X.iterator.return?.());const C=M.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(d={iterator:C,peek:null,current:null,ts0:me,next:async()=>{const L=await C.next();return L.done?null:L.value}},d.peek=await d.next(),!V){for(;d.peek&&d.peek.timestamp<me-1e-4;)d.peek.close(),d.peek=await d.next();d.ts0=d.peek?.timestamp??me}if(se){const L=O=>Number(O.toFixed(6)),X=h-y.start,te=yi(y,X,X+N),oe=te.slice(0,-1).map(([O,Ae],we)=>{const[je,ye]=te[we+1];return{xa:L(O),dx:L(je-O),k:je-O>1e-9?L((ye-Ae)/(je-O)):0}}).filter(O=>O.dx>1e-9);d.out=O=>oe.reduce((Ae,we)=>Ae+Math.min(we.dx,Math.max(0,O-we.xa))*we.k,0)}p.set(de,d)}if(V){const C=Math.round(me*q);for(;d.peek&&Math.round(d.peek.timestamp*q)<=C;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const R=Math.round((e-h)*q),F=C=>d.out?d.out(C-d.ts0):(C-d.ts0)/ie;for(;d.peek&&Math.round(F(d.peek.timestamp)*q)<=R;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const Or=`#version 300 es
|
|
10
|
+
in vec2 p;uniform vec4 dst;uniform vec4 src;out vec2 uv;
|
|
11
|
+
void main(){uv=src.xy+p*src.zw;vec2 q=dst.xy+p*dst.zw;gl_Position=vec4(q.x*2.-1.,1.-q.y*2.,0,1);}`,zr=`#version 300 es
|
|
12
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float alpha;uniform float fade;uniform float white;
|
|
13
|
+
uniform float bright;uniform float contrast;uniform mat3 sat;uniform mat3 rot;uniform float colour;out vec4 o;
|
|
14
|
+
uniform sampler2D matte;uniform float useMatte;uniform vec4 mrect;
|
|
15
|
+
// chroma key (shared/chromaKey.js, the server's geq on the decoded picture): alpha = clip((d − similarity) / blend), d = |CbCr − key|
|
|
16
|
+
// / (255√2) with the picture's own Cb / Cr (8-bit studio range, back from RGB with its matrix: kmat 1 = BT.709, 0 = BT.601) and the
|
|
17
|
+
// key's BT.601 Cb / Cr; then despill (mix 0.5) pulls the green / blue cast back by spill
|
|
18
|
+
uniform vec4 key;uniform vec4 keyOpt;
|
|
19
|
+
// the grade's 1D LUT (shared/timelineGrade.js gradeLut, 256 entries: an 8-bit input lands on an entry) and its 3D table (the colour
|
|
20
|
+
// mixer, timelineMixer.js mixerLut; ffmpeg lut3d trilinear), each on 8-bit values like the server's lut1d / lut3d
|
|
21
|
+
uniform highp sampler2D lut1;uniform highp sampler3D lut3;uniform float useL1;uniform float useL3;
|
|
22
|
+
vec3 tri(vec3 q){int n=textureSize(lut3,0).x;vec3 p=q*float(n-1),f=floor(p),w=p-f;ivec3 i=ivec3(f),j=min(i+1,ivec3(n-1));
|
|
23
|
+
vec3 c000=texelFetch(lut3,i,0).rgb,c100=texelFetch(lut3,ivec3(j.x,i.y,i.z),0).rgb,c010=texelFetch(lut3,ivec3(i.x,j.y,i.z),0).rgb,c110=texelFetch(lut3,ivec3(j.x,j.y,i.z),0).rgb;
|
|
24
|
+
vec3 c001=texelFetch(lut3,ivec3(i.x,i.y,j.z),0).rgb,c101=texelFetch(lut3,ivec3(j.x,i.y,j.z),0).rgb,c011=texelFetch(lut3,ivec3(i.x,j.y,j.z),0).rgb,c111=texelFetch(lut3,j,0).rgb;
|
|
25
|
+
return mix(mix(mix(c000,c100,w.x),mix(c010,c110,w.x),w.y),mix(mix(c001,c101,w.x),mix(c011,c111,w.x),w.y),w.z);}
|
|
26
|
+
void main(){vec4 c=texture(tex,uv);vec3 rgb=c.rgb;
|
|
27
|
+
if(keyOpt.x>.5){vec3 q=floor(rgb*255.+.5);float k=224./255.;
|
|
28
|
+
float u=keyOpt.w>.5?floor((-.114572*q.r-.385428*q.g+.5*q.b)*k+128.5):floor((-.168736*q.r-.331264*q.g+.5*q.b)*k+128.5);
|
|
29
|
+
float v=keyOpt.w>.5?floor((.5*q.r-.454153*q.g-.045847*q.b)*k+128.5):floor((.5*q.r-.418688*q.g-.081312*q.b)*k+128.5);
|
|
30
|
+
float d=length(vec2(u-key.x,v-key.y))/360.62445840513925,a=key.w>1e-4?clamp((d-key.z)/key.w,0.,1.):step(key.z,d)-step(d,key.z)*0.;
|
|
31
|
+
c.a*=floor(a*255.)/255.;
|
|
32
|
+
if(keyOpt.z>0.){if(keyOpt.y>.5){float m=max(0.,rgb.b-(rgb.r*.5+rgb.g*.5));rgb.b=max(0.,rgb.b-m*keyOpt.z);}else{float m=max(0.,rgb.g-(rgb.r*.5+rgb.b*.5));rgb.g=max(0.,rgb.g-m*keyOpt.z);}}}
|
|
33
|
+
if(useMatte>.5)c.a*=texture(matte,(uv-mrect.xy)/mrect.zw).r;
|
|
34
|
+
if(colour>.5){rgb=clamp(rgb*bright,0.,1.);rgb=clamp((rgb-.5)*contrast+.5,0.,1.);rgb=clamp(sat*rgb,0.,1.);rgb=clamp(rot*rgb,0.,1.);}
|
|
35
|
+
if(useL1>.5){ivec3 k=ivec3(floor(rgb*255.+.5));rgb=floor(vec3(texelFetch(lut1,ivec2(k.r,0),0).r,texelFetch(lut1,ivec2(k.g,0),0).g,texelFetch(lut1,ivec2(k.b,0),0).b)*255.+.5)/255.;}
|
|
36
|
+
if(useL3>.5)rgb=floor(clamp(tri(floor(rgb*255.+.5)/255.),0.,1.)*255.+.5)/255.;
|
|
37
|
+
rgb=white>.5?1.-(1.-rgb)*fade:rgb*fade;o=vec4(rgb,c.a*alpha);}`,G=`#version 300 es
|
|
38
|
+
in vec2 p;out vec2 uv;void main(){uv=p;gl_Position=vec4(p*2.-1.,0,1);}`,Gr=`#version 300 es
|
|
39
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float sigma;out vec4 o;
|
|
40
|
+
void main(){int r=min(int(ceil(sigma*3.)),128);vec4 acc=vec4(0);float wsum=0.;
|
|
41
|
+
for(int i=-r;i<=r;i++){float w=exp(-float(i*i)/(2.*sigma*sigma));acc+=texture(tex,uv+step*float(i))*w;wsum+=w;}
|
|
42
|
+
o=acc/wsum;}`,qr=`#version 300 es
|
|
43
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float lo;uniform float k;out vec4 o;
|
|
44
|
+
void main(){vec4 c=texture(tex,uv);o=vec4(clamp(lo+c.rgb*k,0.,1.),c.a);}`,jr=`#version 300 es
|
|
45
|
+
precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float amount;out vec4 o;
|
|
46
|
+
void main(){vec4 x=texture(a,uv),y=texture(b,uv);o=mix(x,1.-(1.-x)*(1.-y),amount);}`,$r=`#version 300 es
|
|
47
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float b;uniform int reach;out vec4 o;
|
|
48
|
+
void main(){vec4 acc=texture(tex,uv);float ws=1.;float w=1.;
|
|
49
|
+
for(int i=1;i<=512;i++){if(i>reach)break;w*=b;acc+=(texture(tex,uv+step*float(i))+texture(tex,uv-step*float(i)))*w;ws+=2.*w;}
|
|
50
|
+
o=acc/ws;}`,Hr=`#version 300 es
|
|
51
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float taps[16];uniform int n;uniform vec2 ctr;out vec4 o;
|
|
52
|
+
void main(){vec4 acc=vec4(0);for(int i=0;i<16;i++){if(i>=n)break;acc+=texture(tex,ctr+(uv-ctr)/taps[i]);}o=acc/float(n);}`,Vr=`#version 300 es
|
|
53
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float sx[8];uniform float sy[8];uniform int n;uniform vec3 gain;out vec4 o;
|
|
54
|
+
void main(){vec4 acc=vec4(0);for(int i=0;i<8;i++){if(i>=n)break;acc+=texture(tex,vec2(.5)+(uv-vec2(.5))/vec2(sx[i],sy[i]));}
|
|
55
|
+
acc/=float(n);o=vec4(min(acc.rgb*gain,1.),acc.a);}`,Yr=`#version 300 es
|
|
56
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float gain;out vec4 o;
|
|
57
|
+
void main(){vec4 c=texture(tex,uv);o=vec4(min(c.rgb*gain,1.),c.a);}`,Wr=`#version 300 es
|
|
58
|
+
precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float w;out vec4 o;
|
|
59
|
+
void main(){o=mix(texture(a,uv),texture(b,uv),w);}`,Kr=`#version 300 es
|
|
60
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec4 colour;uniform float usetex;out vec4 o;
|
|
61
|
+
void main(){o=usetex>.5?texture(tex,vec2(uv.x,1.-uv.y)):colour;}`,Qr=`#version 300 es
|
|
62
|
+
precision highp float;uniform sampler2D tex;uniform mat3 inv;uniform vec2 size;uniform vec4 rnd;uniform float keepPre;out vec4 o;
|
|
63
|
+
// a pinned screen's rounded corners (shared/cornerPin.js pinRoundGraph): the server's geq mask on the stretched plane BEFORE its
|
|
64
|
+
// 2 px inset, at pixel centres, kept at least rnd.z (the portal dive's fade to square corners); rnd.w = on
|
|
65
|
+
float corner(ivec2 i){if(rnd.w<.5)return 1.;vec2 k=size/(size-4.),X=(vec2(i)+.5-2.)*k;
|
|
66
|
+
float dx=max(0.,max(rnd.x-X.x,X.x-(size.x-rnd.x))),dy=max(0.,max(rnd.y-X.y,X.y-(size.y-rnd.y)));
|
|
67
|
+
float m=clamp((1.-sqrt(pow(dx/rnd.x,2.)+pow(dy/rnd.y,2.)))*min(rnd.x,rnd.y)+.5,0.,1.);return max(floor(m*255.)/255.,rnd.z);}
|
|
68
|
+
vec4 px(ivec2 i){ivec2 s=ivec2(size);i=clamp(i,ivec2(0),s-1);vec4 c=texelFetch(tex,ivec2(i.x,s.y-1-i.y),0);float a=c.a*corner(i);return vec4(c.rgb*a,a);}
|
|
69
|
+
void main(){vec2 d=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5);vec3 q=inv*vec3(d,1.);vec2 u=floor(q.xy/q.z*256.+.5)/256.;
|
|
70
|
+
vec2 f=floor(u),w=u-f;ivec2 i=ivec2(f);
|
|
71
|
+
vec4 c=mix(mix(px(i),px(i+ivec2(1,0)),w.x),mix(px(i+ivec2(0,1)),px(i+ivec2(1,1)),w.x),w.y);
|
|
72
|
+
o=keepPre>.5?c:c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,Zr=`#version 300 es
|
|
73
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 size;uniform int kind;uniform float e;uniform float f;uniform float inv;
|
|
74
|
+
uniform vec2 ctr;uniform vec3 csh;uniform float count;out vec4 o;
|
|
75
|
+
void main(){vec4 c=texture(tex,uv);float X=gl_FragCoord.x-.5,Y=size.y-gl_FragCoord.y-.5,W=size.x,H=size.y,r;
|
|
76
|
+
float cx=ctr.x*W,cy=ctr.y*H,dx=X-cx,dy=Y-cy,R=length(vec2(max(cx,W-cx),max(cy,H-cy)));
|
|
77
|
+
if(kind<=2){float lin=(X/W-.5)*csh.x+(Y/H-.5)*csh.y,h=csh.z;if(kind==2)r=abs(lin)/h;else{float u=(lin+h)/(2.*h);r=kind==1?mod(u*count,1.):u;}}
|
|
78
|
+
else if(kind==3)r=length(vec2(dx,dy))/R;
|
|
79
|
+
else if(kind==4)r=(abs(dx)/max(cx,W-cx)+abs(dy)/max(cy,H-cy))/2.;
|
|
80
|
+
else if(kind==5){float u=X/W,v=Y/H,A=W/H;r=.1+.78*length(vec2(dx,dy))/R+.12*((sin(u*A*5.3+1.7)*sin(v*4.9+.4)+.55*sin(u*A*11.3-v*9.7+2.3)+.3*sin(u*A*19.1+v*17.3+.7))/1.85);}
|
|
81
|
+
else if(kind==7){float s=W/count,i=floor(X/s),j=floor(Y/s);r=mod(i*i*31.+j*j*17.+i*j*7.+i*13.+j*29.+11.,97.)/97.;}
|
|
82
|
+
else{float a=atan(dx,-dy);if(a<0.)a+=6.283185307179586;r=a/6.283185307179586;}
|
|
83
|
+
float m=clamp((e-r)/f,0.,1.);if(inv>.5)m=1.-m;m=floor(m*255.+.5)/255.;o=vec4(c.rgb,c.a*m);}`,Jr=`#version 300 es
|
|
84
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform highp sampler2D lut;uniform float m[12];uniform float useM;uniform float useL;out vec4 o;
|
|
85
|
+
void main(){vec4 c=texture(tex,uv),v=floor(c*255.+.5);vec3 q=v.rgb;
|
|
86
|
+
if(useM>.5){vec3 r;for(int i=0;i<3;i++)r[i]=floor(v.r*m[i*4]+.5)+floor(v.g*m[i*4+1]+.5)+floor(v.b*m[i*4+2]+.5)+floor(v.a*m[i*4+3]+.5);q=clamp(r,0.,255.);}
|
|
87
|
+
if(useL>.5)q=vec3(texelFetch(lut,ivec2(int(q.r),0),0).r,texelFetch(lut,ivec2(int(q.g),1),0).r,texelFetch(lut,ivec2(int(q.b),2),0).r)*255.;
|
|
88
|
+
o=vec4(q/255.,c.a);}`,ea=`#version 300 es
|
|
89
|
+
precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
|
|
90
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);
|
|
91
|
+
o=vec4(texelFetch(tex,ivec2(clamp(p.x+px,0,W-1),p.y),0).r,c.g,texelFetch(tex,ivec2(clamp(p.x-px,0,W-1),p.y),0).b,c.a);}`,ta=`#version 300 es
|
|
92
|
+
precision highp float;uniform sampler2D tex;uniform int b;uniform ivec2 small;out vec4 o;
|
|
93
|
+
void main(){ivec2 s=textureSize(tex,0),k=ivec2(gl_FragCoord.xy);k.y=small.y-1-k.y;vec4 sum=vec4(0);float n=0.;
|
|
94
|
+
for(int j=0;j<64;j++){if(j>=b)break;int y=k.y*b+j;if(y>=s.y)break;for(int i=0;i<64;i++){if(i>=b)break;int x=k.x*b+i;if(x>=s.x)break;sum+=texelFetch(tex,ivec2(x,s.y-1-y),0);n+=1.;}}
|
|
95
|
+
o=sum/n;}`,oa=`#version 300 es
|
|
96
|
+
precision highp float;uniform sampler2D small;uniform int b;uniform vec2 size;out vec4 o;
|
|
97
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy),ss=textureSize(small,0);int y=int(size.y)-1-p.y;o=texelFetch(small,ivec2(p.x/b,ss.y-1-y/b),0);}`,ia=`#version 300 es
|
|
98
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 off;uniform vec3 col;uniform float op;uniform float times;uniform vec2 dil;out vec4 o;
|
|
99
|
+
void main(){vec2 p=uv-off;float v=0.;if(p.x>=0.&&p.x<=1.&&p.y>=0.&&p.y<=1.)v=floor(texture(tex,p).a*255.+.5);
|
|
100
|
+
float a=dil.y>0.?clamp(floor((v-dil.x)*dil.y),0.,255.):times<1.5?floor(v*op):floor(255.*(1.-pow(1.-v/255.*op,times)));
|
|
101
|
+
o=vec4(col,a/255.);}`,ra=`#version 300 es
|
|
102
|
+
precision highp float;uniform sampler2D tex;uniform float harden;out vec4 o;
|
|
103
|
+
void main(){float a=floor(texelFetch(tex,ivec2(gl_FragCoord.xy),0).a*255.+.5);if(harden>0.)a=clamp((a-128.)*harden+128.,0.,255.);o=vec4(a/255.,0,0,1);}`,aa=`#version 300 es
|
|
104
|
+
precision highp float;uniform sampler2D tex;uniform ivec2 dir;uniform float sigma;out vec4 o;
|
|
105
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy),n=textureSize(tex,0);int r=min(int(ceil(sigma*3.)),128);float acc=0.,ws=0.;
|
|
106
|
+
for(int i=-r;i<=r;i++){float w=exp(-float(i*i)/(2.*sigma*sigma));ivec2 q=p+dir*i;
|
|
107
|
+
if(q.x>=0&&q.y>=0&&q.x<n.x&&q.y<n.y)acc+=texelFetch(tex,q,0).r*w;ws+=w;}
|
|
108
|
+
o=vec4(floor(acc/ws*255.+.5)/255.,0,0,1);}`,na=`#version 300 es
|
|
109
|
+
precision highp float;uniform sampler2D a;uniform sampler2D b;uniform float arc;uniform vec2 cw;uniform vec2 cen;uniform float start;uniform float cover;uniform float comet;uniform float feather;out vec4 o;
|
|
110
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy);float x=floor(texelFetch(a,p,0).r*255.+.5),y=floor(texelFetch(b,p,0).r*255.+.5);
|
|
111
|
+
float band=floor(x*clamp(2.*(1.-y/max(x,1.)),0.,1.));
|
|
112
|
+
if(arc>.5){float K=${ro}.,TAU=6.283185307179586;vec2 u=vec2(gl_FragCoord.x,cw.y*K-gl_FragCoord.y)/K;float th=atan(u.x-cw.x*cen.x,cw.y*cen.y-u.y);
|
|
113
|
+
float d=mod(mod(th-start,TAU)+TAU,TAU)/TAU,m=d<=cover?1.:0.;if(cover<.999)m*=clamp(min(d,cover-d)/feather,0.,1.);if(comet>.5)m*=d/cover;
|
|
114
|
+
band=floor(band*floor(255.*m)/255.);}
|
|
115
|
+
o=vec4(band/255.,0,0,1);}`,sa=`#version 300 es
|
|
116
|
+
precision highp float;uniform sampler2D pic;uniform sampler2D band;uniform sampler2D glow;uniform vec3 col;uniform float k;uniform float am;out vec4 o;
|
|
117
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy);float b=floor(texelFetch(band,p,0).r*255.+.5),g=floor(texelFetch(glow,p,0).r*255.+.5);
|
|
118
|
+
float rim=clamp(floor(b+g*k),0.,255.);if(am<255.)rim=floor(rim*am/255.);
|
|
119
|
+
vec4 P=texelFetch(pic,p,0);float ra=rim/255.,oa=ra+P.a*(1.-ra);
|
|
120
|
+
o=vec4(oa>0.?(col*ra+P.rgb*P.a*(1.-ra))/oa:P.rgb,oa);}`,ca=`#version 300 es
|
|
121
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){vec4 c=texture(tex,uv);o=vec4(c.rgb*c.a,c.a)*.25;}`,fa=`#version 300 es
|
|
122
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){vec4 c=texture(tex,uv);o=c.a>0.?vec4(min(c.rgb/c.a,1.),c.a):vec4(0);}`,la=`#version 300 es
|
|
123
|
+
precision highp float;uniform sampler2D tex;uniform vec2 big;uniform vec2 small;uniform vec4 q1;uniform vec4 q2;uniform float useQ;
|
|
124
|
+
uniform vec4 w1;uniform vec4 w2;uniform float useW;uniform float inv;out vec4 o;
|
|
125
|
+
float rp(float v,float lo,float hi,float ss){return clamp((v-lo)/ss+1.,0.,1.)*clamp((hi-v)/ss+1.,0.,1.);}
|
|
126
|
+
void main(){vec2 X=floor(gl_FragCoord.xy),c=(X+.5)*big/small;vec3 a=vec3(0);
|
|
127
|
+
for(int j=0;j<2;j++)for(int i=0;i<2;i++)a+=texture(tex,(c+vec2(float(i)*2.-1.,float(j)*2.-1.))/big).rgb;
|
|
128
|
+
vec3 p=floor(a/4.*255.+.5)/255.;float m=1.;
|
|
129
|
+
if(useQ>.5){float h=atan(sqrt(3.)*(p.g-p.b),2.*p.r-p.g-p.b)*180./3.14159265358979;if(h<0.)h+=360.;
|
|
130
|
+
float d=abs(h-q1.x);if(d>180.)d=360.-d;float mh=q1.y>=360.?1.:clamp((q1.y/2.+q1.z-d)/q1.z,0.,1.);
|
|
131
|
+
float ch=max(max(p.r,p.g),p.b)-min(min(p.r,p.g),p.b),l=.2126*p.r+.7152*p.g+.0722*p.b;
|
|
132
|
+
m*=mh*rp(ch,q2.x,q2.y,q1.w)*rp(l,q2.z,q2.w,q1.w);}
|
|
133
|
+
if(useW>.5){float dx=X.x/small.x-w1.x,dy=X.y/small.y-w1.y,x=dx*w2.x-dy*w2.y,y=dx*w2.y+dy*w2.x;
|
|
134
|
+
if(w2.w>1.5)m*=clamp(.5-y/w1.w,0.,1.);
|
|
135
|
+
else{float nx=abs(x)/w1.z,ny=abs(y)/w2.z,dist=w2.w>.5?max(nx,ny):length(vec2(nx,ny));m*=clamp((1.+w1.w/2.-dist)/w1.w,0.,1.);}}
|
|
136
|
+
if(inv>.5)m=1.-m;o=vec4(floor(255.*m+1e-4)/255.,0,0,1);}`,ua=`#version 300 es
|
|
137
|
+
precision highp float;uniform sampler2D tex;uniform highp sampler2D lut;uniform highp sampler3D t3;uniform float useT;uniform float useL;
|
|
138
|
+
uniform float useS;uniform mat3 sat;uniform float useR;uniform mat3 rot;out vec4 o;
|
|
139
|
+
vec3 tri(vec3 q){int n=textureSize(t3,0).x;vec3 p=q*float(n-1),f=floor(p),w=p-f;ivec3 i=ivec3(f),j=min(i+1,ivec3(n-1));
|
|
140
|
+
vec3 c000=texelFetch(t3,i,0).rgb,c100=texelFetch(t3,ivec3(j.x,i.y,i.z),0).rgb,c010=texelFetch(t3,ivec3(i.x,j.y,i.z),0).rgb,c110=texelFetch(t3,ivec3(j.x,j.y,i.z),0).rgb;
|
|
141
|
+
vec3 c001=texelFetch(t3,ivec3(i.x,i.y,j.z),0).rgb,c101=texelFetch(t3,ivec3(j.x,i.y,j.z),0).rgb,c011=texelFetch(t3,ivec3(i.x,j.y,j.z),0).rgb,c111=texelFetch(t3,j,0).rgb;
|
|
142
|
+
return mix(mix(mix(c000,c100,w.x),mix(c010,c110,w.x),w.y),mix(mix(c001,c101,w.x),mix(c011,c111,w.x),w.y),w.z);}
|
|
143
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);vec3 g=floor(c.rgb*255.+.5);
|
|
144
|
+
if(useT>.5)g=floor(clamp(tri(g/255.),0.,1.)*255.+.5);
|
|
145
|
+
if(useL>.5){ivec3 k=ivec3(g);g=floor(vec3(texelFetch(lut,ivec2(k.r,0),0).r,texelFetch(lut,ivec2(k.g,0),0).g,texelFetch(lut,ivec2(k.b,0),0).b)*255.+.5);}
|
|
146
|
+
if(useS>.5)g=floor(clamp(sat*(g/255.),0.,1.)*255.+.5);
|
|
147
|
+
if(useR>.5)g=floor(clamp(rot*(g/255.),0.,1.)*255.+.5);
|
|
148
|
+
o=vec4(g/255.,c.a);}`,ma=`#version 300 es
|
|
149
|
+
precision highp float;uniform sampler2D base;uniform sampler2D over;uniform sampler2D mask;uniform vec2 msz;uniform float full;out vec4 o;
|
|
150
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 b=texelFetch(base,P,0),g=texelFetch(over,P,0);if(full>.5){o=g;return;}
|
|
151
|
+
vec3 q=floor(b.rgb*255.+.5),G=floor(g.rgb*255.+.5);float m=floor(texture(mask,gl_FragCoord.xy/msz).r*255.+.5);
|
|
152
|
+
o=vec4((q+floor((m*(G-q)+128.)/256.))/255.,b.a);}`,pa=`#version 300 es
|
|
153
|
+
precision highp float;uniform sampler2D tex;uniform float k[9];uniform float rdiv;out vec4 o;
|
|
154
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy),S=textureSize(tex,0);vec3 s=vec3(0);
|
|
155
|
+
for(int j=0;j<3;j++)for(int i=0;i<3;i++){int x=abs(P.x+i-1),y=abs(P.y+j-1);x=x>=S.x?2*S.x-1-x:x;y=y>=S.y?2*S.y-1-y:y;s+=floor(texelFetch(tex,ivec2(x,y),0).rgb*255.+.5)*k[j*3+i];}
|
|
156
|
+
vec4 c=texelFetch(tex,P,0);o=vec4(clamp(floor(s*rdiv+.5),0.,255.)/255.,c.a);}`,da=`#version 300 es
|
|
157
|
+
precision highp float;uniform sampler2D tex;uniform sampler2D grain;out vec4 o;
|
|
158
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);float n=floor(texelFetch(grain,P,0).r*255.+.5)-128.;o=vec4(clamp(floor(c.rgb*255.+.5)+n,0.,255.)/255.,c.a);}`,xa=`#version 300 es
|
|
159
|
+
precision highp float;uniform sampler2D res;uniform sampler2D outp;uniform sampler2D inp;out vec4 o;
|
|
160
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 r=texelFetch(res,P,0);vec3 R=floor(r.rgb*255.+.5),O=floor(texelFetch(outp,P,0).rgb*255.+.5),I=floor(texelFetch(inp,P,0).rgb*255.+.5);
|
|
161
|
+
vec3 d=clamp(O-I+128.,0.,255.);o=vec4(clamp(R+d-128.,0.,255.)/255.,r.a);}`,va=`#version 300 es
|
|
162
|
+
precision highp float;uniform sampler2D tex;uniform sampler2D soft;uniform float t;out vec4 o;
|
|
163
|
+
void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);vec3 V=floor(c.rgb*255.+.5),B=floor(texelFetch(soft,P,0).rgb*255.+.5);
|
|
164
|
+
vec3 x=clamp(V-B+128.,0.,255.)-128.,g=clamp((abs(x)-t)/t,0.,1.),d=clamp(floor(128.+x*g*g*(3.-2.*g)+.5),0.,255.);
|
|
165
|
+
o=vec4(clamp(B+d-128.,0.,255.)/255.,c.a);}`,ha=`#version 300 es
|
|
166
|
+
precision highp float;in vec2 uv;uniform sampler2D top;uniform sampler2D bg;uniform int mode;out vec4 o;
|
|
167
|
+
void main(){vec4 s=texture(top,uv),b=texture(bg,uv);vec3 Bp=floor(b.rgb*255.+.5),S=floor(s.rgb*255.+.5);float a=floor(s.a*255.+.5),ab=b.a;
|
|
168
|
+
if(mode==1){o=vec4(min(vec3(255.),Bp+floor(S*a/255.+.5))/255.,min(1.,a/255.+ab));return;}
|
|
169
|
+
// the backdrop is premultiplied (a comp's own transparent picture, gpuExport frames mode): blended against its straight colour, and
|
|
170
|
+
// where it is transparent the layer shows as itself (W3C / After Effects); an opaque backdrop (ab = 1) is the formula as before
|
|
171
|
+
vec3 B=ab>0.?(ab<1.?floor(Bp/ab+.5):Bp):vec3(0),X;
|
|
172
|
+
if(mode==2)X=255.-floor((255.-B)*(255.-S)/255.);
|
|
173
|
+
else if(mode==3)X=floor(B*S/255.);
|
|
174
|
+
else if(mode==4)X=mix(255.-2.*floor((255.-B)*(255.-S)/255.),2.*floor(B*S/255.),step(B,vec3(127.5)));
|
|
175
|
+
else if(mode==5)X=max(B,S);else if(mode==6)X=min(B,S);else if(mode==7)X=abs(B-S);
|
|
176
|
+
else if(mode==9)X=mix(min(vec3(255.),floor(B*256./max(vec3(1.),255.-S))),vec3(255.),step(254.5,S));else X=B+S-2.*floor(B*S/255.);
|
|
177
|
+
X=clamp(X,0.,255.);if(ab<1.)X=mix(S,X,ab);o=vec4(floor((X*a+Bp*(255.-a))/255.+.5)/255.,ab<1.?a/255.+ab*(1.-a/255.):b.a);}`,ga=`#version 300 es
|
|
178
|
+
precision highp float;uniform sampler2D tex;uniform int ss;out vec4 o;
|
|
179
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy)*ss;vec4 c=vec4(0);for(int j=0;j<4;j++){if(j>=ss)break;for(int i=0;i<4;i++){if(i>=ss)break;c+=texelFetch(tex,p+ivec2(i,j),0);}}
|
|
180
|
+
c/=float(ss*ss);o=c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,Ea=`#version 300 es
|
|
181
|
+
precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
|
|
182
|
+
void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);int xr=p.x-px,xb=p.x+px;
|
|
183
|
+
o=vec4(xr>=0&&xr<W?texelFetch(tex,ivec2(xr,p.y),0).r:0.,c.g,xb>=0&&xb<W?texelFetch(tex,ivec2(xb,p.y),0).b:0.,c.a);}`,ba=`#version 300 es
|
|
184
|
+
precision highp float;uniform sampler2D tex;uniform vec2 size;uniform vec2 msize;uniform float v;uniform float fr;out vec4 o;
|
|
185
|
+
float sh(float Y){float band=floor(Y*24./size.y),k=mod(band*73.+fr*151.+17.,97.)/97.;return k>1.-v*.6?(k-.5)*2.*v*.15:0.;}
|
|
186
|
+
float mx(vec2 s){float X=(s.x+.5)*size.x/msize.x-.5,Y=(s.y+.5)*size.y/msize.y-.5;return floor(clamp(X-size.x*sh(Y),0.,size.x-1.));}
|
|
187
|
+
void main(){float X=gl_FragCoord.x-.5,Y=size.y-gl_FragCoord.y-.5;vec2 p=vec2((X+.5)*msize.x/size.x-.5,(Y+.5)*msize.y/size.y-.5),f=floor(p),w=p-f;
|
|
188
|
+
vec2 a=clamp(f,vec2(0),msize-1.),b=clamp(f+1.,vec2(0),msize-1.);
|
|
189
|
+
float m=mix(mix(mx(a),mx(vec2(b.x,a.y)),w.x),mix(mx(vec2(a.x,b.y)),mx(b),w.x),w.y);
|
|
190
|
+
o=texelFetch(tex,ivec2(clamp(int(floor(m+.5)),0,int(size.x)-1),int(size.y)-1-int(Y)),0);}`,Ta=`#version 300 es
|
|
191
|
+
precision highp float;uniform sampler2D tex;uniform vec2 size;uniform float a[8];uniform float sx[8];uniform float sy[8];out vec4 o;
|
|
192
|
+
void main(){vec2 p=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5),c=size*.5-.5;vec4 acc=vec4(0);
|
|
193
|
+
for(int k=0;k<8;k++){vec2 d=p-c;float cs=cos(a[k]),sn=sin(a[k]);vec2 q=vec2(d.x*cs+d.y*sn,-d.x*sn+d.y*cs);vec2 s=q/vec2(sx[k],sy[k])+c;
|
|
194
|
+
vec2 uv=vec2((s.x+.5)/size.x,1.-(s.y+.5)/size.y);acc+=(uv.x<0.||uv.x>1.||uv.y<0.||uv.y>1.)?vec4(0):texture(tex,uv);}
|
|
195
|
+
o=acc/8.;}`,wa=`#version 300 es
|
|
196
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;uniform float w;out vec4 o;
|
|
197
|
+
void main(){vec4 c=texture(tex,uv);o=vec4(mix(c.rgb,1.-c.rgb,w),c.a);}`,ya=`#version 300 es
|
|
198
|
+
precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,Ra=["wipe","blinds","split","iris","diamond","burn"];function So(p,E){const y=Math.max(1e-4,p.feather??.05),e=p.progress?Kt(p.progress,E)??0:E,q=(p.angle??0)*Math.PI/180,h=Math.cos(q),N=Math.sin(q),M=Ra.indexOf(p.type??""),V=p.type==="grid";return{type:"txMask",kind:V?7:M<0?6:M,e:e*(1+2*y)-y,f:y,inv:!!p.invert,cx:p.cx??.5,cy:p.cy??.5,c:h,s:N,h:.5*(Math.abs(h)+Math.abs(N)),count:p.count??(V?Pi:8)}}function Do(p,E,y,e,q=0,h){if(!p)return[];const N=V=>Kt(p[V],E)??0,M=[];if(p.zoomBlur&&M.push({type:"txZoom",taps:Mi(),w:N("zoomBlur"),...h?{c:[h.cx,1-h.cy]}:{}}),p.spinBlur){const V=Si(y,e),ie=se=>Math.max(2,Math.round(se/2)*2);M.push({type:"txSpin",a:V.map(se=>+se.a.toFixed(6)),sx:V.map(se=>ie(y*se.scale)/y),sy:V.map(se=>ie(e*se.scale)/e),w:N("spinBlur")})}if(p.dirBlur){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:N("dirBlur")})}if(p.dirBlurV){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:N("dirBlurV"),v:!0})}return p.blur&&M.push({type:"txGauss",sigma:Di*y/1280,w:N("blur")}),p.glitch&&M.push({type:"txGlitch",v:N("glitch"),fr:Math.floor(q*30+.5)}),p.rgbSplit&&M.push({type:"txRgb",px:Math.trunc(N("rgbSplit")*Ui*y/1280+.5)}),p.exposure&&M.push({type:"txExpo",gain:ki,w:N("exposure")}),p.invert&&M.push({type:"txInv",w:N("invert")}),M}function _a(p,E){const y=new OffscreenCanvas(p,E),e=y.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const q=(a,c)=>{const i=e.createShader(a);if(e.shaderSource(i,c),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(i)));return i},h=(a,c)=>{const i=e.createProgram();if(e.attachShader(i,q(e.VERTEX_SHADER,a)),e.attachShader(i,q(e.FRAGMENT_SHADER,c)),e.bindAttribLocation(i,0,"p"),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(i)));return i},N=h(Or,zr),M=h(G,ia),V=h(G,ra),ie=h(G,aa),se=h(G,na),me=h(G,sa),de=h(G,ca),d=h(G,fa),R=h(G,la),F=h(G,Gr),C=h(G,qr),L=h(G,jr),X=h(G,ya),te=h(G,Vr),oe=h(G,ua),O=h(G,ma),Ae=h(G,pa),we=h(G,da),je=h(G,va),ye=h(G,xa),Ke=h(G,$r),$e=h(G,Hr),nt=h(G,Yr),Me=h(G,Wr),st=h(G,Kr),Qe=h(G,Qr),Re=h(G,Zr),He=h(G,Jr),Ze=h(G,ea),Se=h(G,ta),Xe=h(G,oa),it=h(G,ha),Z=h(G,ga),ge=h(G,Ea),ct=h(G,wa),Ve=h(G,ba),ke=h(G,Ta),rt=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,rt),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0);const Ye=a=>c=>e.getUniformLocation(a,c),A=Ye(N);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ce=()=>{const a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a);for(const[c,i]of[[e.TEXTURE_MIN_FILTER,e.LINEAR],[e.TEXTURE_MAG_FILTER,e.LINEAR],[e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE],[e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE]])e.texParameteri(e.TEXTURE_2D,c,i);return a},ft=ce(),Et=ce();let We=null;const at=ce(),lt=e.createTexture(),Oe={l1:"",l3:""};let bt=!1,Gt=!1,Pe=null;const Qt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8,light:9};let _e=0;const Tt=ce();let U=[],wt=null,yt=null;const Rt=new Map;let Be=!1,be=null;const _t=a=>{const c=Fe(),i=(a+1)%3,o=(a+2)%3;for(const u of U){let g=a;e.disable(e.BLEND),u.sigma>.05&&($(F,c[i].fb,[c[a].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),1/p,0),e.uniform1f(w("sigma"),u.sigma)}),$(F,c[o].fb,[c[i].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),0,1/E),e.uniform1f(w("sigma"),u.sigma)}),g=o),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,l,m]=[1,3,5].map(w=>parseInt(u.color.slice(w,w+2),16)/255);$(M,null,[c[g].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("off"),Math.trunc(u.dx)/p,-Math.trunc(u.dy)/E),e.uniform3f(w("col"),t,l,m),e.uniform1f(w("op"),u.opacity),e.uniform1f(w("times"),u.times),e.uniform2f(w("dil"),u.dilate?+(rr*255).toFixed(3):0,u.dilate?+(1/ar).toFixed(3):0)})}},ut=a=>{const c=Fe();if(Be){le(be.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),$(de,be.fb,[c[a].tex],i=>e.uniform1i(i("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(U.length&&_t(a),_e){Je(c[a].tex);return}le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),$(X,null,[c[a].tex],i=>e.uniform1i(i("tex"),0))},Je=a=>{le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,E,0),e.disable(e.BLEND),$(it,null,[a,Tt],c=>{e.uniform1i(c("top"),0),e.uniform1i(c("bg"),1),e.uniform1i(c("mode"),_e)})};let Ne=null;const Fe=()=>Ne??=[De(),De(),De()],Ft=new Map,Dt=a=>{let c=Ft.get(a);if(c)return c;const i=()=>{const o=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p*a,E*a,0,e.RGBA,e.UNSIGNED_BYTE,null);const u=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,u),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:u}};return c={plane:i(),out:i()},Ft.set(a,c),c},Ut=new Map,qt=new Map,Zt=a=>{let c=Ut.get(a.key);if(c)return c;c=ce();const i=new Uint8Array(256*3);(a.lut??[]).forEach((o,u)=>i.set(o,u*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,i),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);return Ut.set(a.key,c),c},mt=(a,c)=>{const i=`${a}x${c}`;let o=qt.get(i);if(o)return o;const u=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);for(const t of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,t,e.NEAREST);const g=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,g),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,u,0),o={tex:u,fb:g},qt.set(i,o),o},At=new Map,kt=(a,c)=>{const i=`${a}x${c}`;let o=At.get(i);return o||(o=[0,1].map(()=>{const u=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const g=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,g),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,u,0),{tex:u,fb:g}}),At.set(i,o),o)},De=()=>{const a=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p,E,0,e.RGBA,e.UNSIGNED_BYTE,null);const c=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,c),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a,0),{tex:a,fb:c}},le=a=>{e.bindFramebuffer(e.FRAMEBUFFER,a),e.viewport(0,0,p,E)},$=(a,c,i,o)=>Mt(a,c,p,E,i,o),Mt=(a,c,i,o,u,g)=>{e.bindFramebuffer(e.FRAMEBUFFER,c),e.viewport(0,0,i,o),e.useProgram(a);const t=Ye(a);u.forEach((l,m)=>{e.activeTexture(e.TEXTURE0+m),e.bindTexture(e.TEXTURE_2D,l)}),g(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),u.length>1&&r(),e.activeTexture(e.TEXTURE0)},r=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0)},f=(a,c=0)=>{const i=Fe();let o=c;const u=(t,l,m,w)=>{$(F,i[l].fb,[i[t].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),1/p,0),e.uniform1f(n("sigma"),w)}),$(F,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),0,1/E),e.uniform1f(n("sigma"),w)})},g=(t,l,m,w)=>$(Me,i[m].fb,[i[t].tex,i[l].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("w"),w)});for(const t of a){const[l,m,w]=[o,(o+1)%3,(o+2)%3];if(t.type==="blur"){t.sigma>.05&&(u(l,m,w,t.sigma),o=w);continue}if(t.type==="colour"){const n=Zt(t);$(He,i[m].fb,[i[l].tex,n],v=>{e.uniform1i(v("tex"),0),e.uniform1i(v("lut"),1),e.uniform1f(v("useM"),t.m?1:0),e.uniform1f(v("useL"),t.lut?1:0),t.m&&e.uniform1fv(v("m"),t.m.flatMap(S=>[S[0],S[1],S[2],S[3]??0]))}),o=m;continue}if(t.type==="txRgb"){t.px>0&&($(ge,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=m);continue}if(t.type==="txGlitch"){t.v>1e-4&&($(Ve,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),p,E),e.uniform2f(n("msize"),Math.max(2,Math.round(p/4)),Math.max(2,Math.round(E/4))),e.uniform1f(n("v"),t.v),e.uniform1f(n("fr"),t.fr)}),o=m);continue}if(t.type==="txInv"){t.w>1e-4&&($(ct,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("w"),Math.min(1,t.w))}),o=m);continue}if(t.type==="shift"){$(Ze,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=m;continue}if(t.type==="pixel"){const n=Math.ceil(p/t.block),v=Math.ceil(E/t.block),S=mt(n,v);e.bindFramebuffer(e.FRAMEBUFFER,S.fb),e.viewport(0,0,n,v),e.useProgram(Se),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i[l].tex),e.uniform1i(e.getUniformLocation(Se,"tex"),0),e.uniform1i(e.getUniformLocation(Se,"b"),t.block),e.uniform2i(e.getUniformLocation(Se,"small"),n,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),$(Xe,i[m].fb,[S.tex],Y=>{e.uniform1i(Y("small"),0),e.uniform1i(Y("b"),t.block),e.uniform2f(Y("size"),p,E)}),o=m;continue}if(t.type==="txMask"){$(Re,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),p,E),e.uniform1i(n("kind"),t.kind),e.uniform1f(n("e"),t.e),e.uniform1f(n("f"),t.f),e.uniform1f(n("inv"),t.inv?1:0),e.uniform2f(n("ctr"),t.cx,t.cy),e.uniform3f(n("csh"),t.c,t.s,t.h),e.uniform1f(n("count"),t.count)}),o=m;continue}if(t.type==="txGauss"||t.type==="txDir"||t.type==="txZoom"||t.type==="txSpin"||t.type==="txExpo"){if(!(t.w>1e-4))continue;let n=m;t.type==="txGauss"?(u(l,m,w,t.sigma),n=w):t.type==="txDir"?$(Ke,i[m].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),t.v?e.uniform2f(S("step"),0,1/E):e.uniform2f(S("step"),1/p,0),e.uniform1f(S("b"),t.b),e.uniform1i(S("reach"),t.reach)}):t.type==="txZoom"?$($e,i[m].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1fv(S("taps"),t.taps),e.uniform1i(S("n"),t.taps.length),e.uniform2f(S("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?$(ke,i[m].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform2f(S("size"),p,E),e.uniform1fv(S("a"),t.a),e.uniform1fv(S("sx"),t.sx),e.uniform1fv(S("sy"),t.sy)}):$(nt,i[m].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1f(S("gain"),t.gain)});const v=n===w?m:w;g(l,n,v,Math.min(1,t.w)),o=v;continue}if(t.type==="burst"){const{w:n,h:v}=ur(p,E),[S,Y]=kt(n,v),K=cr(fr.burst*t.amount).map(Q=>lr(n,v,Q));$(C,i[m].fb,[i[l].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1f(Q("lo"),t.lo),e.uniform1f(Q("k"),t.k)}),Mt(X,S.fb,n,v,[i[m].tex],Q=>e.uniform1i(Q("tex"),0)),Mt(te,Y.fb,n,v,[S.tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1i(Q("n"),K.length),e.uniform1fv(Q("sx"),K.map(Ee=>Ee.sw/n)),e.uniform1fv(Q("sy"),K.map(Ee=>Ee.sh/v)),e.uniform3f(Q("gain"),...pr(t.amount))}),$(L,i[w].fb,[i[l].tex,Y.tex],Q=>{e.uniform1i(Q("a"),0),e.uniform1i(Q("b"),1),e.uniform1f(Q("amount"),+t.amount.toFixed(4))}),o=w;continue}$(C,i[m].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("lo"),t.lo),e.uniform1f(n("k"),t.k)}),u(m,w,m,t.sigma),$(L,i[w].fb,[i[l].tex,i[m].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("amount"),t.amount)}),o=w}return o};let k=null,x="",b=[],z="";const B=(a,c)=>{if(z!==`${a}x${c}`){for(const i of b)e.deleteTexture(i.tex),e.deleteFramebuffer(i.fb);b=Array.from({length:4},()=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}}),z=`${a}x${c}`}return b},ue=(a,c,i,o)=>{const u=e.getParameter(e.FRAMEBUFFER_BINDING),g=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),l=B(o.ew,o.eh),m=(n,v,S,Y)=>{e.bindFramebuffer(e.FRAMEBUFFER,l[v].fb),e.viewport(0,0,o.ew,o.eh),e.useProgram(n);const K=Ye(n);S.forEach((Q,Ee)=>{e.activeTexture(e.TEXTURE0+Ee),e.bindTexture(e.TEXTURE_2D,l[Q].tex)}),Y(K),e.drawArrays(e.TRIANGLE_STRIP,0,4),S.length>1&&r(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const n=Bt(a,i);e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.disable(e.BLEND),qe(a,[0,0,1,1],c,1,1,!1,n==="win"?null:i,n)}m(V,1,[0],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("harden"),o.harden?tr:0)});const w=(n,v,S,Y)=>{m(ie,v,[n],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),1,0),e.uniform1f(K("sigma"),Y)}),m(ie,S,[v],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),0,1),e.uniform1f(K("sigma"),Y)})};w(1,2,3,o.band),m(se,2,[1,3],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1);const v=o.arc;e.uniform1f(n("arc"),v?1:0),v&&(e.uniform2f(n("cw"),o.ew/ro,o.eh/ro),e.uniform2f(n("cen"),v.cen[0],v.cen[1]),e.uniform1f(n("start"),v.start),e.uniform1f(n("cover"),v.cover),e.uniform1f(n("comet"),v.comet?1:0),e.uniform1f(n("feather"),or*v.cover))}),w(2,1,3,o.glow),m(me,1,[0,2,3],n=>{e.uniform1i(n("pic"),0),e.uniform1i(n("band"),1),e.uniform1i(n("glow"),2),e.uniform3f(n("col"),...o.col),e.uniform1f(n("k"),o.k),e.uniform1f(n("am"),o.am)}),e.bindFramebuffer(e.FRAMEBUFFER,u),e.viewport(g[0],g[1],g[2],g[3]),t&&e.enable(e.BLEND)};let W=null,J="",s=null,_=[],re="";const xe=new Map,ze=new Map,pe=new Map,Ge=new Map,ae=new Map,P=new Map,Le=ce(),Pt=(a,c)=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}},jt=(a,c,i)=>{const o=e.getParameter(e.FRAMEBUFFER_BINDING),u=e.getParameter(e.VIEWPORT),g=e.isEnabled(e.BLEND),t=a.w,l=a.h;if(re!==`${t}x${l}`){for(const H of _)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);_=Array.from({length:7},()=>Pt(t,l)),re=`${t}x${l}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,_[0].fb),e.viewport(0,0,t,l),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),qe(a,[0,1,1,-1],[0,0,1,1],1,1,!1,c,"base");let m=0;const w=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],n=(H,j,dt,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,_[j].fb),e.viewport(0,0,t,l),e.useProgram(H);const Ie=Ye(H);dt.forEach((xt,vt)=>{e.activeTexture(e.TEXTURE0+vt),e.bindTexture(xt.d3?e.TEXTURE_3D:e.TEXTURE_2D,xt.t)}),et(Ie),e.drawArrays(e.TRIANGLE_STRIP,0,4),r()},v=H=>({t:_[H].tex}),S=(H,j,dt,et)=>{n(F,j,[v(H)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),1/t,0),e.uniform1f(Ie("sigma"),et)}),n(F,dt,[v(j)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),0,1/l),e.uniform1f(Ie("sigma"),et)})},Y=i.list,K=Y.map(H=>io(H)),Q=zi(Y),Ee=new Set;for(const[H,j]of Y.entries()){const dt=Q[H];if(H===dt&&Y.some((T,D)=>D>H&&Q[D]===H&&K[D])&&(n(X,2,[v(m)],T=>e.uniform1i(T("tex"),0)),Ee.add(H)),!K[H])continue;const et=H!==dt&&Ee.has(dt)?j.branch:void 0,Ie=et?2:m;let xt=Le,vt=[1,1];if(j.qualifier){const T=Math.max(2,Math.trunc((t+St-1)/St)),D=Math.max(2,Math.trunc((l+St-1)/St)),I=`${T}x${D}`;let ne=xe.get(I);ne||(ne=Pt(T,D),xe.set(I,ne));const ee=j.qualifier,ve=Math.max(.001,ee.soft??.3),Ue=j.window,gt=-(Ue?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ne.fb),e.viewport(0,0,T,D),e.useProgram(R),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,_[Ie].tex);const Te=Ye(R);e.uniform1i(Te("tex"),0),e.uniform2f(Te("big"),t,l),e.uniform2f(Te("small"),T,D),e.uniform4f(Te("q1"),ee.hue,ee.hueWidth,Math.max(1,ve*60),Math.max(.001,ve*.2)),e.uniform4f(Te("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(Te("useQ"),1),e.uniform1f(Te("useW"),Ue?1:0),Ue&&(e.uniform4f(Te("w1"),Ue.cx,Ue.cy,Math.max(1e-4,Ue.w/2),Math.max(.001,Ue.feather??.2)),e.uniform4f(Te("w2"),Math.cos(gt),Math.sin(gt),Math.max(1e-4,Ue.h/2),Ue.type==="gradient"?2:Ue.type==="rect"?1:0)),e.uniform1f(Te("inv"),j.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),xt=ne.tex,vt=[T*St,D*St]}else if(!j.whole&&Gi(j)&&j.window?.type!=="person"){const T=`${i.clip}#${H}`,D=`${t}x${l}@${i.local??0}`,I=yo,ne=Math.max(2,Math.min(yo*2,Math.round(I*l/t)));let ee=Ge.get(T);if(ee||(ee={tex:ce(),at:""},Ge.set(T,ee)),ee.at!==D){const ve=wo(j,i.src,i.local??0,l/t,null),Ue=new Uint8Array(I*ne);for(let gt=0;gt<ne;gt++)for(let Te=0;Te<I;Te++)Ue[gt*I+Te]=Math.round(ve((Te+.5)/I,(gt+.5)/ne,0,0,0)*255);e.bindTexture(e.TEXTURE_2D,ee.tex),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,I,ne,0,e.RED,e.UNSIGNED_BYTE,Ue),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}xt=ee.tex,vt=[t,l]}else if(!j.whole){const T=Ro(j)?i.src?.depthMap:void 0,D=`${i.clip}#${H}@${t}x${l}${T?`@${T.at}:${T.data.length}:${T.data.slice(0,24)}`:""}`;let I=ze.get(D);if(!I){const ne=qi(j,t,l,Ro(j)?wo(j,i.src,0,l/t):null);I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ne.w4,ne.h4,0,e.RED,e.UNSIGNED_BYTE,ne.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ze.set(D,I)}xt=I,vt=[t,l]}const Nt=j.adjust??{},fo=ji(j),Jt=`${i.clip}#${H}`;let $t=pe.get(Jt);if(fo&&!$t){const T=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((I,ne)=>{T[D*4+ne]=+$i(Nt,I,D/255,j.wheels,j.curves).toFixed(6)}),T[D*4+3]=1;$t=ce(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,T);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);pe.set(Jt,$t)}let ht=null;if(Hi(j)){const T=`${Jt}:${JSON.stringify([j.cst,j.look,j.lut,j.mixer])}`;if(ht=ae.get(T)??null,!ht){const D=Vi(j,I=>mr(I));if(!D)throw Error(`LUT "${j.lut?.name??""}" chưa tải xong`);ht=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,ht),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,D.size,D.size,D.size,0,e.RGB,e.FLOAT,D.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const I of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,I,e.NEAREST);for(const I of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,I,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),ae.set(T,ht)}}const{sat:Co,rot:Xo}=Yi(Nt.saturation??1,Nt.hue??0);n(oe,3,[v(Ie),{t:$t??at},{t:ht??lt,d3:!0}],T=>{e.uniform1i(T("tex"),0),e.uniform1i(T("lut"),1),e.uniform1i(T("t3"),2),e.uniform1f(T("useT"),ht?1:0),e.uniform1f(T("useL"),fo?1:0),e.uniform1f(T("useS"),(Nt.saturation??1)!==1?1:0),e.uniform1f(T("useR"),(Nt.hue??0)!==0?1:0),e.uniformMatrix3fv(T("sat"),!1,w(Co)),e.uniformMatrix3fv(T("rot"),!1,w(Xo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),r();let fe=3;const tt=(T,D)=>[3,4,5].find(I=>I!==T&&I!==D);if((j.blur??0)>0){const T=tt(fe),D=tt(fe,T);S(fe,T,D,Math.max(.1,+((j.blur??0)*Wi*t).toFixed(3))),fe=D}const lo=Ki({sharpness:j.sharpen??0});if(lo){const T=tt(fe);n(Ae,T,[v(fe)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),lo),e.uniform1f(D("rdiv"),1/ir)}),fe=T}const he=j.fx?Qi(j.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const T=tt(fe),D=tt(fe,T);n(C,T,[v(fe)],ve=>{e.uniform1i(ve("tex"),0),e.uniform1f(ve("lo"),he.lo),e.uniform1f(ve("k"),he.k)});let I=T;he.tint&&(n(He,D,[v(T),{t:at}],ve=>{e.uniform1i(ve("tex"),0),e.uniform1i(ve("lut"),1),e.uniform1f(ve("useM"),1),e.uniform1f(ve("useL"),0),e.uniform1fv(ve("m"),he.tint.flat())}),I=D),S(I,I===T?D:T,I,he.sigma);const ee=6;n(L,ee,[v(fe),v(I)],ve=>{e.uniform1i(ve("a"),0),e.uniform1i(ve("b"),1),e.uniform1f(ve("amount"),he.amount)}),n(X,3,[v(ee)],ve=>e.uniform1i(ve("tex"),0)),fe=3}else if(he?.type==="grain"){const T=Zi(i.frame??0),D=`${T}:${t}x${l}:${he.amp}`;let I=P.get(D);if(!I){if(P.size>8){for(const ee of P.values())e.deleteTexture(ee);P.clear()}I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,l,0,e.RED,e.UNSIGNED_BYTE,Ji(T,t,l,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),P.set(D,I)}const ne=tt(fe);n(we,ne,[v(fe),{t:I}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),fe=ne}else if(he?.type==="denoise"){const T=tt(fe),D=tt(fe,T);S(fe,T,D,he.sigma),n(je,6,[v(fe),v(D)],I=>{e.uniform1i(I("tex"),0),e.uniform1i(I("soft"),1),e.uniform1f(I("t"),he.t)}),n(X,3,[v(6)],I=>e.uniform1i(I("tex"),0)),fe=3}else if(he?.type==="swirl"){const T=D=>Math.max(2,Math.round(D/2)*2);for(const D of er(t,l,he.deg)){const I=tt(fe);n(ke,I,[v(fe)],ne=>{e.uniform1i(ne("tex"),0),e.uniform2f(ne("size"),t,l),e.uniform1fv(ne("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ne("sx"),D.map(ee=>T(t*ee.scale)/t)),e.uniform1fv(ne("sy"),D.map(ee=>T(l*ee.scale)/l))}),fe=I}}const Oo=et==="parallel"?2:m,zo=et==="parallel"?6:1-m;n(O,zo,[v(Oo),v(fe),{t:xt}],T=>{e.uniform1i(T("base"),0),e.uniform1i(T("over"),1),e.uniform1i(T("mask"),2),e.uniform2f(T("msz"),vt[0],vt[1]),e.uniform1f(T("full"),j.whole?1:0)}),et==="parallel"&&n(ye,1-m,[v(m),v(6),v(2)],T=>{e.uniform1i(T("res"),0),e.uniform1i(T("outp"),1),e.uniform1i(T("inp"),2)}),m=1-m}s=_[m].tex,e.bindFramebuffer(e.FRAMEBUFFER,o),e.viewport(u[0],u[1],u[2],u[3]),g&&e.enable(e.BLEND)},Bt=(a,c)=>W?(J!==W.key&&(jt(a,c,W),J=W.key),"win"):"pic",pt=(a,c,i,o,u,g,t)=>{if(!k){const S=Bt(a,t);qe(a,c,i,o,u,g,S==="win"?null:t,S);return}const l=We??[0,0,1,1];x!==k.key&&(ue(a,l,t,k),x=k.key);const m=(i[0]-l[0])/l[2],w=(i[1]-l[1])/l[3],n=i[2]/l[2],v=i[3]/l[3];qe(a,c,[m,1-w,n,-v],o,u,g,null,"edge")},qe=(a,c,i,o,u,g,t,l)=>{const m=l==="edge"||l==="win",w=l==="pic"||l==="base";if(e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),w&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a.source),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),i[0],i[1],i[2],i[3]),e.uniform1f(A("alpha"),o),e.uniform1f(A("fade"),u),e.uniform1f(A("white"),g?1:0),e.uniform1f(A("colour"),t?1:0),e.uniform1i(A("tex"),0),e.uniform1i(A("matte"),1),e.uniform1f(A("useMatte"),We&&(l==="pic"||l==="win")?1:0),Pe&&!m?(e.uniform4f(A("key"),Pe.u,Pe.v,Pe.similarity,Pe.blend),e.uniform4f(A("keyOpt"),1,Pe.blue?1:0,Pe.spill,a.bt709?1:0)):e.uniform4f(A("keyOpt"),0,0,0,0),e.uniform1i(A("lut1"),2),e.uniform1i(A("lut3"),3),e.uniform1f(A("useL1"),bt&&!m?1:0),e.uniform1f(A("useL3"),Gt&&!m?1:0),We&&e.uniform4f(A("mrect"),We[0],We[1],We[2],We[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l==="edge"?b[1].tex:l==="win"?s:ft),t){const n=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(A("bright"),t.bright),e.uniform1f(A("contrast"),t.contrast),e.uniformMatrix3fv(A("sat"),!1,n(t.sat)),e.uniformMatrix3fv(A("rot"),!1,n(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:y,clear(a=1){le(null),e.clearColor(0,0,0,a),e.clear(e.COLOR_BUFFER_BIT)},pixels(){le(null);const a=new Uint8ClampedArray(p*E*4),c=p*4,i=new Uint8ClampedArray(p*E*4);e.readPixels(0,0,p,E,e.RGBA,e.UNSIGNED_BYTE,a);for(let o=0;o<E;o++){const u=(E-1-o)*c,g=o*c;for(let t=0;t<c;t+=4){const l=a[u+t+3];if(i[g+t+3]=l,l){const m=255/l;i[g+t]=a[u+t]*m,i[g+t+1]=a[u+t+1]*m,i[g+t+2]=a[u+t+2]*m}}}return i},draw(a,c,i,o,u,g,t=null,l=[],m=null){if(!l.length&&!_e&&!U.length&&!Be){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),pt(a,c,i,o,u,g,t);return}Ne??=[De(),De(),De()],le(Ne[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,m??c,i,o,u,g,t);const w=f(l);if(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),_e||U.length||Be){let n=w;m&&(n=(w+1)%3,le(Ne[n].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ne[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),ut(n);return}if(!m){$(X,null,[Ne[w].tex],n=>e.uniform1i(n("tex"),0));return}e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ne[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(a,c,i,o,u,g,t,l,m,w=null,n=null,v=[]){const S=Fe();le(S[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,u,g,t);const Y=f(l),K=_e||U.length||Be||v.length?(Y+1)%3:-1;K>=0?(le(S[K].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),n&&(e.enable(e.SCISSOR_TEST),e.scissor(n[0],E-n[1]-n[3],n[2],n[3])),$(Qe,K>=0?S[K].fb:null,[S[Y].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform2f(Q("size"),p,E),e.uniform1f(Q("keepPre"),0),e.uniformMatrix3fv(Q("inv"),!1,[m[0],m[3],m[6],m[1],m[4],m[7],m[2],m[5],m[8]]),e.uniform4f(Q("rnd"),w?.[0]??0,w?.[1]??0,w?.[2]??0,w?1:0)}),e.disable(e.SCISSOR_TEST),K>=0&&ut(v.length?f(v,K):K)},adjust(a,c,i){const o=Fe();if(le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,E,0),le(o[0].fb),e.disable(e.BLEND),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Tt),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1i(A("tex"),0),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("useMatte"),0),e.uniform1f(A("colour"),a?1:0),a){const g=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(A("bright"),a.bright),e.uniform1f(A("contrast"),a.contrast),e.uniformMatrix3fv(A("sat"),!1,g(a.sat)),e.uniformMatrix3fv(A("rot"),!1,g(a.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const u=f(c);le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[u].tex),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),i),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(a,c){if(bt=!!a,Gt=!!c,a&&Oe.l1!==a.key){const i=new Float32Array(1024);for(let o=0;o<256;o++)i[o*4]=a.r[o],i[o*4+1]=a.g[o],i[o*4+2]=a.b[o],i[o*4+3]=1;e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,i);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);e.activeTexture(e.TEXTURE0),Oe.l1=a.key}if(c&&Oe.l3!==c.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,c.size,c.size,c.size,0,e.RGB,e.FLOAT,c.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const i of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,i,e.NEAREST);for(const i of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,i,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),Oe.l3=c.key}},key(a){if(!a){Pe=null;return}const[c,i,o]=[1,3,5].map(g=>parseInt(a.color.slice(g,g+2),16)),u=224/255;Pe={u:Math.round(-.168736*u*c-.331264*u*i+.5*u*o+128),v:Math.round(.5*u*c-.418688*u*i-.081312*u*o+128),similarity:a.similarity,blend:a.blend,spill:+a.spill.toFixed(3),blue:o>i}},mode(a){_e=a&&Qt[a]||0},shadow(a){U=a},glBegin(){wt??={base:ce(),a:ce(),b:ce()},le(null),e.bindTexture(e.TEXTURE_2D,wt.base),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,E,0),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)},glEnd(a,c,i){const o=wt;if(le(null),e.bindTexture(e.TEXTURE_2D,a==="a"?o.a:o.b),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,E,0),e.disable(e.BLEND),$(X,null,[o.base],t=>e.uniform1i(t("tex"),0)),a==="a")return;let u=Rt.get(c);u||(u=h(G,mi(sr[c])),Rt.set(c,u)),yt??=De(),$(u,yt.fb,[o.a,o.b],t=>{e.uniform1i(t("glFrom"),0),e.uniform1i(t("glTo"),1),e.uniform1f(t("progress"),Math.max(0,Math.min(1,i))),e.uniform1f(t("ratio"),p/E),e.uniform1f(t("glPremul"),1)});const g=_e;_e=0,Je(yt.tex),_e=g},blurBegin(){be??=De(),le(be.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Be=!0},blurEnd(){Be=!1;const a=Fe();e.disable(e.BLEND),$(d,a[0].fb,[be.tex],c=>e.uniform1i(c("tex"),0)),ut(0)},windows(a){W=a},edge(a){k=a},warpBig(a,c,i,o,u,g,t,l,m,w=[]){const n=Dt(m),v=p*m,S=E*m;e.bindFramebuffer(e.FRAMEBUFFER,n.plane.fb),e.viewport(0,0,v,S),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,u,g,t);const Y=Ot(l.map(([Ee,H])=>[Ee*m,H*m]),v,S);e.bindFramebuffer(e.FRAMEBUFFER,n.out.fb),e.viewport(0,0,v,S),e.useProgram(Qe),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.plane.tex);const K=Ye(Qe);if(e.uniform1i(K("tex"),0),e.uniform2f(K("size"),v,S),e.uniform1f(K("keepPre"),1),e.uniform4f(K("rnd"),0,0,0,0),e.uniformMatrix3fv(K("inv"),!1,[Y[0],Y[3],Y[6],Y[1],Y[4],Y[7],Y[2],Y[5],Y[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!w.length&&!_e&&!U.length&&!Be){$(Z,null,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),m)});return}const Q=Fe();e.disable(e.BLEND),$(Z,Q[0].fb,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),m)}),ut(f(w,0))},matte(a,c=[0,0,1,1]){We=a?c:null,a&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a),e.activeTexture(e.TEXTURE0))},overlay(a,c){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),c&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,c.w,c.h,0,e.RGBA,e.UNSIGNED_BYTE,c.data)),$(st,null,c?[ft]:[],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("usetex"),c?1:0),e.uniform4f(i("colour"),...a??[0,0,0,0])})},finish(){e.finish()}}}let Ce="";const ja=()=>Ce;async function Fa(p,{format:E,encode:y=null,tracks:e={},camera:q=null,signal:h,onProgress:N,frames:M,software:V=!1,liveMotion:ie=!1,range:se,only:me,sink:de}){const d=performance.now(),{width:R,height:F,fps:C}=ao(E);Ce="layers",await Promise.all([...new Set(p.filter(r=>!r.colorBypass).flatMap(r=>Ht(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>nr(r))),Go(uo(p.filter(r=>!r.disabled)));const L=p.filter(r=>!r.disabled&&!Uo(r)),X=uo(L),te=qo(L.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*C);if(!(oe>0)&&!M)throw Error("Empty timeline");const O=jo(q)?q:null,Ae=$o(X,e,O?r=>Xi(r,O,R,F):void 0),we=r=>Ae.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,je=()=>{if(h?.aborted)throw new DOMException("Export cancelled","AbortError")},ye=r=>ie&&!M&&!!r.motion&&!r._virtual&&!r.warped,Ke=r=>M||me!=="audio"&&(!se||r.start<se.to/C+1e-6&&r.start+r.duration>se.from/C-1e-6),$e=new Xr,nt=[...L.filter(r=>Wt(r)&&!ye(r)),...Ho(L)].filter(Ke);nt.length&&await(await Lt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-DnCzi_AI.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))).renderTitleFrames(nt,E,$e,h);const Me=new Map;if(L.some(r=>ye(r)&&Ke(r))){const r=await Lt(()=>import("./titleFrames-DnCzi_AI.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));for(const f of L.filter(k=>ye(k)&&Ke(k)))Me.set(f.id,r.liveMotion(f,L,E))}L.some(r=>r.kind==="model")&&await(await Lt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-DgnorHLm.js");return{render3DFrames:r}},__vite__mapDeps([10,1,11,12,13,8,6,7,14,9]))).render3DFrames(p.filter(r=>!r.disabled),E,$e,h,q);for(const r of X.filter(f=>f._group&&f.comp)){const f=[],k=Math.max(1,Math.ceil(r.duration*C-1e-6));await Fa(xr(vr(r),{W:R,H:F}),{format:E,signal:h,frames:{times:Array.from({length:k},(x,b)=>dr(r,b/C)),push:(x,b)=>{f[x]=b}}}),$e.frames.set(r.id,f)}const st=performance.now();je(),Ce="mattes";const Qe=L.filter(r=>r.mask||r.person),Re=Qe.length?await Lt(()=>import("./rotoMatte-BI-vjjrv.js").then(r=>r.r),__vite__mapDeps([15,1,8,6,7,16])):null;Re&&await Re.prepareMattes(Qe);const He=Re?document.createElement("canvas"):null;Ce="media";const Ze=new Map,Se=new Map,Xe=new Map,it=r=>{let f=Ze.get(r);return f||(f=new Fr({source:new Mr(r,{getRetryDelay:Lo}),formats:Ar}),Ze.set(r,f)),f};for(const r of L){if(r.kind==="video"&&!Se.has(r.url)){const f=await it(r.url).getPrimaryVideoTrack();f&&Se.set(r.url,new Rr(f))}if(r.kind==="image"&&!Wt(r)&&!oo(r)&&!r._group&&!Xe.has(r.url)){const f=await createImageBitmap(await Cr(r.url,h),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Xe.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const Z=new Map,ge=async(r,f)=>{const k=Me.get(r.id);if(k)return{source:await k.frame(Math.round((f-r.start)*C)),w:k.W,h:k.H};const x=$e.frames.get(r.id);if(!x?.length)return null;let b=x.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*C),Math.ceil(r.duration*C)-1,x.length-1));for(;b>0&&x[b]==="=";)b--;const z=Z.get(r.id);if(z&&z.index===b)return z.pic;z?.pic?.close?.();const B=await createImageBitmap(await(await fetch(`data:image/webp;base64,${x[b]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ue={source:B,w:B.width,h:B.height,close:()=>B.close()};return Z.set(r.id,{index:b,pic:ue}),ue},ct=L.filter(r=>Vo(r)),Ve=ct.length?await Lt(()=>import("./captionLayout-eiu9QPJu.js"),__vite__mapDeps([17,1])):null,ke=new Map,rt=new Map;if(Ve){for(const r of new Set(ct.flatMap(f=>[eo(Yo(f.captionStyle).font),eo(mo(f.captionStyle).font)])))if(await Ve.captionFontReady(r.id),!ke.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:h})).arrayBuffer());let k="";for(let x=0;x<f.length;x+=32768)k+=String.fromCharCode(...f.subarray(x,x+32768));ke.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(k)})}`)}}const Ye=new Map,A=async(r,f,k)=>{let x=Ye.get(f.start);if(!x||x.owner!==r){const _=pi(r,f.start,f.duration);x={plan:_,starts:di(_.entries,C),owner:r},Ye.clear(),Ye.set(f.start,x)}const b=k-Math.round(f.start*C);let z=-1;for(let _=0;_<x.starts.length&&x.starts[_]<=b;_++)z=_;const B=x.plan.entries[z];if(!B||B.blank)return null;const ue=x.plan.social?x.plan.social.style:mo(r.captionStyle),W=x.plan.social?xi(x.plan.social,B.gi,R,F,Ve.measureCaption):vi({width:R,height:F,text:B.text,style:ue,measure:Ve.measureCaption,second:B.second}),J=hi(W,ue,x.plan.social?B.scale:1,R,F,B.active,B.motion);let s=rt.get(J);if(!s){const _=eo(ue.font),re=URL.createObjectURL(new Blob([J.replace("<defs>",`<defs><style>${ke.get(_.id)??""}</style>`)],{type:"image/svg+xml"}));try{const xe=new Image(R,F);xe.src=re,await xe.decode();const ze=await createImageBitmap(xe,{premultiplyAlpha:"none"});s={source:ze,w:R,h:F,close:()=>ze.close()}}finally{URL.revokeObjectURL(re)}if(rt.size>64){const[xe,ze]=rt.entries().next().value;ze.close?.(),rt.delete(xe)}rt.set(J,s)}return s},ce=[0,0,1,1],ft=new Map,Et=["x","y","zoom","rot","sx","sy"],We=(r,f,k,x)=>{const b=`${r.id}@${f.start}`;let z=ft.get(b);if(!z){const ue=Math.max(1,Math.ceil(f.duration/.1-1e-6)),W=Array.from({length:ue+1},(_,re)=>f.start+f.duration*re/ue),J=W.map(_=>to(r,_-r.start,R,F)),s=_=>+(+_).toFixed(3);z={ts:W.map(_=>+_.toFixed(5)),v:Object.fromEntries(Et.map(_=>[_,J.map(re=>s(re[_]??(_==="sx"||_==="sy"?1:0)))]))},ft.set(b,z)}const B={...x};for(const ue of Et){const W=z.v[ue];if(W.every(re=>re===W[0])){B[ue]=W[0];continue}let J=z.ts.findIndex((re,xe)=>xe<z.ts.length-1&&k<z.ts[xe+1]);J<0&&(J=z.ts.length-2);const s=+(W[J+1]-W[J]).toFixed(3),_=z.ts[J+1]-z.ts[J];B[ue]=Math.abs(W[J+1]-W[J])<1e-4?W[J]:W[J]+s*Math.max(0,Math.min(1,(k-z.ts[J])/_))}return B},at=new Map,lt=new Map,Oe=(r,f,k,x=r,b="")=>{if(!gi(x))return Fo(x,R);const z=`${r.id}${b}@${f.start}`;let B=lt.get(z);B||(B=Ei(x,{offset:f.start-r.start,duration:f.duration,fps:C}),lt.set(z,B));const ue=k-Math.round(f.start*C),W=B.find(J=>ue>=J.from&&ue<J.to)??B[B.length-1];return Fo({effects:bi(x,W.t)},R)},bt=new Map,Gt=(r,f,k)=>{const x=`${r.id}@${f.start}`;bt.has(x)||bt.set(x,O?Bi(r,O,f.start,f.duration,R,F):null);const b=bt.get(x);return b?Oe(r,f,k,b,":dof"):[]},Pe=new Map,Qt=r=>{const f=JSON.stringify(r.grade);let k=Pe.get(f);if(!k){const x=B=>Array.from(B,ue=>+ue.toFixed(6)),b=Ri(r.grade)?_i(r.grade):null,z=r.grade.mixer&&Fi(r.grade.mixer)?Ai(r.grade.mixer):null;k={l1:b?{key:`1${f}`,r:x(b.r),g:x(b.g),b:x(b.b)}:null,l3:z?{key:`3${f}`,size:z.size,data:Float32Array.from(z.data,B=>+B.toFixed(6))}:null},Pe.set(f,k)}return k};let _e=null;const Tt=async(r,f,k)=>{const x=L.find(B=>B.id===r);if(!x||f<x.start||f>=x.start+x.duration)return null;if(Wt(x)){const B=await ge(x,f);return B&&{source:B.source,w:B.w,h:B.h}}if(x.kind==="image"){const B=Xe.get(x.url);return B?{source:B.source,w:B.w,h:B.h}:null}if(x.kind!=="video")return null;const b=await Mo(mt,Se,x,f,C,Math.max(k.start,x.start),k.duration);if(!b)return null;const z=b.toVideoFrame();return{source:z,w:b.displayWidth,h:b.displayHeight,close:()=>z.close()}};Ce="output";const U=_a(R,F),wt=no(y,{width:R,height:F,fps:C},so),yt=y?.codec==="hevc",Rt=y?.container==="mov",Be=!M&&!de&&te*wt/8>15e7&&!!navigator.storage?.getDirectory;let be=null,_t;if(Be){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${Rt?"mov":"mp4"}`,k=await r.getFileHandle(f,{create:!0});be={dir:r,handle:k,name:f},_t=new Ao(await k.createWritable(),{chunked:!0,chunkSize:1<<20})}else _t=de&&!M?new Ao(de,{chunked:!0,chunkSize:1<<22}):new Dr;const ut=de&&!M?!1:Be?"reserve":"in-memory",Je=new Ur({format:Rt?new kr({fastStart:ut}):new Pr({fastStart:ut}),target:_t}),Ne=new Br(U.canvas,{codec:yt?"hevc":"avc",bitrate:wt,keyFrameInterval:2,...yt?{hardwareAcceleration:"prefer-hardware"}:V?{hardwareAcceleration:"prefer-software"}:{}}),Fe=me==="audio"?0:Math.max(0,Math.min(oe,se?.from??0)),Ft=me==="audio"?0:Math.max(Fe,Math.min(oe,se?.to??oe));me!=="audio"&&Je.addVideoTrack(Ne,{frameRate:C,...Be?{maximumPacketCount:Ft-Fe+8}:{}});const Dt=new Nr({codec:"aac",bitrate:No});me!=="video"&&Je.addAudioTrack(Dt,Be?{maximumPacketCount:Math.ceil(te*zt/1024)+16}:{}),M||await Je.start();const Ut=M?new OffscreenCanvas(R,F):null,qt=Ut?.getContext("2d"),Zt=async r=>{qt.putImageData(new ImageData(U.pixels(),R,F),0,0);const f=new Uint8Array(await(await Ut.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let k="";for(let x=0;x<f.length;x+=32768)k+=String.fromCharCode(...f.subarray(x,x+32768));M.push(r,btoa(k))},mt=new Map;let At=0;const kt={decode:0,matte:0,titles:0,captions:0,encode:0},De=async(r,f)=>{const k=performance.now();try{return await f}finally{kt[r]+=performance.now()-k}},le=(r,f)=>{const k=performance.now();try{return f()}finally{kt[r]+=performance.now()-k}};try{for(let f=M?0:Fe,k=M?M.times.length:Ft;f<k;f++){je(),Ce="frame";const x=M?M.times[f]:f/C,b=we(x);U.clear(M?0:1);const z=b&&Ve?Wo(L,b.start+1e-5,e):void 0,B=z&&b?Ko(b.visuals,z.captionStyle?.layerTrack):-1,ue=async()=>{const W=z&&b&&await De("captions",A(z,b,f));W&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(W,ce,ce,1,1,!1,null,[]))};for(const[W,J]of(b?.visuals??[]).entries()){let s=J;if(W===B&&await ue(),s.kind==="audio")continue;const _=b?po(s,b.start,b.start+b.duration):null,re=_?s._txIn===_?"b":"a":null,xe=_?Qo(_,x):0,ze=_&&re?_.spec.gl?.id??null:null;ze&&U.glBegin();e:{if(s.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(xo(s,R)),U.key(null),U.grade(null,null);const o=await ge(s,x);o&&U.draw(o,ce,ce,1,1,!1,null,[]);break e}const pe=x-s.start,Ge=to(s,pe,R,F),ae=(Zo(s)||Jo(s))&&!_&&!(O&&Vt(s))&&!s.pin?We(s,b,x,Ge):Ge;if(!(ae.opacity>1e-4))break e;if(oo(s)){U.adjust(ot(s),Oe(s,b,f),Math.min(1,ae.opacity));break e}let P=null,Le=null;if(Wt(s)||s._group)P=await De("titles",ge(s,x));else if(s.kind==="image")P=Xe.get(s.url)??null;else if(s.kind==="video"){const o=await De("decode",Mo(mt,Se,s,x,C,b.start,b.duration));o&&(Le=o.toVideoFrame(),P={source:Le,w:o.displayWidth,h:o.displayHeight,bt709:Le.colorSpace?.matrix?Le.colorSpace.matrix==="bt709":o.displayHeight>=720})}if(!P)break e;if(ei(s)){const o=s.crop||{left:0,right:0,top:0,bottom:0},u=Math.floor(P.w*o.left/2)*2,g=Math.floor(P.h*o.top/2)*2,t=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),l=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2),m=s.distort.displace?await Tt(s.distort.displace.map,x,b):null;_e??=wr();const w=_e.render({source:P.source,srcW:P.w,srcH:P.h,rect:[u,g,t,l],outW:t,outH:l,distort:s.distort,local:pe,face:yr(s,pe,[u,g,t,l],P.w,P.h),map:m?.source??null,matte:Re&&(s.mask||s.person)?Re.matteCanvas(s,pe,He,!1,L):null});m?.close?.(),P={source:w,w:t,h:l,bt709:P.bt709},s={...s,crop:void 0,mask:void 0,person:void 0}}if(Re&&(s.mask||s.person)){const o=s.crop||{left:0,right:0,top:0,bottom:0},u=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),g=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2);U.matte(le("matte",()=>Re.matteCanvas(s,pe,He,!1,L)),[o.left,o.top,u/P.w,g/P.h])}else U.matte(null);U.mode(s.blend),U.key(s.key),U.shadow(xo(s,R));{const o=s.colorBypass?[]:Ht(s.grade).filter(io);U.windows(o.length?{key:`${s.id}@${f}`,list:Ht(s.grade),clip:s.id,src:s,frame:Math.round((x-s.start)*C),local:Math.round((x-s.start)*C)/C}:null)}if(vo(s)&&ho(go(s),pe)>.001){const o=go(s),u=Re&&(s.mask||s.person),g=s.crop||{left:0,right:0,top:0,bottom:0},t=u?Math.max(2,Math.floor(u.mw*(1-g.left-g.right)/2)*2):P.w,l=u?Math.max(2,Math.floor(u.mh*(1-g.top-g.bottom)/2)*2):P.h,m=t>=l?Yt:Math.max(8,Math.trunc(Yt*t/l/8)*8),w=t>=l?Math.max(8,Math.trunc(Yt*l/t/8)*8):Yt,n=ti(o),v=ho(o,pe),S=!!o.keys?.length||o.amount<.999;U.edge({key:`${s.id}@${f}`,ew:m,eh:w,band:n.band,glow:n.glow,k:o.glow,col:[1,3,5].map(Y=>parseInt(o.color.slice(Y,Y+2),16)/255),am:S?Math.trunc(255*v):255,harden:!!u,arc:o.cover>=.999&&!o.comet?null:{cen:u?oi(s):[.5,.5],start:(o.angle+o.sweep*pe)*Math.PI/180,cover:o.cover,comet:!!o.comet}})}else U.edge(null);{const o=s.grade&&!s.colorBypass?Qt(s):null;U.grade(o?.l1??null,o?.l3??null)}if(s.pin&&!(O&&Vt(s))&&b&&Eo(s,L,b.start,R,F,O)){const o=Eo(s,L,x,R,F,O)??[[0,0],[0,0],[0,0],[0,0]],u=It(s,pe),g=ii(s,L,R,F,O),t=s.pin.dive,l=g&&!s.pin.scene?[+(g[0]*R).toFixed(3),+(g[1]*F).toFixed(3),t?Math.max(0,Math.min(1,(x-t.at)/t.dur)):0]:null;U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),u.k,u.white,ot(s),Oe(s,b,f),Ot(o,R,F),l),Le?.close();break e}const Pt=ri(s,"rot")||ai(s),jt=()=>s.motionBlur?Tr(x,C).map(o=>({...to(s,o-s.start,R,F),rot:ae.rot,opacity:ae.opacity})):[ae];if((Pt||Math.abs(ae.rot||0)>1e-9)&&!(O&&Vt(s))){const o=It(s,pe),u=_&&re?[...Do(_.spec[re],xe,R,F,x,_.spec.zoomAt),...re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]]:[];s.motionBlur&&U.blurBegin();for(const g of jt()){const t=hr(s,P.w,P.h,R,F,g,Pt);U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),o.k,o.white,ot(s),[],Ot(t.quad,R,F),null,t.clip,u)}s.motionBlur&&U.blurEnd(),Le?.close();break e}if(O&&Vt(s)){const o=ni(s,pe,O,x,R,F);if(o){const u=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),g=It(s,pe),t=Oe(s,b,f);let l=at.get(s.id);l===void 0&&(l=s.effects?.some(w=>!w.off)||s.mask||s.person||vo(s)||!s.colorBypass&&Ht(s.grade).some(io)?1:si(ci(s,O,R,F),P.w,P.h,R,F),at.set(s.id,l));const m=Gt(s,b,f);l>1&&!t.length?U.warpBig(P,Ct(u.dst,R,F),u.src,Math.min(1,ae.opacity),g.k,g.white,ot(s),o.quad,l,m):U.warp(P,Ct(u.dst,R,F),u.src,Math.min(1,ae.opacity),g.k,g.white,ot(s),t,Ot(o.quad,R,F),null,null,m)}Le?.close();break e}if(s.motionBlur&&!_&&!Oe(s,b,f).length){const o=It(s,pe);U.blurBegin();for(const u of jt()){const g=Xt(s,P.w,P.h,R,F,u);U.draw(P,g.dst,g.src,Math.min(1,ae.opacity),o.k,o.white,ot(s),[])}U.blurEnd(),Le?.close();break e}const{dst:Bt,src:pt}=Xt(s,P.w,P.h,R,F,ae),qe=It(s,pe),a=[...Oe(s,b,f),..._&&re?Do(_.spec[re],xe,R,F,x,_.spec.zoomAt):[],..._&&re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]],c=_&&re?_.spec[re]?.rot:null;if(c){const o=Kt(c,xe)??0;U.warp(P,Ct([0,0,1,1],R,F),pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),[],Ot(gr(Bt,R,F,o),R,F),null,null,a),Le?.close();break e}if(a.length>0&&!!b&&!s.layout&&!po(s,b.start,b.start+b.duration)&&fi(s,b.start,b.start+b.duration,R,F)){const o=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),u=Xt({},R,F,R,F,ae);U.draw(P,u.dst,o.src,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a,o.dst)}else U.draw(P,Bt,pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a);Le?.close()}if(ze&&U.glEnd(re,ze,xe),_&&re==="b"){if(_.spec.light){const Ge=Math.max(2,Math.ceil(R/bo)),ae=Math.max(2,Math.ceil(F/bo));U.overlay(null,{data:li(_.spec,xe,Ge,ae),w:Ge,h:ae})}const pe=_.spec.flash;if(pe){const Ge=Kt(pe.opacity,xe)??0;if(Ge>1e-4){const ae=parseInt(pe.color.slice(1),16);U.overlay([(ae>>16&255)/255,(ae>>8&255)/255,(ae&255)/255,Math.min(1,Ge)],null)}}}}B>=0&&B>=(b?.visuals.length??0)&&await ue();for(const[W,J]of mt){const s=W.split(`
|
|
199
|
+
`)[0],_=X.find(re=>re.id===s);(!_||x>_.start+_.duration+1)&&(J.current?.close(),J.peek?.close(),await J.iterator.return?.(),mt.delete(W))}if(M){await Zt(f);continue}Ce="video encode",await De("encode",Ne.add((f-Fe)/C,1/C)),N?.((me==="video"?1:.9)*(f+1-Fe)/Math.max(1,Ft-Fe))}if(M)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-d)}};const r=performance.now();if(me==="video")Ne.close(),Ce="finalize",await Je.finalize();else{Ce="audio";const f=new Map(X.map(x=>[x.id,x])),k=await Ma(L.map(x=>f.get(x.id)??x),Ae,te,e,it,h);typeof E.loudness=="number"&&Er([k.getChannelData(0),k.getChannelData(1)],E.loudness,zt),Ce="audio encode",await Dt.add(k),At=performance.now()-r,me!=="audio"&&Ne.close(),Dt.close(),Ce="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),be&&await be.dir.removeEntry(be.name).catch(()=>{}),r}finally{for(const r of mt.values())r.current?.close(),r.peek?.close();_e?.dispose();for(const r of Xe.values())r.close?.();for(const r of Z.values())r.pic?.close?.();for(const r of Me.values())r.close();for(const r of rt.values())r.close?.();for(const r of Ze.values())r.dispose?.()}N?.(1),Ce="file";const $=be?await be.handle.getFile():de?new Blob([]):new Blob([_t.buffer],{type:Rt?"video/quicktime":"video/mp4"});be&&setTimeout(()=>void be.dir.removeEntry(be.name).catch(()=>{}),600*1e3);const Mt=performance.now()-d;return{blob:$,ms:{titles:Math.round(st-d),video:Math.round(Mt-(st-d)-At),audio:Math.round(At),total:Math.round(Mt),parts:Object.fromEntries(Object.entries(kt).map(([r,f])=>[r,Math.round(f)]))}}}function Aa(p,E,y,e,q){const h=[new Float32Array(Math.max(1,Math.round(q*y))),new Float32Array(Math.max(1,Math.round(q*y)))],N=Math.round(Oi*y);return E.forEach((M,V)=>{if(M.silent)return;const ie=Math.round((M.t1-M.t0)*y)+(V<E.length-1?N:0),se=Math.abs(M.rate),me=Math.round(M.t0*y),de=Math.max(0,Math.round(((M.rate>0?M.s0:M.s0-se*ie/y)-e)*y)),d=Math.min(p[0].length,Math.round(((M.rate>0?M.s0+se*ie/y:M.s0)-e)*y));if(d-de<2)return;const R=(d-de)/ie,F=Math.round(.06*y),C=Math.max(0,de-F),L=Math.min(p[0].length,d+F);let X=p.map(oe=>oe.slice(C,L));M.rate<0&&X.forEach(oe=>oe.reverse());const te=Math.round((M.rate<0?L-d:de-C)/R);X=Bo(X,R,y).map(oe=>oe.subarray(te,te+ie));for(let oe=0;oe<2;oe++)for(let O=0;O<ie&&me+O<h[oe].length;O++){const Ae=(V>0&&O<N?O/N:1)*(V<E.length-1&&O>=ie-N?(ie-O)/N:1);h[oe][me+O]+=(X[oe][O]??0)*Ae}}),h}async function Ma(p,E,y,e,q,h){const N=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(y*zt)),sampleRate:zt}),M=1/200,V=p.filter(d=>(d.kind==="video"||d.kind==="audio")&&!d.freeze&&!Po(d)&&(d.volume??1)>0),ie=d=>(d.kind==="video"||d.kind==="audio")&&!!d.url,se=new Map;for(const d of E.flatMap(R=>R.audios))!ie(d)||se.has(d.url)||se.set(d.url,await q(d.url).getPrimaryAudioTrack().then(R=>!!R,()=>!1));const me=d=>ie(d)&&!!se.get(d.url);for(const d of V){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");const R=Math.max(2,Math.ceil(d.duration/M)+1),F=new Float32Array(R);let C=!1;const L=Ni(d.track,e);for(let Z=0;Z<R;Z++){const ge=d.start+Math.min(d.duration,Z*M),ct=E.find(ke=>ge>=ke.start-1e-6&&ge<ke.start+ke.duration-1e-6),Ve=ct?.audios.some(ke=>ke.id===d.id)?Li(d,ge-d.start)*L.gain/Ii(ct.audios,me):0;F[Z]=Ve,Ve>0&&(C=!0)}if(!C)continue;const X=await q(d.url).getPrimaryAudioTrack();if(!X)continue;const te=ko(d)?Ci(d,0,d.duration):null,oe=d.playbackRate||1,O=new Sr(X),Ae=te?te.flatMap(Z=>[Z.s0,Z.s1]):[],we=te?Math.max(0,Math.min(...Ae)-.2):d.inPoint||0,je=te?Math.max(...Ae)+.2:we+d.duration*oe,ye=[];let Ke=we;for await(const Z of O.samples(we,je))ye.length||(Ke=Z.timestamp),ye.push(Z.toAudioBuffer()),Z.close();if(!ye.length)continue;const $e=ye[0].sampleRate,nt=ye.reduce((Z,ge)=>Z+ge.length,0);let Me=[new Float32Array(nt),new Float32Array(nt)],st=0;for(const Z of ye){for(let ge=0;ge<2;ge++)Me[ge].set(Z.getChannelData(Math.min(ge,Z.numberOfChannels-1)),st);st+=Z.length}te?Me=Aa(Me,te,$e,Ke,d.duration):oe!==1&&(Me=Bo(Me,oe,$e));const Qe=N.createBuffer(2,Me[0].length,$e);for(let Z=0;Z<2;Z++)Qe.copyToChannel(Me[Z],Z);const Re=N.createBufferSource();Re.buffer=Qe;const He=N.createGain();He.gain.value=0,He.gain.setValueCurveAtTime(F,d.start,Math.max(M,d.duration));const Ze=N.createChannelSplitter(2),Se=N.createChannelMerger(2),Xe=N.createGain(),it=N.createGain();Xe.gain.value=L.left,it.gain.value=L.right,Re.connect(He),He.connect(Ze),Ze.connect(Xe,0),Ze.connect(it,1),Xe.connect(Se,0,0),it.connect(Se,0,1),Se.connect(N.destination),Re.start(d.start,te?0:Math.max(0,we-Ke)/oe,d.duration)}const de=await N.startRendering();return br([de.getChannelData(0),de.getChannelData(1)]),de}export{za as canEncodeH264,Ga as canEncodeHevc,Oa as canEncodeMp4,Fa as exportOnGpu,so as gpuBitrate,ja as gpuExportStage,qa as gpuExportSupported};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as kt,l as Ft}from"./matteQuality-9X-jgJrH.js";import{
|
|
1
|
+
import{g as kt,l as Ft}from"./matteQuality-9X-jgJrH.js";import{c$ as Q,d0 as jt}from"./timelineOps-f1WsVbgS.js";import"./titleFrameBudget-h4nOQ5u9.js";import"./sceneTrack-CO4fTjft.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./api-CZoVJ9Fy.js";import"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";import"./store-D3Y663py.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";const dt=Object.freeze({core:.5,band:.16,ring:.55,sep:22,lo:.1,hi:.78,guideR:2,guideEps:.002,maxW:512,choke:[.5,.66],close:.08,closeArm:.22,chokeAI:[.45,.62],chokeArm:[.22,.4]}),ut=[[0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[5,9],[9,10],[10,11],[11,12],[9,13],[13,14],[14,15],[15,16],[13,17],[0,17],[17,18],[18,19],[19,20]],at=[0,1,5,9,13,17];function V(l,t,n,g,A,d,y=255){const a=Math.max(0,Math.floor(Math.min(t[0],n[0])-g)),e=Math.min(A-1,Math.ceil(Math.max(t[0],n[0])+g)),p=Math.max(0,Math.floor(Math.min(t[1],n[1])-g)),M=Math.min(d-1,Math.ceil(Math.max(t[1],n[1])+g)),U=n[0]-t[0],i=n[1]-t[1],f=U*U+i*i||1,c=g*g;for(let m=p;m<=M;m++)for(let o=a;o<=e;o++){const N=o+.5-t[0],z=m+.5-t[1],Y=Math.max(0,Math.min(1,(N*U+z*i)/f)),H=N-Y*U,B=z-Y*i;H*H+B*B<=c&&l[m*A+o]<y&&(l[m*A+o]=y)}return l}function W(l,t,n,g,A=255){const d=t.length;if(d<3)return l;let y=1/0,a=-1/0;for(const p of t)p[1]<y&&(y=p[1]),p[1]>a&&(a=p[1]);y=Math.max(0,Math.floor(y)),a=Math.min(g-1,Math.ceil(a));const e=[];for(let p=y;p<=a;p++){const M=p+.5;e.length=0;for(let i=0,f=d-1;i<d;f=i++){const c=t[f],m=t[i];(c[1]<=M&&m[1]>M||m[1]<=M&&c[1]>M)&&e.push([c[0]+(M-c[1])/(m[1]-c[1])*(m[0]-c[0]),m[1]>c[1]?1:-1])}if(e.length<2)continue;e.sort((i,f)=>i[0]-f[0]);let U=0;for(let i=0;i<e.length-1;i++){if(U+=e[i][1],!U)continue;const f=Math.max(0,Math.ceil(e[i][0]-.5)),c=Math.min(n-1,Math.floor(e[i+1][0]-.5)),m=p*n;for(let o=f;o<=c;o++)l[m+o]<A&&(l[m+o]=A)}}return l}function ht(l,t,n,g){const A=t+1,d=l.map(y=>{const a=new Float64Array(A*(n+1));for(let e=0;e<n;e++){let p=0;for(let M=0;M<t;M++)p+=y[e*t+M],a[(e+1)*A+M+1]=a[e*A+M+1]+p}return a});return(y,a,e)=>{const p=d[y],M=Math.max(0,a-g),U=Math.min(t,a+g+1),i=Math.max(0,e-g),f=Math.min(n,e+g+1);return p[f*A+U]-p[i*A+U]-p[f*A+M]+p[i*A+M]}}function Ct(l,t,n,g,A={}){const{learned:d=null,...y}=A,a={...dt,...y},e=t*n,p=new Uint8Array(e),M=new Uint8Array(e),U=new Uint8Array(e),i=new Uint8Array(e),f=new Uint8Array(e),c=(g||[]).filter(r=>r?.lm?.length>=21);if(!c.length)return new Uint8Array(e);const m=r=>r.map(([h,x])=>[h*t,x*n]);let o=0;for(const r of c){o=Math.max(o,Math.hypot((r.lm[0][0]-r.lm[9][0])*t,(r.lm[0][1]-r.lm[9][1])*n)),W(p,m(Q(r.lm,t,n,{edge:r.edge?r.edge.map(x=>Math.min(0,x)):null,scale:a.core})),t,n),W(i,m(Q(r.lm,t,n,{edge:r.edge})),t,n),W(M,m(Q(r.lm,t,n,{edge:r.edge,grow:a.band})),t,n),W(U,m(Q(r.lm,t,n,{edge:r.edge,grow:a.ring})),t,n);const h=Q(r.lm,t,n,{edge:r.edge,grow:a.band});W(f,m(jt.map(x=>h[x])),t,n)}if(d){const r=new Uint8Array(e),h=new Uint8Array(e);for(const u of c){const s=u.lm.map(([P,L])=>[P*t,L*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]),k=Array.isArray(u.armDir)?u.armDir:[(s[0][0]-s[9][0])/(F||1),(s[0][1]-s[9][1])/(F||1)],j=[s[0][0]+k[0]*4*F,s[0][1]+k[1]*4*F];for(const[P,L]of ut)V(r,s[P],s[L],.45*F,t,n),V(h,s[P],s[L],.08*F,t,n);W(r,at.map(P=>s[P]),t,n),W(h,at.map(P=>s[P]),t,n);const K=[s[0][0]+k[0]*Math.max(t,n)*1.5,s[0][1]+k[1]*Math.max(t,n)*1.5];V(r,s[0],K,1.6*F,t,n),V(h,s[0],j,.12*F,t,n)}const x=new Uint8Array(e);for(const u of c){const s=u.lm.map(([k,j])=>[k*t,j*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]);for(const[k,j]of ut)V(x,s[k],s[j],.45*F,t,n);W(x,at.map(k=>s[k]),t,n)}const I=[];for(let u=0;u<e;u+=2)if(h[u]&&x[u]&&d[u]>.6){const s=u*4;I.push([l[s],l[s+1],l[s+2]])}I.sort((u,s)=>u[0]+u[1]+u[2]-s[0]-s[1]-s[2]);const S=I.length>=30?[0,1,2].map(u=>{const s=I.slice(Math.floor(I.length*u/3),Math.floor(I.length*(u+1)/3));return[0,1,2].map(F=>s.reduce((k,j)=>k+j[F],0)/s.length)}):null,D=new Float32Array(e),T=new Float32Array(e),q=new Float32Array(e),C=new Float32Array(e);for(let u=0;u<e;u++)if(d[u]<.1){const s=u*4;D[u]=1,T[u]=l[s],q[u]=l[s+1],C[u]=l[s+2]}const E=S?ht([D,T,q,C],t,n,Math.max(4,Math.round(o*.6))):null,$=u=>{if(!S||!x[u])return 1;const s=u%t,F=u/t|0,k=E(0,s,F);if(k<4)return 1;const j=[E(1,s,F)/k,E(2,s,F)/k,E(3,s,F)/k],K=u*4,P=[l[K],l[K+1],l[K+2]];let L=0,et=1/0;for(const it of S){const R=[it[0]-j[0],it[1]-j[1],it[2]-j[2]],lt=R[0]*R[0]+R[1]*R[1]+R[2]*R[2];et=Math.min(et,Math.sqrt(lt)),lt>=1&&(L=Math.max(L,((P[0]-j[0])*R[0]+(P[1]-j[1])*R[1]+(P[2]-j[2])*R[2])/lt))}if(et<a.sep)return 1;const rt=Math.max(0,Math.min(1,(L-.12)/.2));return rt*rt*(3-2*rt)},v=d,G=new Uint8Array(e),[O,J]=a.chokeAI,[gt,Ut]=a.chokeArm;for(let u=0;u<e;u++){if(!r[u])continue;const s=x[u]?O:gt,F=x[u]?J:Ut;if(v[u]<s)continue;const k=Math.max(0,Math.min(1,(v[u]-s)/(F-s)))*$(u);G[u]=Math.round(255*k*k*(3-2*k))}return pt(G,t,n,{snapped:h,band:r,core:h,arm:f,r:1,rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.03*o*o)})}const N=[];for(let r=0;r<e;r+=3)if(p[r]){const h=r*4;N.push([l[h],l[h+1],l[h+2]])}if(N.length<12)return i;N.sort((r,h)=>r[0]+r[1]+r[2]-h[0]-h[1]-h[2]);const z=r=>{const h=N.slice(Math.floor(N.length*r/3),Math.floor(N.length*(r+1)/3));return[0,1,2].map(x=>h.reduce((I,S)=>I+S[x],0)/h.length)},Y=[z(0),z(1),z(2)],H=new Float32Array(e),B=new Float32Array(e),w=new Float32Array(e),tt=new Float32Array(e);let st=0,ct=0,ft=0,_=0;for(let r=0;r<e;r++)if(U[r]&&!M[r]){const h=r*4;H[r]=1,B[r]=l[h],w[r]=l[h+1],tt[r]=l[h+2],st+=B[r],ct+=w[r],ft+=tt[r],_++}const yt=_?[st/_,ct/_,ft/_]:null,b=ht([H,B,w,tt],t,n,Math.max(3,Math.round(o*.45))),Z=new Float32Array(e),nt=new Uint8Array(e);for(let r=0;r<n;r++)for(let h=0;h<t;h++){const x=r*t+h;if(!M[x]&&!(d&&U[x]&&!f[x]&&d[x]>.3))continue;if(nt[x]=1,p[x]){Z[x]=1;continue}const I=b(0,h,r),S=I>2?[b(1,h,r)/I,b(2,h,r)/I,b(3,h,r)/I]:yt;if(!S){Z[x]=i[x]/255;continue}const D=x*4,T=[l[D],l[D+1],l[D+2]];let q=0,C=1/0;for(const G of Y){const O=[G[0]-S[0],G[1]-S[1],G[2]-S[2]],J=O[0]*O[0]+O[1]*O[1]+O[2]*O[2];C=Math.min(C,Math.sqrt(J)),!(J<1)&&(q=Math.max(q,((T[0]-S[0])*O[0]+(T[1]-S[1])*O[1]+(T[2]-S[2])*O[2])/J))}const E=d&&!f[x]?d[x]:null;if(C<a.sep){Z[x]=E??i[x]/255;continue}const $=Math.max(0,Math.min(1,(q-a.lo)/(a.hi-a.lo))),v=$*$*(3-2*$);Z[x]=E===null?v:E*v}const xt=kt(Z,Ft(l,t,n),t,n,{r:a.guideR,eps:a.guideEps}),ot=new Uint8Array(e),[mt,At]=a.choke;for(let r=0;r<e;r++){if(!nt[r])continue;if(p[r]){ot[r]=255;continue}const h=Math.max(0,Math.min(1,(xt[r]-mt)/(At-mt)));ot[r]=Math.round(255*h*h*(3-2*h))}return pt(ot,t,n,{snapped:i,band:nt,core:p,arm:f,r:Math.max(1,Math.round(o*a.close)),rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.12*o*o)})}function Mt(l,t,n,g,A,d,y){const a=2*d+1,e=new Uint8Array(n+a),p=new Uint8Array(n+a),M=f=>{const c=Math.max(0,Math.min(n-1,f-d));return l[g+c*A]},U=n+2*d,i=y?(f,c)=>f>c?f:c:(f,c)=>f<c?f:c;for(let f=0;f<U;f+=a){const c=Math.min(U,f+a);e[f]=M(f);for(let m=f+1;m<c;m++)e[m]=i(e[m-1],M(m));p[c-1]=M(c-1);for(let m=c-2;m>=f;m--)p[m]=i(p[m+1],M(m))}for(let f=0;f<n;f++)t[g+f*A]=i(p[f],e[f+2*d]??e[U-1])}function X(l,t,n,g,A){const d=new Uint8Array(l.length),y=new Uint8Array(l.length);for(let a=0;a<n;a++)Mt(l,d,t,a*t,1,g,A);for(let a=0;a<t;a++)Mt(d,y,n,a,t,g,A);return y}function pt(l,t,n,{snapped:g,band:A,core:d,arm:y,r:a,rArm:e,small:p}){const M=t*n,U=new Uint8Array(M);for(let o=0;o<M;o++)U[o]=l[o]>=128?255:0;const i=X(X(U,t,n,a,!0),t,n,a,!1),f=X(X(U,t,n,e,!0),t,n,e,!1);for(let o=0;o<M;o++)!U[o]&&A[o]&&(y[o]&&(i[o]||f[o])||!y[o]&&i[o]&&d[o])&&(l[o]=255);It(l,t,n,d,p,y);const c=new Uint8Array(M),m=[];for(let o=0;o<M;o++)d[o]&&l[o]>=64&&m.push(o);for(;m.length;){const o=m.pop();if(c[o]||l[o]<64)continue;c[o]=1;const N=o%t;N>0&&m.push(o-1),N<t-1&&m.push(o+1),o>=t&&m.push(o-t),o<M-t&&m.push(o+t)}for(let o=0;o<M;o++)c[o]||(l[o]=l[o]>=64?0:l[o]);return l}function It(l,t,n,g,A=0,d=null){const y=t*n,a=new Int32Array(y),e=[];for(let i=0;i<t;i++)e.push(i,(n-1)*t+i);for(let i=0;i<n;i++)e.push(i*t,i*t+t-1);const p=(i,f)=>{for(;e.length;){const c=e.pop();if(a[c]||l[c]>=128)continue;a[c]=i,f?.push(c);const m=c%t;m>0&&e.push(c-1),m<t-1&&e.push(c+1),c>=t&&e.push(c-t),c<y-t&&e.push(c+t)}};p(-1);for(let i=0,f=1;i<y;i++){if(a[i]||l[i]>=128)continue;const c=[];e.push(i),p(f++,c);const m=c.length<A&&(!d||c.every(o=>d[o]));for(const o of c)(m||g[o])&&(l[o]=255)}const M=new Uint8Array(y);for(let i=0;i<y;i++)M[i]=a[i]===-1||a[i]>0&&l[i]<128?255:0;const U=X(M,t,n,2,!0);for(let i=0;i<y;i++)l[i]&&l[i]<255&&!U[i]&&(l[i]=255);return l}function Gt(l,t,n=dt.maxW){const g=Math.min(n,l),A=Math.max(2,Math.round(g*t/l/2)*2);return{w:Math.round(g/2)*2,h:A}}export{dt as HAND_MATTE,V as fillCapsule,W as fillPolygon,Ct as handMatteFrame,Gt as handMatteSize};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/objectSegmenter-
|
|
2
|
-
import{b_ as Y,_ as N,a7 as Z,da as tt}from"./titleFrameBudget-BW-N1-cw.js";import{u as W}from"./store-xR02oY0m.js";import{t as j}from"./i18n-C9zFX25m.js";import{m as et,g as at,S as J,M as nt}from"./personHq-Cyq9HWnW.js";import{cO as ot,cP as it,cQ as Q,cR as rt,cS as st,cT as K,cU as ct,ay as z,cV as lt,cW as dt,cX as mt}from"./timelineOps-CEGk2t4h.js";import{handMatteSize as ut,handMatteFrame as ht}from"./handMatte-CvFkZKTL.js";import{t as ft}from"./matteQuality-9X-jgJrH.js";import"./index-CKtv7gGE.js";import"./api-DJC95K48.js";import"./sceneTrack-DyVxpl7i.js";import"./cameraTracker-DFjnZ7tw.js";import"./textAnimators-CeMuG34D.js";import"./timelineComp-D8PHGHgQ.js";import"./rigTrack-B9r9wrdV.js";import"./clientJobs-CuuUyhEy.js";const pt="https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${J}/wasm`,gt=640;let $=null;async function yt(){if(typeof window<"u"&&window.__handTrackerStub)return{detect:window.__handTrackerStub,close:()=>{}};const{FilesetResolver:d,HandLandmarker:w}=await N(async()=>{const{FilesetResolver:c,HandLandmarker:s}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:c,HandLandmarker:s}},[]);$??=d.forVisionTasks(wt).catch(c=>{throw $=null,c});const a=await w.createFromOptions(await $,{baseOptions:{modelAssetPath:pt,delegate:"CPU"},runningMode:"VIDEO",numHands:2,minHandDetectionConfidence:.5,minHandPresenceConfidence:.5,minTrackingConfidence:.5});let f=0;return{detect:(c,s)=>{f=Math.max(f+1,Math.round(s));const b=a.detectForVideo(c,f);return(b.landmarks??[]).map((m,v)=>({lm:m.map(p=>[p.x,p.y]),label:b.handedness?.[v]?.[0]?.categoryName??"",score:b.handedness?.[v]?.[0]?.score??1}))},close:()=>a.close()}}async function Mt({clip:d,url:w,from:a,duration:f,signal:c,onProgress:s}){const b=f*(d.playbackRate||1),m=b*30<=K.maxFrames?30:15,v=Math.max(2,Math.min(K.maxFrames,Math.round(b*m)+1)),{detect:p,close:C}=await yt(),u=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});u.src=w;try{await new Promise((i,h)=>{u.onloadeddata=()=>i(),u.onerror=()=>h(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const x=u.videoWidth||1280,H=u.videoHeight||720,_=Math.min(gt,x),o=Math.max(2,Math.round(_*H/x)),r=Object.assign(document.createElement("canvas"),{width:_,height:o}),y=r.getContext("2d",{willReadFrequently:!0}),E=z(d,a),T=[];let n=[null,null];for(let i=0;i<v;i++){if(c?.aborted)throw new DOMException("Đã huỷ","AbortError");const h=Math.max(0,Math.min(u.duration-1/60,E+i/m));Math.abs(u.currentTime-h)>1e-4&&await new Promise((t,e)=>{const l=window.setTimeout(()=>e(Error(j("Seek video quá lâu"))),8e3);u.onseeked=()=>{window.clearTimeout(l),t()},u.currentTime=h}),y.drawImage(u,0,0,_,o);const S=p(r,(i+1)*1e3/m).filter(t=>Array.isArray(t.lm)&&t.lm.length>=21).slice(0,2),k=[null,null],F=t=>t.label==="Left"?0:t.label==="Right"?1:-1,M=(t,e)=>{const l=n[e];return l?Math.hypot(l.lm[0][0]-t.lm[0][0],l.lm[0][1]-t.lm[0][1]):1/0};if(S.length===2&&F(S[0])===F(S[1])){const t=S[0],e=S[1],l=M(t,0)+M(e,1)<=M(t,1)+M(e,0),[I,A]=Number.isFinite(M(t,0)+M(e,1))||Number.isFinite(M(t,1)+M(e,0))?l?[t,e]:[e,t]:t.lm[0][0]>e.lm[0][0]?[t,e]:[e,t];k[0]={lm:I.lm.map(R=>[R[0],R[1]]),score:I.score},k[1]={lm:A.lm.map(R=>[R[0],R[1]]),score:A.score}}else for(const t of S){let e=F(t);if(e<0&&(e=t.lm[0][0]>.5?0:1),S.length===1){const l=1-e;M(t,l)<.08&&M(t,e)>.15&&(e=l)}k[e]||(k[e]={lm:t.lm.map(l=>[l[0],l[1]]),score:t.score})}if(k.some(Boolean)){const t=y.getImageData(0,0,_,o).data,e=(l,I)=>{const A=(Math.max(0,Math.min(o-1,I))*_+Math.max(0,Math.min(_-1,l)))*4;return[t[A],t[A+1],t[A+2]]};for(const l of k)if(l){const I=dt(l.lm,_,o,e);I&&(l.edge=I)}}T.push(k),n=[k[0]??n[0],k[1]??n[1]],s?.(i+1,v)}return mt({mw:x,mh:H,fps:m,s0:E,frames:T})}finally{u.removeAttribute("src"),u.load(),C()}}let B=null,q=null;async function xt(d,w,a){const f=typeof window<"u"?window.__bodySkinStub:void 0;B??=f?Promise.resolve(f):(async()=>{const{FilesetResolver:p,ImageSegmenter:C}=await N(async()=>{const{FilesetResolver:H,ImageSegmenter:_}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:H,ImageSegmenter:_}},[]),u=await p.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${J}/wasm`),x=await C.createFromOptions(u,{baseOptions:{modelAssetPath:nt,delegate:"CPU"},runningMode:"IMAGE",outputConfidenceMasks:!0,outputCategoryMask:!1});return H=>{const _=x.segment(H);try{const o=_.confidenceMasks?.[2];if(!o)throw Error("no skin mask");return{data:o.getAsFloat32Array().slice(),width:o.width,height:o.height}}finally{_.close()}}})().catch(p=>{throw B=null,p});const c=await B;q??=document.createElement("canvas");const s=960,b=Math.max(2,Math.round(960*d.height/d.width));(q.width!==s||q.height!==b)&&Object.assign(q,{width:s,height:b}),q.getContext("2d").drawImage(d,0,0,s,b);const m=c(q),v=new Float32Array(w*a);for(let p=0;p<a;p++){const C=Math.min(m.height-1,Math.floor((p+.5)/a*m.height))*m.width;for(let u=0;u<w;u++){const x=m.data[C+Math.min(m.width-1,Math.floor((u+.5)/w*m.width))];v[p*w+u]=Math.max(0,Math.min(1,(x-.25)/.4))}}return v}const kt=[0,1,2,3,5,6,7,9,10,11,13,14,15,17,18,19];let G=null;async function bt(d,w,a,f,c,s){const{objectProbability:b}=await N(async()=>{const{objectProbability:o}=await import("./objectSegmenter-oGv8YQbI.js");return{objectProbability:o}},__vite__mapDeps([0,1,2,3,4,5,6,7])),m=new Float32Array(c*s),v=512;G??=Object.assign(document.createElement("canvas"),{width:v,height:v});const p=G.getContext("2d",{willReadFrequently:!0}),C=async(o,r,y,E,T)=>{p.fillStyle="#000",p.fillRect(0,0,v,v),p.drawImage(d,o,r,y,E,0,0,v,v);const n=await b(G,T.map(h=>({x:(h.x-o)/y,y:(h.y-r)/E})).filter(h=>h.x>0&&h.x<1&&h.y>0&&h.y<1)),i=new Float32Array(c*s);for(let h=0;h<s;h++){const S=((h+.5)/s*a-r)/E;if(S<0||S>=1)continue;const k=Math.floor(S*n.height)*n.width;for(let F=0;F<c;F++){const M=((F+.5)/c*w-o)/y;M<0||M>=1||(i[h*c+F]=n.data[k+Math.floor(M*n.width)])}}return i},{fillCapsule:u,fillPolygon:x}=await N(async()=>{const{fillCapsule:o,fillPolygon:r}=await import("./handMatte-CvFkZKTL.js");return{fillCapsule:o,fillPolygon:r}},__vite__mapDeps([8,3,9,1,10,11,12,13,4,5,6,14,15,16])),H=[],_=await xt(d,c,s);for(const{lm:o}of f){const r=o.map(t=>t[0]*w),y=o.map(t=>t[1]*a),E=Math.hypot(r[0]-r[9],y[0]-y[9])||1,T=kt.map(t=>({x:r[t],y:y[t]}));T.push({x:r[0]+(r[0]-r[9])*.6,y:y[0]+(y[0]-y[9])*.6});const i=await C(...((t,e,l,I=1)=>{const A=Math.min(...t)-l,R=Math.max(...t)+l,O=Math.min(...e)-l,g=Math.max(...e)+l,P=Math.max(R-A,g-O),D=Math.min(w,Math.max(R-A,P/I)),V=Math.min(a,Math.max(g-O,P/I)),L=Math.min(D,V*I),U=Math.min(V,D*I);return[Math.max(0,Math.min(w-L,(A+R)/2-L/2)),Math.max(0,Math.min(a-U,(O+g)/2-U/2)),L,U]})([...r,r[0]+(r[0]-r[9])*3],[...y,y[0]+(y[0]-y[9])*3],.6*E),T);let h=(r[0]-r[9])/E,S=(y[0]-y[9])/E;{const t=r[0]/w*c,e=y[0]/a*s,l=E/w*c;let I=0,A=0,R=0;for(let O=0;O<s;O++)for(let g=0;g<c;g++){if(i[O*c+g]<.5)continue;const P=Math.hypot(g-t,O-e);if(P<1.2*l||P>3*l)continue;const D=g-t,V=O-e;D*h+V*S<-.2*P||(I+=g,A+=O,R++)}if(R>20){const O=I/R-t,g=A/R-e,P=Math.hypot(O,g)||1;(O*h+g*S)/P>Math.cos(75*Math.PI/180)&&(h=O/P,S=g/P)}}H.push([h,S]);const k=new Uint8Array(c*s),F=r.map((t,e)=>[t/w*c,y[e]/a*s]),M=E/w*c;for(const[t,e]of[[1,2],[2,3],[3,4],[5,6],[6,7],[7,8],[9,10],[10,11],[11,12],[13,14],[14,15],[15,16],[17,18],[18,19],[19,20],[0,1],[0,5],[0,17]])u(k,F[t],F[e],.35*M,c,s);x(k,[0,1,5,9,13,17].map(t=>F[t]),c,s);for(let t=0;t<c*s;t++){const e=k[t]?Math.max(i[t],_[t]*.5):_[t];e>m[t]&&(m[t]=e)}}return{map:m,armDirs:H}}async function X({clip:d,url:w,from:a,duration:f,until:c=1/0,refine:s=null,store:b=!0,signal:m,onProgress:v}){if(!d.hands)throw Error(j("Không tìm thấy clip video có tay"));const p=ct(d.hands),C=d.playbackRate||1,u=p.fps,x=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});x.src=w;try{await new Promise((t,e)=>{x.onloadeddata=()=>t(),x.onerror=()=>e(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const H=x.videoWidth||p.mw,_=x.videoHeight||p.mh,{w:o,h:r}=ut(H,_),y=Object.assign(document.createElement("canvas"),{width:o,height:r}),E=y.getContext("2d",{willReadFrequently:!0}),T=z(d,a),n=Math.max(1,Math.min(K.maxFrames,Math.round(f*C*u)+1)),i=z(d,c),h=et({mw:H,mh:_,w:o,h:r,fps:u,s0:T},32),S=ft(t=>h.push(t)),k=s?await Z(s):null,F=at(x);let M=!0;for(let t=0;t<n;t++){if(m?.aborted)throw new DOMException("Đã huỷ","AbortError");const e=T+t/u;if(e>i+1e-6){S.push(new Uint8Array(o*r)),v?.(t+1,n);continue}const l=await F(Math.max(0,Math.min(x.duration-1/60,e)));E.drawImage(l,0,0,o,r);const I=Math.max(0,Math.min(p.n-1,Math.round((e-p.s0)*u))),A=[0,1].map(g=>{const P=lt(p,e,g);return P?{lm:P,edge:p.frames[I][g]?.edge??null}:null}).filter(Boolean);let R=null;if(M&&A.length)try{const g=await bt(l,H,_,A,o,r);R=g.map,g.armDirs.forEach((P,D)=>{A[D].armDir=P})}catch(g){M=!1,console.warn("hand cut-out model",g)}let O=A.length?ht(E.getImageData(0,0,o,r).data,o,r,A,{learned:R}):new Uint8Array(o*r);if(k&&s){const g=tt(k,s,e),P=s.w,D=s.h,V=new Uint8Array(o*r);for(let L=0;L<r;L++)for(let U=0;U<o;U++)V[L*o+U]=Math.round(O[L*o+U]*g[Math.min(D-1,Math.floor(L*D/r))*P+Math.min(P-1,Math.floor(U*P/o))]/255);O=V}S.push(O),v?.(t+1,n),t%4===3&&await new Promise(g=>setTimeout(g,0))}return S.finish(),await h.finish({feather:0,grow:0},{store:b})}finally{x.removeAttribute("src"),x.load()}}async function vt(d,w,a){const f=W.getState().clips.find(b=>b.id===d);if(!f||f.kind!=="video")throw Error(j("Không tìm thấy clip video có tay"));if(st(f,w,a))return f;const c=document.querySelector(`video[data-clip-media="${f.id}"]`)?.currentSrc||f.url,s=await Mt({clip:f,url:c,from:w,duration:Math.min(a,K.maxFrames/15/(f.playbackRate||1))});if(!s.data||!/[^A]/.test(s.data.replace(/=+$/,"")))throw Error(j("Không thấy bàn tay nào trong đoạn này"));return W.setState(b=>({clips:b.clips.map(m=>m.id===f.id?{...m,hands:s}:m)})),{...f,hands:s}}const St=d=>new Promise(w=>setTimeout(w,d));async function Wt(d,w){const a=w.params??{},f=await vt(String(a.source),a.from??0,a.duration??d.duration),c=W.getState(),{width:s,height:b}=Y(c.timelineFormat);if(a.mode==="attach"){const n=c.clips.find(i=>i.id===d.id)??d;return ot(n,f,{point:a.point,side:a.side,scale:!!a.scale,offset:a.offset??null,W:s,H:b})}if(a.mode==="wipe"){const n=c.clips.find(e=>e.id===d.id)??d,i=c.clips.find(e=>e.id===f.id)??f,h=n.mask,S=it(n,i,{point:a.point,side:a.side,dir:a.dir,feather:a.feather,W:s,H:b,mw:h?.mw,mh:h?.mh}),k=c.clips.find(e=>e.id===a.cutout),F=document.querySelector(`video[data-clip-media="${i.id}"]`)?.currentSrc||i.url;let M=null;if(k)try{M=await X({clip:i,url:F,from:a.from??0,duration:a.duration??d.duration,refine:k.person??null})}catch(e){console.warn("hand matte",e)}const t=M||!k?void 0:Q({...k,hands:i.hands});return W.setState(e=>({clips:e.clips.map(l=>l.id===a.cutout?M?{...l,person:M,mask:void 0}:t?{...l,mask:t}:l:l)})),S.patch}for(let n=0;n<360&&W.getState().clips.find(i=>i.id===a.wall)?.pendingPin;n++)await St(500);const m=W.getState(),v=m.clips.find(n=>n.id===a.wall),p=m.clips.find(n=>n.id===d.id)??d,C=m.clips.find(n=>n.id===f.id)??f;if(!v)throw Error(j("Không còn tường HUD"));const u=rt({wall:v,layer:p,src:C,clips:m.clips,cam:m.timelineCamera,W:s,H:b,events:a.events??null,grab:a.grab??"auto",side:a.side,fly:a.fly}),x=m.clips.find(n=>n.id===a.cutout),H=document.querySelector(`video[data-clip-media="${C.id}"]`)?.currentSrc||C.url,_=(a.matte?m.clips.find(n=>n.id===a.matte)?.person:null)??x?.person??null;let o=null;if(x)try{o=await X({clip:C,url:H,from:a.from??0,duration:a.duration??d.duration,until:u.cutoutUntil,refine:_})}catch(n){console.warn("hand matte",n)}const r=x?.matteFix?.fixes??[],y=o;if(o&&r.length)try{const{fixedMatte:n}=await N(async()=>{const{fixedMatte:i}=await import("./matteFixRun-BHD3Qnta.js");return{fixedMatte:i}},__vite__mapDeps([17,14,1,6,5,2,3,4,9,10,11,12,13,15,16,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,0,7,35,36,37]));o=await n(o,r,C.hands)}catch(n){console.warn("hand touch-ups",n)}const E=o?void 0:Q(C,{until:u.cutoutUntil}),T=n=>{const i=n.mask?.masks?.find(h=>h.id==="wall");return!i||!n.mask?n:o?{...n,person:o,mask:{...n.mask,masks:[{...i,mode:"add"}]}}:E?{...n,mask:{...E,masks:[...E.masks,{...i,mode:"intersect"}]}}:n};return W.setState(n=>({clips:n.clips.map(i=>i.id===v.id?{...i,motion:u.wall}:i.id===a.cutout?o?{...i,person:o,mask:void 0,...r.length?{matteFix:{auto:y,fixes:r}}:{}}:E?{...i,mask:E}:i:i.id===a.shadow?T(i):i)})),{motion:u.grab}}export{pt as HAND_MODEL_URL,X as buildHandMatte,bt as learnedHands,Wt as runHandTrack,Mt as trackHands};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/objectSegmenter-C4T9qgUL.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/personHq-CBP8v_cw.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/i18n-ClNt3LKg.js","assets/index-CKtv7gGE.js","assets/cutoutClean-CLYYAuXg.js","assets/handMatte-B5sUeqKi.js","assets/timelineOps-f1WsVbgS.js","assets/sceneTrack-CO4fTjft.js","assets/cameraTracker-Df9jWmz6.js","assets/textAnimators-C4eMnVRD.js","assets/timelineComp-Ciu9JCWJ.js","assets/store-D3Y663py.js","assets/rigTrack-BbKqZGs7.js","assets/clientJobs-CuuUyhEy.js","assets/matteFixRun-BCVsuSxf.js","assets/main-C_XcvNyC.js","assets/remote-CpkPQOQH.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/rotoMaskStore-BZBJLcCp.js","assets/spark.module-3Q8DniuL.js","assets/userFonts-BlVEJfDk.js","assets/lottieLayer-DEw0c3to.js","assets/timeline3d-BcW68fQr.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/glTransitionSources.generated-Cs8lVRqs.js","assets/clientJobs-eB-lNyin.js","assets/captionLayout-eiu9QPJu.js","assets/timelineText-Cppd4KB7.js","assets/titleArt-D0YI5xT2.js","assets/sceneTrack-_n6WKKQv.js","assets/rotoMatte-BI-vjjrv.js","assets/distortGL-DQu0Df2c.js","assets/motionBlur-uAm030t9.js","assets/main-DlzdW5C4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{b_ as J,_ as N,a7 as Q,dd as tt}from"./titleFrameBudget-h4nOQ5u9.js";import{u as W}from"./store-D3Y663py.js";import{t as j}from"./i18n-ClNt3LKg.js";import{m as et,g as at,S as Z,M as nt}from"./personHq-CBP8v_cw.js";import{cR as ot,cS as it,cT as X,cU as rt,cV as st,cW as K,cX as ct,aB as z,cY as lt,cZ as dt,c_ as mt}from"./timelineOps-f1WsVbgS.js";import{handMatteSize as ut,handMatteFrame as ht}from"./handMatte-B5sUeqKi.js";import{t as ft}from"./matteQuality-9X-jgJrH.js";import"./index-CKtv7gGE.js";import"./api-CZoVJ9Fy.js";import"./sceneTrack-CO4fTjft.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";const pt="https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${Z}/wasm`,gt=640;let $=null;async function yt(){if(typeof window<"u"&&window.__handTrackerStub)return{detect:window.__handTrackerStub,close:()=>{}};const{FilesetResolver:d,HandLandmarker:w}=await N(async()=>{const{FilesetResolver:c,HandLandmarker:s}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:c,HandLandmarker:s}},[]);$??=d.forVisionTasks(wt).catch(c=>{throw $=null,c});const a=await w.createFromOptions(await $,{baseOptions:{modelAssetPath:pt,delegate:"CPU"},runningMode:"VIDEO",numHands:2,minHandDetectionConfidence:.5,minHandPresenceConfidence:.5,minTrackingConfidence:.5});let f=0;return{detect:(c,s)=>{f=Math.max(f+1,Math.round(s));const b=a.detectForVideo(c,f);return(b.landmarks??[]).map((m,v)=>({lm:m.map(p=>[p.x,p.y]),label:b.handedness?.[v]?.[0]?.categoryName??"",score:b.handedness?.[v]?.[0]?.score??1}))},close:()=>a.close()}}async function Mt({clip:d,url:w,from:a,duration:f,signal:c,onProgress:s}){const b=f*(d.playbackRate||1),m=b*30<=K.maxFrames?30:15,v=Math.max(2,Math.min(K.maxFrames,Math.round(b*m)+1)),{detect:p,close:C}=await yt(),u=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});u.src=w;try{await new Promise((i,h)=>{u.onloadeddata=()=>i(),u.onerror=()=>h(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const x=u.videoWidth||1280,H=u.videoHeight||720,S=Math.min(gt,x),o=Math.max(2,Math.round(S*H/x)),r=Object.assign(document.createElement("canvas"),{width:S,height:o}),y=r.getContext("2d",{willReadFrequently:!0}),E=z(d,a),T=[];let n=[null,null];for(let i=0;i<v;i++){if(c?.aborted)throw new DOMException("Đã huỷ","AbortError");const h=Math.max(0,Math.min(u.duration-1/60,E+i/m));Math.abs(u.currentTime-h)>1e-4&&await new Promise((t,e)=>{const l=window.setTimeout(()=>e(Error(j("Seek video quá lâu"))),8e3);u.onseeked=()=>{window.clearTimeout(l),t()},u.currentTime=h}),y.drawImage(u,0,0,S,o);const _=p(r,(i+1)*1e3/m).filter(t=>Array.isArray(t.lm)&&t.lm.length>=21).slice(0,2),k=[null,null],F=t=>t.label==="Left"?0:t.label==="Right"?1:-1,M=(t,e)=>{const l=n[e];return l?Math.hypot(l.lm[0][0]-t.lm[0][0],l.lm[0][1]-t.lm[0][1]):1/0};if(_.length===2&&F(_[0])===F(_[1])){const t=_[0],e=_[1],l=M(t,0)+M(e,1)<=M(t,1)+M(e,0),[I,A]=Number.isFinite(M(t,0)+M(e,1))||Number.isFinite(M(t,1)+M(e,0))?l?[t,e]:[e,t]:t.lm[0][0]>e.lm[0][0]?[t,e]:[e,t];k[0]={lm:I.lm.map(R=>[R[0],R[1]]),score:I.score},k[1]={lm:A.lm.map(R=>[R[0],R[1]]),score:A.score}}else for(const t of _){let e=F(t);if(e<0&&(e=t.lm[0][0]>.5?0:1),_.length===1){const l=1-e;M(t,l)<.08&&M(t,e)>.15&&(e=l)}k[e]||(k[e]={lm:t.lm.map(l=>[l[0],l[1]]),score:t.score})}if(k.some(Boolean)){const t=y.getImageData(0,0,S,o).data,e=(l,I)=>{const A=(Math.max(0,Math.min(o-1,I))*S+Math.max(0,Math.min(S-1,l)))*4;return[t[A],t[A+1],t[A+2]]};for(const l of k)if(l){const I=dt(l.lm,S,o,e);I&&(l.edge=I)}}T.push(k),n=[k[0]??n[0],k[1]??n[1]],s?.(i+1,v)}return mt({mw:x,mh:H,fps:m,s0:E,frames:T})}finally{u.removeAttribute("src"),u.load(),C()}}let B=null,q=null;async function xt(d,w,a){const f=typeof window<"u"?window.__bodySkinStub:void 0;B??=f?Promise.resolve(f):(async()=>{const{FilesetResolver:p,ImageSegmenter:C}=await N(async()=>{const{FilesetResolver:H,ImageSegmenter:S}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:H,ImageSegmenter:S}},[]),u=await p.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${Z}/wasm`),x=await C.createFromOptions(u,{baseOptions:{modelAssetPath:nt,delegate:"CPU"},runningMode:"IMAGE",outputConfidenceMasks:!0,outputCategoryMask:!1});return H=>{const S=x.segment(H);try{const o=S.confidenceMasks?.[2];if(!o)throw Error("no skin mask");return{data:o.getAsFloat32Array().slice(),width:o.width,height:o.height}}finally{S.close()}}})().catch(p=>{throw B=null,p});const c=await B;q??=document.createElement("canvas");const s=960,b=Math.max(2,Math.round(960*d.height/d.width));(q.width!==s||q.height!==b)&&Object.assign(q,{width:s,height:b}),q.getContext("2d").drawImage(d,0,0,s,b);const m=c(q),v=new Float32Array(w*a);for(let p=0;p<a;p++){const C=Math.min(m.height-1,Math.floor((p+.5)/a*m.height))*m.width;for(let u=0;u<w;u++){const x=m.data[C+Math.min(m.width-1,Math.floor((u+.5)/w*m.width))];v[p*w+u]=Math.max(0,Math.min(1,(x-.25)/.4))}}return v}const kt=[0,1,2,3,5,6,7,9,10,11,13,14,15,17,18,19];let G=null;async function bt(d,w,a,f,c,s){const{objectProbability:b}=await N(async()=>{const{objectProbability:o}=await import("./objectSegmenter-C4T9qgUL.js");return{objectProbability:o}},__vite__mapDeps([0,1,2,3,4,5,6,7])),m=new Float32Array(c*s),v=512;G??=Object.assign(document.createElement("canvas"),{width:v,height:v});const p=G.getContext("2d",{willReadFrequently:!0}),C=async(o,r,y,E,T)=>{p.fillStyle="#000",p.fillRect(0,0,v,v),p.drawImage(d,o,r,y,E,0,0,v,v);const n=await b(G,T.map(h=>({x:(h.x-o)/y,y:(h.y-r)/E})).filter(h=>h.x>0&&h.x<1&&h.y>0&&h.y<1)),i=new Float32Array(c*s);for(let h=0;h<s;h++){const _=((h+.5)/s*a-r)/E;if(_<0||_>=1)continue;const k=Math.floor(_*n.height)*n.width;for(let F=0;F<c;F++){const M=((F+.5)/c*w-o)/y;M<0||M>=1||(i[h*c+F]=n.data[k+Math.floor(M*n.width)])}}return i},{fillCapsule:u,fillPolygon:x}=await N(async()=>{const{fillCapsule:o,fillPolygon:r}=await import("./handMatte-B5sUeqKi.js");return{fillCapsule:o,fillPolygon:r}},__vite__mapDeps([8,3,9,1,10,11,12,13,4,5,6,14,15,16])),H=[],S=await xt(d,c,s);for(const{lm:o}of f){const r=o.map(t=>t[0]*w),y=o.map(t=>t[1]*a),E=Math.hypot(r[0]-r[9],y[0]-y[9])||1,T=kt.map(t=>({x:r[t],y:y[t]}));T.push({x:r[0]+(r[0]-r[9])*.6,y:y[0]+(y[0]-y[9])*.6});const i=await C(...((t,e,l,I=1)=>{const A=Math.min(...t)-l,R=Math.max(...t)+l,O=Math.min(...e)-l,g=Math.max(...e)+l,P=Math.max(R-A,g-O),D=Math.min(w,Math.max(R-A,P/I)),V=Math.min(a,Math.max(g-O,P/I)),L=Math.min(D,V*I),U=Math.min(V,D*I);return[Math.max(0,Math.min(w-L,(A+R)/2-L/2)),Math.max(0,Math.min(a-U,(O+g)/2-U/2)),L,U]})([...r,r[0]+(r[0]-r[9])*3],[...y,y[0]+(y[0]-y[9])*3],.6*E),T);let h=(r[0]-r[9])/E,_=(y[0]-y[9])/E;{const t=r[0]/w*c,e=y[0]/a*s,l=E/w*c;let I=0,A=0,R=0;for(let O=0;O<s;O++)for(let g=0;g<c;g++){if(i[O*c+g]<.5)continue;const P=Math.hypot(g-t,O-e);if(P<1.2*l||P>3*l)continue;const D=g-t,V=O-e;D*h+V*_<-.2*P||(I+=g,A+=O,R++)}if(R>20){const O=I/R-t,g=A/R-e,P=Math.hypot(O,g)||1;(O*h+g*_)/P>Math.cos(75*Math.PI/180)&&(h=O/P,_=g/P)}}H.push([h,_]);const k=new Uint8Array(c*s),F=r.map((t,e)=>[t/w*c,y[e]/a*s]),M=E/w*c;for(const[t,e]of[[1,2],[2,3],[3,4],[5,6],[6,7],[7,8],[9,10],[10,11],[11,12],[13,14],[14,15],[15,16],[17,18],[18,19],[19,20],[0,1],[0,5],[0,17]])u(k,F[t],F[e],.35*M,c,s);x(k,[0,1,5,9,13,17].map(t=>F[t]),c,s);for(let t=0;t<c*s;t++){const e=k[t]?Math.max(i[t],S[t]*.5):S[t];e>m[t]&&(m[t]=e)}}return{map:m,armDirs:H}}async function Y({clip:d,url:w,from:a,duration:f,until:c=1/0,refine:s=null,store:b=!0,signal:m,onProgress:v}){if(!d.hands)throw Error(j("Không tìm thấy clip video có tay"));const p=ct(d.hands),C=d.playbackRate||1,u=p.fps,x=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});x.src=w;try{await new Promise((t,e)=>{x.onloadeddata=()=>t(),x.onerror=()=>e(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const H=x.videoWidth||p.mw,S=x.videoHeight||p.mh,{w:o,h:r}=ut(H,S),y=Object.assign(document.createElement("canvas"),{width:o,height:r}),E=y.getContext("2d",{willReadFrequently:!0}),T=z(d,a),n=Math.max(1,Math.min(K.maxFrames,Math.round(f*C*u)+1)),i=z(d,c),h=et({mw:H,mh:S,w:o,h:r,fps:u,s0:T},32),_=ft(t=>h.push(t)),k=s?await Q(s):null,F=at(x);let M=!0;for(let t=0;t<n;t++){if(m?.aborted)throw new DOMException("Đã huỷ","AbortError");const e=T+t/u;if(e>i+1e-6){_.push(new Uint8Array(o*r)),v?.(t+1,n);continue}const l=await F(Math.max(0,Math.min(x.duration-1/60,e)));E.drawImage(l,0,0,o,r);const I=Math.max(0,Math.min(p.n-1,Math.round((e-p.s0)*u))),A=[0,1].map(g=>{const P=lt(p,e,g);return P?{lm:P,edge:p.frames[I][g]?.edge??null}:null}).filter(Boolean);let R=null;if(M&&A.length)try{const g=await bt(l,H,S,A,o,r);R=g.map,g.armDirs.forEach((P,D)=>{A[D].armDir=P})}catch(g){M=!1,console.warn("hand cut-out model",g)}let O=A.length?ht(E.getImageData(0,0,o,r).data,o,r,A,{learned:R}):new Uint8Array(o*r);if(k&&s){const g=tt(k,s,e),P=s.w,D=s.h,V=new Uint8Array(o*r);for(let L=0;L<r;L++)for(let U=0;U<o;U++)V[L*o+U]=Math.round(O[L*o+U]*g[Math.min(D-1,Math.floor(L*D/r))*P+Math.min(P-1,Math.floor(U*P/o))]/255);O=V}_.push(O),v?.(t+1,n),t%4===3&&await new Promise(g=>setTimeout(g,0))}return _.finish(),await h.finish({feather:0,grow:0},{store:b})}finally{x.removeAttribute("src"),x.load()}}async function vt(d,w,a){const f=W.getState().clips.find(b=>b.id===d);if(!f||f.kind!=="video")throw Error(j("Không tìm thấy clip video có tay"));if(st(f,w,a))return f;const c=document.querySelector(`video[data-clip-media="${f.id}"]`)?.currentSrc||f.url,s=await Mt({clip:f,url:c,from:w,duration:Math.min(a,K.maxFrames/15/(f.playbackRate||1))});if(!s.data||!/[^A]/.test(s.data.replace(/=+$/,"")))throw Error(j("Không thấy bàn tay nào trong đoạn này"));return W.setState(b=>({clips:b.clips.map(m=>m.id===f.id?{...m,hands:s}:m)})),{...f,hands:s}}const _t=d=>new Promise(w=>setTimeout(w,d));async function Wt(d,w){const a=w.params??{},f=await vt(String(a.source),a.from??0,a.duration??d.duration),c=W.getState(),{width:s,height:b}=J(c.timelineFormat);if(a.mode==="attach"){const n=c.clips.find(i=>i.id===d.id)??d;return ot(n,f,{point:a.point,side:a.side,scale:!!a.scale,offset:a.offset??null,W:s,H:b})}if(a.mode==="wipe"){const n=c.clips.find(e=>e.id===d.id)??d,i=c.clips.find(e=>e.id===f.id)??f,h=n.mask,_=it(n,i,{point:a.point,side:a.side,dir:a.dir,feather:a.feather,W:s,H:b,mw:h?.mw,mh:h?.mh}),k=c.clips.find(e=>e.id===a.cutout),F=document.querySelector(`video[data-clip-media="${i.id}"]`)?.currentSrc||i.url;let M=null;if(k)try{M=await Y({clip:i,url:F,from:a.from??0,duration:a.duration??d.duration,refine:k.person??null})}catch(e){console.warn("hand matte",e)}const t=M||!k?void 0:X({...k,hands:i.hands});return W.setState(e=>({clips:e.clips.map(l=>l.id===a.cutout?M?{...l,person:M,mask:void 0}:t?{...l,mask:t}:l:l)})),_.patch}for(let n=0;n<360&&W.getState().clips.find(i=>i.id===a.wall)?.pendingPin;n++)await _t(500);const m=W.getState(),v=m.clips.find(n=>n.id===a.wall),p=m.clips.find(n=>n.id===d.id)??d,C=m.clips.find(n=>n.id===f.id)??f;if(!v)throw Error(j("Không còn tường HUD"));const u=rt({wall:v,layer:p,src:C,clips:m.clips,cam:m.timelineCamera,W:s,H:b,events:a.events??null,grab:a.grab??"auto",side:a.side,fly:a.fly}),x=m.clips.find(n=>n.id===a.cutout),H=document.querySelector(`video[data-clip-media="${C.id}"]`)?.currentSrc||C.url,S=(a.matte?m.clips.find(n=>n.id===a.matte)?.person:null)??x?.person??null;let o=null;if(x)try{o=await Y({clip:C,url:H,from:a.from??0,duration:a.duration??d.duration,until:u.cutoutUntil,refine:S})}catch(n){console.warn("hand matte",n)}const r=x?.matteFix?.fixes??[],y=o;if(o&&r.length)try{const{fixedMatte:n}=await N(async()=>{const{fixedMatte:i}=await import("./matteFixRun-BCVsuSxf.js");return{fixedMatte:i}},__vite__mapDeps([17,14,1,6,5,2,3,4,9,10,11,12,13,15,16,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,0,7,35,36,37]));o=await n(o,r,C.hands)}catch(n){console.warn("hand touch-ups",n)}const E=o?void 0:X(C,{until:u.cutoutUntil}),T=n=>{const i=n.mask?.masks?.find(h=>h.id==="wall");return!i||!n.mask?n:o?{...n,person:o,mask:{...n.mask,masks:[{...i,mode:"add"}]}}:E?{...n,mask:{...E,masks:[...E.masks,{...i,mode:"intersect"}]}}:n};return W.setState(n=>({clips:n.clips.map(i=>i.id===v.id?{...i,motion:u.wall}:i.id===a.cutout?o?{...i,person:o,mask:void 0,...r.length?{matteFix:{auto:y,fixes:r}}:{}}:E?{...i,mask:E}:i:i.id===a.shadow?T(i):i)})),{motion:u.grab}}export{pt as HAND_MODEL_URL,Y as buildHandMatte,bt as learnedHands,Wt as runHandTrack,Mt as trackHands};
|