Rev 1624 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1624 | giacomo | 1 | /* Reference_IDCT.c, Inverse Discrete Fourier Transform, double precision */ |
2 | |||
3 | /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ |
||
4 | |||
5 | /* |
||
6 | * Disclaimer of Warranty |
||
7 | * |
||
8 | * These software programs are available to the user without any license fee or |
||
9 | * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims |
||
10 | * any and all warranties, whether express, implied, or statuary, including any |
||
11 | * implied warranties or merchantability or of fitness for a particular |
||
12 | * purpose. In no event shall the copyright-holder be liable for any |
||
13 | * incidental, punitive, or consequential damages of any kind whatsoever |
||
14 | * arising from the use of these programs. |
||
15 | * |
||
16 | * This disclaimer of warranty extends to the user of these programs and user's |
||
17 | * customers, employees, agents, transferees, successors, and assigns. |
||
18 | * |
||
19 | * The MPEG Software Simulation Group does not represent or warrant that the |
||
20 | * programs furnished hereunder are free of infringement of any third-party |
||
21 | * patents. |
||
22 | * |
||
23 | * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, |
||
24 | * are subject to royalty fees to patent holders. Many of these patents are |
||
25 | * general enough such that they are unavoidable regardless of implementation |
||
26 | * design. |
||
27 | * |
||
28 | */ |
||
29 | |||
30 | /* Perform IEEE 1180 reference (64-bit floating point, separable 8x1 |
||
31 | * direct matrix multiply) Inverse Discrete Cosine Transform |
||
32 | */ |
||
33 | |||
34 | |||
35 | /* Here we use math.h to generate constants. Compiler results may |
||
36 | vary a little */ |
||
37 | |||
38 | #include <math.h> |
||
39 | |||
40 | #include "config.h" |
||
41 | |||
42 | #ifndef PI |
||
43 | # ifdef M_PI |
||
44 | # define PI M_PI |
||
45 | # else |
||
46 | # define PI 3.14159265358979323846 |
||
47 | # endif |
||
48 | #endif |
||
49 | |||
50 | /* global declarations */ |
||
51 | void Initialize_Fast_IDCTref _ANSI_ARGS_((void)); |
||
52 | void Reference_IDCT _ANSI_ARGS_((short *block)); |
||
53 | |||
54 | /* private data */ |
||
55 | |||
56 | /* cosine transform matrix for 8x1 IDCT */ |
||
57 | static double c[8][8]; |
||
58 | |||
59 | /* initialize DCT coefficient matrix */ |
||
60 | |||
61 | void Initialize_Reference_IDCT() |
||
62 | { |
||
63 | int freq, time; |
||
64 | double scale; |
||
65 | |||
66 | for (freq=0; freq < 8; freq++) |
||
67 | { |
||
68 | scale = (freq == 0) ? sqrt(0.125) : 0.5; |
||
69 | for (time=0; time<8; time++) |
||
70 | c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5)); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /* perform IDCT matrix multiply for 8x8 coefficient block */ |
||
75 | |||
76 | void Reference_IDCT(block) |
||
77 | short *block; |
||
78 | { |
||
79 | int i, j, k, v; |
||
80 | double partial_product; |
||
81 | double tmp[64]; |
||
82 | |||
83 | for (i=0; i<8; i++) |
||
84 | for (j=0; j<8; j++) |
||
85 | { |
||
86 | partial_product = 0.0; |
||
87 | |||
88 | for (k=0; k<8; k++) |
||
89 | partial_product+= c[k][j]*block[8*i+k]; |
||
90 | |||
91 | tmp[8*i+j] = partial_product; |
||
92 | } |
||
93 | |||
94 | /* Transpose operation is integrated into address mapping by switching |
||
95 | loop order of i and j */ |
||
96 | |||
97 | for (j=0; j<8; j++) |
||
98 | for (i=0; i<8; i++) |
||
99 | { |
||
100 | partial_product = 0.0; |
||
101 | |||
102 | for (k=0; k<8; k++) |
||
103 | partial_product+= c[k][i]*tmp[8*k+j]; |
||
104 | |||
105 | v = (int) floor(partial_product+0.5); |
||
106 | block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v); |
||
107 | } |
||
108 | } |