annotate fdctref.c @ 8590:7a463923ecd1 libavcodec

Change semantic of CONFIG_*, HAVE_* and ARCH_*. They are now always defined to either 0 or 1.
author aurel
date Tue, 13 Jan 2009 23:44:16 +0000
parents 2b72f9bc4f06
children 18737839ed27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1106
1e39f273ecd6 per file doxy
michaelni
parents: 635
diff changeset
1 /**
1e39f273ecd6 per file doxy
michaelni
parents: 635
diff changeset
2 * @file fdctref.c
1e39f273ecd6 per file doxy
michaelni
parents: 635
diff changeset
3 * forward discrete cosine transform, double precision.
1e39f273ecd6 per file doxy
michaelni
parents: 635
diff changeset
4 */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
5
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
986e461dc072 Initial revision
glantau
parents:
diff changeset
7
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 * Disclaimer of Warranty
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * These software programs are available to the user without any license fee or
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * any and all warranties, whether express, implied, or statuary, including any
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 * implied warranties or merchantability or of fitness for a particular
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 * purpose. In no event shall the copyright-holder be liable for any
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * incidental, punitive, or consequential damages of any kind whatsoever
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 * arising from the use of these programs.
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 * This disclaimer of warranty extends to the user of these programs and user's
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 * customers, employees, agents, transferees, successors, and assigns.
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 * The MPEG Software Simulation Group does not represent or warrant that the
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 * programs furnished hereunder are free of infringement of any third-party
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 * patents.
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 * are subject to royalty fees to patent holders. Many of these patents are
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 * general enough such that they are unavoidable regardless of implementation
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 * design.
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
31
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 #include <math.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
33
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 #ifndef PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 # ifdef M_PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 # define PI M_PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 # else
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 # define PI 3.14159265358979323846
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 # endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
41
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 /* global declarations */
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 void init_fdct (void);
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 void fdct (short *block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
45
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 /* private data */
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 static double c[8][8]; /* transform coefficients */
986e461dc072 Initial revision
glantau
parents:
diff changeset
48
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 void init_fdct()
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 int i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 double s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 for (i=0; i<8; i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 s = (i==0) ? sqrt(0.125) : 0.5;
986e461dc072 Initial revision
glantau
parents:
diff changeset
57
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 for (j=0; j<8; j++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 c[i][j] = s * cos((PI/8.0)*i*(j+0.5));
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
62
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 void fdct(block)
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 short *block;
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
66 register int i, j;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
67 double s;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
68 double tmp[64];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
69
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
70 for(i = 0; i < 8; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
71 for(j = 0; j < 8; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
72 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
73 s = 0.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
74
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 /*
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
76 * for(k = 0; k < 8; k++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
77 * s += c[j][k] * block[8 * i + k];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 */
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
79 s += c[j][0] * block[8 * i + 0];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
80 s += c[j][1] * block[8 * i + 1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
81 s += c[j][2] * block[8 * i + 2];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
82 s += c[j][3] * block[8 * i + 3];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
83 s += c[j][4] * block[8 * i + 4];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
84 s += c[j][5] * block[8 * i + 5];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
85 s += c[j][6] * block[8 * i + 6];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
86 s += c[j][7] * block[8 * i + 7];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
87
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
88 tmp[8 * i + j] = s;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
89 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
90
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
91 for(j = 0; j < 8; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
92 for(i = 0; i < 8; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
93 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
94 s = 0.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
95
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 /*
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
97 * for(k = 0; k < 8; k++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
98 * s += c[i][k] * tmp[8 * k + j];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 */
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
100 s += c[i][0] * tmp[8 * 0 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
101 s += c[i][1] * tmp[8 * 1 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
102 s += c[i][2] * tmp[8 * 2 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
103 s += c[i][3] * tmp[8 * 3 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
104 s += c[i][4] * tmp[8 * 4 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
105 s += c[i][5] * tmp[8 * 5 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
106 s += c[i][6] * tmp[8 * 6 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
107 s += c[i][7] * tmp[8 * 7 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
108 s*=8.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
109
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
110 block[8 * i + j] = (short)floor(s + 0.499999);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 * reason for adding 0.499999 instead of 0.5:
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 * s is quite often x.5 (at least for i and/or j = 0 or 4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 * and setting the rounding threshold exactly to 0.5 leads to an
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 * extremely high arithmetic implementation dependency of the result;
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 * s being between x.5 and x.500001 (which is now incorrectly rounded
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 * downwards instead of upwards) is assumed to occur less often
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 * (if at all)
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
121 }
35
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
122
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
123 /* perform IDCT matrix multiply for 8x8 coefficient block */
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
124
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
125 void idct(block)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
126 short *block;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
127 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
128 int i, j, k, v;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
129 double partial_product;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
130 double tmp[64];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
131
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
132 for (i=0; i<8; i++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
133 for (j=0; j<8; j++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
134 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
135 partial_product = 0.0;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
136
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
137 for (k=0; k<8; k++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
138 partial_product+= c[k][j]*block[8*i+k];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
139
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
140 tmp[8*i+j] = partial_product;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
141 }
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
142
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1106
diff changeset
143 /* Transpose operation is integrated into address mapping by switching
35
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
144 loop order of i and j */
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
145
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
146 for (j=0; j<8; j++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
147 for (i=0; i<8; i++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
148 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
149 partial_product = 0.0;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
150
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
151 for (k=0; k<8; k++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
152 partial_product+= c[k][i]*tmp[8*k+j];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
153
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
154 v = (int) floor(partial_product+0.5);
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
155 block[8*i+j] = v;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
156 }
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
157 }