2 * Copyright (C) 2004 the ffmpeg project
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.
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.
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
21 * Standard C DSP-oriented functions cribbed from the original VP3
29 #define IdctAdjustBeforeShift 8
38 #define M(a,b) (((a) * (b))>>16)
40 static always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type)
43 uint8_t *cm = cropTbl + MAX_NEG_CROP;
45 int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;
46 int Ed, Gd, Add, Bdd, Fd, Hd;
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]);
59 Ad = M(xC4S4, (A - C));
60 Bd = M(xC4S4, (B - D));
65 E = M(xC4S4, (ip[0] + ip[4]));
66 F = M(xC4S4, (ip[0] - ip[4]));
68 G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]);
69 H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]);
80 /* Final sequence of operations over-write original inputs. */
94 ip += 8; /* next row */
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] ) {
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]);
109 Ad = M(xC4S4, (A - C));
110 Bd = M(xC4S4, (B - D));
115 E = M(xC4S4, (ip[0*8] + ip[4*8])) + 8;
116 F = M(xC4S4, (ip[0*8] - ip[4*8])) + 8;
123 G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]);
124 H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]);
135 /* Final sequence of operations over-write original inputs. */
137 ip[0*8] = (Gd + Cd ) >> 4;
138 ip[7*8] = (Gd - Cd ) >> 4;
140 ip[1*8] = (Add + Hd ) >> 4;
141 ip[2*8] = (Add - Hd ) >> 4;
143 ip[3*8] = (Ed + Dd ) >> 4;
144 ip[4*8] = (Ed - Dd ) >> 4;
146 ip[5*8] = (Fd + Bdd ) >> 4;
147 ip[6*8] = (Fd - Bdd ) >> 4;
149 dst[0*stride] = cm[(Gd + Cd ) >> 4];
150 dst[7*stride] = cm[(Gd - Cd ) >> 4];
152 dst[1*stride] = cm[(Add + Hd ) >> 4];
153 dst[2*stride] = cm[(Add - Hd ) >> 4];
155 dst[3*stride] = cm[(Ed + Dd ) >> 4];
156 dst[4*stride] = cm[(Ed - Dd ) >> 4];
158 dst[5*stride] = cm[(Fd + Bdd ) >> 4];
159 dst[6*stride] = cm[(Fd - Bdd ) >> 4];
161 dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd ) >> 4)];
162 dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd ) >> 4)];
164 dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)];
165 dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)];
167 dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd ) >> 4)];
168 dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd ) >> 4)];
170 dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)];
171 dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)];
183 ip[7*8] = ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
192 dst[7*stride]= 128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
195 int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
196 dst[0*stride] = cm[dst[0*stride] + v];
197 dst[1*stride] = cm[dst[1*stride] + v];
198 dst[2*stride] = cm[dst[2*stride] + v];
199 dst[3*stride] = cm[dst[3*stride] + v];
200 dst[4*stride] = cm[dst[4*stride] + v];
201 dst[5*stride] = cm[dst[5*stride] + v];
202 dst[6*stride] = cm[dst[6*stride] + v];
203 dst[7*stride] = cm[dst[7*stride] + v];
208 ip++; /* next column */
213 void ff_vp3_idct_c(DCTELEM *block/* align 16*/){
214 idct(NULL, 0, block, 0);
217 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
218 idct(dest, line_size, block, 1);
221 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
222 idct(dest, line_size, block, 2);