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

📄 spiht3d.c

📁 该文件是小波信源编码SPIHT算法的C语言代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (QccListAppendNode(LIS, new_node))              {                QccErrorAddMessage("(QccSPIHT3DAlgorithmInitialize): Error calling QccListAppendNode()");                return(1);              }          }    return(0);}static double QccSPIHT3DMaximumCoefficient(QccWAVSubbandPyramid3D                                           *subband_pyramid,                                           int base_frame,                                           int base_row,                                           int base_col,                                           int block_size){  int frame, row, col;  double maximum_coefficient = -MAXFLOAT;    for (frame = 0; frame < block_size; frame++)    for (row = 0; row < block_size; row++)      for (col = 0; col < block_size; col++)        if (subband_pyramid->volume            [base_frame + frame][base_row + row][base_col + col] >            maximum_coefficient)          maximum_coefficient =            subband_pyramid->volume            [base_frame + frame][base_row + row][base_col + col];    return(maximum_coefficient);}static int QccSPIHT3DDescendantsSignificance(QccWAVSubbandPyramid3D                                             *subband_pyramid,                                             int frame, int row, int col,                                             double threshold,                                             int block_size,                                             int zerotree_type){  int offspring_frame[8];  int offspring_row[8];  int offspring_col[8];  int num_offspring;  int offspring;    num_offspring =     QccSPIHT3DGetOffspring(subband_pyramid,                           frame, row, col,                           offspring_frame, offspring_row, offspring_col,                           block_size,                           zerotree_type);    if (!num_offspring)    return(-1);    for (offspring = 0; offspring < num_offspring; offspring++)    if (QccSPIHT3DMaximumCoefficient(subband_pyramid,                                     offspring_frame[offspring],                                     offspring_row[offspring],                                     offspring_col[offspring],                                     block_size) >=        threshold)      return(1);    for (offspring = 0; offspring < num_offspring; offspring++)    if (QccSPIHT3DDescendantsSignificance(subband_pyramid,                                          offspring_frame[offspring],                                          offspring_row[offspring],                                          offspring_col[offspring],                                          threshold,                                          block_size,                                          zerotree_type) == 1)      return(1);    return(0);}static int QccSPIHT3DLSignificance(QccWAVSubbandPyramid3D                                   *subband_pyramid,                                   int frame, int row, int col,                                   double threshold,                                   int block_size,                                   int zerotree_type){  int offspring_frame[8];  int offspring_row[8];  int offspring_col[8];  int num_offspring;  int offspring;  int return_value;    num_offspring =     QccSPIHT3DGetOffspring(subband_pyramid,                           frame, row, col,                           offspring_frame, offspring_row, offspring_col,                           block_size,                           zerotree_type);    if (!num_offspring)    return(-1);    for (offspring = 0; offspring < num_offspring; offspring++)    if ((return_value =          QccSPIHT3DDescendantsSignificance(subband_pyramid,                                           offspring_frame[offspring],                                           offspring_row[offspring],                                           offspring_col[offspring],                                           threshold,                                           block_size,                                           zerotree_type)))      return(return_value);    return(0);}static int QccSPIHT3DInputOutputRefinementBit(QccWAVSubbandPyramid3D                                              *subband_pyramid,                                              QccBitBuffer *buffer,                                              double threshold,                                              QccSPIHT3DCoefficientBlock                                              *coefficient,                                              int method,                                              QccENTArithmeticModel *model,                                              int target_bit_cnt){  int bit;    if (method == QCCSPIHT3D_ENCODE)    {      bit =         (subband_pyramid->volume         [coefficient->frame][coefficient->row][coefficient->col] >=         threshold);            if (bit)        subband_pyramid->volume          [coefficient->frame][coefficient->row][coefficient->col] -=          threshold;    }    if (model != NULL)    if (QccENTArithmeticSetModelContext(model, QCCSPIHT3D_REFINEMENT_CONTEXT))      {        QccErrorAddMessage("(QccSPIHT3DInputOutputRefinementBit): Error calling QccENTArithmeticSetModelContext()");        return(2);      }  if (QccSPIHT3DInputOutput(buffer, &bit, method, model, target_bit_cnt))    {      QccErrorAddMessage("(QccSPIHT3DInputOutputRefinementBit): Error calling QccSPIHT3DInputOutput()");      return(2);    }    if (method == QCCSPIHT3D_DECODE)    QccSPIHT3DRefineCoefficient(&(subband_pyramid->volume                                  [coefficient->frame]                                  [coefficient->row][coefficient->col]),                                bit,                                threshold);    return(0);}static int QccSPIHT3DUpdateState(int state, int bit,                                 int frame, int row, int col,                                 int block_size){  int mask = 0;    if (bit)    {      mask = 1 << ((frame * block_size + row) * block_size + col);      state |= mask;    }    return(state);}static int QccSPIHT3DIsSignificant(int state,                                   int frame, int row, int col,                                   int block_size){  int mask = 0;  mask = 1 << ((frame * block_size + row) * block_size + col);  return(state & mask);}static int QccSPIHT3DInputOutputSignificanceBits(QccWAVSubbandPyramid3D                                                 *subband_pyramid,                                                 QccBitBuffer *buffer,                                                 QccSPIHT3DCoefficientBlock                                                 *coefficient_block,                                                 double threshold,                                                 int method,                                                 QccENTArithmeticModel *model,                                                 int target_bit_cnt,                                                 int block_size){  int base_frame, base_row, base_col;  int frame, row, col;  int bit;  int mask;  int symbol = 0;  int old_state;    base_frame = coefficient_block->frame;  base_row = coefficient_block->row;  base_col = coefficient_block->col;  old_state = coefficient_block->state;    if (model == NULL)    {      for (frame = 0; frame < block_size; frame++)        for (row = 0; row < block_size; row++)          for (col = 0; col < block_size; col++)            if (!QccSPIHT3DIsSignificant(old_state,                                         frame, row, col, block_size))              {                if (method == QCCSPIHT3D_ENCODE)                  bit =                    subband_pyramid->volume                    [base_frame + frame][base_row + row][base_col + col] >=                    threshold;                if (QccSPIHT3DInputOutput(buffer, &bit, method, model,                                          target_bit_cnt))                  {                    QccErrorAddMessage("(QccSPIHT3DInputOutputSignificanceBits): Error calling QccSPIHT3DInputOutput()");                    return(2);                  }                coefficient_block->state =                  QccSPIHT3DUpdateState(coefficient_block->state, bit,                                        frame, row, col,                                        block_size);              }    }  else    {      if (method == QCCSPIHT3D_ENCODE)        for (frame = 0, mask = 1; frame < block_size; frame++)          for (row = 0; row < block_size; row++)            for (col = 0; col < block_size; col++)              if (!QccSPIHT3DIsSignificant(old_state,                                           frame, row, col, block_size))                {                  bit =                    subband_pyramid->volume                    [base_frame + frame][base_row + row][base_col + col] >=                    threshold;                  if (bit)                    symbol |= mask;                  coefficient_block->state =                    QccSPIHT3DUpdateState(coefficient_block->state, bit,                                          frame, row, col,                                          block_size);                                    mask <<= 1;                }            if (QccSPIHT3DInputOutput(buffer, &symbol, method,                                model, target_bit_cnt))        {          QccErrorAddMessage("(QccSPIHT3DInputOutputSignificanceBits): Error calling QccSPIHT3DInputOutput()");          return(2);        }            if (method == QCCSPIHT3D_DECODE)        for (frame = 0, mask = 1; frame < block_size; frame++)          for (row = 0; row < block_size; row++)            for (col = 0; col < block_size; col++)              if (!QccSPIHT3DIsSignificant(old_state,                                           frame, row, col, block_size))                {                  bit =                    symbol & mask;                  coefficient_block->state =                    QccSPIHT3DUpdateState(coefficient_block->state, bit,                                          frame, row, col,                                          block_size);                  mask <<= 1;                }          }    return(0);}static int QccSPIHT3DAddNodeToLSP(QccList *LSP,                                  int frame,                                  int row,                                  int col,                                  QccWAVSubbandPyramid3D *subband_pyramid,                                  double threshold,                                  int ***sign_array,                                  QccBitBuffer *buffer,                                  int method,                                  QccENTArithmeticModel *model,                                  int target_bit_cnt){  QccSPIHT3DCoefficientBlock coefficient_block;  QccListNode *new_node = NULL;    coefficient_block.frame = frame;  coefficient_block.row = row;  coefficient_block.col = col;  coefficient_block.type = QCCSPIHT3D_TYPE_A;  coefficient_block.state = 0;    if ((new_node =       QccListCreateNode(sizeof(QccSPIHT3DCoefficientBlock),                         (void *)(&coefficient_block))) == NULL)    {      QccErrorAddMessage("(QccSPIHT3DAddNodeToLSP): Error calling QccListCreateNode()");      return(1);    }    if (QccListAppendNode(LSP, new_node))    {      QccErrorAddMessage("(QccSPIHT3DAddNodeToLSP): Error calling QccListAppendNode()");      return(1);    }    if (model != NULL)    if (QccENTArithmeticSetModelContext(model, QCCSPIHT3D_SIGN_CONTEXT))      {        QccErrorAddMessage("(QccSPIHT3DAddNodeToLSP): Error calling QccENTArithmeticSetModel()");        return(2);      }    if (QccSPIHT3DInputOutput(buffer,                            &sign_array[frame][row][col],                            method,                            model,                            target_bit_cnt))    {      QccErrorAddMessage("(QccSPIHT3DAddNodeToLSP): Error calling QccSPIHT3DInputOutput()");      return(2);    }    if (method == QCCSPIHT3D_ENCODE)    subband_pyramid->volume[frame][row][col] -= threshold;  else    subband_pyramid->volume[frame][row][col] = 1.5 * threshold;  

⌨️ 快捷键说明

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