Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.0 KiB

  1. /* File: sv_h263_quant.c */
  2. /*****************************************************************************
  3. ** Copyright (c) Digital Equipment Corporation, 1995, 1997 **
  4. ** **
  5. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  6. ** laws of the United States. **
  7. ** **
  8. ** The software contained on this media is proprietary to and embodies **
  9. ** the confidential technology of Digital Equipment Corporation. **
  10. ** Possession, use, duplication or dissemination of the software and **
  11. ** media is authorized only pursuant to a valid written license from **
  12. ** Digital Equipment Corporation. **
  13. ** **
  14. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  15. ** Government is subject to restrictions as set forth in Subparagraph **
  16. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  17. ******************************************************************************/
  18. #include "sv_h263.h"
  19. #include "proto.h"
  20. /**********************************************************************
  21. *
  22. * Name: Quant
  23. * Description: quantizer for SIM3
  24. *
  25. * Input: pointers to coeff and qcoeff
  26. *
  27. * Returns:
  28. * Side effects:
  29. *
  30. ***********************************************************************/
  31. int sv_H263Quant(short *coeff, int QP, int Mode)
  32. {
  33. register int i;
  34. register int Q2, hfQ;
  35. register short *ptn, tmp;
  36. unsigned __int64 *dp ;
  37. if (QP) {
  38. Q2 = QP << 1 ;
  39. if(Mode == H263_MODE_INTRA || Mode == H263_MODE_INTRA_Q) { /* Intra */
  40. coeff[0] = mmax(1,mmin(254,coeff[0]/8));
  41. ptn = coeff + 1;
  42. if (Q2 > 10)
  43. for (i=1; i < 64; i++, ptn++) *ptn /= (short)Q2;
  44. else
  45. for (i=1; i < 64; i++, ptn++) {
  46. if(tmp = *ptn)
  47. *ptn = (tmp > 0) ? mmin(127,tmp/Q2) : mmax(-127,-(-tmp/Q2));
  48. }
  49. /* check CBP */
  50. ptn = coeff + 1;
  51. for (i=1; i < 64; i++) if(*ptn++) return 1;
  52. return 0;
  53. }
  54. else { /* non Intra */
  55. hfQ = QP >> 1;
  56. ptn = coeff;
  57. if( Q2 > 10)
  58. for (i = 0; i < 64; i++, ptn++) {
  59. if(tmp = *ptn)
  60. *ptn = (tmp>0) ? (tmp-hfQ)/Q2 : (tmp+hfQ)/Q2 ;
  61. }
  62. else
  63. for (i = 0; i < 64; i++, ptn++) {
  64. if(tmp = *ptn)
  65. *ptn = (tmp>0) ? mmin(127,(tmp-hfQ)/Q2) : mmax(-127,-((-tmp-hfQ)/Q2));
  66. }
  67. }
  68. }
  69. /* IF(QP == 0). No quantizing.
  70. Used only for testing. Bitstream will not be decodable
  71. whether clipping is performed or not */
  72. /* check CBP */
  73. dp = (unsigned __int64 *) coeff ;
  74. for (i = 0; i < 16; i++) if(*dp++) return 1;
  75. return 0;
  76. }
  77. /**********************************************************************
  78. *
  79. * Name: Dequant
  80. * Description: dequantizer for SIM3
  81. *
  82. * Input: pointers to coeff and qcoeff
  83. *
  84. * Returns:
  85. * Side effects:
  86. *
  87. ***********************************************************************/
  88. void sv_H263Dequant(short *qcoeff, short *rcoeff, int QP, int Mode)
  89. {
  90. int i;
  91. register int Q2;
  92. register short *inptr, *outptr, tmp;
  93. inptr = qcoeff;
  94. outptr = rcoeff;
  95. Q2 = QP << 1;
  96. if (QP) {
  97. if((QP%2) == 1){
  98. for (i = 0; i < 64; i++) {
  99. if (!(tmp = *inptr++)) *outptr++ = 0;
  100. else *outptr++ = (tmp > 0) ? Q2*tmp+QP : Q2*tmp-QP ;
  101. }
  102. }
  103. else {
  104. for (i = 0; i < 64; i++) {
  105. if (!(tmp = *inptr++)) *outptr++ = 0;
  106. else *outptr++ = (tmp > 0) ? Q2*tmp+QP-1 : Q2*tmp-QP+1 ;
  107. }
  108. }
  109. /* Intra */
  110. if (Mode == H263_MODE_INTRA || Mode == H263_MODE_INTRA_Q)
  111. rcoeff[0] = qcoeff[0] << 3;
  112. }
  113. else {
  114. /* No quantizing at all */
  115. for (i = 0; i < 64; i++) *outptr++ = *inptr++;
  116. }
  117. return;
  118. }
  119.