Upload index-1.html
Browse files- index-1.html +288 -0
index-1.html
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="id">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta name="theme-color" content="#e8e1cf">
|
| 7 |
+
<title>Lumina Studio</title>
|
| 8 |
+
<style>
|
| 9 |
+
:root{--bg:#e8e1cf;--paper:#f5f0e1;--ink:#211e18;--mute:#72695a;--acc:#bf4a2f;--ok:#3d6a38}
|
| 10 |
+
*{box-sizing:border-box}
|
| 11 |
+
body{margin:0;background:var(--bg);color:var(--ink);font:14px/1.5 "Courier New",Courier,ui-monospace,monospace}
|
| 12 |
+
button,input,select{font:inherit;color:inherit}button{cursor:pointer}
|
| 13 |
+
.app{max-width:1040px;margin:auto;padding:20px 16px 48px}
|
| 14 |
+
header{border-bottom:3px double var(--ink);padding-bottom:10px;margin-bottom:16px}
|
| 15 |
+
h1{font:700 24px Georgia,"Times New Roman",serif;letter-spacing:.06em;margin:0}
|
| 16 |
+
.tabs{display:flex;margin-bottom:14px}
|
| 17 |
+
.tab{border:2px solid var(--ink);background:var(--paper);padding:6px 18px;margin-right:-2px}
|
| 18 |
+
.tab.active{background:var(--ink);color:var(--paper)}
|
| 19 |
+
.layout{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(250px,.8fr);gap:16px}
|
| 20 |
+
.panel{background:var(--paper);border:2px solid var(--ink);box-shadow:4px 4px 0 var(--ink);padding:14px;min-width:0}
|
| 21 |
+
.panel h2{font-size:12px;text-transform:uppercase;letter-spacing:.14em;margin:0 0 12px;padding-bottom:6px;border-bottom:1px solid var(--ink)}
|
| 22 |
+
.drop{border:2px dashed var(--ink);min-height:210px;display:flex;align-items:center;justify-content:center;text-align:center;padding:20px;position:relative;background:#efe8d4}
|
| 23 |
+
.drop.drag{background:#e3d9bd}.drop input{position:absolute;inset:0;opacity:0;cursor:pointer}.dropcontent{pointer-events:none}.drop small{display:block;color:var(--mute);margin-top:4px}
|
| 24 |
+
.preview{display:none;margin-top:12px}.preview video{width:100%;max-height:480px;background:#000}
|
| 25 |
+
.compare{display:grid;grid-template-columns:1fr 1fr;gap:10px}.compare label{display:block;font-size:11px;letter-spacing:.1em;color:var(--mute);margin-bottom:4px}
|
| 26 |
+
.compare img{width:100%;max-height:320px;object-fit:contain;background:#d9d1ba;border:2px solid var(--ink);display:block}
|
| 27 |
+
.controls{display:grid;gap:12px}
|
| 28 |
+
.control label{display:flex;justify-content:space-between;font-size:12px;margin-bottom:4px}.control output{color:var(--acc);font-weight:700}
|
| 29 |
+
input[type=range]{width:100%;accent-color:var(--acc)}
|
| 30 |
+
.select{width:100%;padding:7px 8px;background:#fbf8ee;border:2px solid var(--ink);border-radius:0}
|
| 31 |
+
.actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:16px}
|
| 32 |
+
.btn,.tab{position:relative;overflow:hidden;transition:transform .12s,box-shadow .12s,background .15s;-webkit-tap-highlight-color:transparent}
|
| 33 |
+
.btn{border:2px solid var(--ink);background:var(--paper);box-shadow:3px 3px 0 var(--ink);padding:7px 14px;border-radius:0}
|
| 34 |
+
.btn:not(:disabled):hover{transform:translate(-1px,-1px);box-shadow:4px 4px 0 var(--ink)}
|
| 35 |
+
.btn:not(:disabled):active{transform:translate(3px,3px);box-shadow:0 0 0 var(--ink)}
|
| 36 |
+
.tab:hover{background:#e3d9bd}.tab.active:hover{background:var(--ink)}.tab:active{transform:translateY(2px)}
|
| 37 |
+
.btn.primary{background:var(--acc);color:#fff7ea}
|
| 38 |
+
.btn:disabled{opacity:.4;cursor:not-allowed;box-shadow:none}
|
| 39 |
+
.btn:focus-visible,.tab:focus-visible{outline:2px solid var(--acc);outline-offset:2px}
|
| 40 |
+
.btn.sm{padding:3px 9px;font-size:12px;box-shadow:2px 2px 0 var(--ink)}
|
| 41 |
+
.btn.busy{animation:blink 1s steps(2) infinite;pointer-events:none}
|
| 42 |
+
@keyframes blink{50%{background:#e3d9bd;color:var(--ink)}}
|
| 43 |
+
.ripple{position:absolute;border-radius:50%;background:rgba(0,0,0,.14);transform:scale(0);animation:rip .5s ease-out forwards;pointer-events:none}
|
| 44 |
+
@keyframes rip{to{transform:scale(4);opacity:0}}
|
| 45 |
+
.status{font-size:12px;color:var(--mute);margin-top:12px;min-height:18px}
|
| 46 |
+
.aibar{height:8px;border:2px solid var(--ink);margin-top:12px;background:#efe8d4}.aibar i{display:block;height:100%;width:0;background:var(--acc);transition:width .15s}
|
| 47 |
+
.queue{margin-top:14px;border:2px solid var(--ink);padding:10px;background:#efe8d4}
|
| 48 |
+
.qhead{display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:10px;font-size:12px;text-transform:uppercase;letter-spacing:.1em}.qhead span{display:flex;gap:8px;flex-wrap:wrap}
|
| 49 |
+
.qitem{display:grid;grid-template-columns:52px minmax(0,1fr);gap:10px;padding:8px;border:1px solid var(--ink);margin-bottom:8px;cursor:pointer;background:var(--paper)}
|
| 50 |
+
.qitem:hover{background:#fbf8ee}.qitem.on{border:2px solid var(--acc)}
|
| 51 |
+
.qitem img{width:52px;height:52px;object-fit:cover;border:1px solid var(--ink)}
|
| 52 |
+
.qn{font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.qm{font-size:11px;color:var(--mute)}.qm.ok{color:var(--ok)}.qm.err{color:var(--acc)}
|
| 53 |
+
.qb{display:flex;gap:8px;margin-top:6px;flex-wrap:wrap}.qbar{height:5px;border:1px solid var(--ink);margin-top:5px}.qbar i{display:block;height:100%;background:var(--acc)}
|
| 54 |
+
.hidden{display:none!important}
|
| 55 |
+
@media(max-width:780px){.layout{grid-template-columns:1fr}.app{padding:14px 12px 36px}.compare{grid-template-columns:1fr}}
|
| 56 |
+
@media(prefers-reduced-motion:reduce){.btn,.tab,.ripple,.btn.busy{animation:none!important;transition:none!important}}
|
| 57 |
+
</style>
|
| 58 |
+
</head>
|
| 59 |
+
<body>
|
| 60 |
+
<div class="app">
|
| 61 |
+
<header><h1>LUMINA STUDIO</h1></header>
|
| 62 |
+
<div class="tabs"><button class="tab active" id="photoTab">Foto</button><button class="tab" id="videoTab">Video</button></div>
|
| 63 |
+
<div class="layout">
|
| 64 |
+
<section class="panel">
|
| 65 |
+
<h2 id="workTitle">Foto</h2>
|
| 66 |
+
<div class="drop" id="drop"><input id="fileInput" type="file" accept="image/*" multiple><div class="dropcontent"><strong>Pilih atau tarik foto ke sini</strong><small>JPG, PNG, WEBP</small></div></div>
|
| 67 |
+
<div class="preview" id="photoPreview"><div class="compare"><div><label>ASLI</label><img id="beforeImg" alt=""></div><div><label>HASIL</label><img id="afterImg" alt=""></div></div></div>
|
| 68 |
+
<div class="queue hidden" id="queue"><div class="qhead"><b>Antrean</b><span><button class="btn sm" id="qAdd">Tambah</button><button class="btn sm primary" id="qStart">Mulai semua</button><button class="btn sm" id="qDl">Unduh semua</button></span></div><div id="qlist"></div></div>
|
| 69 |
+
<div class="preview" id="videoPreview"><video id="video" controls playsinline></video></div>
|
| 70 |
+
<div class="actions"><button class="btn" id="resetBtn">Reset</button><button class="btn primary" id="aiBtn" disabled>Jalankan AI</button><button class="btn hidden" id="cancelBtn">Batal</button><button class="btn primary" id="exportBtn" disabled>Unduh</button></div>
|
| 71 |
+
<div class="aibar hidden" id="aibar"><i id="aifill"></i></div>
|
| 72 |
+
<div class="status" id="status"></div>
|
| 73 |
+
</section>
|
| 74 |
+
<aside class="panel">
|
| 75 |
+
<h2>Pengaturan</h2>
|
| 76 |
+
<div id="photoControls" class="controls">
|
| 77 |
+
<div class="control"><label for="scale">Pembesaran</label><select id="scale" class="select"><option value="2" selected>2×</option><option value="4">4×</option><option value="8">8×</option><option value="16">16×</option><option value="1">1×</option></select></div>
|
| 78 |
+
<div class="control"><label for="engine">Mesin</label><select id="engine" class="select"><option value="ai" selected>Real-ESRGAN (AI)</option><option value="std">Standar</option></select></div>
|
| 79 |
+
<div class="control hidden" id="srvBox"><input id="srvUrl" type="hidden"></div>
|
| 80 |
+
<div class="control"><label for="imageType">Jenis</label><select id="imageType" class="select"><option value="photo">Foto</option><option value="art">Ilustrasi / anime</option></select></div>
|
| 81 |
+
<div class="control"><label for="noise">Noise</label><select id="noise" class="select"><option value="0" selected>Tidak ada</option><option value="1">Rendah</option><option value="2">Sedang</option><option value="3">Tinggi</option><option value="4">Tertinggi</option></select></div>
|
| 82 |
+
<div class="control"><label for="format">Format</label><select id="format" class="select"><option value="auto" selected>Sama seperti asli</option><option value="image/webp">WebP</option><option value="image/jpeg">JPG</option><option value="image/png">PNG</option></select></div>
|
| 83 |
+
<div class="control"><label for="aistr">Kekuatan AI <output id="aistrVal">60</output></label><input id="aistr" type="range" min="0" max="100" value="60"></div>
|
| 84 |
+
<div class="control"><label for="sharp">Ketajaman <output id="sharpVal">0</output></label><input id="sharp" type="range" min="0" max="100" value="0"></div>
|
| 85 |
+
<div class="control"><label for="brightness">Cahaya <output id="brightnessVal">0</output></label><input id="brightness" type="range" min="-30" max="30" value="0"></div>
|
| 86 |
+
<div class="control"><label for="contrast">Kontras <output id="contrastVal">0</output></label><input id="contrast" type="range" min="-20" max="50" value="0"></div>
|
| 87 |
+
<div class="control"><label for="saturation">Warna <output id="saturationVal">0</output></label><input id="saturation" type="range" min="-50" max="50" value="0"></div>
|
| 88 |
+
</div>
|
| 89 |
+
<div id="videoControls" class="controls hidden">
|
| 90 |
+
<div class="control"><label for="vsharp">Ketajaman <output id="vsharpVal">15</output></label><input id="vsharp" type="range" min="0" max="40" value="15"></div>
|
| 91 |
+
<div class="control"><label for="vbright">Cahaya <output id="vbrightVal">5</output></label><input id="vbright" type="range" min="-20" max="30" value="5"></div>
|
| 92 |
+
<div class="control"><label for="vcontrast">Kontras <output id="vcontrastVal">10</output></label><input id="vcontrast" type="range" min="-20" max="40" value="10"></div>
|
| 93 |
+
<div class="control"><label for="vsat">Warna <output id="vsatVal">8</output></label><input id="vsat" type="range" min="-40" max="40" value="8"></div>
|
| 94 |
+
<button class="btn primary" id="recordBtn" disabled>Rekam & unduh</button>
|
| 95 |
+
</div>
|
| 96 |
+
</aside>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
<canvas id="canvas" class="hidden"></canvas>
|
| 100 |
+
<script>
|
| 101 |
+
const $=id=>document.getElementById(id);
|
| 102 |
+
let mode='photo', image=new Image(), originalURL=null, videoURL=null, file=null, processedCanvas=null;
|
| 103 |
+
const photoSliders=['aistr','sharp','brightness','contrast','saturation'];
|
| 104 |
+
const videoSliders=['vsharp','vbright','vcontrast','vsat'];
|
| 105 |
+
function setStatus(t){$('status').textContent=t}
|
| 106 |
+
function switchMode(m){mode=m;$('photoTab').classList.toggle('active',m==='photo');$('videoTab').classList.toggle('active',m==='video');$('photoControls').classList.toggle('hidden',m!=='photo');$('videoControls').classList.toggle('hidden',m!=='video');$('photoPreview').style.display='none';$('videoPreview').style.display='none';$('drop').style.display='flex';$('fileInput').value='';$('exportBtn').disabled=true;$('recordBtn').disabled=true;$('workTitle').textContent=m==='photo'?'Foto':'Video';$('drop').querySelector('strong').textContent=m==='photo'?'Pilih atau tarik foto ke sini':'Pilih atau tarik video ke sini';$('drop').querySelector('small').textContent=m==='photo'?'JPG, PNG, WEBP':'MP4, WEBM, MOV';$('fileInput').multiple=m==='photo';$('fileInput').accept=m==='photo'?'image/*':'video/*';setStatus('');if(typeof afterMode==='function')afterMode()}
|
| 107 |
+
$('photoTab').onclick=()=>switchMode('photo');$('videoTab').onclick=()=>switchMode('video');
|
| 108 |
+
function values(){return {sharp:+$('sharp').value,brightness:+$('brightness').value,contrast:+$('contrast').value,saturation:+$('saturation').value}}
|
| 109 |
+
const MAXPX=40e6,NOISE_STD=[0,.15,.3,.5,.75],NOISE_AI=[0,.25,.5,.8,1.2];
|
| 110 |
+
let tasks=[],active=null,seq=0,busy=false;
|
| 111 |
+
const sleep=ms=>new Promise(r=>setTimeout(r,ms));
|
| 112 |
+
const esc=t=>t.replace(/[&<>"]/g,c=>({'&':'&','<':'<','>':'>','"':'"'})[c]);
|
| 113 |
+
const fmtBytes=b=>b>1048576?(b/1048576).toFixed(1)+' MB':Math.max(1,Math.round(b/1024))+' KB';
|
| 114 |
+
const extOf=m=>m==='image/png'?'png':m==='image/webp'?'webp':'jpg';
|
| 115 |
+
function outMime(t){const f=$('format').value;return f!=='auto'?f:(['image/png','image/webp'].includes(t.file.type)?t.file.type:'image/jpeg')}
|
| 116 |
+
function curKey(){return [$('scale').value,$('imageType').value,$('noise').value,$('engine').value].join('|')}
|
| 117 |
+
function nameOf(t,b,m){return t.file.name.replace(/\.[^.]+$/,'')+`-lumina-${$('scale').value}x.${extOf((b&&b.type)||m)}`}
|
| 118 |
+
let lzc={};
|
| 119 |
+
function lanczos(src,w,h){
|
| 120 |
+
const sw=src.naturalWidth||src.width,sh=src.naturalHeight||src.height;
|
| 121 |
+
const a=document.createElement('canvas');a.width=sw;a.height=sh;const ax=a.getContext('2d',{willReadFrequently:true});ax.drawImage(src,0,0);
|
| 122 |
+
const sd=ax.getImageData(0,0,sw,sh).data,L=x=>x===0?1:Math.abs(x)>=3?0:3*Math.sin(Math.PI*x)*Math.sin(Math.PI*x/3)/(Math.PI*Math.PI*x*x);
|
| 123 |
+
const taps=(n,sn)=>{const sc=n/sn,idx=new Int32Array(n*6),wt=new Float32Array(n*6);for(let i=0;i<n;i++){const c=(i+.5)/sc-.5,f=Math.floor(c);let sum=0;for(let k=0;k<6;k++){const p=f-2+k,wv=L(c-p);wt[i*6+k]=wv;sum+=wv;idx[i*6+k]=Math.min(sn-1,Math.max(0,p))}for(let k=0;k<6;k++)wt[i*6+k]/=sum}return{idx,wt}};
|
| 124 |
+
const hx=taps(w,sw),vy=taps(h,sh),tmp=new Float32Array(w*sh*4);
|
| 125 |
+
for(let y=0;y<sh;y++)for(let x=0;x<w;x++){let r=0,g=0,b=0,al=0;for(let k=0;k<6;k++){const i=(y*sw+hx.idx[x*6+k])*4,wv=hx.wt[x*6+k];r+=sd[i]*wv;g+=sd[i+1]*wv;b+=sd[i+2]*wv;al+=sd[i+3]*wv}const o=(y*w+x)*4;tmp[o]=r;tmp[o+1]=g;tmp[o+2]=b;tmp[o+3]=al}
|
| 126 |
+
const out=new ImageData(w,h),od=out.data;
|
| 127 |
+
for(let y=0;y<h;y++)for(let x=0;x<w;x++){let r=0,g=0,b=0,al=0;for(let k=0;k<6;k++){const i=(vy.idx[y*6+k]*w+x)*4,wv=vy.wt[y*6+k];r+=tmp[i]*wv;g+=tmp[i+1]*wv;b+=tmp[i+2]*wv;al+=tmp[i+3]*wv}const o=(y*w+x)*4;od[o]=r;od[o+1]=g;od[o+2]=b;od[o+3]=al}
|
| 128 |
+
const c=document.createElement('canvas');c.width=w;c.height=h;c.getContext('2d').putImageData(out,0,0);return c}
|
| 129 |
+
function compose(src,w,h,useAI,orig){
|
| 130 |
+
if(!useAI&&w*h<=16e6&&w>(src.naturalWidth||src.width)){if(lzc.src!==src||lzc.w!==w||lzc.h!==h)lzc={src,w,h,c:lanczos(src,w,h)};src=lzc.c}
|
| 131 |
+
const v=values(),n=+$('noise').value,sharpenBoost=$('imageType').value==='art'?1.12:1;
|
| 132 |
+
const c=document.createElement('canvas');c.width=w;c.height=h;const ctx=c.getContext('2d',{willReadFrequently:w*h<=16e6});
|
| 133 |
+
ctx.filter=`blur(${useAI?0:NOISE_STD[n]}px) brightness(${100+v.brightness}%) contrast(${100+v.contrast}%) saturate(${100+v.saturation}%)`;
|
| 134 |
+
ctx.imageSmoothingEnabled=true;ctx.imageSmoothingQuality='high';const str=+$('aistr').value/100;
|
| 135 |
+
if(useAI&&orig&&str<1){let b=orig;if(w*h<=16e6){if(lzc.src!==orig||lzc.w!==w||lzc.h!==h)lzc={src:orig,w,h,c:lanczos(orig,w,h)};b=lzc.c}ctx.drawImage(b,0,0,w,h);ctx.globalAlpha=str}
|
| 136 |
+
ctx.drawImage(src,0,0,w,h);ctx.globalAlpha=1;ctx.filter='none';
|
| 137 |
+
if(v.sharp>0&&w*h<=16e6){let src=ctx.getImageData(0,0,w,h),dst=ctx.createImageData(w,h),s=src.data,d=dst.data,k=v.sharp/100*.65*sharpenBoost;
|
| 138 |
+
for(let y=1;y<h-1;y++)for(let x=1;x<w-1;x++){let i=(y*w+x)*4;for(let ch=0;ch<3;ch++){let val=s[i+ch]* (1+4*k)-k*(s[i-4+ch]+s[i+4+ch]+s[i-w*4+ch]+s[i+w*4+ch]);d[i+ch]=Math.max(0,Math.min(255,val))}d[i+3]=s[i+3]}
|
| 139 |
+
for(let x=0;x<w;x++){for(let y of [0,h-1]){let i=(y*w+x)*4;d[i]=s[i];d[i+1]=s[i+1];d[i+2]=s[i+2];d[i+3]=s[i+3]}}
|
| 140 |
+
for(let y=1;y<h-1;y++)for(let x of [0,w-1]){let i=(y*w+x)*4;d.set(s.slice(i,i+4),i)}
|
| 141 |
+
ctx.putImageData(dst,0,0)}
|
| 142 |
+
return c}
|
| 143 |
+
function sizeFor(t,useAI){const sc=+$('scale').value;return useAI?[t.ai.width,t.ai.height]:[Math.round(t.w*sc),Math.round(t.h*sc)]}
|
| 144 |
+
function renderPhoto(){
|
| 145 |
+
const t=active;if(!t)return;
|
| 146 |
+
const useAI=!!t.ai&&t.key===curKey(),[w,h]=sizeFor(t,useAI);
|
| 147 |
+
if(w*h>MAXPX){setStatus(`Hasil ${w}×${h}px terlalu besar untuk browser (maks ±40 MP). Kecilkan pembesaran atau gambar.`);$('exportBtn').disabled=true;return}
|
| 148 |
+
$('exportBtn').disabled=false;
|
| 149 |
+
try{processedCanvas=compose(useAI?t.ai:t.img,w,h,useAI,t.img)}catch(e){setStatus('Memori browser tidak cukup untuk ukuran ini.');return}
|
| 150 |
+
const k=Math.min(1,1600/Math.max(w,h)),p=document.createElement('canvas');p.width=Math.max(1,Math.round(w*k));p.height=Math.max(1,Math.round(h*k));p.getContext('2d').drawImage(processedCanvas,0,0,p.width,p.height);
|
| 151 |
+
$('afterImg').src=p.toDataURL('image/jpeg',.92);
|
| 152 |
+
if(!useAI&&$('engine').value!=='std')setStatus('Pratinjau standar. Klik Jalankan AI untuk hasil AI.');
|
| 153 |
+
}
|
| 154 |
+
function setActive(t){active=t;image=t.img;file=t.file;$('beforeImg').src=t.url;$('drop').style.display='none';$('photoPreview').style.display='block';$('aiBtn').disabled=false;renderPhoto();setStatus(`${t.w} × ${t.h} px · ${fmtBytes(t.size)} · dipilih.`);renderQueue()}
|
| 155 |
+
function afterMode(){renderQueue();if(mode==='photo'&&active){$('drop').style.display='none';$('photoPreview').style.display='block';$('aiBtn').disabled=false;renderPhoto()}}
|
| 156 |
+
async function addFiles(list){
|
| 157 |
+
let last=null;
|
| 158 |
+
for(const f of list){
|
| 159 |
+
if(!f.type.startsWith('image/')){setStatus(`${f.name}: bukan file gambar.`);continue}
|
| 160 |
+
if(f.size>50*1048576){setStatus(`${f.name}: melebihi 50 MB.`);continue}
|
| 161 |
+
const url=URL.createObjectURL(f),img=new Image();
|
| 162 |
+
try{await new Promise((ok,no)=>{img.onload=ok;img.onerror=no;img.src=url})}catch(e){setStatus(`${f.name}: gambar tidak terbaca.`);URL.revokeObjectURL(url);continue}
|
| 163 |
+
last={id:++seq,file:f,url,img,w:img.naturalWidth,h:img.naturalHeight,size:f.size,status:'wait',pct:0,ai:null,key:'',blob:null,cfg:''};tasks.push(last);
|
| 164 |
+
if(!active)setActive(last);else renderQueue();
|
| 165 |
+
}
|
| 166 |
+
if(last&&last!==active&&list.length===1)setActive(last);
|
| 167 |
+
}
|
| 168 |
+
function loadFiles(fl){if(mode==='photo')addFiles(fl);else loadFile(fl[0])}
|
| 169 |
+
function renderQueue(){
|
| 170 |
+
$('queue').classList.toggle('hidden',mode!=='photo'||!tasks.length);
|
| 171 |
+
$('qlist').innerHTML=tasks.map(t=>{
|
| 172 |
+
const st={wait:'Menunggu',run:`Memproses… ${Math.round(t.pct*100)}%`,done:`Selesai · ${t.outW}×${t.outH}px · ${fmtBytes(t.blob?t.blob.size:0)} · ${t.cfg}`,err:t.msg||'Gagal'}[t.status];
|
| 173 |
+
const b=t.status==='run'?'':t.status==='done'?'<button class="btn sm primary" data-act="dl">Unduh</button><button class="btn sm" data-act="retry">Ulangi</button>':t.status==='err'?'<button class="btn sm" data-act="retry">Coba lagi</button>':'<button class="btn sm primary" data-act="start">Mulai</button>';
|
| 174 |
+
return `<div class="qitem${t===active?' on':''}" data-id="${t.id}"><img src="${t.url}" alt=""><div style="min-width:0"><div class="qn">${esc(t.file.name)}</div><div class="qm">${t.w}×${t.h}px · ${fmtBytes(t.size)}</div><div class="qm ${t.status==='done'?'ok':t.status==='err'?'err':''}">${esc(st)}</div>${t.status==='run'?`<div class="qbar"><i style="width:${Math.round(t.pct*100)}%"></i></div>`:''}<div class="qb">${b}<button class="btn sm" data-act="del">Hapus</button></div></div></div>`}).join('');
|
| 175 |
+
}
|
| 176 |
+
function dl(t){if(!t.blob)return;const a=document.createElement('a'),u=URL.createObjectURL(t.blob);a.href=u;a.download=t.outName;a.click();setTimeout(()=>URL.revokeObjectURL(u),1500)}
|
| 177 |
+
function delTask(t){if(t.status==='run')return;URL.revokeObjectURL(t.url);tasks=tasks.filter(x=>x!==t);if(active===t){active=null;if(tasks.length)setActive(tasks[0]);else{switchMode(mode);setStatus('')}}else renderQueue()}
|
| 178 |
+
$('qlist').onclick=e=>{const c=e.target.closest('[data-id]');if(!c)return;const t=tasks.find(x=>x.id==c.dataset.id);if(!t)return;const a=(e.target.closest('[data-act]')||{dataset:{}}).dataset.act;
|
| 179 |
+
if(a==='start'||a==='retry')runTask(t);else if(a==='dl')dl(t);else if(a==='del')delTask(t);else setActive(t)};
|
| 180 |
+
$('qAdd').onclick=()=>$('fileInput').click();
|
| 181 |
+
$('qStart').onclick=async()=>{for(const t of tasks.slice())if(tasks.includes(t)&&t.status!=='done'&&t.status!=='run')await runTask(t)};
|
| 182 |
+
$('qDl').onclick=async()=>{for(const t of tasks.filter(x=>x.blob)){dl(t);await sleep(500)}};
|
| 183 |
+
function loadFile(f){if(!f)return;file=f; if(mode==='photo'){if(!f.type.startsWith('image/')){setStatus('Pilih file gambar.');return}if(originalURL)URL.revokeObjectURL(originalURL);originalURL=URL.createObjectURL(f);image=new Image();image.onload=()=>{$('beforeImg').src=originalURL;$('drop').style.display='none';$('photoPreview').style.display='block';aiCanvas=null;$('aiBtn').disabled=false;$('exportBtn').disabled=false;renderPhoto();setStatus(`${image.naturalWidth} × ${image.naturalHeight} px · Foto siap diproses.`)};image.src=originalURL}else{if(!f.type.startsWith('video/')){setStatus('Pilih file video.');return}if(videoURL)URL.revokeObjectURL(videoURL);videoURL=URL.createObjectURL(f);$('video').src=videoURL;$('drop').style.display='none';$('videoPreview').style.display='block';$('recordBtn').disabled=false;applyVideoFilter();setStatus('Video siap untuk preview.')} }
|
| 184 |
+
$('fileInput').onchange=e=>{const fl=Array.from(e.target.files);e.target.value='';loadFiles(fl)};
|
| 185 |
+
const drop=$('drop');drop.addEventListener('dragover',e=>{e.preventDefault();drop.classList.add('drag')});drop.addEventListener('dragleave',()=>drop.classList.remove('drag'));drop.addEventListener('drop',e=>{e.preventDefault();drop.classList.remove('drag');loadFiles(Array.from(e.dataTransfer.files))});
|
| 186 |
+
let rpT=0;photoSliders.forEach(id=>$(id).addEventListener('input',()=>{$(id+'Val').value=$(id).value;clearTimeout(rpT);rpT=setTimeout(renderPhoto,160)}));
|
| 187 |
+
$('scale').onchange=renderPhoto;
|
| 188 |
+
/* ===== AI Super Resolution (UpscalerJS + ESRGAN) ===== */
|
| 189 |
+
const ORT_BASE='https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/';
|
| 190 |
+
const HF='https://huggingface.co/nimjinwei/designerplatform-models/resolve/main/';
|
| 191 |
+
const ONNX_URLS={art:['models/realesr-animevideov3.onnx',HF+'realesr-animevideov3.onnx'],photo:['models/realesr-general-x4v3.onnx',HF+'realesr-general-x4v3.onnx','https://huggingface.co/jonathanst29/tinier-upscale-models/resolve/main/realesr-general-x4v3.onnx','https://huggingface.co/momoapps/optimix-models/resolve/main/realesr-general-x4v3.onnx']};
|
| 192 |
+
let curAbort=null;
|
| 193 |
+
const loaded={};
|
| 194 |
+
function loadScript(u){return loaded[u]||(loaded[u]=new Promise((ok,no)=>{const t=document.createElement('script');t.src=u;t.onload=ok;t.onerror=()=>{delete loaded[u];no(new Error('Gagal memuat '+u))};document.head.appendChild(t)}))}
|
| 195 |
+
const sessions={};
|
| 196 |
+
async function getSession(kind,wasmOnly){
|
| 197 |
+
const key=kind+(wasmOnly?'w':'');if(sessions[key])return sessions[key];
|
| 198 |
+
if(!window.ort){try{await loadScript(ORT_BASE+'ort.webgpu.min.js')}catch(e){await loadScript(ORT_BASE+'ort.min.js')}}
|
| 199 |
+
ort.env.wasm.wasmPaths=ORT_BASE;
|
| 200 |
+
let buf=null;
|
| 201 |
+
for(const u of ONNX_URLS[kind]){try{const r=await fetch(u);if(!r.ok)throw 0;buf=await r.arrayBuffer();if(buf.byteLength>1e6)break;buf=null}catch(e){}}
|
| 202 |
+
if(!buf)throw new Error('Model Real-ESRGAN gagal diunduh. Periksa koneksi internet.');
|
| 203 |
+
let sess;
|
| 204 |
+
try{sess=await ort.InferenceSession.create(buf,{executionProviders:wasmOnly?['wasm']:['webgpu','wasm']})}
|
| 205 |
+
catch(e){sess=await ort.InferenceSession.create(buf,{executionProviders:['wasm']})}
|
| 206 |
+
sess.isGpu=!wasmOnly&&!!navigator.gpu;
|
| 207 |
+
return sessions[key]=sess}
|
| 208 |
+
async function onnxPass(sess,src,onp,base,span){
|
| 209 |
+
const sw=src.width,sh=src.height,sd=src.getContext('2d',{willReadFrequently:true}).getImageData(0,0,sw,sh).data;
|
| 210 |
+
const T=96,P=8,N=T+2*P,M=N*4,plane=N*N,ow=sw*4,oh=sh*4,out=new ImageData(ow,oh),od=out.data;
|
| 211 |
+
const inName=sess.inputNames[0],outName=sess.outputNames[0],buf=new Float32Array(3*plane);
|
| 212 |
+
const total=Math.ceil(sw/T)*Math.ceil(sh/T);let done=0;
|
| 213 |
+
for(let ty=0;ty<sh;ty+=T)for(let tx=0;tx<sw;tx+=T){
|
| 214 |
+
if(curAbort&&curAbort.signal.aborted)throw new Error('Dibatalkan');
|
| 215 |
+
for(let y=0;y<N;y++){const sy=Math.min(sh-1,Math.max(0,ty-P+y));for(let x=0;x<N;x++){const sx=Math.min(sw-1,Math.max(0,tx-P+x)),i=(sy*sw+sx)*4,o=y*N+x;buf[o]=sd[i]/255;buf[plane+o]=sd[i+1]/255;buf[2*plane+o]=sd[i+2]/255}}
|
| 216 |
+
const res=await sess.run({[inName]:new ort.Tensor('float32',buf,[1,3,N,N])});
|
| 217 |
+
const r=res[outName].data,th=Math.min(T,sh-ty),tw=Math.min(T,sw-tx);
|
| 218 |
+
for(let y=0;y<th*4;y++){const row=(P*4+y)*M+P*4,orow=((ty*4+y)*ow+tx*4)*4;for(let x=0;x<tw*4;x++){const k=row+x,o=orow+x*4;od[o]=r[k]*255;od[o+1]=r[M*M+k]*255;od[o+2]=r[2*M*M+k]*255;od[o+3]=255}}
|
| 219 |
+
done++;onp(base+span*done/total);await sleep(0);
|
| 220 |
+
}
|
| 221 |
+
const c=document.createElement('canvas');c.width=ow;c.height=oh;c.getContext('2d').putImageData(out,0,0);return c}
|
| 222 |
+
async function aiUpscale(t,onp){
|
| 223 |
+
const sc=+$('scale').value,kind=$('imageType').value==='art'?'art':'photo',passes=sc>4?2:1;
|
| 224 |
+
if(sc>4&&t.w*t.h*17>4e6)throw new Error(`Gambar terlalu besar untuk ${sc}× di browser (maks ±${(4/17).toFixed(2)} MP).`);
|
| 225 |
+
setStatus('Memuat model Real-ESRGAN…');
|
| 226 |
+
let sess=await getSession(kind),cur=document.createElement('canvas');cur.width=t.w;cur.height=t.h;
|
| 227 |
+
const pc=cur.getContext('2d'),n=+$('noise').value;pc.filter=n?`blur(${NOISE_AI[n]}px)`:'none';pc.drawImage(t.img,0,0);pc.filter='none';
|
| 228 |
+
setStatus(sess.isGpu?'Memproses dengan GPU…':'Memproses (tanpa GPU, lebih lambat)…');
|
| 229 |
+
for(let i=0;i<passes;i++){
|
| 230 |
+
try{cur=await onnxPass(sess,cur,onp,i/passes,1/passes)}
|
| 231 |
+
catch(e){if(i===0&&sess.isGpu&&!(curAbort&&curAbort.signal.aborted)){sess=await getSession(kind,true);setStatus('GPU tidak didukung, memakai CPU…');cur=await onnxPass(sess,cur,onp,0,1/passes)}else throw e}
|
| 232 |
+
}
|
| 233 |
+
const tw=t.w*sc,th=t.h*sc;
|
| 234 |
+
if(cur.width!==tw){const f=document.createElement('canvas');f.width=tw;f.height=th;const x=f.getContext('2d');x.imageSmoothingEnabled=true;x.imageSmoothingQuality='high';x.drawImage(cur,0,0,tw,th);cur=f}
|
| 235 |
+
return cur}
|
| 236 |
+
async function runTask(t){
|
| 237 |
+
while(busy)await sleep(300);
|
| 238 |
+
if(!tasks.includes(t))return;
|
| 239 |
+
busy=true;t.status='run';t.pct=0;t.msg='';renderQueue();$('aiBtn').classList.add('busy');
|
| 240 |
+
const sc=+$('scale').value,eng=$('engine').value,ai=eng!=='std';curAbort=new AbortController();$('cancelBtn').classList.remove('hidden');
|
| 241 |
+
const nm=['Tanpa noise reduction','Noise rendah','Noise sedang','Noise tinggi','Noise tertinggi'][+$('noise').value];
|
| 242 |
+
try{
|
| 243 |
+
if(ai){
|
| 244 |
+
if(sc<2)throw new Error('Pilih pembesaran 2× atau lebih untuk AI.');
|
| 245 |
+
if(t.w*t.h*sc*sc>MAXPX)throw new Error(`Hasil terlalu besar (${t.w*sc}×${t.h*sc}px, maks ±40 MP).`);
|
| 246 |
+
$('aibar').classList.remove('hidden');
|
| 247 |
+
t.ai=await aiUpscale(t,p=>{t.pct=p;$('aifill').style.width=Math.max(3,Math.round(p*100))+'%';setStatus(`Memproses ${t.file.name}… ${Math.round(p*100)}%`);renderQueue()});
|
| 248 |
+
t.key=curKey();
|
| 249 |
+
}else{t.ai=null}
|
| 250 |
+
const useAI=!!t.ai,[w,h]=sizeFor(t,useAI);
|
| 251 |
+
if(w*h>MAXPX)throw new Error(`Hasil terlalu besar (${w}×${h}px).`);
|
| 252 |
+
const c=compose(useAI?t.ai:t.img,w,h,useAI,t.img),m=outMime(t);
|
| 253 |
+
const blob=await new Promise(r=>c.toBlob(r,m,.95));if(!blob)throw new Error('Gagal menyiapkan file.');
|
| 254 |
+
t.blob=blob;t.outW=w;t.outH=h;t.outName=nameOf(t,blob,m);t.cfg=`${sc}× ${$('imageType').value==='art'?'Ilustrasi':'Foto'} · ${nm}`;t.status='done';t.pct=1;
|
| 255 |
+
setStatus(`Selesai · ${t.file.name} → ${w} × ${h} px.`);
|
| 256 |
+
}catch(e){console.error(e);t.status='err';t.msg=e.message;setStatus('Gagal: '+e.message)}
|
| 257 |
+
finally{busy=false;curAbort=null;$('cancelBtn').classList.add('hidden');$('aiBtn').classList.remove('busy');setTimeout(()=>{if(!busy)$('aibar').classList.add('hidden')},1000)}
|
| 258 |
+
renderQueue();if(t===active)renderPhoto();
|
| 259 |
+
}
|
| 260 |
+
$('aiBtn').onclick=()=>{if(active)runTask(active)};
|
| 261 |
+
function syncEngine(){const e=$('engine').value;$('aiBtn').classList.toggle('hidden',e==='std');0}
|
| 262 |
+
$('cancelBtn').onclick=()=>{if(curAbort)curAbort.abort()};
|
| 263 |
+
$('engine').onchange=()=>{syncEngine();renderPhoto()};
|
| 264 |
+
syncEngine();
|
| 265 |
+
|
| 266 |
+
document.addEventListener('pointerdown',e=>{const b=e.target.closest('.btn,.tab');if(!b||b.disabled)return;const r=b.getBoundingClientRect(),d=Math.max(r.width,r.height),p=document.createElement('span');p.className='ripple';p.style.cssText=`width:${d}px;height:${d}px;left:${e.clientX-r.left-d/2}px;top:${e.clientY-r.top-d/2}px`;b.appendChild(p);setTimeout(()=>p.remove(),650)});
|
| 267 |
+
|
| 268 |
+
$('imageType').onchange=renderPhoto;
|
| 269 |
+
$('noise').onchange=renderPhoto;
|
| 270 |
+
$('exportBtn').onclick=()=>{if(!processedCanvas||!active)return;const m=outMime(active),t=active;processedCanvas.toBlob(b=>{if(!b){setStatus('Gagal menyiapkan file. Coba ukuran lebih kecil.');return}dl({blob:b,outName:nameOf(t,b,m)})},m,.95)};
|
| 271 |
+
function applyVideoFilter(){let s=+$('vsharp').value,b=+$('vbright').value,c=+$('vcontrast').value,sa=+$('vsat').value;$('video').style.filter=`brightness(${100+b}%) contrast(${100+c}%) saturate(${100+sa}%)`;$('video').style.transform='translateZ(0)';$('vsharpVal').value=s;$('vbrightVal').value=b;$('vcontrastVal').value=c;$('vsatVal').value=sa}
|
| 272 |
+
videoSliders.forEach(id=>$(id).addEventListener('input',applyVideoFilter));
|
| 273 |
+
$('recordBtn').onclick=async()=>{const v=$('video');if(!v.src||!v.videoWidth){setStatus('Putar video sebentar hingga siap, lalu coba lagi.');return}const c=$('canvas');c.width=v.videoWidth;c.height=v.videoHeight;const ctx=c.getContext('2d');const stream=c.captureStream(30);const rec=new MediaRecorder(stream,{mimeType:MediaRecorder.isTypeSupported('video/webm;codecs=vp9')?'video/webm;codecs=vp9':'video/webm'});let chunks=[];rec.ondataavailable=e=>{if(e.data.size)chunks.push(e.data)};rec.onstop=()=>{let blob=new Blob(chunks,{type:'video/webm'}),url=URL.createObjectURL(blob),a=document.createElement('a');a.href=url;a.download='lumina-enhanced.webm';a.click();setStatus('Ekspor selesai. Video tersimpan sebagai WEBM tanpa audio.');setTimeout(()=>URL.revokeObjectURL(url),3000)};let s=+$('vsharp').value,b=+$('vbright').value,co=+$('vcontrast').value,sa=+$('vsat').value;ctx.filter=`brightness(${100+b}%) contrast(${100+co}%) saturate(${100+sa}%)`;rec.start();v.currentTime=0;await v.play();setStatus('Sedang merekam hasil visual video… jangan pindah tab.');function frame(){if(rec.state!=='recording')return;ctx.drawImage(v,0,0,c.width,c.height);if(v.ended){rec.stop();stream.getTracks().forEach(t=>t.stop());return}requestAnimationFrame(frame)}frame();v.onended=()=>{if(rec.state==='recording'){rec.stop();stream.getTracks().forEach(t=>t.stop())}}};
|
| 274 |
+
$('resetBtn').onclick=()=>{
|
| 275 |
+
photoSliders.forEach(id=>{$(id).value=({sharp:0,brightness:0,contrast:0,saturation:0,aistr:60})[id];$(id+'Val').value=$(id).value});
|
| 276 |
+
[['vsharp',15],['vbright',5],['vcontrast',10],['vsat',8]].forEach(([id,v])=>$(id).value=v);
|
| 277 |
+
$('scale').value='2';$('engine').value='ai';$('imageType').value='photo';$('noise').value='0';$('format').value='auto';
|
| 278 |
+
if(originalURL){URL.revokeObjectURL(originalURL);originalURL=null}
|
| 279 |
+
if(videoURL){URL.revokeObjectURL(videoURL);videoURL=null}
|
| 280 |
+
tasks.forEach(t=>URL.revokeObjectURL(t.url));tasks=[];active=null;image=new Image();file=null;processedCanvas=null;
|
| 281 |
+
$('beforeImg').removeAttribute('src');$('afterImg').removeAttribute('src');$('video').removeAttribute('src');$('video').load();
|
| 282 |
+
$('aiBtn').disabled=true;$('aibar').classList.add('hidden');
|
| 283 |
+
syncEngine();switchMode(mode);applyVideoFilter();
|
| 284 |
+
setStatus('');
|
| 285 |
+
};
|
| 286 |
+
</script>
|
| 287 |
+
</body>
|
| 288 |
+
</html>
|