DeInterlace.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /****************************************************************************
  2. *
  3. * Module Title : DeInterlace.c
  4. *
  5. * Description : De-Interlace routines.
  6. *
  7. ***************************************************************************/
  8. /****************************************************************************
  9. * Header Files
  10. ****************************************************************************/
  11. #include <memory.h>
  12. #include "type_aliases.h"
  13. /****************************************************************************
  14. *
  15. * ROUTINE : CFastDeInterlace
  16. *
  17. * INPUTS : UINT8 *SrcPtr : Pointer to input image.
  18. * UINT8 *DstPtr : Pointer to output image.
  19. * INT32 Width : Image width.
  20. * INT32 Height : Image height.
  21. * INT32 Stride : Image stride.
  22. *
  23. * OUTPUTS : None.
  24. *
  25. * RETURNS : void
  26. *
  27. * FUNCTION : Applies a 3-tap filter vertically to remove interlacing
  28. * artifacts.
  29. *
  30. * SPECIAL NOTES : This function use a three tap filter [1, 2, 1] to blur
  31. * veritically in an interlaced frame. This function assumes:
  32. * 1) SrcPtr & DstPtr buffers have the same geometry.
  33. * 2) SrcPtr != DstPtr.
  34. *
  35. ****************************************************************************/
  36. void CFastDeInterlace
  37. (
  38. UINT8 *SrcPtr,
  39. UINT8 *DstPtr,
  40. INT32 Width,
  41. INT32 Height,
  42. INT32 Stride
  43. )
  44. {
  45. INT32 i, j;
  46. UINT32 x0, x1, x2;
  47. UINT8 *PrevSrcPtr, *NextSrcPtr;
  48. UINT8 *CurrentSrcPtr = SrcPtr;
  49. UINT8 *CurrentDstPtr = DstPtr;
  50. // Always copy the first line
  51. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  52. for ( i=1; i<Height-1; i++ )
  53. {
  54. PrevSrcPtr = CurrentSrcPtr;
  55. CurrentSrcPtr += Stride;
  56. NextSrcPtr = CurrentSrcPtr + Stride;
  57. CurrentDstPtr += Stride;
  58. for ( j=0; j<Width; j++ )
  59. {
  60. x0 = PrevSrcPtr[j];
  61. x1 = (CurrentSrcPtr[j]<<1);
  62. x2 = NextSrcPtr[j];
  63. CurrentDstPtr[j] = (UINT8)( (x0 + x1 + x2 + 2)>>2 );
  64. }
  65. }
  66. // Copy the last line
  67. CurrentSrcPtr += Stride;
  68. CurrentDstPtr += Stride;
  69. memcpy ( CurrentDstPtr, CurrentSrcPtr, Width );
  70. }