/Users/lyon/j4p/src/ip/apurva/SPxform.java

1    package ip.apurva; 
2     
3     
4    public class SPxform { 
5     
6        public static short[][] transpose(short in[][]) { 
7            int width = in.length; 
8            int height = in[0].length; 
9            short[][] output = new short[height][width]; 
10    
11           for (int j = 0; j < width; j++) 
12               for (int i = 0; i < height; i++) 
13                   output[j][i] = in[i][j]; 
14    
15           return output; 
16       } 
17    
18       public static void S_plus_P_Xform(short in[][]) { 
19           for (int x = 0; x < in.length; x++) 
20               SPxform(in[x], in.length); 
21           in = transpose(in); 
22           for (int x = 0; x < in.length; x++) 
23               SPxform(in[x], in.length); 
24           in = transpose(in); 
25    
26       } 
27    
28       public static void SPxform(short in[], int n) { 
29           int i; 
30           if (n < 2) return; 
31           int nOn2 = n / 2; 
32           short s[] = new short[nOn2]; 
33           short d[] = new short[nOn2]; 
34           short delta[] = new short[in.length]; 
35    
36           for (i = 0; i < nOn2; i++) { 
37               s[i] = in[2 * i]; 
38               d[i] = in[2 * i + 1]; 
39           } 
40    
41           for (i = 1; i < s.length; i++) 
42               delta[i] = (short) (s[i - 1] - s[i]); 
43    
44           for (i = 1; i < s.length - 1; i++) { 
45               d[i] = (short) (d[i] + 0 * delta[i - 1] + 1 / 4 * delta[i] + 3 / 8 * delta[i + 1] - 1 / 4 * d[i + 1]); 
46    
47           } 
48    
49           for (i = 0; i < s.length; i++) { 
50               in[i] = s[i]; 
51               in[i + nOn2] = d[i]; 
52           } 
53           SPxform(in, nOn2); 
54       } 
55   //i was trying to write inverse s+p xform code here code here 
56       public static void inversXform(short in[][]) { 
57           for (int x = 0; x < in.length; x++) 
58               inverseform(in[x]); 
59           in = transpose(in); 
60           for (int x = 0; x < in.length; x++) 
61               inverseform(in[x]); 
62           in = transpose(in); 
63    
64       } 
65    
66       public static void inverseform(short in[]) { 
67           int i; 
68           int n = in.length; 
69           if (n < 2) return; 
70           int nOn2 = n / 2; 
71           short s[] = new short[nOn2]; 
72           short delta[] = new short[nOn2]; 
73           for (i = 0; i < nOn2; i++) 
74               s[i] = in[i]; 
75           inverseform(s); 
76           nOn2 = in.length / 2; 
77           short d[] = new short[nOn2]; 
78           for (i = 0; i < d.length; i++) 
79               d[i] = in[i + nOn2]; 
80    
81           for (i = 1; i < s.length; i++) 
82               delta[i] = (short) (s[i - 1] - s[i]); 
83    
84           for (i = 1; i < s.length - 1; i++) { 
85               d[i] = (short) (d[i] - 0 * delta[i - 1] - 1 / 4 * delta[i] - 3 / 8 * delta[i + 1] + 1 / 4 * d[i + 1]); 
86           } 
87           for (i = 0; i < s.length; i++) { 
88               in[2 * i] = s[i]; 
89               in[2 * i + 1] = d[i]; 
90           } 
91       } 
92   }