/*
 * Implementation of class StandardTransform
 *
 * $Date$
 * $Revision$
 *
 */

#include "Wave/StandardTransform.hh"
#include "WImage/ColumnVector.hh"
#include "WImage/RowVector.hh"
#include "WImage/debug.h"

#if !(defined __WATCOMC__ && __WATCOMC__ < 1230)
using namespace std;
#endif

void
StandardTransform::doanalysis (int steps)
{
  int row;
  int col;

  RowVector &rv1 = m_image->row (0);
  RowVector &rv2 = m_buffer->row (0);
  ColumnVector &cv1 = m_image->col (0);
  ColumnVector &cv2 = m_buffer->col (0);
  
  int level = m_wavelet->level (rv1, rv2, steps);

  if (steps <= 0 || steps >= level)
    {
      /* Can't fully decompose an m_image if a symmetric filter is used! */
      steps = m_filter->issym ()? level - 1: level;
    }

  m_image->anasteps (steps);

  /*
   * First decompose rows, then cols...
   */
  for (row = 0; row < cv1.size (); row++)
    {
      rv1.go (row);
      rv2.go (row);
      m_wavelet->analysis (rv2, rv1, steps);
    }
  for (col = 0; col < rv1.size (); col++)
    {
      cv1.go (col);
      cv2.go (col);
      m_wavelet->analysis (cv1, cv2, steps);
    }
}

void
StandardTransform::dosynthesis (int steps, int prevSteps)
{
  int row;
  int col;
  
  RowVector &rv1 = m_image->row (0);
  RowVector &rv2 = m_buffer->row (0);
  ColumnVector &cv1 = m_image->col (0);
  ColumnVector &cv2 = m_buffer->col (0);
  
  int level = m_wavelet->level (rv1, rv2, steps);

  if (steps <= 0 || steps > level)
    {
      steps = level;
    }

  m_image->synsteps (steps);

  /*
  m_image->synsteps (steps);
   */
  for (col = 0; col < rv1.size (); col++)
    {
      cv1.go (col);
      cv2.go (col);
      m_wavelet->synthesis (cv2, cv1, steps, prevSteps);
    }
  for (row = 0; row < cv1.size (); row++)
    {
      rv1.go (row);
      rv2.go (row);
      m_wavelet->synthesis (rv1, rv2, steps, prevSteps);
    }
}
