/media/libvpx/vp8/common/extend.c

http://github.com/zpao/v8monkey · C · 131 lines · 96 code · 21 blank · 14 comment · 5 complexity · 7e7d5945601c344967254c9c30fd8e81 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "extend.h"
  11. #include "vpx_mem/vpx_mem.h"
  12. static void copy_and_extend_plane
  13. (
  14. unsigned char *s, /* source */
  15. int sp, /* source pitch */
  16. unsigned char *d, /* destination */
  17. int dp, /* destination pitch */
  18. int h, /* height */
  19. int w, /* width */
  20. int et, /* extend top border */
  21. int el, /* extend left border */
  22. int eb, /* extend bottom border */
  23. int er /* extend right border */
  24. )
  25. {
  26. int i;
  27. unsigned char *src_ptr1, *src_ptr2;
  28. unsigned char *dest_ptr1, *dest_ptr2;
  29. int linesize;
  30. /* copy the left and right most columns out */
  31. src_ptr1 = s;
  32. src_ptr2 = s + w - 1;
  33. dest_ptr1 = d - el;
  34. dest_ptr2 = d + w;
  35. for (i = 0; i < h; i++)
  36. {
  37. vpx_memset(dest_ptr1, src_ptr1[0], el);
  38. vpx_memcpy(dest_ptr1 + el, src_ptr1, w);
  39. vpx_memset(dest_ptr2, src_ptr2[0], er);
  40. src_ptr1 += sp;
  41. src_ptr2 += sp;
  42. dest_ptr1 += dp;
  43. dest_ptr2 += dp;
  44. }
  45. /* Now copy the top and bottom lines into each line of the respective
  46. * borders
  47. */
  48. src_ptr1 = d - el;
  49. src_ptr2 = d + dp * (h - 1) - el;
  50. dest_ptr1 = d + dp * (-et) - el;
  51. dest_ptr2 = d + dp * (h) - el;
  52. linesize = el + er + w;
  53. for (i = 0; i < et; i++)
  54. {
  55. vpx_memcpy(dest_ptr1, src_ptr1, linesize);
  56. dest_ptr1 += dp;
  57. }
  58. for (i = 0; i < eb; i++)
  59. {
  60. vpx_memcpy(dest_ptr2, src_ptr2, linesize);
  61. dest_ptr2 += dp;
  62. }
  63. }
  64. void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
  65. YV12_BUFFER_CONFIG *dst)
  66. {
  67. int et = dst->border;
  68. int el = dst->border;
  69. int eb = dst->border + dst->y_height - src->y_height;
  70. int er = dst->border + dst->y_width - src->y_width;
  71. copy_and_extend_plane(src->y_buffer, src->y_stride,
  72. dst->y_buffer, dst->y_stride,
  73. src->y_height, src->y_width,
  74. et, el, eb, er);
  75. et = dst->border >> 1;
  76. el = dst->border >> 1;
  77. eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
  78. er = (dst->border >> 1) + dst->uv_width - src->uv_width;
  79. copy_and_extend_plane(src->u_buffer, src->uv_stride,
  80. dst->u_buffer, dst->uv_stride,
  81. src->uv_height, src->uv_width,
  82. et, el, eb, er);
  83. copy_and_extend_plane(src->v_buffer, src->uv_stride,
  84. dst->v_buffer, dst->uv_stride,
  85. src->uv_height, src->uv_width,
  86. et, el, eb, er);
  87. }
  88. /* note the extension is only for the last row, for intra prediction purpose */
  89. void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr)
  90. {
  91. int i;
  92. YPtr += ybf->y_stride * 14;
  93. UPtr += ybf->uv_stride * 6;
  94. VPtr += ybf->uv_stride * 6;
  95. for (i = 0; i < 4; i++)
  96. {
  97. YPtr[i] = YPtr[-1];
  98. UPtr[i] = UPtr[-1];
  99. VPtr[i] = VPtr[-1];
  100. }
  101. YPtr += ybf->y_stride;
  102. UPtr += ybf->uv_stride;
  103. VPtr += ybf->uv_stride;
  104. for (i = 0; i < 4; i++)
  105. {
  106. YPtr[i] = YPtr[-1];
  107. UPtr[i] = UPtr[-1];
  108. VPtr[i] = VPtr[-1];
  109. }
  110. }