📄 tce3d_lossless.c
字号:
/* * * QccPack: Quantization, compression, and coding utilities * Copyright (C) 1997-2007 James E. Fowler * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *//* * * Written by * * Jing Zhang, at Mississippi State University, 2008 * */#include "libQccPack.h"#define QCCTCE3D_BOUNDARY_VALUE (1e-6)//definition used in context information#define QCCTCE3D_Z 0 //zero, AKA, insignificant#define QCCTCE3D_NZN_NEW 2 //non-zero-neighbor#define QCCTCE3D_S 3 //significant#define QCCTCE3D_S_NEW 4#define QCCTCE3D_NZN 5// more refinement can be made if direction of Tarp filter is considered// but the improvement is minor//ugly fix, use 1-D IIR filter to provide PMF estimate#define QCCWAVTCE3D_ALPHA_1D 0.995 #define QCCWAVTCE3D_ALPHA_1D_O 0.005// this should be 0.5, however, 0.3 seems to work a little better (minor)// reason unknown#define QCCWAVTCE3D_REFINE_HOLDER 0.3 // threshold for cross-scale prediction...#define QCCWAVTCE3D_PREDICT_THRESHOLD 0.05 //weight factor for cross-scale and current scale#define QCCWAVTCE3D_CURRENT_SCALE 0.6 #define QCCWAVTCE3D_PARENT_SCALE 0.4static int QccWAVtce3DEncodeBitPlaneInfo(QccBitBuffer *output_buffer, int num_subbands, int *max_coefficient_bits){ int subband; int num_zeros = 0; for (subband = 1; subband < num_subbands; subband++) { for (num_zeros = max_coefficient_bits[0] - max_coefficient_bits[subband]; num_zeros > 0; num_zeros--) if (QccBitBufferPutBit(output_buffer, 0)) return(1); if (QccBitBufferPutBit(output_buffer, 1)) return(1); } return(0);}static int QccWAVtce3DDecodeBitPlaneInfo(QccBitBuffer *input_buffer, int num_subbands, int *max_bits, int max_coefficient_bits){ int subband; int bit_value; max_bits[0] = max_coefficient_bits; for (subband = 1; subband < num_subbands; subband++) { max_bits[subband] = max_coefficient_bits; do { if (QccBitBufferGetBit(input_buffer,&bit_value)) return(1); max_bits[subband]--; } while (bit_value == 0); max_bits[subband]++; } return(0);}static int QccWAVTce3DUpdateModel(QccENTArithmeticModel *model, double prob){ double p[2]; p[0] = 1 - prob; p[1] = prob; if (QccENTArithmeticSetModelProbabilities(model, p, 0)) { QccErrorAddMessage("(QccWAVTarp3DUpdateModel): Error calling QccENTArithmeticSetModelProbabilities()"); return(1); } return(0);}static int QccWAVtce3DLosslessEncodeDWT(QccWAVSubbandPyramid3DInt *image_subband_pyramid, char ***sign_array, const QccIMGImageCube *image, int transform_type, int temporal_num_levels, int spatial_num_levels, int *image_mean, int *max_coefficient_bits, const QccWAVWavelet *wavelet){ int coefficient_magnitude; int max_coefficient = -MAXINT; int frame, row, col; int num_subbands,subband; int subband_origin_frame; int subband_origin_row; int subband_origin_col; int subband_num_frames; int subband_num_rows; int subband_num_cols; num_subbands = QccWAVSubbandPyramid3DIntNumLevelsToNumSubbandsPacket(temporal_num_levels, spatial_num_levels); for (frame = 0; frame <image->num_frames; frame++) for (row = 0; row <image->num_rows; row++) for (col = 0; col <image->num_cols; col++) image_subband_pyramid->volume[frame][row][col] = (int)image->volume[frame][row][col]; if (QccWAVSubbandPyramid3DIntSubtractMean(image_subband_pyramid, image_mean )) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeDWT): Error calling QccWAVSubbandPyramid3DIntSubtractMean()"); return(1); } if (QccWAVSubbandPyramid3DIntDWT(image_subband_pyramid, transform_type, temporal_num_levels, spatial_num_levels, wavelet)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeDWT): Error calling QccWAVSubbandPyramid3DIntDWT()"); return(1); } for (subband = 0; subband < num_subbands; subband++) { if (QccWAVSubbandPyramid3DIntSubbandSize(image_subband_pyramid, subband, &subband_num_frames, &subband_num_rows, &subband_num_cols)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeDWT): Error calling QccWAVSubbandPyramid3DIntSubbandSize(()"); return(1); } if (QccWAVSubbandPyramid3DIntSubbandOffsets(image_subband_pyramid, subband, &subband_origin_frame, &subband_origin_row, &subband_origin_col)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeDWT): Error calling QQccWAVSubbandPyramid3DIntSubbandOffsets()"); return(1); } max_coefficient = -MAXINT; for (frame = 0; frame < subband_num_frames; frame++) for (row = 0; row < subband_num_rows; row++) for (col = 0; col < subband_num_cols; col++) { coefficient_magnitude = fabs(image_subband_pyramid->volume [subband_origin_frame+frame] [subband_origin_row+row] [subband_origin_col+col]); if (image_subband_pyramid->volume [subband_origin_frame+frame] [subband_origin_row+row] [subband_origin_col+col] != coefficient_magnitude) { image_subband_pyramid->volume [subband_origin_frame+frame] [subband_origin_row+row] [subband_origin_col+col] = coefficient_magnitude; sign_array [subband_origin_frame+frame] [subband_origin_row + row] [subband_origin_col + col] = 1; } else sign_array [subband_origin_frame+frame] [subband_origin_row + row] [subband_origin_col + col] = 0; if (coefficient_magnitude > max_coefficient) max_coefficient = coefficient_magnitude; } max_coefficient_bits[subband] = (int)floor(QccMathMax(0, QccMathLog2(max_coefficient + 0.0001))); } return(0);}int QccWAVtce3DLosslessEncodeHeader(QccBitBuffer *buffer, int transform_type, int temporal_num_levels, int spatial_num_levels, int num_frames, int num_rows, int num_cols, int image_mean, int *max_coefficient_bits, double alpha){ int return_value; if (QccBitBufferPutBit(buffer, transform_type)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutBit()"); goto Error; } if (transform_type == QCCWAVSUBBANDPYRAMID3D_PACKET) { if (QccBitBufferPutChar(buffer, (unsigned char)temporal_num_levels)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPuChar()"); goto Error; } } if (QccBitBufferPutChar(buffer, (unsigned char)spatial_num_levels)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPuChar()"); goto Error; } if (QccBitBufferPutInt(buffer, num_frames)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutInt()"); goto Error; } if (QccBitBufferPutInt(buffer, num_rows)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutInt()"); goto Error; } if (QccBitBufferPutInt(buffer, num_cols)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutInt()"); goto Error; } if (QccBitBufferPutInt(buffer, image_mean)) { QccErrorAddMessage("(QccWAVTarp3DEncodeHeader): Error calling QccBitBufferPutDouble()"); goto Error; } if (QccBitBufferPutInt(buffer, max_coefficient_bits[0])) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutInt()"); goto Error; } if (QccBitBufferPutDouble(buffer, alpha)) { QccErrorAddMessage("(QccWAVtce3DLosslessEncodeHeader): Error calling QccBitBufferPutDouble()"); goto Error; } return_value = 0; goto Return; Error: return_value = 1; Return: return(return_value);}static int QccWAVtce3DIntRevEst(QccWAVSubbandPyramid3DInt *coefficients, char ***significance_map, int subband, double *subband_significance, double ***p, double alpha){ int return_value; int subband_origin_frame; int subband_origin_row; int subband_origin_col; int subband_num_frames; int subband_num_rows; int subband_num_cols; int frame,row, col; int current_frame,current_row, current_col; QccMatrix p1=NULL; QccVector p2 = NULL; QccMatrix p3=NULL; QccMatrix p4=NULL; QccVector p5 = NULL; char *p_char; int v; double filter_coef; filter_coef = (1 - alpha) * (1 - alpha)*(1 - alpha) / (3*alpha + alpha*alpha*alpha)/3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -