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.

180 lines
4.5 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*****************************************************************************
  15. *
  16. * exutil.cpp
  17. *
  18. * DESCRIPTION:
  19. * Common encoder utility routines
  20. *
  21. * Routines: Prototypes in:
  22. * trace exutil.h
  23. * cnvt_fdct_output
  24. */
  25. // $Header: S:\h26x\src\enc\exutil.cpv 1.2 18 Nov 1996 17:11:36 MBODART $
  26. // $Log: S:\h26x\src\enc\exutil.cpv $
  27. //
  28. // Rev 1.2 18 Nov 1996 17:11:36 MBODART
  29. // Replaced all debug message invocations with Active Movie's DbgLog.
  30. //
  31. // Rev 1.1 13 Dec 1995 17:17:58 DBRUCKS
  32. //
  33. // Include file needed for Ring0 compile
  34. //
  35. // Rev 1.0 13 Dec 1995 14:00:14 DBRUCKS
  36. // Initial revision.
  37. #include "precomp.h"
  38. /*****************************************************************************
  39. *
  40. * trace
  41. *
  42. * Output a string ot the trace file 'trace.txt'.
  43. */
  44. #ifdef DEBUG_ENC
  45. #include <stdio.h>
  46. void trace(char *str)
  47. {
  48. FILE *fp;
  49. fp = fopen("trace.txt", "a");
  50. fprintf(fp, "%s\n", str);
  51. fclose(fp);
  52. } /* end trace() */
  53. #endif
  54. /*****************************************************************************
  55. *
  56. * cnvt_fdct_output
  57. *
  58. * This is a DCT debug utility routine
  59. */
  60. #ifdef DEBUG_DCT
  61. void cnvt_fdct_output(
  62. unsigned short *DCTcoeff,
  63. int DCTarray[64],
  64. int bIntraBlock)
  65. {
  66. register int i;
  67. static int coefforder[64] = {
  68. // 0 1 2 3 4 5 6 7
  69. 6,38, 4,36,70,100,68,102, // 0
  70. 10,46, 8,44,74,104,72,106, // 1
  71. 18,50,16,48,82,112,80,114, // 2
  72. 14,42,12,40,78,108,76,110, // 3
  73. 22,54,20,52,86,116,84,118, // 4
  74. 2,34, 0,32,66, 96,64, 98, // 5
  75. 26,58,24,56,90,120,88,122, // 6
  76. 30,62,28,60,94,124,92,126 // 7
  77. };
  78. static int zigzag[64] = {
  79. 0, 1, 5, 6, 14, 15, 27, 28,
  80. 2, 4, 7, 13, 16, 26, 29, 42,
  81. 3, 8, 12, 17, 25, 30, 41, 43,
  82. 9, 11, 18, 24, 31, 40, 44, 53,
  83. 10, 19, 23, 32, 39, 45, 52, 54,
  84. 20, 22, 33, 38, 46, 51, 55, 60,
  85. 21, 34, 37, 47, 50, 56, 59, 61,
  86. 35, 36, 48, 49, 57, 58, 62, 63
  87. };
  88. unsigned int index;
  89. for (i = 0; i < 64; i++)
  90. {
  91. index = (coefforder[i])>>1;
  92. if( (i ==0) && bIntraBlock )
  93. {
  94. DCTarray[zigzag[i]] = ((int)(DCTcoeff[index])) >> 4 ;
  95. }
  96. else
  97. {
  98. DCTarray[zigzag[i]] = ((int)(DCTcoeff[index] - 0x8000)) >> 4;
  99. }
  100. }
  101. } /* end cnvt_fdct_output() */
  102. #endif
  103. /************************************************************************
  104. *
  105. * Increment_TR_UsingFrameRate
  106. */
  107. void Increment_TR_UsingFrameRate(
  108. U8 * pu8TR,
  109. float * pfTR_Error,
  110. float fFrameRate,
  111. int bFirstFrame,
  112. U8 u8TRMask)
  113. {
  114. float fTemp;
  115. int iIncrement;
  116. int iNewTR;
  117. if (bFirstFrame)
  118. {
  119. *pu8TR = 0; /* First Frame */
  120. *pfTR_Error = (float) 0.0;
  121. }
  122. else
  123. {
  124. fTemp = ((float)29.97 / fFrameRate) + *pfTR_Error;
  125. iIncrement = (int)fTemp;
  126. *pfTR_Error = fTemp - (float)iIncrement;
  127. iNewTR = *pu8TR + iIncrement;
  128. *pu8TR = (U8)(iNewTR & u8TRMask);
  129. }
  130. } /* end Increment_TR_UsingFrameRate() */
  131. /************************************************************************
  132. *
  133. * Increment_TR_UsingTemporalValue
  134. */
  135. void Increment_TR_UsingTemporalValue(
  136. U8 * pu8TR,
  137. U8 * pu8LastTR,
  138. long lTemporal,
  139. int bFirstFrame,
  140. U8 u8TRMask)
  141. {
  142. *pu8TR = (lTemporal & u8TRMask);
  143. if (! bFirstFrame)
  144. {
  145. #if defined(H261)
  146. /* For H.261, encountering two successive frames with the same
  147. temporal value is harmless. We don't want to ASSERT here
  148. for two reasons. First, it leads to an innocuous difference
  149. between the release and debug builds.
  150. Second, for some clips the temporal difference between two frames
  151. can be a multiple of 32. Two such temporal values are identical
  152. in our eyes because we look only at the least significant 5 bits.
  153. We should gracefully allow such input, an assert is not appropriate.
  154. */
  155. if (*pu8TR == *pu8LastTR)
  156. DBOUT("Identical consecutive temporal values");
  157. #else
  158. ASSERT(*pu8TR != *pu8LastTR);
  159. #endif
  160. }
  161. *pu8LastTR = *pu8TR;
  162. } /* end Increment_TR_UsingTemporalValue() */