]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/vp3dsp.c
remove 166 useless underscores, and make this file valid c code as a result
[frescor/ffmpeg.git] / libavcodec / vp3dsp.c
1 /*
2  * Copyright (C) 2004 the ffmpeg project
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /**
20  * @file vp3dsp.c
21  * Standard C DSP-oriented functions cribbed from the original VP3
22  * source code.
23  */
24
25 #include "common.h"
26 #include "avcodec.h"
27 #include "dsputil.h"
28
29 #define IdctAdjustBeforeShift 8
30 #define xC1S7 64277
31 #define xC2S6 60547
32 #define xC3S5 54491
33 #define xC4S4 46341
34 #define xC5S3 36410
35 #define xC6S2 25080
36 #define xC7S1 12785
37
38 #define M(a,b) (((a) * (b))>>16)
39
40 static always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type)
41 {
42     int16_t *ip = input;
43     uint8_t *cm = cropTbl + MAX_NEG_CROP;
44
45     int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;
46     int Ed, Gd, Add, Bdd, Fd, Hd;
47
48     int i;
49
50     /* Inverse DCT on the rows now */
51     for (i = 0; i < 8; i++) {
52         /* Check for non-zero values */
53         if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
54             A = M(xC1S7, ip[1]) + M(xC7S1, ip[7]);
55             B = M(xC7S1, ip[1]) - M(xC1S7, ip[7]);
56             C = M(xC3S5, ip[3]) + M(xC5S3, ip[5]);
57             D = M(xC3S5, ip[5]) - M(xC5S3, ip[3]);
58
59             Ad = M(xC4S4, (A - C));
60             Bd = M(xC4S4, (B - D));
61
62             Cd = A + C;
63             Dd = B + D;
64
65             E = M(xC4S4, (ip[0] + ip[4]));
66             F = M(xC4S4, (ip[0] - ip[4]));
67
68             G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]);
69             H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]);
70
71             Ed = E - G;
72             Gd = E + G;
73
74             Add = F + Ad;
75             Bdd = Bd - H;
76
77             Fd = F - Ad;
78             Hd = Bd + H;
79
80             /*  Final sequence of operations over-write original inputs. */
81             ip[0] = Gd + Cd ;
82             ip[7] = Gd - Cd ;
83
84             ip[1] = Add + Hd;
85             ip[2] = Add - Hd;
86
87             ip[3] = Ed + Dd ;
88             ip[4] = Ed - Dd ;
89
90             ip[5] = Fd + Bdd;
91             ip[6] = Fd - Bdd;
92         }
93
94         ip += 8;            /* next row */
95     }
96
97     ip = input;
98
99     for ( i = 0; i < 8; i++) {
100         /* Check for non-zero values (bitwise or faster than ||) */
101         if ( ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
102              ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
103
104             A = M(xC1S7, ip[1*8]) + M(xC7S1, ip[7*8]);
105             B = M(xC7S1, ip[1*8]) - M(xC1S7, ip[7*8]);
106             C = M(xC3S5, ip[3*8]) + M(xC5S3, ip[5*8]);
107             D = M(xC3S5, ip[5*8]) - M(xC5S3, ip[3*8]);
108
109             Ad = M(xC4S4, (A - C));
110             Bd = M(xC4S4, (B - D));
111
112             Cd = A + C;
113             Dd = B + D;
114
115             E = M(xC4S4, (ip[0*8] + ip[4*8]));
116             F = M(xC4S4, (ip[0*8] - ip[4*8]));
117
118             G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]);
119             H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]);
120
121             Ed = E - G;
122             Gd = E + G;
123
124             Add = F + Ad;
125             Bdd = Bd - H;
126
127             Fd = F - Ad;
128             Hd = Bd + H;
129
130             if(type==1){  //HACK
131                 Gd += 16*128;
132                 Add+= 16*128;
133                 Ed += 16*128;
134                 Fd += 16*128;
135             }
136             Gd += IdctAdjustBeforeShift;
137             Add += IdctAdjustBeforeShift;
138             Ed += IdctAdjustBeforeShift;
139             Fd += IdctAdjustBeforeShift;
140
141             /* Final sequence of operations over-write original inputs. */
142             if(type==0){
143                 ip[0*8] = (Gd + Cd )  >> 4;
144                 ip[7*8] = (Gd - Cd )  >> 4;
145
146                 ip[1*8] = (Add + Hd ) >> 4;
147                 ip[2*8] = (Add - Hd ) >> 4;
148
149                 ip[3*8] = (Ed + Dd )  >> 4;
150                 ip[4*8] = (Ed - Dd )  >> 4;
151
152                 ip[5*8] = (Fd + Bdd ) >> 4;
153                 ip[6*8] = (Fd - Bdd ) >> 4;
154             }else if(type==1){
155                 dst[0*stride] = cm[(Gd + Cd )  >> 4];
156                 dst[7*stride] = cm[(Gd - Cd )  >> 4];
157
158                 dst[1*stride] = cm[(Add + Hd ) >> 4];
159                 dst[2*stride] = cm[(Add - Hd ) >> 4];
160
161                 dst[3*stride] = cm[(Ed + Dd )  >> 4];
162                 dst[4*stride] = cm[(Ed - Dd )  >> 4];
163
164                 dst[5*stride] = cm[(Fd + Bdd ) >> 4];
165                 dst[6*stride] = cm[(Fd - Bdd ) >> 4];
166             }else{
167                 dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd )  >> 4)];
168                 dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd )  >> 4)];
169
170                 dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)];
171                 dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)];
172
173                 dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd )  >> 4)];
174                 dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd )  >> 4)];
175
176                 dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)];
177                 dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)];
178             }
179
180         } else {
181             if(type==0){
182                 ip[0*8] =
183                 ip[1*8] =
184                 ip[2*8] =
185                 ip[3*8] =
186                 ip[4*8] =
187                 ip[5*8] =
188                 ip[6*8] =
189                 ip[7*8] = ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
190             }else if(type==1){
191                 dst[0*stride]=
192                 dst[1*stride]=
193                 dst[2*stride]=
194                 dst[3*stride]=
195                 dst[4*stride]=
196                 dst[5*stride]=
197                 dst[6*stride]=
198                 dst[7*stride]= 128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
199             }else{
200                 if(ip[0*8]){
201                     int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
202                     dst[0*stride] = cm[dst[0*stride] + v];
203                     dst[1*stride] = cm[dst[1*stride] + v];
204                     dst[2*stride] = cm[dst[2*stride] + v];
205                     dst[3*stride] = cm[dst[3*stride] + v];
206                     dst[4*stride] = cm[dst[4*stride] + v];
207                     dst[5*stride] = cm[dst[5*stride] + v];
208                     dst[6*stride] = cm[dst[6*stride] + v];
209                     dst[7*stride] = cm[dst[7*stride] + v];
210                 }
211             }
212         }
213
214         ip++;            /* next column */
215         dst++;
216     }
217 }
218
219 void ff_vp3_idct_c(DCTELEM *block/* align 16*/){
220     idct(NULL, 0, block, 0);
221 }
222
223 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
224     idct(dest, line_size, block, 1);
225 }
226
227 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
228     idct(dest, line_size, block, 2);
229 }