diff --git a/JPEGVisualRepairTool.html b/JPEGVisualRepairTool.html index c7b8e2d..d097d8f 100644 --- a/JPEGVisualRepairTool.html +++ b/JPEGVisualRepairTool.html @@ -9,7 +9,7 @@
-JPEG visual repair tool v1.2 info
+JPEG visual repair tool v1.3 info
  @@ -28,7 +28,7 @@
-Shift MCU
+Shift MCU

@@ -82,6 +82,7 @@
+ Image info


@@ -89,7 +90,7 @@
-

JPEG visual repair tool v1.2 (Sep '23)

by Alberto Maccioni

+

JPEG visual repair tool v1.3 (Oct '23)

by Alberto Maccioni

This tool can load JPEG images while preserving MCU (Minimum Coded Unit) coding data and allows editing at MCU level.
The purpose is to correct artifacts resulting from file corruption.
@@ -114,12 +115,15 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert ctrl-v ⇒ paste before selected MCU
ctrl-z ⇒ undo last operation
del ⇒ delete MCU
+arrows ⇒ change selected MCU
+f ⇒ zoom fit
i ⇒ extra MCU info
s ⇒ shift MCU rendering using left/right keys
1 ⇒ switch to RGB view
2 ⇒ switch to Y view
3 ⇒ switch to Cb view
4 ⇒ switch to Cr view
+] [ ⇒ zoom in/out

@@ -217,6 +221,10 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert noClick=false; return; } + if(shiftRendering!=0){ + resetShift(); //reset shift + selectedUpdate(); + } var x = e.pageX - cPicture.offsetLeft; var y = e.pageY - cPicture.offsetTop; var rate=ctx.canvas.width/ctxPicture.canvas.width/zoomFactor; @@ -302,6 +310,9 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert if(zDxJPEG visual repair tool v1.2 (Sep '23) by Albert updateAllMCU(item.position); } } - if(key==219){ //[ + if(key==70){ //f fit + zoomFactor=1; + zDx=zDy=0; + ctxPicture.drawImage(pictInt,zDx,zDy,ctxPicture.canvas.width*zoomFactor,ctxPicture.canvas.height*zoomFactor); + document.getElementById("zoom").innerHTML="Zoom:"+zoomFactor.toFixed(2); } - if(key==221){ //] + if(key==219){ //[ zoom-out + var xorig=(cPicture.offsetWidth/2-zDx)/zoomFactor; //center in original picture coordinates + var yorig=(cPicture.offsetHeight/2-zDy)/zoomFactor; + zoomFactor*=0.8; + if(zoomFactor<1){ + zoomFactor=1; + zDx=zDy=0; + } + else{ + zDx=(cPicture.offsetWidth/2-cPicture.offsetLeft)-xorig*zoomFactor; //shift to center + zDy=(cPicture.offsetHeight/2-cPicture.offsetTop)-yorig*zoomFactor; + if(zDx>0) zDx=0; + if(zDy>0) zDy=0; + if(zDx100) zoomFactor=100; + zDx=(cPicture.offsetWidth/2-cPicture.offsetLeft)-xorig*zoomFactor; //shift to center + zDy=(cPicture.offsetHeight/2-cPicture.offsetTop)-yorig*zoomFactor; + if(zDx>0) zDx=0; + if(zDy>0) zDy=0; + if(zDxarr.indexOf(item)===index); } @@ -994,9 +1048,9 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert link.id="downloadID"; link.href = blobUrl; link.download = filename.replace(/\./,"_corrected."); - document.body.appendChild(link); // Or append it whereever you want + document.body.appendChild(link); // Or append it wherever you want document.querySelector("#downloadID").click() //can add an id to be specific if multiple anchor tag, and use #id - document.body.removeChild(link); // Or append it whereever you want + document.body.removeChild(link); } //change layer and redraw selection rectangle @@ -1041,7 +1095,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert var X=0,Y=0; var sof0=0,endoffset=0; var drioffset=0; - var infoStr="Image info
"+filename+"
"; + var infoStr=filename+"
"; scanoffset=0; dht.length=0; dqt.length=0; @@ -1263,8 +1317,6 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert var decode_result,restartCount=0; var rstErrStat_extra=0,errnum,next_rstnum=0,rst; iblock=0; -// rstErrStat=new Array; -// for(i=0;i<50;i++) rstErrStat[i]=0; var row=0; var col=0; var addRestart2NextMCU=-1; @@ -1345,8 +1397,6 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert MCUarray[mcucount].blocks[iblock].errors+= " Restart interval error: +"+errnum; console.log("MCU"+mcucount+MCUarray[mcucount].blocks[iblock].errors); - //if(errnum<50) rstErrStat[errnum]++; - //else rstErrStat_extra=1; } restartCount=0; } @@ -1414,7 +1464,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert ctxZoom.canvas.style.width=mcuPixX*10; ctxZoom.canvas.style.height=mcuPixY*10; ctxPicture.imageSmoothingEnabled = false; - ctxPicture.canvas.width=document.documentElement.clientWidth-250;//ctxZoom.canvas.width; + ctxPicture.canvas.width=document.documentElement.clientWidth-270; //+20 ctxPicture.canvas.height=ctx.canvas.height/ctx.canvas.width*ctxPicture.canvas.width; if(ctxPicture.canvas.height>document.documentElement.clientHeight-10){ //too high ctxPicture.canvas.height=document.documentElement.clientHeight-10; @@ -1502,7 +1552,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert j=MCUarray[i].blocks.length; } } - if(drawRestart&&MCUarray[i].restart>-1){ + if(drawRestart&&MCUarray[i].restart>-1){ //Restart marker ctx.beginPath(); ctx.lineWidth = "1"; //ctx.strokeStyle = "green"; @@ -1737,7 +1787,8 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert } //Fix color difference between MCU(x,y) and MCU(x,y-1) -//by changing DC coefficient of the currently selected MCU +//by changing DC coefficient of MCU(x,y) +//MCU list in colorFixList function fixColorDiff(){ if(selectedMCU.i<0||colorFixList.length==0) return; var refMCU=[]; //MCUs to be matched in color @@ -1783,7 +1834,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert objComp=getAvgComponents(O,0); //average components, upper row deltaComp={Y:objComp.Y-refComp.Y,C1:objComp.C1-refComp.C1,C2:objComp.C2-refComp.C2}; //console.log("x=["+x.Y+" "+x.C1+" "+x.C2+"] f(x)=["+deltaComp.Y+" "+deltaComp.C1+" "+deltaComp.C2+"]"); - for(var j=0;j<10;j++){ + for(var j=0;j<10;j++){ //at most 10 iterations if(deltaComp.Y!=deltaCompZ.Y) MCUarray[O].blocks[0].coeff[0]=Math.round(x.Y-deltaComp.Y*(x.Y-xZ.Y)/(deltaComp.Y-deltaCompZ.Y)); if(deltaComp.C1!=deltaCompZ.C1) MCUarray[O].blocks[bC].coeff[0]=Math.round(x.C1-deltaComp.C1*(x.C1-xZ.C1)/(deltaComp.C1-deltaCompZ.C1)); if(deltaComp.C2!=deltaCompZ.C2) MCUarray[O].blocks[bC2].coeff[0]=Math.round(x.C2-deltaComp.C2*(x.C2-xZ.C2)/(deltaComp.C2-deltaCompZ.C2)); @@ -2191,6 +2242,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert const HTAB_ERR=-3000000; const RESTART_MARKER=-4000000; //decode DC value from buffer f using Huffman table Htable +//if present, fill bs structure with bitstream //return value: //EOF_ERR -> end of file //EOI_MARKER -> EOI marker @@ -2245,6 +2297,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert const EOB=0x1000000; const ZRL=0x2000000; //decode AC value from buffer f using Huffman table Htable +//if present, fill bs structure with bitstream //return value: //EOF_ERR -> end of file //EOI_MARKER -> EOI marker @@ -2322,7 +2375,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert //v=1 out on console //type=0 Y //type=1 C -//bs=string to save bitstream (0=none) +//bs=structure with string used to save bitstream (0=none) //return value: // DECODE_UNKNOWN -> unknown code // DECODE_EOF -> end of data @@ -2435,10 +2488,9 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert } const ENC_ERR=-1; -//encode DC value using Huffman table Htable -//return value: //encode x (DC value, max 11 bit) using Huffman table Htable -//result: {code: coded value, n: total number of bits} +//return value: +//{code: coded value, n: total number of bits} //ENC_ERR if x requires more than 11 bits or code not found in table function encodeHvalDC(Htable,x){ var val=x>0?x:-x; @@ -2455,7 +2507,8 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert //encode AC value using Huffman table Htable //R=zero run length //x=coefficient -//result: {code: coded value, n: total number of bits} +//return value: +//{code: coded value, n: total number of bits} //ENC_ERR if x requires more than 10 bits or code not found in table function encodeHvalAC(Htable,R,x){ var val=x>0?x:-x; @@ -2471,7 +2524,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert } -//Standard IDCT +//Standard IDCT according to definition function idct2dB(mat){ const cos = Math.cos, PI = Math.PI, isqrt2 = 1 / Math.sqrt(2); mat2=new Array(); @@ -2569,6 +2622,7 @@

JPEG visual repair tool v1.2 (Sep '23)

by Albert } //print matrix in rows of 8 +//to console or string function printmat(m,n="",console=1){ var NL=console==1?"\n":"
"; var i,r=0,str=n+"["+NL;