extend.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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(unsigned char *s, /* source */
  13. int sp, /* source pitch */
  14. unsigned char *d, /* destination */
  15. int dp, /* destination pitch */
  16. int h, /* height */
  17. int w, /* width */
  18. int et, /* extend top border */
  19. int el, /* extend left border */
  20. int eb, /* extend bottom border */
  21. int er) { /* extend right border */
  22. int i;
  23. unsigned char *src_ptr1, *src_ptr2;
  24. unsigned char *dest_ptr1, *dest_ptr2;
  25. int linesize;
  26. /* copy the left and right most columns out */
  27. src_ptr1 = s;
  28. src_ptr2 = s + w - 1;
  29. dest_ptr1 = d - el;
  30. dest_ptr2 = d + w;
  31. for (i = 0; i < h; ++i) {
  32. memset(dest_ptr1, src_ptr1[0], el);
  33. memcpy(dest_ptr1 + el, src_ptr1, w);
  34. memset(dest_ptr2, src_ptr2[0], er);
  35. src_ptr1 += sp;
  36. src_ptr2 += sp;
  37. dest_ptr1 += dp;
  38. dest_ptr2 += dp;
  39. }
  40. /* Now copy the top and bottom lines into each line of the respective
  41. * borders
  42. */
  43. src_ptr1 = d - el;
  44. src_ptr2 = d + dp * (h - 1) - el;
  45. dest_ptr1 = d + dp * (-et) - el;
  46. dest_ptr2 = d + dp * (h)-el;
  47. linesize = el + er + w;
  48. for (i = 0; i < et; ++i) {
  49. memcpy(dest_ptr1, src_ptr1, linesize);
  50. dest_ptr1 += dp;
  51. }
  52. for (i = 0; i < eb; ++i) {
  53. memcpy(dest_ptr2, src_ptr2, linesize);
  54. dest_ptr2 += dp;
  55. }
  56. }
  57. void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
  58. YV12_BUFFER_CONFIG *dst) {
  59. int et = dst->border;
  60. int el = dst->border;
  61. int eb = dst->border + dst->y_height - src->y_height;
  62. int er = dst->border + dst->y_width - src->y_width;
  63. copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer,
  64. dst->y_stride, src->y_height, src->y_width, et, el, eb,
  65. er);
  66. et = dst->border >> 1;
  67. el = dst->border >> 1;
  68. eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
  69. er = (dst->border >> 1) + dst->uv_width - src->uv_width;
  70. copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer,
  71. dst->uv_stride, src->uv_height, src->uv_width, et, el,
  72. eb, er);
  73. copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer,
  74. dst->uv_stride, src->uv_height, src->uv_width, et, el,
  75. eb, er);
  76. }
  77. void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
  78. YV12_BUFFER_CONFIG *dst, int srcy,
  79. int srcx, int srch, int srcw) {
  80. int et = dst->border;
  81. int el = dst->border;
  82. int eb = dst->border + dst->y_height - src->y_height;
  83. int er = dst->border + dst->y_width - src->y_width;
  84. int src_y_offset = srcy * src->y_stride + srcx;
  85. int dst_y_offset = srcy * dst->y_stride + srcx;
  86. int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
  87. int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
  88. /* If the side is not touching the bounder then don't extend. */
  89. if (srcy) et = 0;
  90. if (srcx) el = 0;
  91. if (srcy + srch != src->y_height) eb = 0;
  92. if (srcx + srcw != src->y_width) er = 0;
  93. copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride,
  94. dst->y_buffer + dst_y_offset, dst->y_stride, srch, srcw,
  95. et, el, eb, er);
  96. et = (et + 1) >> 1;
  97. el = (el + 1) >> 1;
  98. eb = (eb + 1) >> 1;
  99. er = (er + 1) >> 1;
  100. srch = (srch + 1) >> 1;
  101. srcw = (srcw + 1) >> 1;
  102. copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride,
  103. dst->u_buffer + dst_uv_offset, dst->uv_stride, srch,
  104. srcw, et, el, eb, er);
  105. copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride,
  106. dst->v_buffer + dst_uv_offset, dst->uv_stride, srch,
  107. srcw, et, el, eb, er);
  108. }
  109. /* note the extension is only for the last row, for intra prediction purpose */
  110. void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr,
  111. unsigned char *UPtr, unsigned char *VPtr) {
  112. int i;
  113. YPtr += ybf->y_stride * 14;
  114. UPtr += ybf->uv_stride * 6;
  115. VPtr += ybf->uv_stride * 6;
  116. for (i = 0; i < 4; ++i) {
  117. YPtr[i] = YPtr[-1];
  118. UPtr[i] = UPtr[-1];
  119. VPtr[i] = VPtr[-1];
  120. }
  121. YPtr += ybf->y_stride;
  122. UPtr += ybf->uv_stride;
  123. VPtr += ybf->uv_stride;
  124. for (i = 0; i < 4; ++i) {
  125. YPtr[i] = YPtr[-1];
  126. UPtr[i] = UPtr[-1];
  127. VPtr[i] = VPtr[-1];
  128. }
  129. }