Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vp3dsp.c @ 2029f312

History | View | Annotate | Download (6.78 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 "avcodec.h"
28 e96682e6 Michael Niedermayer
#include "dsputil.h"
29 44cb64ee Mike Melanson
30
#define IdctAdjustBeforeShift 8
31
#define xC1S7 64277
32
#define xC2S6 60547
33
#define xC3S5 54491
34
#define xC4S4 46341
35
#define xC5S3 36410
36
#define xC6S2 25080
37
#define xC7S1 12785
38
39 e003ea06 Michael Niedermayer
#define M(a,b) (((a) * (b))>>16)
40
41 849f1035 Måns Rullgård
static av_always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type)
42 44cb64ee Mike Melanson
{
43 8b6103da Michael Niedermayer
    int16_t *ip = input;
44 55fde95e Måns Rullgård
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
45 44cb64ee Mike Melanson
46 d26a9ea0 Michael Niedermayer
    int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;
47
    int Ed, Gd, Add, Bdd, Fd, Hd;
48 44cb64ee Mike Melanson
49 bf4e3bd2 Måns Rullgård
    int i;
50 115329f1 Diego Biurrun
51 44cb64ee Mike Melanson
    /* Inverse DCT on the rows now */
52
    for (i = 0; i < 8; i++) {
53
        /* Check for non-zero values */
54
        if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
55 d26a9ea0 Michael Niedermayer
            A = M(xC1S7, ip[1]) + M(xC7S1, ip[7]);
56
            B = M(xC7S1, ip[1]) - M(xC1S7, ip[7]);
57
            C = M(xC3S5, ip[3]) + M(xC5S3, ip[5]);
58
            D = M(xC3S5, ip[5]) - M(xC5S3, ip[3]);
59 44cb64ee Mike Melanson
60 d26a9ea0 Michael Niedermayer
            Ad = M(xC4S4, (A - C));
61
            Bd = M(xC4S4, (B - D));
62 44cb64ee Mike Melanson
63 d26a9ea0 Michael Niedermayer
            Cd = A + C;
64
            Dd = B + D;
65 44cb64ee Mike Melanson
66 d26a9ea0 Michael Niedermayer
            E = M(xC4S4, (ip[0] + ip[4]));
67
            F = M(xC4S4, (ip[0] - ip[4]));
68 44cb64ee Mike Melanson
69 d26a9ea0 Michael Niedermayer
            G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]);
70
            H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]);
71 44cb64ee Mike Melanson
72 d26a9ea0 Michael Niedermayer
            Ed = E - G;
73
            Gd = E + G;
74 44cb64ee Mike Melanson
75 d26a9ea0 Michael Niedermayer
            Add = F + Ad;
76
            Bdd = Bd - H;
77 44cb64ee Mike Melanson
78 d26a9ea0 Michael Niedermayer
            Fd = F - Ad;
79
            Hd = Bd + H;
80 44cb64ee Mike Melanson
81
            /*  Final sequence of operations over-write original inputs. */
82 d26a9ea0 Michael Niedermayer
            ip[0] = Gd + Cd ;
83
            ip[7] = Gd - Cd ;
84 44cb64ee Mike Melanson
85 d26a9ea0 Michael Niedermayer
            ip[1] = Add + Hd;
86
            ip[2] = Add - Hd;
87 44cb64ee Mike Melanson
88 d26a9ea0 Michael Niedermayer
            ip[3] = Ed + Dd ;
89
            ip[4] = Ed - Dd ;
90 44cb64ee Mike Melanson
91 d26a9ea0 Michael Niedermayer
            ip[5] = Fd + Bdd;
92
            ip[6] = Fd - Bdd;
93 44cb64ee Mike Melanson
        }
94
95
        ip += 8;            /* next row */
96
    }
97 115329f1 Diego Biurrun
98 8b6103da Michael Niedermayer
    ip = input;
99 44cb64ee Mike Melanson
100
    for ( i = 0; i < 8; i++) {
101
        /* Check for non-zero values (bitwise or faster than ||) */
102 8b6103da Michael Niedermayer
        if ( ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
103 44cb64ee Mike Melanson
             ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
104
105 d26a9ea0 Michael Niedermayer
            A = M(xC1S7, ip[1*8]) + M(xC7S1, ip[7*8]);
106
            B = M(xC7S1, ip[1*8]) - M(xC1S7, ip[7*8]);
107
            C = M(xC3S5, ip[3*8]) + M(xC5S3, ip[5*8]);
108
            D = M(xC3S5, ip[5*8]) - M(xC5S3, ip[3*8]);
109 44cb64ee Mike Melanson
110 d26a9ea0 Michael Niedermayer
            Ad = M(xC4S4, (A - C));
111
            Bd = M(xC4S4, (B - D));
112 44cb64ee Mike Melanson
113 d26a9ea0 Michael Niedermayer
            Cd = A + C;
114
            Dd = B + D;
115 44cb64ee Mike Melanson
116 d9cf32d9 Michael Niedermayer
            E = M(xC4S4, (ip[0*8] + ip[4*8])) + 8;
117
            F = M(xC4S4, (ip[0*8] - ip[4*8])) + 8;
118
119
            if(type==1){  //HACK
120
                E += 16*128;
121
                F += 16*128;
122
            }
123 44cb64ee Mike Melanson
124 d26a9ea0 Michael Niedermayer
            G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]);
125
            H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]);
126 44cb64ee Mike Melanson
127 d26a9ea0 Michael Niedermayer
            Ed = E - G;
128
            Gd = E + G;
129 44cb64ee Mike Melanson
130 d26a9ea0 Michael Niedermayer
            Add = F + Ad;
131
            Bdd = Bd - H;
132 44cb64ee Mike Melanson
133 d26a9ea0 Michael Niedermayer
            Fd = F - Ad;
134
            Hd = Bd + H;
135 44cb64ee Mike Melanson
136
            /* Final sequence of operations over-write original inputs. */
137 8b6103da Michael Niedermayer
            if(type==0){
138 d26a9ea0 Michael Niedermayer
                ip[0*8] = (Gd + Cd )  >> 4;
139
                ip[7*8] = (Gd - Cd )  >> 4;
140 115329f1 Diego Biurrun
141 d26a9ea0 Michael Niedermayer
                ip[1*8] = (Add + Hd ) >> 4;
142
                ip[2*8] = (Add - Hd ) >> 4;
143 115329f1 Diego Biurrun
144 d26a9ea0 Michael Niedermayer
                ip[3*8] = (Ed + Dd )  >> 4;
145
                ip[4*8] = (Ed - Dd )  >> 4;
146 115329f1 Diego Biurrun
147 d26a9ea0 Michael Niedermayer
                ip[5*8] = (Fd + Bdd ) >> 4;
148
                ip[6*8] = (Fd - Bdd ) >> 4;
149 8b6103da Michael Niedermayer
            }else if(type==1){
150 d26a9ea0 Michael Niedermayer
                dst[0*stride] = cm[(Gd + Cd )  >> 4];
151
                dst[7*stride] = cm[(Gd - Cd )  >> 4];
152 115329f1 Diego Biurrun
153 d26a9ea0 Michael Niedermayer
                dst[1*stride] = cm[(Add + Hd ) >> 4];
154
                dst[2*stride] = cm[(Add - Hd ) >> 4];
155 115329f1 Diego Biurrun
156 d26a9ea0 Michael Niedermayer
                dst[3*stride] = cm[(Ed + Dd )  >> 4];
157
                dst[4*stride] = cm[(Ed - Dd )  >> 4];
158 115329f1 Diego Biurrun
159 d26a9ea0 Michael Niedermayer
                dst[5*stride] = cm[(Fd + Bdd ) >> 4];
160
                dst[6*stride] = cm[(Fd - Bdd ) >> 4];
161 8b6103da Michael Niedermayer
            }else{
162 d26a9ea0 Michael Niedermayer
                dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd )  >> 4)];
163
                dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd )  >> 4)];
164 115329f1 Diego Biurrun
165 d26a9ea0 Michael Niedermayer
                dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)];
166
                dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)];
167 115329f1 Diego Biurrun
168 d26a9ea0 Michael Niedermayer
                dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd )  >> 4)];
169
                dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd )  >> 4)];
170 115329f1 Diego Biurrun
171 d26a9ea0 Michael Niedermayer
                dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)];
172
                dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)];
173 8b6103da Michael Niedermayer
            }
174 44cb64ee Mike Melanson
175
        } else {
176 8b6103da Michael Niedermayer
            if(type==0){
177 115329f1 Diego Biurrun
                ip[0*8] =
178
                ip[1*8] =
179
                ip[2*8] =
180
                ip[3*8] =
181
                ip[4*8] =
182
                ip[5*8] =
183 8b6103da Michael Niedermayer
                ip[6*8] =
184
                ip[7*8] = ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
185
            }else if(type==1){
186
                dst[0*stride]=
187
                dst[1*stride]=
188
                dst[2*stride]=
189
                dst[3*stride]=
190
                dst[4*stride]=
191
                dst[5*stride]=
192
                dst[6*stride]=
193
                dst[7*stride]= 128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
194
            }else{
195
                if(ip[0*8]){
196
                    int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
197
                    dst[0*stride] = cm[dst[0*stride] + v];
198
                    dst[1*stride] = cm[dst[1*stride] + v];
199
                    dst[2*stride] = cm[dst[2*stride] + v];
200
                    dst[3*stride] = cm[dst[3*stride] + v];
201
                    dst[4*stride] = cm[dst[4*stride] + v];
202
                    dst[5*stride] = cm[dst[5*stride] + v];
203
                    dst[6*stride] = cm[dst[6*stride] + v];
204
                    dst[7*stride] = cm[dst[7*stride] + v];
205
                }
206
            }
207 44cb64ee Mike Melanson
        }
208
209
        ip++;            /* next column */
210 8b6103da Michael Niedermayer
        dst++;
211 44cb64ee Mike Melanson
    }
212
}
213 8b6103da Michael Niedermayer
214
void ff_vp3_idct_c(DCTELEM *block/* align 16*/){
215
    idct(NULL, 0, block, 0);
216
}
217 115329f1 Diego Biurrun
218 8b6103da Michael Niedermayer
void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
219
    idct(dest, line_size, block, 1);
220
}
221
222
void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
223
    idct(dest, line_size, block, 2);
224
}