Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

line_int.h

Go to the documentation of this file.
00001 
00002 #ifndef _LINE_INT_H_
00003 #define _LINE_INT_H_
00004 
00005 
00006 
00039 
00040 #include "stdio.h"
00041 #include "liftbase.h"
00042 
00043 
00059 template<class T>
00060 class line_int : public liftbase<T, int>
00061 {
00062 public:
00064   line_int() {}
00066   ~line_int() {}
00068   line_int( const line_int &rhs );
00069 private:
00074    int new_n_plus1( int y1, int y2)
00075    {
00076      int y = 2 * y2 - y1;
00077      return y;
00078    }
00079 
00080   
00085   int new_n_minus1( int y1, int y2)
00086   {
00087     int y = 2 * y1 - y2;
00088     return y;
00089   }
00090 
00091 protected:
00092 
00132   void predict( T & vec, int N, transDirection direction )
00133   {
00134     int half = N >> 1;
00135     int predictVal;
00136 
00137     for (int i = 0; i < half; i++) {
00138       int j = i + half;
00139       if (i < half-1) {
00140         predictVal = (int)((((float)vec[i] + (float)vec[i+1])/2.0) + 0.5);
00141       }
00142       else if (N == 2) {
00143         predictVal = vec[0];
00144       }
00145       else {
00146         // i == half-1
00147         // Calculate the last "odd" prediction
00148         int n_plus1 = new_n_plus1( vec[i-1], vec[i] );
00149         predictVal = (int)((((float)vec[i] + (float)n_plus1)/2.0) + 0.5);
00150       }
00151 
00152       if (direction == forward) {
00153         vec[j] = vec[j] - predictVal;
00154       }
00155       else if (direction == inverse) {
00156         vec[j] = vec[j] + predictVal;
00157       }
00158       else {
00159         printf("line::predict: bad direction value\n");
00160       }
00161     }
00162   } // predict
00163 
00164 
00234   void update( T & vec, int N, transDirection direction )
00235   {
00236     int half = N >> 1;
00237 
00238     for (int i = 0; i < half; i++) {
00239       int j = i + half;
00240       int val;
00241 
00242       if (i == 0 && N == 2) {
00243         val = (int)(((float)vec[j]/2.0) + 0.5);
00244       }
00245       else if (i == 0 && N > 2) {
00246         int v_n_minus_1 = new_n_minus1( vec[j], vec[j+1] );
00247         val = (int)((((float)v_n_minus_1 + (float)vec[j])/4.0) + 0.5);
00248       }
00249       else {
00250         val = (int)((((float)vec[j-1] + (float)vec[j])/4.0) + 0.5);
00251       }
00252       if (direction == forward) {
00253         vec[i] = vec[i] + val;
00254       }
00255       else if (direction == inverse) {
00256         vec[i] = vec[i] - val;
00257       }
00258       else {
00259         printf("update: bad direction value\n");
00260       }
00261     } // for    
00262   } // update
00263 
00264 
00265 }; // line_int
00266 
00267 
00268 #endif

Generated at Sat Aug 10 13:23:34 2002 for Wavelet Packet Transform and Lossless Compression by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001