📄 sadwt_int.c
字号:
/* * * 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 QccWAVWaveletShapeAdaptiveAnalysis1DInt(const QccVectorInt input_signal, QccVectorInt output_signal, QccVectorInt subsequence, const QccVectorInt input_mask, QccVectorInt 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 (QccWAVWaveletLWTInt(input_mask, output_mask, signal_length, 0, 0)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1DInt): Error calling QccWAVWaveletLWTInt()"); goto Error; } QccVectorIntZero(output_signal, signal_length); QccVectorIntZero(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 (QccVectorIntCopy(subsequence, &input_signal[subsequence_position], subsequence_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1DInt): Error calling QccVectorIntCopy()"); goto Error; } /* Do transform of current subsequence */ if (QccWAVWaveletAnalysis1DInt(subsequence, subsequence_length, phase, wavelet)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveAnalysis1DInt): Error calling QccWAVWaveletAnalysis1DInt()"); 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 */ QccVectorIntCopy(&output_signal[lowband_position], subsequence, lowband_length); QccVectorIntCopy(&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 QccWAVWaveletShapeAdaptiveSynthesis1DInt(const QccVectorInt input_signal, QccVectorInt output_signal, QccVectorInt subsequence, const QccVectorInt input_mask, QccVectorInt 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 (QccWAVWaveletInverseLWTInt(input_mask, output_mask, signal_length, 0, 0)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1DInt): Error calling QccWAVWaveletInverseLWTInt()"); goto Error; } QccVectorIntZero(output_signal, signal_length); QccVectorIntZero(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 */ QccVectorIntCopy(subsequence, &input_signal[lowband_position], lowband_length); QccVectorIntCopy(&subsequence[lowband_length], &input_signal[highband_position], highband_length); /* Inverse transform */ if (QccWAVWaveletSynthesis1DInt(subsequence, subsequence_length, phase, wavelet)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1DInt): Error calling QccWAVWaveletSynthesis1DInt()"); goto Error; } if (QccVectorIntCopy(&output_signal[subsequence_position], subsequence, subsequence_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveSynthesis1DInt): Error calling QccVectorIntCopy()"); goto Error; } index1 = index2; } } return_value = 0; goto Return; Error: return_value = 1; Return: return(return_value);}int QccWAVWaveletShapeAdaptiveDWT1DInt(QccVectorInt signal, QccVectorInt mask, int signal_length, int num_scales, const QccWAVWavelet *wavelet){ int return_value; int scale; QccVectorInt temp_signal = NULL; QccVectorInt temp_mask = NULL; QccVectorInt 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 = QccVectorIntAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccVectorIntAlloc()"); goto Error; } if ((temp_mask = QccVectorIntAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccVectorIntAlloc()"); goto Error; } if ((subsequence = QccVectorIntAlloc(signal_length)) == NULL) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccVectorIntAlloc()"); goto Error; } if (QccVectorIntCopy(temp_signal, signal, signal_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccVectorIntCopy()"); goto Error; } if (QccVectorIntCopy(temp_mask, mask, signal_length)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccVectorIntCopy()"); goto Error; } current_length = signal_length; for (scale = 0; scale < num_scales; scale++) { if (QccWAVWaveletShapeAdaptiveAnalysis1DInt(temp_signal, signal, subsequence, temp_mask, mask, current_length, wavelet)) { QccErrorAddMessage("(QccWAVWaveletShapeAdaptiveDWT1DInt): Error calling QccWAVWaveletShapeAdaptiveAnalysis1DInt()"); goto Error; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -