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.

214 lines
6.2 KiB

  1. /* File: sv_h261_cdd6.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. /* Some Modifications were done to incorporate a scaled IDCT scheme
  19. on the DecodeXXX routines. These modifications are to
  20. improve the performance -S.I.S. September 29, 1993.
  21. */
  22. /*************************************************************
  23. This file contains the routines to run-length encode the ac and dc
  24. coefficients.
  25. *************************************************************/
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <math.h>
  29. #include "sv_intrn.h"
  30. #include "SC_err.h"
  31. #include "sv_h261.h"
  32. #include "proto.h"
  33. #ifndef WIN32
  34. long __CVTTQ(double);
  35. #endif /* !WIN32 */
  36. /* Scaled stuff - S.I.S. */
  37. extern const unsigned int tdzz[];
  38. extern const unsigned int tzz[];
  39. float static quantiscale[32][64];
  40. float static qs[64];
  41. float DCIscale;
  42. /*PRIVATE*/
  43. extern int bit_set_mask[];
  44. extern int extend_mask[];
  45. #define MYPI 3.1415926535897931
  46. void DGenScaleMat()
  47. {
  48. double dbli, dblj;
  49. float dij;
  50. int i, j, k, quantindex;
  51. for(k=0;k<64;k++)
  52. quantiscale[0][k] = (float)1.0;
  53. for(quantindex=1;quantindex<2;quantindex++) {
  54. k=0;
  55. for(i=0;i<8;i++) {
  56. for(j=0;j<8;j++) {
  57. dbli = MYPI*i/16.0;
  58. dblj = MYPI*j/16.0;
  59. dij = (float)(16.0*(float)cos(dbli)*cos(dblj));
  60. if(i==0) dij = (float)(dij/sqrt(2.0));
  61. if(j==0) dij = (float)(dij/sqrt(2.0));
  62. qs[tdzz[k]] = (float)(1.0/dij);
  63. k++;
  64. }
  65. }
  66. }
  67. DCIscale = (float)(4.0*quantiscale[1][0]);
  68. }
  69. SvStatus_t DecodeAC_Scale(SvH261Info_t *H261, ScBitstream_t *bs, int index,
  70. int QuantUse, float *fmatrix)
  71. {
  72. float *mptr;
  73. register int k, r, l, temp;
  74. register unsigned short cb;
  75. DHUFF *huff = H261->T1DHuff;
  76. for(mptr=fmatrix+index; mptr<fmatrix+H261_BLOCKSIZE; mptr++)
  77. *mptr = (float)0.0;
  78. for(k=index; k<H261_BLOCKSIZE; k++) /* JPEG Mistake */
  79. {
  80. DecodeHuffB(bs, huff, r, l, cb, temp);
  81. if (l & bit_set_mask[7])
  82. l |= extend_mask[7];
  83. k += r;
  84. if (k < H261_BLOCKSIZE)
  85. {
  86. if (QuantUse&1)
  87. temp = (l>0) ? ( ((l<<1)+1)*QuantUse ) : ( ((l<<1)-1)*QuantUse );
  88. else
  89. temp = (l>0) ? ( ((l<<1)+1)*QuantUse -1 ) : ( ((l<<1)-1)*QuantUse +1 );
  90. fmatrix[tzz[k]] = temp*qs[k];
  91. H261->NumberNZ++;
  92. }
  93. }
  94. DecodeHuffA(bs, huff, r, cb, temp);
  95. return(SvErrorVideoInput);
  96. }
  97. SvStatus_t CBPDecodeAC_Scale(SvH261Info_t *H261, ScBitstream_t *bs,
  98. int index, int QuantUse, int BlockType,
  99. float *fmatrix)
  100. {
  101. int k,r,l, temp;
  102. float *mptr, *local_qptr;
  103. register unsigned short cb;
  104. DHUFF *huff = H261->T2DHuff;
  105. local_qptr = &quantiscale[QuantUse][0];
  106. for(mptr=fmatrix+index;mptr<fmatrix+H261_BLOCKSIZE;mptr++) {*mptr = (float)0.0;}
  107. k = index;
  108. DecodeHuffB(bs, huff, r, l, cb, temp);
  109. if (l & bit_set_mask[7])
  110. l |= extend_mask[7];
  111. k += r;
  112. if(((k==0) & (BlockType==1)))
  113. fmatrix[0] = (float) l;
  114. else {
  115. if(QuantUse&1) {
  116. temp = (l>0) ? ( ((l<<1)+1)*QuantUse ) : ( ((l<<1)-1)*QuantUse );
  117. }
  118. else {
  119. temp = (l>0) ? ( ((l<<1)+1)*QuantUse-1) : ( ((l<<1)-1)*QuantUse+1);
  120. }
  121. fmatrix[tzz[k]] = temp*qs[k];
  122. }
  123. k++;
  124. H261->NumberNZ++;
  125. huff=H261->T1DHuff;
  126. while(k<H261_BLOCKSIZE)
  127. {
  128. DecodeHuffB(bs, huff, r, l, cb, temp);
  129. if (l & bit_set_mask[7]) {l |= extend_mask[7];}
  130. k += r;
  131. if (k < H261_BLOCKSIZE)
  132. {
  133. if(QuantUse&1)
  134. {
  135. temp = (l>0) ? ( ((l<<1)+1)*QuantUse ) : ( ((l<<1)-1)*QuantUse );
  136. }
  137. else
  138. {
  139. temp = (l>0) ? ( ((l<<1)+1)*QuantUse -1 ) : ( ((l<<1)-1)*QuantUse +1 );
  140. }
  141. fmatrix[tzz[k]] = temp*qs[k];
  142. k++;
  143. H261->NumberNZ++;
  144. }
  145. }
  146. DecodeHuffA(bs, huff, r, cb, temp);
  147. return (SvErrorVideoInput);
  148. }
  149. /*
  150. ** Function: DecodeDC_Scale()
  151. ** Purpose: Decodes a dc element from the stream.
  152. */
  153. float DecodeDC_Scale(SvH261Info_t *H261, ScBitstream_t *bs,
  154. int BlockType, int QuantUse)
  155. {
  156. int l, temp;
  157. l = (int)ScBSGetBits(bs,8);
  158. if (bs->EOI) return ((float)l);
  159. if (l==255) {l=128;}
  160. if (l!=1){H261->NumberNZ++;}
  161. if(BlockType) {
  162. return ((float) l);
  163. }
  164. else {
  165. if(QuantUse&1) {
  166. if(l>0) {
  167. temp = ((l<<1)+1)*QuantUse;
  168. return((float)temp*qs[0]);
  169. }
  170. else if(l<0) {
  171. temp = ((l<<1)-1)*QuantUse;
  172. return((float)temp*qs[0]);
  173. }
  174. }
  175. else {
  176. if(l>0) {
  177. temp = ((l<<1)+1)*QuantUse -1;
  178. return((float)temp*qs[0]);
  179. }
  180. else if(l<0) {
  181. temp = ((l<<1)-1)*QuantUse +1;
  182. return((float)temp*qs[0]);
  183. }
  184. }
  185. }
  186. return((float)0);
  187. }
  188. int DecodeDC(SvH261Info_t *H261, ScBitstream_t *bs)
  189. {
  190. int l;
  191. l = (int)ScBSGetBits(bs,8);
  192. if (l==255) {l=128;}
  193. if (l!=1){H261->NumberNZ++;}
  194. return(l);
  195. }
  196.