/***************************************************************** * tmn (TMN encoder) * Copyright (C) 1995 Telenor R&D * Karl Olav Lillevold * * *****************************************************************/ #include"sim.h" /********************************************************************** * * Name: Quant * Description: quantizer for SIM3 * * Input: pointers to coeff and qcoeff * * Returns: * Side effects: * * Date: 940111 Author: Karl.Lillevold@nta.no * ***********************************************************************/ void Quant(int *coeff, int *qcoeff, int QP, int Mode,int qmode) { 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(-128,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(-128,sign(coeff[i]) * level)); } /* note QMODE_BI is no longer treated as a special case */ } } else { /* No quantizing at all */ 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: * * Date: 940111 Author: Karl.Lillevold@nta.no * ***********************************************************************/ 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; }