Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vp3dsp.c @ bb54f6ab

History | View | Annotate | Download (6.79 KB)

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