Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* idctref.c, Inverse Discrete Fourier Transform, double precision          */
2
 
3
/* Copyright (C) 1994, 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
#ifndef __STDC__
41
#define _ANSI_ARGS_(x) ()
42
#else
43
#define _ANSI_ARGS_(x) x
44
#endif
45
 
46
#define RB "rb"
47
#define WB "wb"
48
 
49
#ifndef O_BINARY
50
#define O_BINARY 0
51
#endif
52
 
53
#ifndef PI
54
# ifdef M_PI
55
#  define PI M_PI
56
# else
57
#  define PI 3.14159265358979323846
58
# endif
59
#endif
60
 
61
/* global declarations */
62
void init_float_idct _ANSI_ARGS_((void));
63
void float_idct _ANSI_ARGS_((short *block));
64
 
65
/* private data */
66
 
67
/* cosine transform matrix for 8x1 IDCT */
68
static double c[8][8];
69
 
70
/* initialize DCT coefficient matrix */
71
 
72
void init_float_idct()
73
{
74
  int freq, time;
75
  double scale;
76
 
77
  for (freq=0; freq < 8; freq++)
78
  {
79
    scale = (freq == 0) ? sqrt(0.125) : 0.5;
80
    for (time=0; time<8; time++)
81
      c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));
82
  }
83
}
84
 
85
/* perform IDCT matrix multiply for 8x8 coefficient block */
86
 
87
void float_idct(block)
88
short *block;
89
{
90
  int i, j, k, v;
91
  double partial_product;
92
  double tmp[64];
93
 
94
  for (i=0; i<8; i++)
95
    for (j=0; j<8; j++)
96
    {
97
      partial_product = 0.0;
98
 
99
      for (k=0; k<8; k++)
100
        partial_product+= c[k][j]*block[8*i+k];
101
 
102
      tmp[8*i+j] = partial_product;
103
    }
104
 
105
  /* Transpose operation is integrated into address mapping by switching
106
     loop order of i and j */
107
 
108
  for (j=0; j<8; j++)
109
    for (i=0; i<8; i++)
110
    {
111
      partial_product = 0.0;
112
 
113
      for (k=0; k<8; k++)
114
        partial_product+= c[k][i]*tmp[8*k+j];
115
 
116
      v = floor(partial_product+0.5);
117
      block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
118
    }
119
}