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

📄 quant.c

📁 基于H.263的图像压缩编解码的C源码
💻 C
字号:
/************************************************************************
 *
 *  quant.c, part of tmn (TMN encoder)
 *
 ************************************************************************/

#include        "sim.h"

/**********************************************************************
 *
 *      Name:           Quant
 *	Description:	quantizer for SIM3
 *	
 *      Input:          pointers to coeff and qcoeff
 *        
 *	Returns:	
 *	Side effects:	
 *
 *      Date: 940111 
 *
 ***********************************************************************/


void Quant(int *coeff, int *qcoeff, int QP, int Mode)
{
  int i;
  int level;
  
  if (QP) {
    if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { /* Intra */
      qcoeff[0] = mmax(1,mmin(254,coeff[0]/8));

      for (i = 1; i < 64; i++) {
        level = (abs(coeff[i])) / (2*QP);
        qcoeff[i] =  mmin(127,mmax(-127,sign(coeff[i]) * level));
      }
    }
    else { /* non Intra */
      for (i = 0; i < 64; i++) {
        level = (abs(coeff[i])-QP/2)  / (2*QP);
        qcoeff[i] = mmin(127,mmax(-127,sign(coeff[i]) * level));
      }
    }
  }
  else {
    /* No quantizing.
       Used only for testing. Bitstream will not be decodable 
       whether clipping is performed or not */
    for (i = 0; i < 64; i++) {
      qcoeff[i] = coeff[i];
    }
  }
  return;
}

/**********************************************************************
 *
 *      Name:           Dequant
 *	Description:	dequantizer for SIM3
 *	
 *      Input:          pointers to coeff and qcoeff
 *        
 *	Returns:	
 *	Side effects:	
 *
 ***********************************************************************/


void Dequant(int *qcoeff, int *rcoeff, int QP, int Mode)
{
  int i;
  
  if (QP) {
    for (i = 0; i < 64; i++) {
      if (qcoeff[i]) {
        if ((QP % 2) == 1)
          rcoeff[i] = QP * (2*abs(qcoeff[i]) + 1);
        else
          rcoeff[i] = QP * (2*abs(qcoeff[i]) + 1) - 1;
        rcoeff[i] = sign(qcoeff[i]) * rcoeff[i];
      }
      else
        rcoeff[i] = 0;
    }
    if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { /* Intra */
      rcoeff[0] = qcoeff[0]*8;
    }
  }
  else {
    /* No quantizing at all */
    for (i = 0; i < 64; i++) {
      rcoeff[i] = qcoeff[i];
    }
  }
  return;
}



⌨️ 快捷键说明

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