/media/libvpx/vpx_scale/generic/yv12extend.c

http://github.com/zpao/v8monkey · C · 280 lines · 183 code · 46 blank · 51 comment · 12 complexity · d861b03b506dd17845b81c6399924123 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 "vpx_scale/yv12config.h"
  11. #include "vpx_mem/vpx_mem.h"
  12. #include "vpx_scale/vpxscale.h"
  13. /****************************************************************************
  14. * Exports
  15. ****************************************************************************/
  16. /****************************************************************************
  17. *
  18. ****************************************************************************/
  19. void
  20. vp8_yv12_extend_frame_borders(YV12_BUFFER_CONFIG *ybf)
  21. {
  22. int i;
  23. unsigned char *src_ptr1, *src_ptr2;
  24. unsigned char *dest_ptr1, *dest_ptr2;
  25. unsigned int Border;
  26. int plane_stride;
  27. int plane_height;
  28. int plane_width;
  29. /***********/
  30. /* Y Plane */
  31. /***********/
  32. Border = ybf->border;
  33. plane_stride = ybf->y_stride;
  34. plane_height = ybf->y_height;
  35. plane_width = ybf->y_width;
  36. /* copy the left and right most columns out */
  37. src_ptr1 = ybf->y_buffer;
  38. src_ptr2 = src_ptr1 + plane_width - 1;
  39. dest_ptr1 = src_ptr1 - Border;
  40. dest_ptr2 = src_ptr2 + 1;
  41. for (i = 0; i < plane_height; i++)
  42. {
  43. vpx_memset(dest_ptr1, src_ptr1[0], Border);
  44. vpx_memset(dest_ptr2, src_ptr2[0], Border);
  45. src_ptr1 += plane_stride;
  46. src_ptr2 += plane_stride;
  47. dest_ptr1 += plane_stride;
  48. dest_ptr2 += plane_stride;
  49. }
  50. /* Now copy the top and bottom source lines into each line of the respective borders */
  51. src_ptr1 = ybf->y_buffer - Border;
  52. src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
  53. dest_ptr1 = src_ptr1 - (Border * plane_stride);
  54. dest_ptr2 = src_ptr2 + plane_stride;
  55. for (i = 0; i < (int)Border; i++)
  56. {
  57. vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
  58. vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
  59. dest_ptr1 += plane_stride;
  60. dest_ptr2 += plane_stride;
  61. }
  62. /***********/
  63. /* U Plane */
  64. /***********/
  65. plane_stride = ybf->uv_stride;
  66. plane_height = ybf->uv_height;
  67. plane_width = ybf->uv_width;
  68. Border /= 2;
  69. /* copy the left and right most columns out */
  70. src_ptr1 = ybf->u_buffer;
  71. src_ptr2 = src_ptr1 + plane_width - 1;
  72. dest_ptr1 = src_ptr1 - Border;
  73. dest_ptr2 = src_ptr2 + 1;
  74. for (i = 0; i < plane_height; i++)
  75. {
  76. vpx_memset(dest_ptr1, src_ptr1[0], Border);
  77. vpx_memset(dest_ptr2, src_ptr2[0], Border);
  78. src_ptr1 += plane_stride;
  79. src_ptr2 += plane_stride;
  80. dest_ptr1 += plane_stride;
  81. dest_ptr2 += plane_stride;
  82. }
  83. /* Now copy the top and bottom source lines into each line of the respective borders */
  84. src_ptr1 = ybf->u_buffer - Border;
  85. src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
  86. dest_ptr1 = src_ptr1 - (Border * plane_stride);
  87. dest_ptr2 = src_ptr2 + plane_stride;
  88. for (i = 0; i < (int)(Border); i++)
  89. {
  90. vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
  91. vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
  92. dest_ptr1 += plane_stride;
  93. dest_ptr2 += plane_stride;
  94. }
  95. /***********/
  96. /* V Plane */
  97. /***********/
  98. /* copy the left and right most columns out */
  99. src_ptr1 = ybf->v_buffer;
  100. src_ptr2 = src_ptr1 + plane_width - 1;
  101. dest_ptr1 = src_ptr1 - Border;
  102. dest_ptr2 = src_ptr2 + 1;
  103. for (i = 0; i < plane_height; i++)
  104. {
  105. vpx_memset(dest_ptr1, src_ptr1[0], Border);
  106. vpx_memset(dest_ptr2, src_ptr2[0], Border);
  107. src_ptr1 += plane_stride;
  108. src_ptr2 += plane_stride;
  109. dest_ptr1 += plane_stride;
  110. dest_ptr2 += plane_stride;
  111. }
  112. /* Now copy the top and bottom source lines into each line of the respective borders */
  113. src_ptr1 = ybf->v_buffer - Border;
  114. src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
  115. dest_ptr1 = src_ptr1 - (Border * plane_stride);
  116. dest_ptr2 = src_ptr2 + plane_stride;
  117. for (i = 0; i < (int)(Border); i++)
  118. {
  119. vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
  120. vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
  121. dest_ptr1 += plane_stride;
  122. dest_ptr2 += plane_stride;
  123. }
  124. }
  125. static void
  126. extend_frame_borders_yonly(YV12_BUFFER_CONFIG *ybf)
  127. {
  128. int i;
  129. unsigned char *src_ptr1, *src_ptr2;
  130. unsigned char *dest_ptr1, *dest_ptr2;
  131. unsigned int Border;
  132. int plane_stride;
  133. int plane_height;
  134. int plane_width;
  135. /***********/
  136. /* Y Plane */
  137. /***********/
  138. Border = ybf->border;
  139. plane_stride = ybf->y_stride;
  140. plane_height = ybf->y_height;
  141. plane_width = ybf->y_width;
  142. /* copy the left and right most columns out */
  143. src_ptr1 = ybf->y_buffer;
  144. src_ptr2 = src_ptr1 + plane_width - 1;
  145. dest_ptr1 = src_ptr1 - Border;
  146. dest_ptr2 = src_ptr2 + 1;
  147. for (i = 0; i < plane_height; i++)
  148. {
  149. vpx_memset(dest_ptr1, src_ptr1[0], Border);
  150. vpx_memset(dest_ptr2, src_ptr2[0], Border);
  151. src_ptr1 += plane_stride;
  152. src_ptr2 += plane_stride;
  153. dest_ptr1 += plane_stride;
  154. dest_ptr2 += plane_stride;
  155. }
  156. /* Now copy the top and bottom source lines into each line of the respective borders */
  157. src_ptr1 = ybf->y_buffer - Border;
  158. src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
  159. dest_ptr1 = src_ptr1 - (Border * plane_stride);
  160. dest_ptr2 = src_ptr2 + plane_stride;
  161. for (i = 0; i < (int)Border; i++)
  162. {
  163. vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
  164. vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
  165. dest_ptr1 += plane_stride;
  166. dest_ptr2 += plane_stride;
  167. }
  168. plane_stride /= 2;
  169. plane_height /= 2;
  170. plane_width /= 2;
  171. Border /= 2;
  172. }
  173. /****************************************************************************
  174. *
  175. * ROUTINE : vp8_yv12_copy_frame
  176. *
  177. * INPUTS :
  178. *
  179. * OUTPUTS : None.
  180. *
  181. * RETURNS : void
  182. *
  183. * FUNCTION : Copies the source image into the destination image and
  184. * updates the destination's UMV borders.
  185. *
  186. * SPECIAL NOTES : The frames are assumed to be identical in size.
  187. *
  188. ****************************************************************************/
  189. void
  190. vp8_yv12_copy_frame(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc)
  191. {
  192. int row;
  193. unsigned char *source, *dest;
  194. source = src_ybc->y_buffer;
  195. dest = dst_ybc->y_buffer;
  196. for (row = 0; row < src_ybc->y_height; row++)
  197. {
  198. vpx_memcpy(dest, source, src_ybc->y_width);
  199. source += src_ybc->y_stride;
  200. dest += dst_ybc->y_stride;
  201. }
  202. source = src_ybc->u_buffer;
  203. dest = dst_ybc->u_buffer;
  204. for (row = 0; row < src_ybc->uv_height; row++)
  205. {
  206. vpx_memcpy(dest, source, src_ybc->uv_width);
  207. source += src_ybc->uv_stride;
  208. dest += dst_ybc->uv_stride;
  209. }
  210. source = src_ybc->v_buffer;
  211. dest = dst_ybc->v_buffer;
  212. for (row = 0; row < src_ybc->uv_height; row++)
  213. {
  214. vpx_memcpy(dest, source, src_ybc->uv_width);
  215. source += src_ybc->uv_stride;
  216. dest += dst_ybc->uv_stride;
  217. }
  218. vp8_yv12_extend_frame_borders_ptr(dst_ybc);
  219. }
  220. void
  221. vp8_yv12_copy_frame_yonly(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc)
  222. {
  223. int row;
  224. unsigned char *source, *dest;
  225. source = src_ybc->y_buffer;
  226. dest = dst_ybc->y_buffer;
  227. for (row = 0; row < src_ybc->y_height; row++)
  228. {
  229. vpx_memcpy(dest, source, src_ybc->y_width);
  230. source += src_ybc->y_stride;
  231. dest += dst_ybc->y_stride;
  232. }
  233. extend_frame_borders_yonly(dst_ybc);
  234. }