annotate fdctref.c @ 528:7f05b0eff4b9 libavcodec

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