asfdec: also read Metadata Library Object
[FFMpeg-mirror/mplayer-patches.git] / libavcodec / faanidct.c
blob5cacfdd2a31b61acb23b8c654d0e4c735bdedd32
1 /*
2 * Floating point AAN IDCT
3 * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "faanidct.h"
22 #include "libavutil/common.h"
24 /* To allow switching to double. */
25 #define FLOAT float
27 #define B0 1.0000000000000000000000
28 #define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2)
29 #define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2)
30 #define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2)
31 #define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2)
32 #define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2)
33 #define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2)
34 #define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2)
36 #define A4 0.70710678118654752438 // cos(pi*4/16)
37 #define A2 0.92387953251128675613 // cos(pi*2/16)
39 static const FLOAT prescale[64]={
40 B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8,
41 B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8,
42 B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8,
43 B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8,
44 B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8,
45 B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8,
46 B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8,
47 B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8,
50 static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){
51 int i;
52 FLOAT av_unused tmp0;
53 FLOAT s04, d04, s17, d17, s26, d26, s53, d53;
54 FLOAT os07, os16, os25, os34;
55 FLOAT od07, od16, od25, od34;
57 for(i=0; i<y*8; i+=y){
58 s17= temp[1*x + i] + temp[7*x + i];
59 d17= temp[1*x + i] - temp[7*x + i];
60 s53= temp[5*x + i] + temp[3*x + i];
61 d53= temp[5*x + i] - temp[3*x + i];
63 od07= s17 + s53;
64 od25= (s17 - s53)*(2*A4);
66 #if 0 //these 2 are equivalent
67 tmp0= (d17 + d53)*(2*A2);
68 od34= d17*( 2*B6) - tmp0;
69 od16= d53*(-2*B2) + tmp0;
70 #else
71 od34= d17*(2*(B6-A2)) - d53*(2*A2);
72 od16= d53*(2*(A2-B2)) + d17*(2*A2);
73 #endif
75 od16 -= od07;
76 od25 -= od16;
77 od34 += od25;
79 s26 = temp[2*x + i] + temp[6*x + i];
80 d26 = temp[2*x + i] - temp[6*x + i];
81 d26*= 2*A4;
82 d26-= s26;
84 s04= temp[0*x + i] + temp[4*x + i];
85 d04= temp[0*x + i] - temp[4*x + i];
87 os07= s04 + s26;
88 os34= s04 - s26;
89 os16= d04 + d26;
90 os25= d04 - d26;
92 if(type==0){
93 temp[0*x + i]= os07 + od07;
94 temp[7*x + i]= os07 - od07;
95 temp[1*x + i]= os16 + od16;
96 temp[6*x + i]= os16 - od16;
97 temp[2*x + i]= os25 + od25;
98 temp[5*x + i]= os25 - od25;
99 temp[3*x + i]= os34 - od34;
100 temp[4*x + i]= os34 + od34;
101 }else if(type==1){
102 data[0*x + i]= lrintf(os07 + od07);
103 data[7*x + i]= lrintf(os07 - od07);
104 data[1*x + i]= lrintf(os16 + od16);
105 data[6*x + i]= lrintf(os16 - od16);
106 data[2*x + i]= lrintf(os25 + od25);
107 data[5*x + i]= lrintf(os25 - od25);
108 data[3*x + i]= lrintf(os34 - od34);
109 data[4*x + i]= lrintf(os34 + od34);
110 }else if(type==2){
111 dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));
112 dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));
113 dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));
114 dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));
115 dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));
116 dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));
117 dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));
118 dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));
119 }else{
120 dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));
121 dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));
122 dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));
123 dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));
124 dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));
125 dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));
126 dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));
127 dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));
132 void ff_faanidct(int16_t block[64]){
133 FLOAT temp[64];
134 int i;
136 emms_c();
138 for(i=0; i<64; i++)
139 temp[i] = block[i] * prescale[i];
141 p8idct(block, temp, NULL, 0, 1, 8, 0);
142 p8idct(block, temp, NULL, 0, 8, 1, 1);
145 void ff_faanidct_add(uint8_t *dest, int line_size, int16_t block[64]){
146 FLOAT temp[64];
147 int i;
149 emms_c();
151 for(i=0; i<64; i++)
152 temp[i] = block[i] * prescale[i];
154 p8idct(block, temp, NULL, 0, 1, 8, 0);
155 p8idct(NULL , temp, dest, line_size, 8, 1, 2);
158 void ff_faanidct_put(uint8_t *dest, int line_size, int16_t block[64]){
159 FLOAT temp[64];
160 int i;
162 emms_c();
164 for(i=0; i<64; i++)
165 temp[i] = block[i] * prescale[i];
167 p8idct(block, temp, NULL, 0, 1, 8, 0);
168 p8idct(NULL , temp, dest, line_size, 8, 1, 3);