-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInversePsvd.java
More file actions
102 lines (78 loc) · 3.7 KB
/
Copy pathInversePsvd.java
File metadata and controls
102 lines (78 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cn.edu.ustc.aaron.decoder;
import java.util.*;
import cn.edu.ustc.aaron.common.*;
import Jama.*;
public class InversePsvd {
private boolean codeCbCr;
private Matrix[] stackedToOneColMat;
private Matrix[] reshapedProductUVBaseMat;
private Residue residue;
private Diag diag;
public InversePsvd (Matrix[] reshapedProductUVBaseMat, boolean codeCbCr) {
this.reshapedProductUVBaseMat = reshapedProductUVBaseMat;
this.codeCbCr = codeCbCr;
allocMemory();
}
private void allocMemory () {
int row = reshapedProductUVBaseMat[0].getRowDimension();
int rowD = reshapedProductUVBaseMat[0].getColumnDimension();
residue = new Residue(row, 1, codeCbCr);
diag = new Diag(rowD, 1, codeCbCr);
}
private class CreateInitSuper extends MatrixCreationAndOperation {
public CreateInitSuper (int matHeight, int matWidth, int matHeightC, boolean codeCbCr) {
super(matHeight, matWidth, codeCbCr);
super.matHeightC = matHeightC; // Bugs for Diag initialization.
super.allocMemory();
}
public void operateMatrix(Matrix[]... srcs) {
// init Matrix
Matrix[] zeroMat = srcs[0];
super.mat[0].setMatrix(0, super.matHeight-1, 0, super.matWidth-1, zeroMat[0]);
if (codeCbCr) {
super.mat[1].setMatrix(0, super.matHeightC-1, 0, super.matWidthC-1, zeroMat[0]);
super.mat[2].setMatrix(0, super.matHeightC-1, 0, super.matWidthC-1, zeroMat[0]);
}
}
}
private class Residue extends CreateInitSuper {
public Residue (int matHeight, int matWidth, boolean codeCbCr) {
super(matHeight, matWidth, matHeight >> 2, codeCbCr);
}
}
private class Diag extends CreateInitSuper {
public Diag (int matHeight, int matWidth, boolean codeCbCr) {
super(matHeight, matWidth, matHeight, codeCbCr);
}
}
private void unpackDiag (Iterator diagLinkedListIt, int color) {
Matrix diagMat = diag.getMatrix(color);
for (int i = 0; i < diagMat.getRowDimension(); i++) {
diagMat.set(i, 0, (double)(int)diagLinkedListIt.next());
}
}
public Matrix[] invPsvd () {
Matrix[] residueMat = residue.getMatrix();
Matrix[] diagMat = diag.getMatrix();
Matrix[] decStackedToOneColMat = new Matrix[3];
decStackedToOneColMat[0] = reshapedProductUVBaseMat[0].times(diagMat[0]).plus(residueMat[0]).timesEquals(255.0);
if (codeCbCr) {
decStackedToOneColMat[1] = reshapedProductUVBaseMat[1].times(diagMat[1]).plus(residueMat[1]).timesEquals(255.0);
decStackedToOneColMat[2] = reshapedProductUVBaseMat[2].times(diagMat[2]).plus(residueMat[2]).timesEquals(255.0);
}
return decStackedToOneColMat;
}
public Matrix[] invPsvd (Matrix[] residueMat, Iterator[] diagLinkedListIt) {
Matrix[] diagMat = diag.getMatrix();
Matrix[] decStackedToOneColMat = new Matrix[3];
unpackDiag (diagLinkedListIt[0], 0);
decStackedToOneColMat[0] = reshapedProductUVBaseMat[0].times(diagMat[0]).plus(residueMat[0]).timesEquals(255.0);
if (codeCbCr) {
unpackDiag (diagLinkedListIt[1], 1);
decStackedToOneColMat[1] = reshapedProductUVBaseMat[1].times(diagMat[1]).plus(residueMat[1]).timesEquals(255.0);
unpackDiag (diagLinkedListIt[2], 2);
decStackedToOneColMat[2] = reshapedProductUVBaseMat[2].times(diagMat[2]).plus(residueMat[2]).timesEquals(255.0);
}
return decStackedToOneColMat;
}
}