1 /************************************************************************
2 *
3 * idctref.c, inverse DCT, double precision, for tmndecode (H.263 decoder)
4 * Copyright (C) 1995, 1996 Telenor R&D, Norway
5 *
6 * Contacts:
7 * Robert Danielsen <Robert.Danielsen@nta.no>
8 *
9 * Telenor Research and Development http://www.nta.no/brukere/DVC/
10 * P.O.Box 83 tel.: +47 63 84 84 00
11 * N-2007 Kjeller, Norway fax.: +47 63 81 00 76
12 *
13 * Copyright (C) 1997 University of BC, Canada
14 * Modified by: Michael Gallant <mikeg@ee.ubc.ca>
15 * Guy Cote <guyc@ee.ubc.ca>
16 * Berna Erol <bernae@ee.ubc.ca>
17 *
18 * Contacts:
19 * Michael Gallant <mikeg@ee.ubc.ca>
20 *
21 * UBC Image Processing Laboratory http://www.ee.ubc.ca/image
22 * 2356 Main Mall tel.: +1 604 822 4051
23 * Vancouver BC Canada V6T1Z4 fax.: +1 604 822 5949
24 *
25 ************************************************************************/
26
27 /* Disclaimer of Warranty
28 *
29 * These software programs are available to the user without any license fee
30 * or royalty on an "as is" basis. The University of British Columbia
31 * disclaims any and all warranties, whether express, implied, or
32 * statuary, including any implied warranties or merchantability or of
33 * fitness for a particular purpose. In no event shall the
34 * copyright-holder be liable for any incidental, punitive, or
35 * consequential damages of any kind whatsoever arising from the use of
36 * these programs.
37 *
38 * This disclaimer of warranty extends to the user of these programs and
39 * user's customers, employees, agents, transferees, successors, and
40 * assigns.
41 *
42 * The University of British Columbia does not represent or warrant that the
43 * programs furnished hereunder are free of infringement of any
44 * third-party patents.
45 *
46 * Commercial implementations of H.263, including shareware, are subject to
47 * royalty fees to patent holders. Many of these patents are general
48 * enough such that they are unavoidable regardless of implementation
49 * design.
50 *
51 */
52
53
54
55 /* based on mpeg2decode, (C) 1994, MPEG Software Simulation Group and
56 * mpeg2play, (C) 1994 Stefan Eckart <stefan@lis.e-technik.tu-muenchen.de>
57 *
58 */
59
60
61 /* Perform IEEE 1180 reference (64-bit floating point, separable 8x1
62 * direct matrix multiply) Inverse Discrete Cosine Transform */
63
64
65 /* Here we use math.h to generate constants. Compiler results may vary a
66 * little */
67
68 #include <math.h>
69
70 #include "config.h"
71
72 #ifndef PI
73 # ifdef M_PI
74 # define PI M_PI
75 # else
76 # define PI 3.14159265358979323846
77 # endif
78 #endif
79
80 /* global declarations */
81 void init_idctref _ANSI_ARGS_ ((void));
82 void idctref _ANSI_ARGS_ ((short *block));
83
84 /* private data */
85
86 /* cosine transform matrix for 8x1 IDCT */
87 static double c[8][8];
88
89 /* initialize DCT coefficient matrix */
90
91 void init_idctref ()
92 {
93 int freq, time;
94 double scale;
95
96 for (freq = 0; freq < 8; freq++)
97 {
98 scale = (freq == 0) ? sqrt (0.125) : 0.5;
99 for (time = 0; time < 8; time++)
100 c[freq][time] = scale * cos ((PI / 8.0) * freq * (time + 0.5));
101 }
102 }
103
104 /* perform IDCT matrix multiply for 8x8 coefficient block */
105
106 void idctref (short *block)
107 {
108 int i, j, k, v;
109 double partial_product;
110 double tmp[64];
111
112 for (i = 0; i < 8; i++)
113 for (j = 0; j < 8; j++)
114 {
115 partial_product = 0.0;
116
117 for (k = 0; k < 8; k++)
118 partial_product += c[k][j] * block[8 * i + k];
119
120 tmp[8 * i + j] = partial_product;
121 }
122
123 /* Transpose operation is integrated into address mapping by switching
124 * loop order of i and j */
125
126 for (j = 0; j < 8; j++)
127 for (i = 0; i < 8; i++)
128 {
129 partial_product = 0.0;
130
131 for (k = 0; k < 8; k++)
132 partial_product += c[k][i] * tmp[8 * k + j];
133
134 v = (int) floor (partial_product + 0.5);
135 block[8 * i + j] = (v < -256) ? -256 : ((v > 255) ? 255 : v);
136 }
137 }
138
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.