📄 subband_pyramid.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"int QccWAVSubbandPyramidInitialize(QccWAVSubbandPyramid *subband_pyramid){ if (subband_pyramid == NULL) return(0); QccStringMakeNull(subband_pyramid->filename); QccStringCopy(subband_pyramid->magic_num, QCCWAVSUBBANDPYRAMID_MAGICNUM); QccGetQccPackVersion(&subband_pyramid->major_version, &subband_pyramid->minor_version, NULL); subband_pyramid->num_levels = 0; subband_pyramid->num_rows = 0; subband_pyramid->num_cols = 0; subband_pyramid->origin_row = 0; subband_pyramid->origin_col = 0; subband_pyramid->subsample_pattern_row = 0; subband_pyramid->subsample_pattern_col = 0; subband_pyramid->matrix = NULL; return(0);}int QccWAVSubbandPyramidAlloc(QccWAVSubbandPyramid *subband_pyramid){ int return_value; if (subband_pyramid == NULL) return(0); if (subband_pyramid->matrix != NULL) return(0); if ((subband_pyramid->matrix = QccMatrixAlloc(subband_pyramid->num_rows, subband_pyramid->num_cols)) == NULL) { QccErrorAddMessage("(QccWAVSubbandPyramidAlloc): Error calling QccMatrixAlloc()"); goto Error; } return_value = 0; goto Return; Error: QccWAVSubbandPyramidFree(subband_pyramid); return_value = 1; Return: return(return_value);}void QccWAVSubbandPyramidFree(QccWAVSubbandPyramid *subband_pyramid){ if (subband_pyramid == NULL) return; QccMatrixFree(subband_pyramid->matrix, subband_pyramid->num_rows); subband_pyramid->matrix = NULL;}int QccWAVSubbandPyramidNumLevelsToNumSubbands(int num_levels){ return(num_levels*3 + 1);}int QccWAVSubbandPyramidNumSubbandsToNumLevels(int num_subbands){ if (num_subbands <= 0) return(0); if ((num_subbands - 1) % 3) return(0); return((num_subbands - 1) / 3);}int QccWAVSubbandPyramidCalcLevelFromSubband(int subband, int num_levels){ if (!num_levels) return(0); if (!subband) return(num_levels); return(num_levels - (subband - 1)/3);}#if 0static int QccWAVSubbandPyramidPattern(const QccWAVSubbandPyramid *subband_pyramid, int *subsample_pattern_row, int *subsample_pattern_col){ int subsample_pattern_row1 = 0; int subsample_pattern_col1 = 0; int scale; int mask = 1; int mask_row = 1; int mask_col = 1; for (scale = 0; scale < subband_pyramid->num_levels; scale++) { if (subband_pyramid->subsample_pattern & mask) subsample_pattern_row1 |= mask_row; mask <<= 1; if (subband_pyramid->subsample_pattern & mask) subsample_pattern_col1 |= mask_col; mask <<= 1; mask_row <<= 1; mask_col <<= 1; } if (subsample_pattern_row != NULL) *subsample_pattern_row = subsample_pattern_row1; if (subsample_pattern_col != NULL) *subsample_pattern_col = subsample_pattern_col1; return(0);}#endifint QccWAVSubbandPyramidSubbandSize(const QccWAVSubbandPyramid *subband_pyramid, int subband, int *subband_num_rows, int *subband_num_cols){ int num_rows = 0; int num_cols = 0; int level; level = QccWAVSubbandPyramidCalcLevelFromSubband(subband, subband_pyramid->num_levels); if (!subband) { num_rows = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_rows, level, 0, subband_pyramid->origin_row, subband_pyramid->subsample_pattern_row); num_cols = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_cols, level, 0, subband_pyramid->origin_col, subband_pyramid->subsample_pattern_col); } else switch ((subband - 1) % 3) { case 0: num_rows = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_rows, level, 1, subband_pyramid->origin_row, subband_pyramid->subsample_pattern_row); num_cols = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_cols, level, 0, subband_pyramid->origin_col, subband_pyramid->subsample_pattern_col); break; case 1: num_rows = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_rows, level, 0, subband_pyramid->origin_row, subband_pyramid->subsample_pattern_row); num_cols = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_cols, level, 1, subband_pyramid->origin_col, subband_pyramid->subsample_pattern_col); break; case 2: num_rows = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_rows, level, 1, subband_pyramid->origin_row, subband_pyramid->subsample_pattern_row); num_cols = QccWAVWaveletDWTSubbandLength(subband_pyramid->num_cols, level, 1, subband_pyramid->origin_col, subband_pyramid->subsample_pattern_col); break; } if (!num_rows || !num_cols) num_rows = num_cols = 0; if (subband_num_rows != NULL) *subband_num_rows = num_rows; if (subband_num_cols != NULL) *subband_num_cols = num_cols; return(0);}int QccWAVSubbandPyramidSubbandOffsets(const QccWAVSubbandPyramid *subband_pyramid, int subband, int *row_offset, int *col_offset){ int subband_num_rows; int subband_num_cols; QccWAVSubbandPyramid temp; if (subband < 0) return(0); QccWAVSubbandPyramidInitialize(&temp); temp.num_levels = QccWAVSubbandPyramidCalcLevelFromSubband(subband, subband_pyramid->num_levels); temp.num_rows = subband_pyramid->num_rows; temp.num_cols = subband_pyramid->num_cols; temp.origin_row = subband_pyramid->origin_row; temp.origin_col = subband_pyramid->origin_col; temp.subsample_pattern_row = subband_pyramid->subsample_pattern_row; temp.subsample_pattern_col = subband_pyramid->subsample_pattern_col; if (QccWAVSubbandPyramidSubbandSize(&temp, 0, &subband_num_rows, &subband_num_cols)) { QccErrorAddMessage("(QccWAVSubbandPyramidSubbandOffsets): Error calling QccWAVSubbandPyramidSubbandSize()"); return(1); } if (!subband) { *row_offset = 0; *col_offset = 0; } else switch ((subband - 1) % 3) { case 0: *row_offset = subband_num_rows; *col_offset = 0; break; case 1: *row_offset = 0; *col_offset = subband_num_cols; break; case 2: *row_offset = subband_num_rows; *col_offset = subband_num_cols; break; } return(0);}void QccWAVSubbandPyramidSubbandToQccString(int subband, int num_levels, QccString qccstring){ int level; level = QccWAVSubbandPyramidCalcLevelFromSubband(subband, num_levels); if (!subband) QccStringSprintf(qccstring, "B%d", level); else switch ((subband - 1) % 3) { case 0: QccStringSprintf(qccstring, "H%d", level); break; case 1: QccStringSprintf(qccstring, "V%d", level); break; case 2: QccStringSprintf(qccstring, "D%d", level); break; }}int QccWAVSubbandPyramidPrint(const QccWAVSubbandPyramid *subband_pyramid){ int row, col; if (QccFilePrintFileInfo(subband_pyramid->filename, subband_pyramid->magic_num, subband_pyramid->major_version, subband_pyramid->minor_version)) return(1); printf("Levels of decomposition: %d\n", subband_pyramid->num_levels); printf("size: %dx%d\n", subband_pyramid->num_cols, subband_pyramid->num_rows); printf("Origin: (%d, %d)\n", subband_pyramid->origin_row, subband_pyramid->origin_col); printf("\nMatrix:\n\n"); for (row = 0; row < subband_pyramid->num_rows; row++) { for (col = 0; col < subband_pyramid->num_cols; col++) { printf("% 10.4f ", subband_pyramid->matrix[row][col]); } printf("\n"); } return(0);}static int QccWAVSubbandPyramidReadHeader(FILE *infile,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -