annotate fdctref.c @ 2243:b8bad8bbbc64 libavcodec

check if the user specified timestamps are strictly monotone timestamp guess code 10l fix
author michael
date Mon, 20 Sep 2004 13:47:47 +0000
parents 1e39f273ecd6
children ef2149182f1c
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 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 register int i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 double s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 double tmp[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
70
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 for(i = 0; i < 8; i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 for(j = 0; j < 8; j++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 s = 0.0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
75
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 * for(k = 0; k < 8; k++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 * s += c[j][k] * block[8 * i + k];
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 s += c[j][0] * block[8 * i + 0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 s += c[j][1] * block[8 * i + 1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 s += c[j][2] * block[8 * i + 2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 s += c[j][3] * block[8 * i + 3];
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 s += c[j][4] * block[8 * i + 4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 s += c[j][5] * block[8 * i + 5];
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 s += c[j][6] * block[8 * i + 6];
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 s += c[j][7] * block[8 * i + 7];
986e461dc072 Initial revision
glantau
parents:
diff changeset
88
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 tmp[8 * i + j] = s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
91
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 for(j = 0; j < 8; j++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 for(i = 0; i < 8; i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 s = 0.0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
96
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 * for(k = 0; k < 8; k++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 * s += c[i][k] * tmp[8 * k + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 s += c[i][0] * tmp[8 * 0 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 s += c[i][1] * tmp[8 * 1 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 s += c[i][2] * tmp[8 * 2 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 s += c[i][3] * tmp[8 * 3 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 s += c[i][4] * tmp[8 * 4 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 s += c[i][5] * tmp[8 * 5 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 s += c[i][6] * tmp[8 * 6 + j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 s += c[i][7] * tmp[8 * 7 + j];
635
3e0f62e5eed6 dct cleanup
michaelni
parents: 35
diff changeset
109 s*=8.0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
110
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 block[8 * i + j] = (short)floor(s + 0.499999);
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
c77207dc78f4 added idct reference code
glantau
parents: 11
diff changeset
144 /* Transpose operation is integrated into address mapping by switching
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 }