From 6716abca664e1c913bd09fb4b129168e3dc9d94d Mon Sep 17 00:00:00 2001 From: GliGli Date: Mon, 17 Oct 2022 18:15:45 +0200 Subject: [PATCH] cleanup --- tilingencoder.pas | 195 ---------------------------------------------- 1 file changed, 195 deletions(-) diff --git a/tilingencoder.pas b/tilingencoder.pas index 784a00f..458a95e 100644 --- a/tilingencoder.pas +++ b/tilingencoder.pas @@ -519,8 +519,6 @@ TTilingEncoder = class function LABToRGB(ll, aa, bb: TFloat; GammaCor: Integer): Integer; function YUVToRGB(y, u, v: TFloat; GammaCor: Integer): Integer; - procedure WaveletGS(Data: PFloat; Output: PFloat; dx, dy, depth: cardinal); - procedure DeWaveletGS(wl: PFloat; pic: PFloat; dx, dy, depth: longint); procedure ComputeTilePsyVisFeatures(const ATile: TTile; FromPal, UseLAB, QWeighting, HMirror, VMirror, Inversible: Boolean; GammaCor: Integer; const pal: TIntegerDynArray; DCT: PFloat); inline; overload; procedure ComputeTilePsyVisFeatures(const ATile: TTile; FromPal, UseLAB, QWeighting, HMirror, VMirror, @@ -3763,199 +3761,6 @@ procedure TTilingEncoder.SetQuantizerDennisLeeBitsPerComponent(AValue: Integer); FQuantizerDennisLeeBitsPerComponent := EnsureRange(AValue, 2, 8); end; -// from https://lists.freepascal.org/pipermail/fpc-announce/2006-September/000508.html -procedure TTilingEncoder.WaveletGS(Data : PFloat; Output : PFloat; dx, dy, depth : cardinal); -var - x, y: longint; - offset: cardinal; - factor: TFloat; - tempX: array[0 .. sqr(cTileWidth) - 1] of TFloat; - tempY: array[0 .. sqr(cTileWidth) - 1] of TFloat; -begin - FillChar(tempX[0], SizeOf(tempX), 0); - FillChar(tempY[0], SizeOf(tempY), 0); - - factor:=(1.0 / sqrt(2.0)); //Normalized Haar - - for y:=0 to dy - 1 do //Transform Rows - begin - offset := y * cTileWidth; - for x := 0 to (dx div 2) - 1 do - begin - tempX[x + offset] := (Data[x * 2 + offset] + Data[(x * 2 + 1) + offset]) * factor; //LOW-PASS - tempX[(x + dx div 2) +offset] := (Data[x * 2 + offset] - Data[(x * 2 + 1) + offset]) * factor; //HIGH-PASS - end; - end; - - for x := 0 to dx - 1 do //Transform Columns - for y := 0 to (dy div 2) - 1 do - begin - tempY[x +y * cTileWidth] := (tempX[x +y * 2 * cTileWidth] + tempX[x +(y * 2 + 1) * cTileWidth]) * factor; //LOW-PASS - tempY[x +(y + dy div 2) * cTileWidth] := (tempX[x +y * 2 * cTileWidth] - tempX[x +(y * 2 + 1) * cTileWidth]) * factor; //HIGH-PASS - end; - - for y := 0 to dy - 1 do - Move(tempY[y * cTileWidth], Output[y * cTileWidth], dx * sizeof(TFloat)); //Copy to Wavelet - - if depth>0 then - waveletgs(Output, Output, dx div 2, dy div 2, depth - 1); //Repeat for SubDivisionDepth -end; - -procedure TTilingEncoder.DeWaveletGS(wl: PFloat; pic: PFloat; dx, dy, depth: longint); - Var x,y : longint; - tempX: array[0 .. sqr(cTileWidth) - 1] of TFloat; - tempY: array[0 .. sqr(cTileWidth) - 1] of TFloat; - offset,offsetm1,offsetp1 : longint; - factor : TFloat; - dyoff,yhalf,yhalfoff,yhalfoff2,yhalfoff3 : longint; -BEGIN - FillChar(tempX[0], SizeOf(tempX), 0); - FillChar(tempY[0], SizeOf(tempY), 0); - - if depth>0 then dewaveletgs(wl,wl,dx div 2,dy div 2,depth-1); //Repeat for SubDivisionDepth - - factor:=(1.0/sqrt(2.0)); //Normalized Haar - - //// - - yhalf:=(dy div 2)-1; - dyoff:=(dy div 2)*cTileWidth; - yhalfoff:=yhalf*cTileWidth; - yhalfoff2:=(yhalf+(dy div 2))*cTileWidth; - yhalfoff3:=yhalfoff*2 +cTileWidth; - - if (yhalf>0) then begin //The first and last pixel has to be done "normal" - for x:=0 to dx-1 do begin - tempy[x] := (wl[x] + wl[x+dyoff])*factor; //LOW-PASS - tempy[x+cTileWidth]:= (wl[x] - wl[x+dyoff])*factor; //HIGH-PASS - - tempy[x +yhalfoff*2]:= (wl[x +yhalfoff] + wl[x +yhalfoff2])*factor; //LOW-PASS - tempy[x +yhalfoff3] := (wl[x +yhalfoff] - wl[x +yhalfoff2])*factor; //HIGH-PASS - end; - end else begin - for x:=0 to dx-1 do begin - tempy[x] := (wl[x] + wl[x+dyoff])*factor; //LOW-PASS - tempy[x+cTileWidth]:= (wl[x] - wl[x+dyoff])*factor; //HIGH-PASS - end; - end; - - // - - dyoff:=(dy div 2)*cTileWidth; - yhalf:=(dy div 2)-2; - - if (yhalf>=1) then begin //More then 2 pixels in the row? - // - if (dy>=4) then begin //DY must be greater then 4 to make the faked algo look good.. else it must be done "normal" - // - for x:=0 to dx-1 do begin //Inverse Transform Colums (fake: if (high-pass coefficient=0.0) and (surrounding high-pass coefficients=0.0) then interpolate between surrounding low-pass coefficients) - offsetm1:=0; - offset:=cTileWidth; - offsetp1:=cTileWidth*2; - - for y:=1 to yhalf do begin - if (wl[x +offset+dyoff]<>0.0) then begin //!UPDATED - tempy[x +offset*2] := (wl[x +offset] + wl[x +offset+dyoff])*factor; //LOW-PASS - tempy[x +offset*2 +cTileWidth] := (wl[x +offset] - wl[x +offset+dyoff])*factor; //HIGH-PASS - end else begin //!UPDATED - if (wl[x +offsetm1 +dyoff]=0.0) and (wl[x +offsetp1]<>wl[x +offset]) and ((y=yhalf) or (wl[x +offsetp1]<>wl[x +offsetp1 +cTileWidth])) then tempy[x +offset*2]:=(wl[x +offset]*0.8 + wl[x +offsetm1]*0.2)*factor //LOW-PASS - else tempy[x +offset*2]:=wl[x +offset]*factor; - if (wl[x +offsetp1 +dyoff]=0.0) and (wl[x +offsetm1]<>wl[x +offset]) and ((y=1) or (wl[x +offsetm1]<>wl[x +offsetm1 -cTileWidth])) then tempy[x +offset*2 +cTileWidth]:=(wl[x +offset]*0.8 + wl[x +offsetp1]*0.2)*factor //HIGH-PASS - else tempy[x +offset*2 +cTileWidth]:=wl[x +offset]*factor; - end; - - inc(offsetm1,cTileWidth); - inc(offset,cTileWidth); - inc(offsetp1,cTileWidth); - end; - - end; - // - end else //DY<4 - // - for x:=0 to dx-1 do begin - offset:=cTileWidth; - for y:=1 to yhalf do begin - tempy[x +offset*2] := (wl[x +offset] + wl[x +offset +dyoff])*factor; //LOW-PASS - tempy[x +offset*2+cTileWidth] := (wl[x +offset] - wl[x +offset +dyoff])*factor; //HIGH-PASS - - inc(offset,cTileWidth); - end; - end; - // - end; - - //// - - offset:=0; - yhalf:=(dx div 2)-1; - yhalfoff:=(yhalf+dx div 2); - yhalfoff2:=yhalf*2+1; - - if (yhalf>0) then begin - for y:=0 to dy-1 do begin //The first and last pixel has to be done "normal" - tempx[offset] :=(tempy[offset] + tempy[yhalf+1 +offset])*factor; //LOW-PASS - tempx[offset+1] :=(tempy[offset] - tempy[yhalf+1 +offset])*factor; //HIGH-PASS - - tempx[yhalf*2 +offset] :=(tempy[yhalf +offset] + tempy[yhalfoff +offset])*factor; //LOW-PASS - tempx[yhalfoff2 +offset] :=(tempy[yhalf +offset] - tempy[yhalfoff +offset])*factor; //HIGH-PASS - - inc(offset,cTileWidth); - end; - end else begin - for y:=0 to dy-1 do begin //The first and last pixel has to be done "normal" - tempx[offset] :=(tempy[offset] + tempy[yhalf+1 +offset])*factor; //LOW-PASS - tempx[offset+1] :=(tempy[offset] - tempy[yhalf+1 +offset])*factor; //HIGH-PASS - - inc(offset,cTileWidth); - end; - end; - - // - - dyoff:=(dx div 2); - yhalf:=(dx div 2)-2; - - if (yhalf>=1) then begin - - if (dx>=4) then begin - - offset:=0; - for y:=0 to dy-1 do begin //Inverse Transform Rows (fake: if (high-pass coefficient=0.0) and (surrounding high-pass coefficients=0.0) then interpolate between surrounding low-pass coefficients) - for x:=1 to yhalf do - if (tempy[x +dyoff +offset]<>0.0) then begin //!UPDATED - tempx[x*2 +offset] :=(tempy[x +offset] + tempy[x +dyoff +offset])*factor; //LOW-PASS - tempx[x*2+1 +offset] :=(tempy[x +offset] - tempy[x +dyoff +offset])*factor; //HIGH-PASS - end else begin //!UPDATED - if (tempy[x-1+dyoff +offset]=0.0) and (tempy[x+1 +offset]<>tempy[x +offset]) and ((x=yhalf) or (tempy[x+1 +offset]<>tempy[x+2 +offset])) then tempx[x*2 +offset]:=(tempy[x +offset]*0.8 + tempy[x-1 +offset]*0.2)*factor //LOW-PASS - else tempx[x*2 +offset]:=tempy[x +offset]*factor; - if (tempy[x+1+dyoff +offset]=0.0) and (tempy[x-1 +offset]<>tempy[x +offset]) and ((x=1) or (tempy[x-1 +offset]<>tempy[x-2 +offset])) then tempx[x*2+1 +offset]:=(tempy[x +offset]*0.8 + tempy[x+1 +offset]*0.2)*factor //HIGH-PASS - else tempx[x*2+1 +offset]:=tempy[x +offset]*factor; - end; - inc(offset,cTileWidth); - end; - - end else begin //DX<4 - - offset:=0; - for y:=0 to dy-1 do begin //Inverse Transform Rows (fake: if (high-pass coefficient=0.0) and (surrounding high-pass coefficients=0.0) then interpolate between surrounding low-pass coefficients) - for x:=1 to yhalf do begin - tempx[x*2 +offset] := (tempy[x +offset] + tempy[x +dyoff +offset])*factor; //LOW-PASS - tempx[x*2+1 +offset] := (tempy[x +offset] - tempy[x +dyoff +offset])*factor; //HIGH-PASS - end; - inc(offset,cTileWidth); - end; - - end; - - end; - - //// - - for y:=0 to dy-1 do - move(tempx[y*cTileWidth],pic[y*cTileWidth],dx*sizeof(TFloat)); //Copy to Pic -END; - generic function DCTInner(pCpn, pLut: T): Double; begin Result := 0;