extend.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. memset(dest_ptr1, src_ptr1[0], el);
  38. memcpy(dest_ptr1 + el, src_ptr1, w);
  39. 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. memcpy(dest_ptr1, src_ptr1, linesize);
  56. dest_ptr1 += dp;
  57. }
  58. for (i = 0; i < eb; i++)
  59. {
  60. 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. void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
  89. YV12_BUFFER_CONFIG *dst,
  90. int srcy, int srcx,
  91. int srch, int srcw)
  92. {
  93. int et = dst->border;
  94. int el = dst->border;
  95. int eb = dst->border + dst->y_height - src->y_height;
  96. int er = dst->border + dst->y_width - src->y_width;
  97. int src_y_offset = srcy * src->y_stride + srcx;
  98. int dst_y_offset = srcy * dst->y_stride + srcx;
  99. int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
  100. int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
  101. /* If the side is not touching the bounder then don't extend. */
  102. if (srcy)
  103. et = 0;
  104. if (srcx)
  105. el = 0;
  106. if (srcy + srch != src->y_height)
  107. eb = 0;
  108. if (srcx + srcw != src->y_width)
  109. er = 0;
  110. copy_and_extend_plane(src->y_buffer + src_y_offset,
  111. src->y_stride,
  112. dst->y_buffer + dst_y_offset,
  113. dst->y_stride,
  114. srch, srcw,
  115. et, el, eb, er);
  116. et = (et + 1) >> 1;
  117. el = (el + 1) >> 1;
  118. eb = (eb + 1) >> 1;
  119. er = (er + 1) >> 1;
  120. srch = (srch + 1) >> 1;
  121. srcw = (srcw + 1) >> 1;
  122. copy_and_extend_plane(src->u_buffer + src_uv_offset,
  123. src->uv_stride,
  124. dst->u_buffer + dst_uv_offset,
  125. dst->uv_stride,
  126. srch, srcw,
  127. et, el, eb, er);
  128. copy_and_extend_plane(src->v_buffer + src_uv_offset,
  129. src->uv_stride,
  130. dst->v_buffer + dst_uv_offset,
  131. dst->uv_stride,
  132. srch, srcw,
  133. et, el, eb, er);
  134. }
  135. /* note the extension is only for the last row, for intra prediction purpose */
  136. void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf,
  137. unsigned char *YPtr,
  138. unsigned char *UPtr,
  139. unsigned char *VPtr)
  140. {
  141. int i;
  142. YPtr += ybf->y_stride * 14;
  143. UPtr += ybf->uv_stride * 6;
  144. VPtr += ybf->uv_stride * 6;
  145. for (i = 0; i < 4; i++)
  146. {
  147. YPtr[i] = YPtr[-1];
  148. UPtr[i] = UPtr[-1];
  149. VPtr[i] = VPtr[-1];
  150. }
  151. YPtr += ybf->y_stride;
  152. UPtr += ybf->uv_stride;
  153. VPtr += ybf->uv_stride;
  154. for (i = 0; i < 4; i++)
  155. {
  156. YPtr[i] = YPtr[-1];
  157. UPtr[i] = UPtr[-1];
  158. VPtr[i] = VPtr[-1];
  159. }
  160. }