⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sadwt.c

📁 spiht的压缩解压缩c编写的
💻 C
字号:
#include "spiht.h"
#include "spihtdecode.h"

static int QccWAVWaveletShapeAdaptiveSynthesis1D(const QccVector input_data,
                                                 QccVector output_data,
                                                 QccVector subsequence,
                                                 const QccVector input_mask,
                                                 QccVector output_mask,
                                                 int signal_length,
                                                 const QccWAVWavelet *wavelet)
{
  int return_value = 0;
  int index1, index2;
  int subsequence_position;
  int subsequence_length;
  int lowband_position;
  int lowband_length;
  int highband_position;
  int highband_length;
  int midpoint;
  int phase;
  
  /* Inverse LWT mask */
  if (QccWAVWaveletInverseLWT(input_mask, output_mask,
                              signal_length, 0, 0))
    {
      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1D): Error calling QccWAVWaveletInverseLWT()");
      goto Error;
    }
  
  QccVectorZero(output_data, signal_length);
  QccVectorZero(subsequence, signal_length);
  
  /* Midpoint separates lowpass and highpass subbands in output */
  midpoint = 
    QccWAVWaveletDWTSubbandLength(signal_length, 1, 0, 0, 0);
  
  for (index1 = 0; index1 < signal_length; index1++)
    {
      /* Find start of subsequence of contiguous object */
      if (!QccAlphaTransparent(output_mask[index1]))
        {
          /* Find end of subsequence of contiguous object */
          for (index2 = index1; index2 < signal_length; index2++)
            if (QccAlphaTransparent(output_mask[index2]))
              break;
          
          subsequence_position = index1;
          subsequence_length = index2 - index1;
          
          phase =
            (subsequence_position % 2) ? QCCWAVWAVELET_PHASE_ODD :
            QCCWAVWAVELET_PHASE_EVEN;
          
          /* Find lowpass subband position */
          lowband_position =
            (phase == QCCWAVWAVELET_PHASE_ODD) ?
            ((subsequence_position + 1) >> 1) :
            (subsequence_position >> 1);
          lowband_length =
            QccWAVWaveletDWTSubbandLength(subsequence_length, 1, 0, 0,
                                          phase);
          
          /* Find highpass subband position */
          highband_position = midpoint +
            ((phase == QCCWAVWAVELET_PHASE_ODD) ?
             (subsequence_position >> 1) :
             (subsequence_position + 1) >> 1);
          highband_length =
            QccWAVWaveletDWTSubbandLength(subsequence_length, 1, 1, 0,
                                          phase);
          
          /* Extract subbands */
          QccVectorCopy(subsequence,
                        &input_data[lowband_position],
                        lowband_length);
          QccVectorCopy(&subsequence[lowband_length],
                        &input_data[highband_position],
                        highband_length);
          
          /* Inverse transform */
          if (QccWAVWaveletSynthesis1D(subsequence,
                                       &output_data[subsequence_position],
                                       subsequence_length,
                                       phase,
                                       wavelet))
            {
              QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1D): Error calling QccWAVWaveletSynthesis1D()");
              goto Error;
            }
          
          index1 = index2;
        }
    }
  
  return_value = 0;
  goto Return;
 Error:
  return_value = 1;
 Return:
  return(return_value);
}

int QccWAVWaveletInverseShapeAdaptiveDWT2D(const QccMatrix input_data, 
                                           const QccMatrix input_mask, 
                                           QccMatrix output_data, 
                                           QccMatrix output_mask,
                                           int num_rows,
                                           int num_cols,
                                           int num_scales,
                                           const QccWAVWavelet *wavelet)
{
  int return_value;
  QccVector input_data_vector = NULL;
  QccVector output_data_vector = NULL;
  QccVector subsequence = NULL;
  QccVector input_mask_vector = NULL;
  QccVector output_mask_vector = NULL;
  int scale;
  int row, col;
  int baseband_num_rows;
  int baseband_num_cols;
  
  /* Allocate temporary working arrays */
  if ((input_data_vector =
       QccVectorAlloc(QccMathMax(num_rows, num_cols))) == NULL)
    {
      QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccVectorAlloc()");
      goto Error;
    }
  if ((output_data_vector =
       QccVectorAlloc(QccMathMax(num_rows, num_cols))) == NULL)
    {
      QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccVectorAlloc()");
      goto Error;
    }
  if ((subsequence =
       QccVectorAlloc(QccMathMax(num_rows, num_cols))) == NULL)
    {
      QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccVectorAlloc()");
      goto Error;
    }
  if ((input_mask_vector =
       QccVectorAlloc(QccMathMax(num_rows, num_cols))) == NULL)
    {
      QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccVectorAlloc()");
      goto Error;
    }
  if ((output_mask_vector =
       QccVectorAlloc(QccMathMax(num_rows, num_cols))) == NULL)
    
    {
      QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccVectorAlloc()");
      goto Error;
    }
  
  for (row = 0; row < num_rows; row++)
    for (col = 0; col < num_cols; col++)
      {
        output_data[row][col] = input_data[row][col];
        output_mask[row][col] = input_mask[row][col];
      }
  
  for (scale = num_scales - 1; scale >= 0; scale--)
    {
      baseband_num_rows =
        QccWAVWaveletDWTSubbandLength(num_rows, scale, 0, 0, 0);
      baseband_num_cols =
        QccWAVWaveletDWTSubbandLength(num_cols, scale, 0, 0, 0);
      
      for (col = 0; col < baseband_num_cols; col++)
        {
          for (row = 0; row < baseband_num_rows; row++)
            {
              input_data_vector[row] = output_data[row][col];
              input_mask_vector[row] = output_mask[row][col];
            }
          
          if (QccWAVWaveletShapeAdaptiveSynthesis1D(input_data_vector,
                                                    output_data_vector,
                                                    subsequence,
                                                    input_mask_vector,
                                                    output_mask_vector,
                                                    baseband_num_rows,
                                                    wavelet))
            {
              QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccWAVWaveletShapeAdaptiveSynthesis1D()");
              goto Error;
            }
          
          for (row = 0; row < baseband_num_rows; row++)
            {
              output_data[row][col] = output_data_vector[row];
              output_mask[row][col] = output_mask_vector[row];
            }
        }
      
      for (row = 0; row < baseband_num_rows; row++)
        {
          for (col = 0; col < baseband_num_cols; col++)
            {
              input_data_vector[col] = output_data[row][col];
              input_mask_vector[col] = output_mask[row][col];
            }
          
          if (QccWAVWaveletShapeAdaptiveSynthesis1D(input_data_vector,
                                                    output_data_vector,
                                                    subsequence,
                                                    input_mask_vector,
                                                    output_mask_vector,
                                                    baseband_num_cols,
                                                    wavelet))
            {
              QccErrorAddMessage("(QccWAVWaveletInverseShapeAdaptiveDWT2D): Error calling QccWAVWaveletShapeAdaptiveSynthesis1D()");
              goto Error;
            }
          
          for (col = 0; col < baseband_num_cols; col++)
            {
              output_data[row][col] = output_data_vector[col];
              output_mask[row][col] = output_mask_vector[col];
            }
        }
    }
  
  return_value = 0;
  goto Return;
 Error:
  return_value = 1;
 Return:
  QccVectorFree(input_data_vector);
  QccVectorFree(output_data_vector);
  QccVectorFree(subsequence);
  QccVectorFree(input_mask_vector);
  QccVectorFree(output_mask_vector);
  return(return_value);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -