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

📄 sadwt.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  * QccPack: Quantization, compression, and coding libraries * Copyright (C) 1997-2009  James E. Fowler *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. *  * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. *  */#include "libQccPack.h"static int QccWAVWaveletShapeAdaptiveAnalysis1D(const QccVector input_signal,                                                QccVector output_signal,                                                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;    /*  LWT transform mask */  if (QccWAVWaveletLWT(input_mask, output_mask,                       signal_length, 0, 0))    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1D): Error calling QccWAVWaveletLWT()");      goto Error;    }    QccVectorZero(output_signal, 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(input_mask[index1]))        {          /* Find end of subsequence of contiguous object */          for (index2 = index1; index2 < signal_length; index2++)            if (QccAlphaTransparent(input_mask[index2]))              break;                    subsequence_position = index1;          subsequence_length = index2 - index1;          phase =            (subsequence_position % 2) ? QCCWAVWAVELET_PHASE_ODD :            QCCWAVWAVELET_PHASE_EVEN;                    if (QccVectorCopy(subsequence,                            &input_signal[subsequence_position],                            subsequence_length))            {              QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1D): Error calling QccVectorCopy()");              goto Error;            }          /* Do transform of current subsequence */          if (QccWAVWaveletAnalysis1D(subsequence,                                      subsequence_length,                                      phase,                                      wavelet))            {              QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1D): Error calling QccWAVWaveletAnalysis1D()");              goto Error;            }                    /* 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);                    /* Place subbands into output array */          QccVectorCopy(&output_signal[lowband_position],                        subsequence,                        lowband_length);          QccVectorCopy(&output_signal[highband_position],                        &subsequence[lowband_length],                        highband_length);                    index1 = index2;        }    }    return_value = 0;  goto Return; Error:  return_value = 1; Return:  return(return_value);}static int QccWAVWaveletShapeAdaptiveSynthesis1D(const QccVector input_signal,                                                 QccVector output_signal,                                                 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_signal, 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_signal[lowband_position],                        lowband_length);          QccVectorCopy(&subsequence[lowband_length],                        &input_signal[highband_position],                        highband_length);                    /* Inverse transform */          if (QccWAVWaveletSynthesis1D(subsequence,                                       subsequence_length,                                       phase,                                       wavelet))            {              QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1D): Error calling QccWAVWaveletSynthesis1D()");              goto Error;            }                    if (QccVectorCopy(&output_signal[subsequence_position],                            subsequence,                            subsequence_length))            {              QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1D): Error calling QccVectorCopy()");              goto Error;            }          index1 = index2;        }    }    return_value = 0;  goto Return; Error:  return_value = 1; Return:  return(return_value);}int QccWAVWaveletShapeAdaptiveDWT1D(QccVector signal,                                    QccVector mask,                                    int signal_length,                                    int num_scales,                                    const QccWAVWavelet *wavelet){    int return_value;  int scale;  QccVector temp_signal = NULL;  QccVector temp_mask = NULL;  QccVector subsequence = NULL;  int current_length;    if (signal == NULL)    return(0);  if (mask == NULL)    return(0);  if (wavelet == NULL)    return(0);    if (num_scales <= 0)    return(0);    if ((temp_signal = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()");      goto Error;    }  if ((temp_mask = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()");      goto Error;    }  if ((subsequence = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()");      goto Error;    }    if (QccVectorCopy(temp_signal, signal, signal_length))    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()");      goto Error;    }  if (QccVectorCopy(temp_mask, mask, signal_length))    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()");      goto Error;    }    current_length = signal_length;    for (scale = 0; scale < num_scales; scale++)    {      if (QccWAVWaveletShapeAdaptiveAnalysis1D(temp_signal,                                               signal,                                               subsequence,                                               temp_mask,                                               mask,                                               current_length,                                               wavelet))        {          QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccWAVWaveletShapeAdaptiveAnalysis1D()");          goto Error;        }            current_length =        QccWAVWaveletDWTSubbandLength(signal_length, scale + 1, 0, 0, 0);            if (QccVectorCopy(temp_signal, signal, current_length))        {          QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()");          goto Error;        }      if (QccVectorCopy(temp_mask, mask, current_length))        {          QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()");          goto Error;        }    }    return_value = 0;  goto Return; Error:  return_value = 1; Return:  QccVectorFree(temp_signal);  QccVectorFree(temp_mask);  QccVectorFree(subsequence);  return(return_value);}int QccWAVWaveletInverseShapeAdaptiveDWT1D(QccVector signal,                                           QccVector mask,                                           int signal_length,                                           int num_scales,                                           const QccWAVWavelet *wavelet){  int return_value;  int scale;  QccVector temp_signal = NULL;  QccVector temp_mask = NULL;  QccVector subsequence = NULL;  int current_length;    if (signal == NULL)    return(0);  if (mask == NULL)    return(0);  if (wavelet == NULL)    return(0);    if (num_scales <= 0)    return(0);    if ((temp_signal = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorAlloc()");      goto Error;    }  if ((temp_mask = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorAlloc()");      goto Error;    }  if ((subsequence = QccVectorAlloc(signal_length)) == NULL)    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorAlloc()");      goto Error;    }    if (QccVectorCopy(temp_signal, signal, signal_length))    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorCopy()");      goto Error;    }  if (QccVectorCopy(temp_mask, mask, signal_length))    {      QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorCopy()");      goto Error;    }    for (scale = num_scales - 1; scale >= 0 ; scale--)    {      current_length =         QccWAVWaveletDWTSubbandLength(signal_length, scale, 0, 0, 0);            if (QccWAVWaveletShapeAdaptiveSynthesis1D(temp_signal,                                                signal,                                                subsequence,                                                temp_mask,                                                mask,                                                current_length,                                                wavelet))        {          QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccWAVWaveletShapeAdaptiveSynthesis1D()");          goto Error;        }            if (QccVectorCopy(temp_signal, signal, current_length))        {          QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveInverseDWT1D): Error calling QccVectorCopy()");          goto Error;        }      if (QccVectorCopy(temp_mask, mask, current_length))        {

⌨️ 快捷键说明

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