mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 21:01:20 -08:00
Refactor code structure for improved readability and maintainability
Remove debugging border from the websr plugin's styling Enhance canvas sizing logic in artplayer-plugin-websr - Updated canvas positioning to center it within the player. - Introduced a new function to calculate canvas size based on the video aspect ratio. - Adjusted canvas dimensions during initialization and on resize events to maintain aspect ratio. - Ensured canvas styles are updated to reflect the calculated dimensions. feat: add comparison mode to artplayer-plugin-websr - Updated README.md to reflect new comparison feature and simplified content. - Modified package.json to remove unnecessary keywords. - Enhanced index.js to implement comparison functionality, allowing users to compare original and upscaled video. - Added new methods for enabling, disabling, and toggling comparison mode, as well as setting and getting the comparison position. - Updated TypeScript definitions to include new comparison options and methods.
This commit is contained in:
1 parent
07a5b0c0f0
commit
7dffd99cfd
308 files changed
+3175
-852
No files matched your search
@@ -5,4 +5,4 @@
|
||||
* (c) 2017-2026 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,n,s,a,o,l){var i="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},u="function"==typeof i[n]&&i[n],p=u.i||{},c=u.cache||{},d="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!c[t]){if(!e[t]){if(s[t])return s[t];var a="function"==typeof i[n]&&i[n];if(!r&&a)return a(t,!0);if(u)return u(t,!0);if(d&&"string"==typeof t)return d(t);var o=Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}p.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},p.cache={};var l=c[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,i)}return c[t].exports;function p(e){var t=p.resolve(e);if(!1===t)return{};if(Array.isArray(t)){var r={__esModule:!0};return t.forEach(function(e){var t=e[0],n=e[1],s=e[2]||e[0],a=f(n);"*"===t?Object.keys(a).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return a[e]}})}):"*"===s?Object.defineProperty(r,t,{enumerable:!0,value:a}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===s?a.__esModule?a.default:a:a[s]}})}),r}return f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=d,this.exports={}},f.modules=e,f.cache=c,f.parent=u,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=p,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return i[n]}}),i[n]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var m=f(r);"object"==typeof exports&&"u">typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"1AHlH":[function(e,t,r,n){var s=e("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",()=>l);var a=e("@tensorflow-models/body-segmentation"),o=e("@tensorflow/tfjs-core");function l(e={}){return t=>{let{template:{$video:r,$danmuku:n}}=t,s=null,l=null,i=null,u=null,p=!1,c={solutionPath:e.solutionPath||"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation",modelSelection:e.modelSelection||1,smoothSegmentation:void 0===e.smoothSegmentation||e.smoothSegmentation,minDetectionConfidence:e.minDetectionConfidence||.5,minTrackingConfidence:e.minTrackingConfidence||.5,selfieMode:e.selfieMode||!1,drawContour:e.drawContour||!1,foregroundThreshold:e.foregroundThreshold||.5,opacity:e.opacity||1,maskBlurAmount:e.maskBlurAmount||3};async function d(){try{await o.setBackend("webgl")}catch(e){console.warn("WebGL backend not available, falling back to CPU",e.message),await o.setBackend("cpu")}}async function f(){await d();let e=a.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:c.solutionPath,modelSelection:c.modelSelection,smoothSegmentation:c.smoothSegmentation,minDetectionConfidence:c.minDetectionConfidence,minTrackingConfidence:c.minTrackingConfidence,selfieMode:c.selfieMode};try{s=await a.createSegmenter(e,t),p=!0}catch(e){console.error("Error initializing segmenter:",e),p=!1}}async function h(){if(!p||r.paused||r.ended){u=requestAnimationFrame(h);return}try{l.width=r.videoWidth,l.height=r.videoHeight;let e=await s.segmentPeople(r);if(!e||0===e.length){u=requestAnimationFrame(h);return}let t=await a.toBinaryMask(e,{r:255,g:255,b:255,a:255},{r:0,g:0,b:0,a:255},c.drawContour,c.foregroundThreshold);await a.drawMask(l,r,t,c.opacity,c.maskBlurAmount);let o=i.getImageData(0,0,l.width,l.height);i.putImageData(function(e){let t=e.data;for(let e=0;e<t.length;e+=4)t[e]>250&&t[e+1]>250&&t[e+2]>250&&(t[e+3]=0);return e}(o),0,0),n.style.maskImage=`url(${l.toDataURL()})`}catch(e){console.error("Error in segmentBody:",e)}u=requestAnimationFrame(h)}async function m(){p||await f(),l||(i=(l=document.createElement("canvas")).getContext("2d")),Object.assign(n.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),h()}function g(){n.style.maskImage="none",u&&(cancelAnimationFrame(u),u=null)}return t.on("ready",m),t.on("destroy",g),{name:"artplayerPluginDanmukuMask",start:m,stop:g}}}e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu"),"u">typeof window&&(window.artplayerPluginDanmukuMask=l)},{"@tensorflow-models/body-segmentation":"9d7iE","@tensorflow/tfjs-core":"hADTC","@tensorflow/tfjs-backend-webgl":"3qRAd","@tensorflow/tfjs-backend-cpu":"ilpJu","@parcel/transformer-js/src/esmodule-helpers.js":"loqXi"}],"9d7iE":[function(e,t,r,n){var s,a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"SupportedModels",()=>eR),a.export(r,"blurBodyPart",()=>eQ),a.export(r,"bodyPixMaskValueToRainbowColor",()=>_),a.export(r,"createSegmenter",()=>eP),a.export(r,"drawBokehEffect",()=>eZ),a.export(r,"drawMask",()=>eJ),a.export(r,"drawPixelatedMask",()=>eY),a.export(r,"toBinaryMask",()=>eH),a.export(r,"toColoredMask",()=>eK);var o=e("@tensorflowLine truncated
|
||||
!function(e,t,r,n,s){var a="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},o="function"==typeof a[n]&&a[n],l=o.i||{},i=o.cache||{},u="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,r){if(!i[t]){if(!e[t]){if(s[t])return s[t];var l="function"==typeof a[n]&&a[n];if(!r&&l)return l(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}f.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},f.cache={};var d=i[t]=new p.Module(t);e[t][0].call(d.exports,f,d,d.exports,a)}return i[t].exports;function f(e){var t=f.resolve(e);if(!1===t)return{};if(Array.isArray(t)){var r={__esModule:!0};return t.forEach(function(e){var t=e[0],n=e[1],s=e[2]||e[0],a=p(n);"*"===t?Object.keys(a).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return a[e]}})}):"*"===s?Object.defineProperty(r,t,{enumerable:!0,value:a}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===s?a.__esModule?a.default:a:a[s]}})}),r}return p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=u,this.exports={}},p.modules=e,p.cache=i,p.parent=o,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=l,p.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return a[n]}}),a[n]=p;for(var c=0;c<t.length;c++)p(t[c]);if(r){var d=p(r);"object"==typeof exports&&"u">typeof module?module.exports=d:"function"==typeof define&&define.amd&&define(function(){return d})}}({"1AHlH":[function(e,t,r,n){var s=e("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",()=>l);var a=e("@tensorflow-models/body-segmentation"),o=e("@tensorflow/tfjs-core");function l(e={}){return t=>{let{template:{$video:r,$danmuku:n}}=t,s=null,l=null,i=null,u=null,p=!1,c={solutionPath:e.solutionPath||"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation",modelSelection:e.modelSelection||1,smoothSegmentation:void 0===e.smoothSegmentation||e.smoothSegmentation,minDetectionConfidence:e.minDetectionConfidence||.5,minTrackingConfidence:e.minTrackingConfidence||.5,selfieMode:e.selfieMode||!1,drawContour:e.drawContour||!1,foregroundThreshold:e.foregroundThreshold||.5,opacity:e.opacity||1,maskBlurAmount:e.maskBlurAmount||3};async function d(){try{await o.setBackend("webgl")}catch(e){console.warn("WebGL backend not available, falling back to CPU",e.message),await o.setBackend("cpu")}}async function f(){await d();let e=a.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:c.solutionPath,modelSelection:c.modelSelection,smoothSegmentation:c.smoothSegmentation,minDetectionConfidence:c.minDetectionConfidence,minTrackingConfidence:c.minTrackingConfidence,selfieMode:c.selfieMode};try{s=await a.createSegmenter(e,t),p=!0}catch(e){console.error("Error initializing segmenter:",e),p=!1}}async function h(){if(!p||r.paused||r.ended){u=requestAnimationFrame(h);return}try{l.width=r.videoWidth,l.height=r.videoHeight;let e=await s.segmentPeople(r);if(!e||0===e.length){u=requestAnimationFrame(h);return}let t=await a.toBinaryMask(e,{r:255,g:255,b:255,a:255},{r:0,g:0,b:0,a:255},c.drawContour,c.foregroundThreshold);await a.drawMask(l,r,t,c.opacity,c.maskBlurAmount);let o=i.getImageData(0,0,l.width,l.height);i.putImageData(function(e){let t=e.data;for(let e=0;e<t.length;e+=4)t[e]>250&&t[e+1]>250&&t[e+2]>250&&(t[e+3]=0);return e}(o),0,0),n.style.maskImage=`url(${l.toDataURL()})`}catch(e){console.error("Error in segmentBody:",e)}u=requestAnimationFrame(h)}async function m(){p||await f(),l||(i=(l=document.createElement("canvas")).getContext("2d")),Object.assign(n.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),h()}function g(){n.style.maskImage="none",u&&(cancelAnimationFrame(u),u=null)}return t.on("ready",m),t.on("destroy",g),{name:"artplayerPluginDanmukuMask",start:m,stop:g}}}e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu"),"u">typeof window&&(window.artplayerPluginDanmukuMask=l)},{"@tensorflow-models/body-segmentation":"9d7iE","@tensorflow/tfjs-core":"hADTC","@tensorflow/tfjs-backend-webgl":"3qRAd","@tensorflow/tfjs-backend-cpu":"ilpJu","@parcel/transformer-js/src/esmodule-helpers.js":"loqXi"}],"9d7iE":[function(e,t,r,n){var s,a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"SupportedModels",()=>eR),a.export(r,"blurBodyPart",()=>eQ),a.export(r,"bodyPixMaskValueToRainbowColor",()=>_),a.export(r,"createSegmenter",()=>eP),a.export(r,"drawBokehEffect",()=>eZ),a.export(r,"drawMask",()=>eJ),a.export(r,"drawPixelatedMask",()=>eY),a.export(r,"toBinaryMask",()=>eH),a.export(r,"toColoredMask",()=>eK);var o=e("@tensorflow/tfjs-Line truncated
|
||||
Reference in new issue
Block a user