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

📄 klttce3d_lossless.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * * 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 QCCWAVKLTTCE3D_BOUNDARY_VALUE (1e-6)//definition used in context information#define QCCWAVKLTTCE3D_Z 0 //zero, AKA, insignificant#define QCCWAVKLTTCE3D_NZN_NEW 2 //non-zero-neighbor#define QCCWAVKLTTCE3D_S 3 //significant#define QCCWAVKLTTCE3D_S_NEW 4#define QCCWAVKLTTCE3D_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 QCCWAVKLTTCE3D_ALPHA_1D 0.995 #define QCCWAVKLTTCE3D_ALPHA_1D_O 0.005// this should be 0.5, however, 0.3 seems to work a little better (minor)// reason unknown#define QCCWAVKLTTCE3D_REFINE_HOLDER 0.3 // threshold for cross-scale prediction...#define QCCWAVKLTTCE3D_PREDICT_THRESHOLD 0.05  //weight factor for cross-scale and current scale#define QCCWAVKLTTCE3D_CURRENT_SCALE 0.6 #define QCCWAVKLTTCE3D_PARENT_SCALE 0.4                                      static int QccWAVklttce3DEncodeBitPlaneInfo(QccBitBuffer *output_buffer,                                            int num_subbands,                                            int *max_coefficient_bits){  int subband;  int num_zeros = 0;  for (subband = 1; subband < num_subbands; subband++)    {      num_zeros = max_coefficient_bits[subband-1] - max_coefficient_bits[subband];      if(num_zeros>0)                   QccBitBufferPutBit(output_buffer, 0);      else        QccBitBufferPutBit(output_buffer, 1);    }    for (subband = 1; subband < num_subbands; subband++)    {      for (num_zeros = abs(max_coefficient_bits[subband-1] - 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 QccWAVklttce3DDecodeBitPlaneInfo(QccBitBuffer *input_buffer,                                            int num_subbands,                                            int *max_bits,                                            int max_coefficient_bits){  int subband;  int bit_value;  int *max_bits_sign;  if ((max_bits_sign =       (int *)malloc(sizeof(int) * num_subbands )) == NULL)    {      QccErrorAddMessage("(QccWAVklttce3DDecodeBitPlaneInfo): Error allocating memory");          }    max_bits[0] = max_coefficient_bits;  for (subband = 1; subband < num_subbands; subband++)    {            QccBitBufferGetBit(input_buffer,&bit_value);                  if (bit_value == 0)        max_bits_sign[subband]=1;        else        max_bits_sign[subband]=-1;    }    for (subband = 1; subband < num_subbands; subband++)    {      max_bits[subband] = 0;      do        {          if (QccBitBufferGetBit(input_buffer,&bit_value))            return(1);          max_bits[subband]++;        }      while (bit_value == 0);      max_bits[subband]--;        max_bits[subband] = max_bits[subband-1] -         max_bits[subband]*max_bits_sign[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 QccWAVklttceForwardKLTDWT(QccWAVSubbandPyramid3DInt                                     *image_subband_pyramid,                                     int num_levels,                                     const QccWAVWavelet *wavelet,                                     QccHYPrklt *rklt){  int return_value;  image_subband_pyramid->temporal_num_levels = 0;  image_subband_pyramid->spatial_num_levels = 0;   if (QccHYPrkltTrain(image_subband_pyramid->volume,                      image_subband_pyramid->num_frames,                      image_subband_pyramid->num_rows,                      image_subband_pyramid->num_cols,                      rklt))    {      QccErrorAddMessage("(QccWAVklttceForwardKLTDWT): Error calling QccHYPrkltTrain()");      goto Error;    }  if (QccHYPrkltFactorization(rklt))    {      QccErrorAddMessage("(QccWAVklttceForwardKLTDWT): Error calling QccHYPrkltFactorization()");      goto Error;    }  if (QccHYPrkltTransform(image_subband_pyramid->volume,                          image_subband_pyramid->num_frames,                          image_subband_pyramid->num_rows,                          image_subband_pyramid->num_cols,                          rklt))    {      QccErrorAddMessage("(QccWAVklttceForwardKLTDWT): Error calling QccHYPrkltTransform()");      goto Error;    }     if (QccWAVSubbandPyramid3DIntDWT(image_subband_pyramid,                                   QCCWAVSUBBANDPYRAMID3DINT_PACKET,                                   0,                                   num_levels,                                   wavelet))    {      QccErrorAddMessage("(QccWAVklttceForwardKLTDWT): Error calling QccWAVSubbandPyramid3DIntDWT()");      goto Error;    }  return_value = 0;  goto Return; Error:  return_value = 1; Return:  return(return_value);}static int QccWAVklttceInverseKLTDWT(QccWAVSubbandPyramid3DInt                                     *image_subband_pyramid,                                     const QccWAVWavelet *wavelet,                                     int num_levels,                                     const QccHYPrklt *rklt){  int return_value;    if (QccWAVSubbandPyramid3DIntInverseDWT(image_subband_pyramid,                                          wavelet))    {      QccErrorAddMessage("(QccWAVklttceInverseKLTDWT): Error calling QccWAVSubbandPyramid3DIntInverseDWT()");      goto Error;    }  if (QccHYPrkltInverseTransform(image_subband_pyramid->volume,                                 image_subband_pyramid->num_frames,                                 image_subband_pyramid->num_rows,                                 image_subband_pyramid->num_cols,                                 rklt))    {      QccErrorAddMessage("(QccWAVklttceInverseKLTDWT): Error calling QccHYPrkltInverseTransform(()");      goto Error;    }    return_value = 0;  goto Return; Error:  return_value = 1; Return:  return(return_value);}static int QccWAVklttce3DLosslessForwardTransform(QccWAVSubbandPyramid3DInt                                                  *image_subband_pyramid,                                                  char ***sign_array,                                                  const QccIMGImageCube *image,                                                  int num_levels,                                                  int **max_coefficient_bits,                                                  const QccWAVWavelet *wavelet,                                                  QccHYPrklt *rklt){  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(0, 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 (QccWAVklttceForwardKLTDWT(image_subband_pyramid,                                num_levels,                                wavelet,                                rklt))    {      QccErrorAddMessage("(QccWAVklttce3DLosslessForwardTransform): Error calling QccWAVklttceForwardKLTDWT()");      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("(QccWAVklttce3DLosslessForwardTransform): Error calling QccWAVSubbandPyramid3DIntSubbandSize()");          return(1);        }      if (QccWAVSubbandPyramid3DIntSubbandOffsets(image_subband_pyramid,                                                  subband,                                                  &subband_origin_frame,                                                  &subband_origin_row,                                                  &subband_origin_col))        {          QccErrorAddMessage("(QccWAVklttce3DLosslessForwardTransform): Error calling QccWAVSubbandPyramid3DIntSubbandOffsets()");          return(1);        }               for (frame = 0; frame < subband_num_frames; frame++)        {          max_coefficient = -MAXINT;          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;

⌨️ 快捷键说明

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