?? sadwt.c
字號:
/* * * QccPack: Quantization, compression, and coding libraries * Copyright (C) 1997-2005 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_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; /* LWT transform mask */ if (QccWAVWaveletLWT(input_mask, output_mask, signal_length, 0, 0)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1D): Error calling QccWAVWaveletLWT()"); 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(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; /* Do transform of current subsequence */ if (QccWAVWaveletAnalysis1D(&input_data[subsequence_position], 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_data[lowband_position], subsequence, lowband_length); QccVectorCopy(&output_data[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_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 QccWAVWaveletShapeAdaptiveDWT1D(const QccVector input_signal, const QccVector input_mask, QccVector output_signal, QccVector output_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 (input_signal == NULL) return(0); if (input_mask == NULL) return(0); if (output_signal == NULL) return(0); if (output_mask == NULL) return(0); if (wavelet == NULL) return(0); if (num_scales < 0) return(0); if (num_scales == 0 ) { QccVectorCopy(output_signal, input_signal, signal_length); QccVectorCopy(output_mask, input_mask, signal_length); return(0); } if ((temp_signal = QccVectorAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()"); goto QccError; } if ((temp_mask = QccVectorAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()"); goto QccError; } if ((subsequence = QccVectorAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorAlloc()"); goto QccError; } if (QccVectorCopy(temp_signal, input_signal, signal_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()"); goto QccError; } if (QccVectorCopy(temp_mask, input_signal, signal_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()"); goto QccError; } current_length = signal_length; for (scale = 0; scale < num_scales; scale++) { if (QccWAVWaveletShapeAdaptiveAnalysis1D(temp_signal, output_signal, subsequence, temp_mask, output_mask, current_length, wavelet)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccWAVWaveletShapeAdaptiveAnalysis1D()"); goto QccError; } current_length = QccWAVWaveletDWTSubbandLength(signal_length, scale + 1, 0, 0, 0); if (QccVectorCopy(temp_signal, output_signal, current_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()"); goto QccError; } if (QccVectorCopy(temp_mask, output_mask, current_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1D): Error calling QccVectorCopy()"); goto QccError; } } return_value = 0; goto QccReturn; QccError: return_value = 1; QccReturn: QccVectorFree(temp_signal); QccVectorFree(temp_mask); QccVectorFree(subsequence); return(return_value);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -