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

📄 tce.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 5 页
字号:
    for (subband = 0; subband < num_subbands; subband++)
      {
        if (QccWAVSubbandPyramidSubbandSize(image_subband_pyramid,
                                            subband,
                                            &subband_num_rows,
                                            &subband_num_cols))
            {
              QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccWAVSubbandPyramidSubbandSize()");
              return(1);
            }
          if (QccWAVSubbandPyramidSubbandOffsets(image_subband_pyramid,
                                                 subband,
                                                 &subband_origin_row,
                                                 &subband_origin_col))
            {
              QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccWAVSubbandPyramidSubbandOffsets()");
              return(1);         
            } 
          
          for (row = 0; row < subband_num_rows; row++)
            for (col = 0; col < subband_num_cols; col++)
              {
                if (sign_array[subband_origin_row + row]
                    [subband_origin_col + col])
                  image_subband_pyramid->matrix
                    [subband_origin_row + row][subband_origin_col + col] *= -1;
                image_subband_pyramid->matrix
                  [subband_origin_row + row][subband_origin_col + col] *=
                  stepsize;
              }
      }
  else
    {
      for (row = 0; row < image_subband_pyramid->num_rows; row++)
        for (col = 0; col < image_subband_pyramid->num_cols; col++)
          if (sign_array[row][col])
            image_subband_pyramid->matrix[row][col] *= -1;  
    }
  
  if (QccWAVSubbandPyramidInverseDWT(image_subband_pyramid,wavelet))
    {
      QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccWAVSubbandPyramidInverseDWT()");
      return(1);
    }
  
  if (QccWAVSubbandPyramidAddMean(image_subband_pyramid, image_mean))
    {
      QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccWAVSubbandPyramidAddMean()");
      return(1);
    }
  
  if (QccMatrixCopy(image->image,
                    image_subband_pyramid->matrix,
                    image->num_rows, image->num_cols))
    {
      QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccMatrixCopy()");
      return(1);
    }

  if (QccIMGImageComponentSetMaxMin(image))
    {
      QccErrorAddMessage("(QccWAVtceDecodeInverseDWT): Error calling QccIMGImageComponentSetMaxMin()");
      return(1);
    }

  return(0);
}


int QccWAVtceDecodeHeader(QccBitBuffer *input_buffer, 
                          int *num_levels, 
                          int *num_rows,
                          int *num_cols,
                          double *image_mean,
                          double *stepsize,
                          int *max_coefficient_bits)
{
  int return_value;
  unsigned char ch;
  
  if (QccBitBufferGetChar(input_buffer, &ch))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferPuChar()");
      goto Error;
    }
  *num_levels = (int)ch;
  
  if (QccBitBufferGetInt(input_buffer, num_rows))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferGetInt()");
      goto Error;
    }
  
  if (QccBitBufferGetInt(input_buffer, num_cols))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferGetInt()");
      goto Error;
    }
  
  if (QccBitBufferGetDouble(input_buffer, image_mean))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferGetDouble()");
      goto Error;
    }
  if (QccBitBufferGetDouble(input_buffer, stepsize))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferGetDouble()");
      goto Error;
    }
  
  if (QccBitBufferGetInt(input_buffer, max_coefficient_bits))
    {
      QccErrorAddMessage("(QccWAVtceDecodeHeader): Error calling QccBitBufferGetChar()");
      goto Error;
    }
  
  return_value = 0;
  goto Return;
 Error:
  return_value = 1;
 Return:
  return(return_value);
}


int QccWAVtceDecode(QccBitBuffer *input_buffer,
                    QccIMGImageComponent *image,
                    int num_levels,
                    const QccWAVWavelet *wavelet,
                    double image_mean,
                    double stepsize,
                    int max_coefficient_bits,
                    int target_bit_cnt)
{
  int return_value;
  QccENTArithmeticModel *model = NULL;
  QccWAVSubbandPyramid image_subband_pyramid;
  char **sign_array = NULL;
  char **significance_map = NULL;
  double **p_estimation = NULL;
  int *max_bits = NULL;
  double *subband_significance = NULL;
  double threshold;
  int row, col;
  int num_symbols[1] = { 2 };
  int num_subbands;
  int bitplane_cnt = 0;
  
  if (image == NULL)
    return(0);
  if (input_buffer == NULL)
    return(0);
  if (wavelet == NULL)
    return(0);
  
  num_subbands = QccWAVSubbandPyramidNumLevelsToNumSubbands(num_levels);
  if ((max_bits = (int *)malloc(sizeof(int) * num_subbands)) == NULL)
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
      goto Error;
    }
  
  if (QccWAVtceDecodeBitPlaneInfo(input_buffer,
                                  num_subbands,
                                  max_bits,
                                  max_coefficient_bits))
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceEncodeBitPlaneInfo()");
      goto Error;
    }
  
  QccWAVSubbandPyramidInitialize(&image_subband_pyramid);
  
  image_subband_pyramid.num_levels = num_levels;
  image_subband_pyramid.num_rows = image->num_rows;
  image_subband_pyramid.num_cols = image->num_cols;
  if (QccWAVSubbandPyramidAlloc(&image_subband_pyramid))
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVSubbandPyramidAlloc()");
      goto Error;
    }
  
  if ((sign_array = (char **)malloc(sizeof(char *) * image->num_rows)) == NULL)
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
      goto Error;
    }
  for (row = 0; row < image->num_rows; row++)
    if ((sign_array[row] =
         (char *)malloc(sizeof(char) * image->num_cols)) == NULL)
      {
        QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
        goto Error;
      }

  if ((significance_map =
       (char **)malloc(sizeof(char *) * image->num_rows)) == NULL)
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
      goto Error;
    }
  for (row = 0; row < image->num_rows; row++)
    if ((significance_map[row] =
         (char *)malloc(sizeof(char) * image->num_cols)) == NULL)
      {
        QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
        goto Error;
      }

  for (row = 0; row < image->num_rows; row++)
    for (col = 0; col < image->num_cols; col++)
      {
        image_subband_pyramid.matrix[row][col] = 0.0;
        sign_array[row][col] = 0;
        significance_map[row][col] = QCCTCE_Z;
      }

  if ((p_estimation =
       (double **)malloc(sizeof(double *) * image->num_rows)) == NULL)
    {   
      QccErrorAddMessage("(QccWAVtceEncode): Error allocating memory");
      goto Error;
    }
  for (row = 0; row < image->num_rows; row++)
    if ((p_estimation[row] =
         (double *)malloc(sizeof(double) * image->num_cols)) == NULL)
      {
        QccErrorAddMessage("(QccWAVtceEncode): Error allocating memory");
        goto Error;
      }
  
  for (row = 0; row < image->num_rows; row++)
    for (col = 0; col < image->num_cols; col++)
      p_estimation[row][col] = 0.0000001;
  
  if ((subband_significance =
       (double*)calloc(num_subbands,sizeof(double))) == NULL)
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error allocating memory");
      goto Error;
    }
  
  if ((model = QccENTArithmeticDecodeStart(input_buffer,
                                           num_symbols,
                                           1,
                                           NULL,
                                           target_bit_cnt)) == NULL)
    {
      QccErrorAddMessage("(QccWAVtceDecode): Error calling QccENTArithmeticDecodeStart()");
      goto Error;
    }
  
  QccENTArithmeticSetModelAdaption(model, QCCENT_NONADAPTIVE);    
  threshold = pow((double)2, (double)max_coefficient_bits); 
  
  if (stepsize <= 0)
    while (1)
      {
        return_value = QccWAVtceNZNPass(&image_subband_pyramid,    
                                        significance_map,
                                        sign_array,
                                        threshold,
                                        p_estimation,
                                        subband_significance,
                                        model,
                                        input_buffer,
                                        max_bits);
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceNZNPass()");
            goto Error;
          }
        else
          {
            if (return_value == 2)
              goto Finished;
          }
        
        return_value = QccWAVtceIPPass(&image_subband_pyramid,    
                                       significance_map,
                                       sign_array,
                                       threshold,
                                       p_estimation,
                                       subband_significance,
                                       model,
                                       input_buffer,
                                       max_bits);
        
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceIPPass()");
            goto Error;
          }
        else
          {
            if (return_value == 2)
              goto Finished;
          }
        
        return_value = QccWAVtceSPass(&image_subband_pyramid,    
                                      significance_map,
                                      threshold,
                                      model,
                                      input_buffer,
                                      max_bits);
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceSPass()");
            goto Error;
          }
        else
          {
            if (return_value == 2)
              goto Finished;
          }
        
        bitplane_cnt++;
        threshold /= 2.0;
      }
  else
    while (threshold > 0.75)
      {
        return_value = QccWAVtceNZNPass(&image_subband_pyramid,    
                                        significance_map,
                                        sign_array,
                                        threshold,
                                        p_estimation,
                                        subband_significance,
                                        model,
                                        input_buffer,
                                        max_bits);
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceNZNPass()");
            goto Error;
          }
        else
          {
            if (return_value == 2)
              goto Finished;
          }
        
        return_value = QccWAVtceIPPass(&image_subband_pyramid,    
                                       significance_map,
                                       sign_array,
                                       threshold,
                                       p_estimation,
                                       subband_significance,
                                       model,
                                       input_buffer,
                                       max_bits);
        
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceIPPass()");
            goto Error;
          }
        else
          {
            if (return_value == 2)
              goto Finished;
          }
        
        return_value = QccWAVtceSPass(&image_subband_pyramid,    
                                      significance_map,
                                      threshold,
                                      model,
                                      input_buffer,
                                      max_bits);
        if (return_value == 1)
          {
            QccErrorAddMessage("(QccWAVtceDecode): Error calling QccWAVtceSPass()");
            

⌨️ 快捷键说明

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