reconstruct.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /****************************************************************************
  2. *
  3. * Module Title : Reconstruct.c
  4. *
  5. * Description : Block reconstruction functions.
  6. *
  7. ****************************************************************************/
  8. #define STRICT // Strict type checking
  9. /****************************************************************************
  10. * Header Files
  11. ****************************************************************************/
  12. #include "reconstruct.h"
  13. #include "codec_common.h"
  14. /****************************************************************************
  15. *
  16. * ROUTINE : SatUnsigned8
  17. *
  18. * INPUTS : INT16 *DataBlock : Pointer to 8x8 input block.
  19. * UINT32 ResultLineStep : Stride of output block.
  20. * UINT32 DataLineStep : Stride of input block.
  21. *
  22. * OUTPUTS : UINT8 *ResultPtr : Pointer to 8x8 output block.
  23. *
  24. * RETURNS : void
  25. *
  26. * FUNCTION : Saturates the input data to 8 bits unsigned and stores
  27. * in the output buffer.
  28. *
  29. * SPECIAL NOTES : None.
  30. *
  31. ****************************************************************************/
  32. void SatUnsigned8 ( UINT8 *ResultPtr, INT16 *DataBlock, UINT32 ResultLineStep, UINT32 DataLineStep )
  33. {
  34. INT32 i;
  35. // Partly expanded loop
  36. for ( i=0; i<BLOCK_HEIGHT_WIDTH; i++ )
  37. {
  38. ResultPtr[0] = (char) LIMIT(DataBlock[0]);
  39. ResultPtr[1] = (char) LIMIT(DataBlock[1]);
  40. ResultPtr[2] = (char) LIMIT(DataBlock[2]);
  41. ResultPtr[3] = (char) LIMIT(DataBlock[3]);
  42. ResultPtr[4] = (char) LIMIT(DataBlock[4]);
  43. ResultPtr[5] = (char) LIMIT(DataBlock[5]);
  44. ResultPtr[6] = (char) LIMIT(DataBlock[6]);
  45. ResultPtr[7] = (char) LIMIT(DataBlock[7]);
  46. DataBlock += DataLineStep;
  47. ResultPtr += ResultLineStep;
  48. }
  49. }
  50. /****************************************************************************
  51. *
  52. * ROUTINE : ScalarReconIntra
  53. *
  54. * INPUTS : INT16 *TmpDataBuffer : Pointer to 8x8 temporary buffer for internal use.
  55. * UINT16 *ChangePtr : Pointer to 8x8 intra prediction block.
  56. * UINT32 LineStep : Stride of reconstruction block.
  57. *
  58. * OUTPUTS : UINT8 *ReconPtr : Pointer to 8x8 block to hold reconstructed block.
  59. *
  60. * RETURNS : None
  61. *
  62. * FUNCTION : Reconstructs an intra block.
  63. *
  64. * SPECIAL NOTES : None.
  65. *
  66. ****************************************************************************/
  67. void ScalarReconIntra ( INT16 *TmpDataBuffer, UINT8 *ReconPtr, UINT16 *ChangePtr, UINT32 LineStep )
  68. {
  69. UINT32 i;
  70. INT16 *TmpDataPtr = TmpDataBuffer;
  71. for ( i=0; i<BLOCK_HEIGHT_WIDTH; i++ )
  72. {
  73. TmpDataPtr[0] = (INT16) ( ChangePtr[0] + 128 );
  74. TmpDataPtr[1] = (INT16) ( ChangePtr[1] + 128 );
  75. TmpDataPtr[2] = (INT16) ( ChangePtr[2] + 128 );
  76. TmpDataPtr[3] = (INT16) ( ChangePtr[3] + 128 );
  77. TmpDataPtr[4] = (INT16) ( ChangePtr[4] + 128 );
  78. TmpDataPtr[5] = (INT16) ( ChangePtr[5] + 128 );
  79. TmpDataPtr[6] = (INT16) ( ChangePtr[6] + 128 );
  80. TmpDataPtr[7] = (INT16) ( ChangePtr[7] + 128 );
  81. TmpDataPtr += BLOCK_HEIGHT_WIDTH;
  82. ChangePtr += BLOCK_HEIGHT_WIDTH;
  83. }
  84. // Saturate the output to unsigned 8 bit values in recon buffer
  85. SatUnsigned8 ( ReconPtr, TmpDataBuffer, LineStep, BLOCK_HEIGHT_WIDTH );
  86. }
  87. /****************************************************************************
  88. *
  89. * ROUTINE : ScalarReconInter
  90. *
  91. * INPUTS : INT16 *TmpDataBuffer : Pointer to 8x8 temporary buffer for internal use.
  92. * UINT8 *RefPtr : Pointer to 8x8 reference block.
  93. * INT16 *ChangePtr : Pointer to 8x8 inter prediction error block.
  94. * UINT32 LineStep : Stride of reference and output blocks.
  95. *
  96. * OUTPUTS : UINT8 *ReconPtr : Pointer to 8x8 block to hold reconstructed block.
  97. *
  98. * RETURNS : None
  99. *
  100. * FUNCTION : Reconstructs an inter-coded block by adding a prediction
  101. * error to a reference block in the previous frame
  102. * reconstruction buffer.
  103. *
  104. * SPECIAL NOTES : None.
  105. *
  106. ****************************************************************************/
  107. void ScalarReconInter ( INT16 *TmpDataBuffer, UINT8 *ReconPtr, UINT8 *RefPtr, INT16 *ChangePtr, UINT32 LineStep )
  108. {
  109. UINT32 i;
  110. INT16 *TmpDataPtr = TmpDataBuffer;
  111. for ( i=0; i<BLOCK_HEIGHT_WIDTH; i++ )
  112. {
  113. // Form each row
  114. TmpDataPtr[0] = (INT16)(RefPtr[0] + ChangePtr[0]);
  115. TmpDataPtr[1] = (INT16)(RefPtr[1] + ChangePtr[1]);
  116. TmpDataPtr[2] = (INT16)(RefPtr[2] + ChangePtr[2]);
  117. TmpDataPtr[3] = (INT16)(RefPtr[3] + ChangePtr[3]);
  118. TmpDataPtr[4] = (INT16)(RefPtr[4] + ChangePtr[4]);
  119. TmpDataPtr[5] = (INT16)(RefPtr[5] + ChangePtr[5]);
  120. TmpDataPtr[6] = (INT16)(RefPtr[6] + ChangePtr[6]);
  121. TmpDataPtr[7] = (INT16)(RefPtr[7] + ChangePtr[7]);
  122. // Next row of Block
  123. ChangePtr += BLOCK_HEIGHT_WIDTH;
  124. TmpDataPtr += BLOCK_HEIGHT_WIDTH;
  125. RefPtr += LineStep;
  126. }
  127. // Saturate the output to unsigned 8 bit values in recon buffer
  128. SatUnsigned8 ( ReconPtr, TmpDataBuffer, LineStep, BLOCK_HEIGHT_WIDTH );
  129. }
  130. /****************************************************************************
  131. *
  132. * ROUTINE : ScalarReconInterHalfPixel2
  133. *
  134. * INPUTS : INT16 *TmpDataBuffer : Pointer to 8x8 temporary buffer for internal use.
  135. * UINT8 *RefPtr1 : Pointer to first 8x8 reference block.
  136. * UINT8 *RefPtr2 : Pointer to second 8x8 reference block.
  137. * INT16 *ChangePtr : Pointer to 8x8 inter prediction error block.
  138. * UINT32 LineStep : Stride of reference blocks.
  139. *
  140. * OUTPUTS : UINT8 *ReconPtr : Pointer to 8x8 block to hold reconstructed block.
  141. *
  142. * RETURNS : None
  143. *
  144. * FUNCTION : Reconstructs an inter-coded block by adding a prediction
  145. * error to a reference block computed by averaging the two
  146. * specified reference blocks. The two reference blocks are
  147. * those that bracket the 1/2-pixel accuracy motion vector.
  148. *
  149. * SPECIAL NOTES : None.
  150. *
  151. ****************************************************************************/
  152. void ScalarReconInterHalfPixel2
  153. (
  154. INT16 *TmpDataBuffer,
  155. UINT8 *ReconPtr,
  156. UINT8 *RefPtr1,
  157. UINT8 *RefPtr2,
  158. INT16 *ChangePtr,
  159. UINT32 LineStep
  160. )
  161. {
  162. UINT32 i;
  163. INT16 *TmpDataPtr = TmpDataBuffer;
  164. for ( i=0; i<BLOCK_HEIGHT_WIDTH; i++ )
  165. {
  166. // Form each row
  167. TmpDataPtr[0] = (INT16)( (((INT32)RefPtr1[0] + (INT32)RefPtr2[0]) >> 1) + ChangePtr[0] );
  168. TmpDataPtr[1] = (INT16)( (((INT32)RefPtr1[1] + (INT32)RefPtr2[1]) >> 1) + ChangePtr[1] );
  169. TmpDataPtr[2] = (INT16)( (((INT32)RefPtr1[2] + (INT32)RefPtr2[2]) >> 1) + ChangePtr[2] );
  170. TmpDataPtr[3] = (INT16)( (((INT32)RefPtr1[3] + (INT32)RefPtr2[3]) >> 1) + ChangePtr[3] );
  171. TmpDataPtr[4] = (INT16)( (((INT32)RefPtr1[4] + (INT32)RefPtr2[4]) >> 1) + ChangePtr[4] );
  172. TmpDataPtr[5] = (INT16)( (((INT32)RefPtr1[5] + (INT32)RefPtr2[5]) >> 1) + ChangePtr[5] );
  173. TmpDataPtr[6] = (INT16)( (((INT32)RefPtr1[6] + (INT32)RefPtr2[6]) >> 1) + ChangePtr[6] );
  174. TmpDataPtr[7] = (INT16)( (((INT32)RefPtr1[7] + (INT32)RefPtr2[7]) >> 1) + ChangePtr[7] );
  175. // Next row of Block
  176. ChangePtr += BLOCK_HEIGHT_WIDTH;
  177. TmpDataPtr += BLOCK_HEIGHT_WIDTH;
  178. RefPtr1 += LineStep;
  179. RefPtr2 += LineStep;
  180. }
  181. // Saturate the output to unsigned 8 bit values in recon buffer
  182. SatUnsigned8( ReconPtr, TmpDataBuffer, LineStep, BLOCK_HEIGHT_WIDTH );
  183. }
  184. /****************************************************************************
  185. *
  186. * ROUTINE : ReconBlock_C
  187. *
  188. * INPUTS : INT16 *SrcBlock : Pointer to 8x8 prediction error.
  189. * INT16 *ReconRefPtr : Pointer to 8x8 block prediction.
  190. * UINT32 LineStep : Stride of output block.
  191. *
  192. * OUTPUTS : UINT8 *DestBlock : Pointer to 8x8 reconstructed block.
  193. *
  194. * RETURNS : void
  195. *
  196. * FUNCTION : Reconstrut a block by adding the prediction error
  197. * block to the source block and clipping values.
  198. *
  199. * SPECIAL NOTES : None.
  200. *
  201. ****************************************************************************/
  202. void ReconBlock_C ( INT16 *SrcBlock, INT16 *ReconRefPtr, UINT8 *DestBlock, UINT32 LineStep )
  203. {
  204. UINT32 i;
  205. INT16 *SrcBlockPtr = SrcBlock;
  206. // For each block row
  207. for ( i=0; i<BLOCK_HEIGHT_WIDTH; i++ )
  208. {
  209. SrcBlock[0] = (INT16)(SrcBlock[0] + ReconRefPtr[0]);
  210. SrcBlock[1] = (INT16)(SrcBlock[1] + ReconRefPtr[1]);
  211. SrcBlock[2] = (INT16)(SrcBlock[2] + ReconRefPtr[2]);
  212. SrcBlock[3] = (INT16)(SrcBlock[3] + ReconRefPtr[3]);
  213. SrcBlock[4] = (INT16)(SrcBlock[4] + ReconRefPtr[4]);
  214. SrcBlock[5] = (INT16)(SrcBlock[5] + ReconRefPtr[5]);
  215. SrcBlock[6] = (INT16)(SrcBlock[6] + ReconRefPtr[6]);
  216. SrcBlock[7] = (INT16)(SrcBlock[7] + ReconRefPtr[7]);
  217. // Next row...
  218. SrcBlock += BLOCK_HEIGHT_WIDTH;
  219. ReconRefPtr += BLOCK_HEIGHT_WIDTH;
  220. }
  221. // Saturate the output to unsigned 8 bit values in recon buffer
  222. SatUnsigned8( DestBlock, SrcBlockPtr, LineStep, BLOCK_HEIGHT_WIDTH );
  223. }