DeInterlaceWmt.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /****************************************************************************
  2. *
  3. * Module Title : DeInterlaceWmt.c
  4. *
  5. * Description : DeInterlace
  6. *
  7. ***************************************************************************/
  8. /****************************************************************************
  9. * Header Frames
  10. ****************************************************************************/
  11. #include "postp.h"
  12. /****************************************************************************
  13. * Module constants.
  14. ****************************************************************************/
  15. #if defined(_WIN32_WCE)
  16. #pragma pack(16)
  17. short Eight2s[] = { 2, 2, 2, 2, 2, 2, 2, 2 };
  18. #pragma pack()
  19. #else
  20. __declspec(align(16)) short Eight2s[] = { 2, 2, 2, 2, 2, 2, 2, 2 };
  21. #endif
  22. /****************************************************************************
  23. *
  24. * ROUTINE : WmtFastDeInterlace
  25. *
  26. * INPUTS : UINT8 *SrcPtr : Pointer to input frame.
  27. * UINT8 *DstPtr : Pointer to output frame.
  28. * INT32 Width : Width of frame in pixels.
  29. * INT32 Height : Height of frame in pixels.
  30. * INT32 Stride : Stride of images.
  31. *
  32. * OUTPUTS : None.
  33. *
  34. * RETURNS : void
  35. *
  36. * FUNCTION : Applies a 3 tap filter vertically to remove interlacing
  37. * artifacts.
  38. *
  39. * SPECIAL NOTES : This function use a three tap filter [1, 2, 1] to blur
  40. * veritically in an interlaced frame. This function assumes:
  41. * 1) Buffers SrcPtr and DstPtr point to have the same geometery,
  42. * 2) SrcPtr and DstPtr can _not_ be same.
  43. *
  44. ****************************************************************************/
  45. void WmtFastDeInterlace
  46. (
  47. UINT8 *SrcPtr,
  48. UINT8 *DstPtr,
  49. INT32 Width,
  50. INT32 Height,
  51. INT32 Stride
  52. )
  53. {
  54. INT32 i;
  55. UINT8 *CurrentSrcPtr = SrcPtr;
  56. UINT8 *CurrentDstPtr = DstPtr;
  57. #if defined(_WIN32_WCE)
  58. return;
  59. #else
  60. // Always copy the first line
  61. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  62. for ( i=1; i<Height-1; i++ )
  63. {
  64. CurrentDstPtr += Stride;
  65. __asm
  66. {
  67. mov esi, [CurrentSrcPtr]
  68. mov edi, [CurrentDstPtr]
  69. xor ecx, ecx
  70. mov edx, [Stride]
  71. lea eax, [esi + edx]
  72. lea edx, [eax + edx]
  73. mov ebx, [Width]
  74. pxor xmm7, xmm7
  75. WmtDeInterlaceLoop:
  76. movq xmm0, QWORD ptr [esi + ecx]
  77. movq xmm1, QWORD ptr [eax + ecx]
  78. punpcklbw xmm0, xmm7
  79. movq xmm2, QWORD ptr [edx + ecx]
  80. punpcklbw xmm1, xmm7
  81. paddw xmm0, Eight2s
  82. psllw xmm1, 1
  83. punpcklbw xmm2, xmm7
  84. paddw xmm0, xmm1
  85. paddw xmm0, xmm2
  86. psraw xmm0, 2
  87. packuswb xmm0, xmm7
  88. movq QWORD ptr [edi+ecx], xmm0
  89. add ecx, 8
  90. cmp ecx, ebx
  91. jl WmtDeInterlaceLoop
  92. }
  93. CurrentSrcPtr += Stride;
  94. /*
  95. for(j=0;j<Width;j++)
  96. {
  97. x0 = PrevSrcPtr[j];
  98. x1 = (CurrentSrcPtr[j]<<1);
  99. x2 = NextSrcPtr[j];
  100. CurrentDstPtr[j] = (UINT8)( (x0 + x1 + x2)>>2 );
  101. }
  102. */
  103. }
  104. //copy the last line
  105. CurrentSrcPtr += Stride;
  106. CurrentDstPtr += Stride;
  107. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  108. #endif
  109. }