DeInterlaceMmx.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /****************************************************************************
  2. *
  3. * Module Title : DeInterlaceWmt.c
  4. *
  5. * Description : DeInterlace Routines
  6. *
  7. ***************************************************************************/
  8. /****************************************************************************
  9. * Header Files
  10. ****************************************************************************/
  11. #include "postp.h"
  12. /****************************************************************************
  13. * Module constants.
  14. ****************************************************************************/
  15. #if defined(_WIN32_WCE)
  16. #pragma pack(16)
  17. short four2s[] = { 2, 2, 2, 2 };
  18. #pragma pack()
  19. #else
  20. __declspec(align(16)) short four2s[] = { 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 MmxFastDeInterlace
  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. // Always copy the first line
  58. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  59. for ( i=1; i<Height-1; i++ )
  60. {
  61. CurrentDstPtr += Stride;
  62. __asm
  63. {
  64. mov esi, [CurrentSrcPtr]
  65. mov edi, [CurrentDstPtr]
  66. xor ecx, ecx
  67. mov edx, [Stride]
  68. lea eax, [esi + edx]
  69. lea edx, [eax + edx]
  70. mov ebx, [Width]
  71. pxor mm7, mm7
  72. MmxDeInterlaceLoop:
  73. movq mm0, QWORD ptr [esi + ecx] // line -1
  74. movq mm1, QWORD ptr [eax + ecx] // line 0
  75. movq mm3, mm0 // line -1
  76. punpcklbw mm0, mm7 // line -1 low
  77. movq mm2, QWORD ptr [edx + ecx] // line 1
  78. punpckhbw mm3, mm7 // line -1 high
  79. movq mm4, mm1 // line 0
  80. punpcklbw mm1, mm7 // line 0 low
  81. paddw mm0, four2s // line -1 low + 2s
  82. paddw mm3, four2s // line -1 high + 2s
  83. punpckhbw mm4, mm7 // line 0 high
  84. psllw mm1, 1 // line 0 * 2
  85. psllw mm4, 1 // line 0 * 2
  86. movq mm5, mm2 // line 1
  87. punpcklbw mm2, mm7 // line 1 low
  88. paddw mm0, mm1 // line -1 + line 0 * 2
  89. paddw mm3, mm4 // line -1 + line 0 * 2
  90. punpckhbw mm5, mm7 // line 1 high
  91. paddw mm0, mm2 // -1 + 0 * 2 + 1
  92. paddw mm3, mm5 // -1 + 0 * 2 + 1
  93. psraw mm0, 2 // >> 2
  94. psraw mm3, 2 // >> 2
  95. packuswb mm0, mm3
  96. movq QWORD ptr [edi+ecx], mm0
  97. add ecx, 8
  98. cmp ecx, ebx
  99. jl MmxDeInterlaceLoop
  100. }
  101. CurrentSrcPtr += Stride;
  102. /*
  103. for(j=0;j<Width;j++)
  104. {
  105. x0 = PrevSrcPtr[j];
  106. x1 = (CurrentSrcPtr[j]<<1);
  107. x2 = NextSrcPtr[j];
  108. CurrentDstPtr[j] = (UINT8)( (x0 + x1 + x2)>>2 );
  109. }
  110. */
  111. }
  112. // copy the last line
  113. CurrentSrcPtr += Stride;
  114. CurrentDstPtr += Stride;
  115. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  116. }