1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 
12 #include <math.h>
13 
vp8_short_fdct4x4_c(short * input,short * output,int pitch)14 void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
15 {
16     int i;
17     int a1, b1, c1, d1;
18     short *ip = input;
19     short *op = output;
20 
21     for (i = 0; i < 4; i++)
22     {
23         a1 = ((ip[0] + ip[3]) * 8);
24         b1 = ((ip[1] + ip[2]) * 8);
25         c1 = ((ip[1] - ip[2]) * 8);
26         d1 = ((ip[0] - ip[3]) * 8);
27 
28         op[0] = a1 + b1;
29         op[2] = a1 - b1;
30 
31         op[1] = (c1 * 2217 + d1 * 5352 +  14500)>>12;
32         op[3] = (d1 * 2217 - c1 * 5352 +   7500)>>12;
33 
34         ip += pitch / 2;
35         op += 4;
36 
37     }
38     ip = output;
39     op = output;
40     for (i = 0; i < 4; i++)
41     {
42         a1 = ip[0] + ip[12];
43         b1 = ip[4] + ip[8];
44         c1 = ip[4] - ip[8];
45         d1 = ip[0] - ip[12];
46 
47         op[0]  = ( a1 + b1 + 7)>>4;
48         op[8]  = ( a1 - b1 + 7)>>4;
49 
50         op[4]  =((c1 * 2217 + d1 * 5352 +  12000)>>16) + (d1!=0);
51         op[12] = (d1 * 2217 - c1 * 5352 +  51000)>>16;
52 
53         ip++;
54         op++;
55     }
56 }
57 
vp8_short_fdct8x4_c(short * input,short * output,int pitch)58 void vp8_short_fdct8x4_c(short *input, short *output, int pitch)
59 {
60     vp8_short_fdct4x4_c(input,   output,    pitch);
61     vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
62 }
63 
vp8_short_walsh4x4_c(short * input,short * output,int pitch)64 void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
65 {
66     int i;
67     int a1, b1, c1, d1;
68     int a2, b2, c2, d2;
69     short *ip = input;
70     short *op = output;
71 
72 
73     for (i = 0; i < 4; i++)
74     {
75         a1 = ((ip[0] + ip[2]) * 4);
76         d1 = ((ip[1] + ip[3]) * 4);
77         c1 = ((ip[1] - ip[3]) * 4);
78         b1 = ((ip[0] - ip[2]) * 4);
79 
80         op[0] = a1 + d1 + (a1!=0);
81         op[1] = b1 + c1;
82         op[2] = b1 - c1;
83         op[3] = a1 - d1;
84         ip += pitch / 2;
85         op += 4;
86     }
87 
88     ip = output;
89     op = output;
90 
91     for (i = 0; i < 4; i++)
92     {
93         a1 = ip[0] + ip[8];
94         d1 = ip[4] + ip[12];
95         c1 = ip[4] - ip[12];
96         b1 = ip[0] - ip[8];
97 
98         a2 = a1 + d1;
99         b2 = b1 + c1;
100         c2 = b1 - c1;
101         d2 = a1 - d1;
102 
103         a2 += a2<0;
104         b2 += b2<0;
105         c2 += c2<0;
106         d2 += d2<0;
107 
108         op[0] = (a2+3) >> 3;
109         op[4] = (b2+3) >> 3;
110         op[8] = (c2+3) >> 3;
111         op[12]= (d2+3) >> 3;
112 
113         ip++;
114         op++;
115     }
116 }
117