annotate fdctref.c @ 2979:bfabfdf9ce55 libavcodec

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents ef2149182f1c
children 2b72f9bc4f06
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 #include <math.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
34
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 #ifndef PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 # ifdef M_PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 # define PI M_PI
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 # else
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 # define PI 3.14159265358979323846
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 # endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
42
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 /* global declarations */
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 void init_fdct (void);
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 void fdct (short *block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
46
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 /* private data */
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 static double c[8][8]; /* transform coefficients */
986e461dc072 Initial revision
glantau
parents:
diff changeset
49
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 void init_fdct()
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 int i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 double s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
54
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 for (i=0; i<8; i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 s = (i==0) ? sqrt(0.125) : 0.5;
986e461dc072 Initial revision
glantau
parents:
diff changeset
58
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 for (j=0; j<8; j++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 c[i][j] = s * cos((PI/8.0)*i*(j+0.5));
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
63
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 void fdct(block)
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 short *block;
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
67 register int i, j;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
68 double s;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
69 double tmp[64];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
70
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
71 for(i = 0; i < 8; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
72 for(j = 0; j < 8; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
73 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
74 s = 0.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
75
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 /*
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
77 * for(k = 0; k < 8; k++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
78 * s += c[j][k] * block[8 * i + k];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 */
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
80 s += c[j][0] * block[8 * i + 0];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
81 s += c[j][1] * block[8 * i + 1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
82 s += c[j][2] * block[8 * i + 2];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
83 s += c[j][3] * block[8 * i + 3];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
84 s += c[j][4] * block[8 * i + 4];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
85 s += c[j][5] * block[8 * i + 5];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
86 s += c[j][6] * block[8 * i + 6];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
87 s += c[j][7] * block[8 * i + 7];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
88
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
89 tmp[8 * i + j] = s;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
90 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
91
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
92 for(j = 0; j < 8; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
93 for(i = 0; i < 8; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
94 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
95 s = 0.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
96
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 /*
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
98 * for(k = 0; k < 8; k++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
99 * s += c[i][k] * tmp[8 * k + j];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 */
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
101 s += c[i][0] * tmp[8 * 0 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
102 s += c[i][1] * tmp[8 * 1 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
103 s += c[i][2] * tmp[8 * 2 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
104 s += c[i][3] * tmp[8 * 3 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
105 s += c[i][4] * tmp[8 * 4 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
106 s += c[i][5] * tmp[8 * 5 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
107 s += c[i][6] * tmp[8 * 6 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
108 s += c[i][7] * tmp[8 * 7 + j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
109 s*=8.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
110
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
111 block[8 * i + j] = (short)floor(s + 0.499999);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 * reason for adding 0.499999 instead of 0.5:
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 * s is quite often x.5 (at least for i and/or j = 0 or 4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 * and setting the rounding threshold exactly to 0.5 leads to an
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 * extremely high arithmetic implementation dependency of the result;
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 * s being between x.5 and x.500001 (which is now incorrectly rounded
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 * downwards instead of upwards) is assumed to occur less often
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 * (if at all)
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
121 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
122 }
35
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
123
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
124 /* perform IDCT matrix multiply for 8x8 coefficient block */
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
125
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
126 void idct(block)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
127 short *block;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
128 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
129 int i, j, k, v;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
130 double partial_product;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
131 double tmp[64];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
132
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
133 for (i=0; i<8; i++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
134 for (j=0; j<8; j++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
135 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
136 partial_product = 0.0;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
137
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
138 for (k=0; k<8; k++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
139 partial_product+= c[k][j]*block[8*i+k];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
140
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
141 tmp[8*i+j] = partial_product;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
142 }
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
143
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 1106
diff changeset
144 /* Transpose operation is integrated into address mapping by switching
35
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
145 loop order of i and j */
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
146
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
147 for (j=0; j<8; j++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
148 for (i=0; i<8; i++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
149 {
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
150 partial_product = 0.0;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
151
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
152 for (k=0; k<8; k++)
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
153 partial_product+= c[k][i]*tmp[8*k+j];
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
154
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
155 v = (int) floor(partial_product+0.5);
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
156 block[8*i+j] = v;
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
157 }
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
158 }