Main Page | Namespace List | Compound List | File List | Compound Members | File Members

idct1d.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "idct1d.h"
00012 
00013 /* Useful constants: */
00014 
00015 /* This version is IEEE compliant using 16-bit arithmetic. */
00016 
00017 /* The number of bits coefficients are scaled up before 2-D IDCT: */
00018 const unsigned int S_BITS = 3;
00019 
00020 /* The number of bits in the fractional part of a fixed point constant: */
00021 const unsigned int C_BITS = 14;
00022 
00023 inline
00024 VYApixel ADD(VYApixel x, VYApixel y)
00025 {
00026   return x + y;
00027 }
00028 
00029 inline
00030 VYApixel SUB(VYApixel x, VYApixel y)
00031 {
00032   return x - y;
00033 }
00034 
00035 inline
00036 VYApixel CMUL(VYApixel C, VYApixel x)
00037 {
00038   return (C * x + (1 << (C_BITS-1))) >> C_BITS;
00039 }
00040 
00041 /* Butterfly: but(a,b,x,y) = rot(sqrt(2),4,a,b,x,y) */
00042 
00043 inline 
00044 void but(VYApixel a, VYApixel b, VYApixel& x, VYApixel& y)
00045 {
00046   x = SUB(a, b);
00047   y = ADD(a, b);
00048 }
00049 
00050 IDCT1D::IDCT1D(
00051   const Id& n, 
00052   In<VYApixel>&   cin, 
00053   Out<VYApixel>&  cout)
00054 :
00055       Process(n),
00056       CIn(  id("CIn"),  cin),
00057       COut( id("Cout"), cout)
00058 {
00059 }
00060 
00061 /* Inverse 1-D Discrete Cosine Transform.
00062    Result Y is scaled up by factor sqrt(8).
00063    Original Loeffler algorithm.
00064 */
00065 void IDCT1D::main()
00066 {
00067       VYApixel Y[8];
00068       VYApixel z1[8], z2[8], z3[8];
00069 
00070       while (true)
00071       {
00072     read(CIn, Y, 8);
00073 
00074           // Stage 1:
00075           but(Y[0], Y[4], z1[1], z1[0]);
00076           // rot(sqrt(2), 6, Y[2], Y[6], &z1[2], &z1[3]);
00077           z1[2] = SUB(CMUL( 8867, Y[2]), CMUL(21407, Y[6]));
00078           z1[3] = ADD(CMUL(21407, Y[2]), CMUL( 8867, Y[6]));
00079           but(Y[1], Y[7], z1[4], z1[7]);
00080           // z1[5] = CMUL(sqrt(2), Y[3]);
00081           // z1[6] = CMUL(sqrt(2), Y[5]);
00082           z1[5] = CMUL(23170, Y[3]);
00083           z1[6] = CMUL(23170, Y[5]);
00084 
00085           // Stage 2:
00086           but(z1[0], z1[3], z2[3], z2[0]);
00087           but(z1[1], z1[2], z2[2], z2[1]);
00088           but(z1[4], z1[6], z2[6], z2[4]);
00089           but(z1[7], z1[5], z2[5], z2[7]);
00090 
00091           // Stage 3:
00092           z3[0] = z2[0];
00093           z3[1] = z2[1];
00094           z3[2] = z2[2];
00095           z3[3] = z2[3];
00096           // rot(1, 3, z2[4], z2[7], &z3[4], &z3[7]);
00097           z3[4] = SUB(CMUL(13623, z2[4]), CMUL( 9102, z2[7]));
00098           z3[7] = ADD(CMUL( 9102, z2[4]), CMUL(13623, z2[7]));
00099           // rot(1, 1, z2[5], z2[6], &z3[5], &z3[6]); 
00100           z3[5] = SUB(CMUL(16069, z2[5]), CMUL( 3196, z2[6]));
00101           z3[6] = ADD(CMUL( 3196, z2[5]), CMUL(16069, z2[6]));
00102 
00103           // Stage 4:
00104           but(z3[0], z3[7], Y[7], Y[0]);
00105           but(z3[1], z3[6], Y[6], Y[1]);
00106           but(z3[2], z3[5], Y[5], Y[2]);
00107           but(z3[3], z3[4], Y[4], Y[3]);
00108 
00109           write(COut, Y, 8);
00110       }
00111 }

Generated on Wed Feb 15 14:52:45 2006 for jpegdec by doxygen 1.3.2