yv12extend_dspr2.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2013 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 <assert.h>
  11. #include "./vpx_config.h"
  12. #include "vpx_scale/yv12config.h"
  13. #include "vpx_mem/vpx_mem.h"
  14. #include "vpx_scale/vpx_scale.h"
  15. #if HAVE_DSPR2
  16. static void extend_plane(uint8_t *const src, int src_stride, int width,
  17. int height, int extend_top, int extend_left,
  18. int extend_bottom, int extend_right) {
  19. int i, j;
  20. uint8_t *left_src, *right_src;
  21. uint8_t *left_dst_start, *right_dst_start;
  22. uint8_t *left_dst, *right_dst;
  23. uint8_t *top_src, *bot_src;
  24. uint8_t *top_dst, *bot_dst;
  25. uint32_t left_pix;
  26. uint32_t right_pix;
  27. uint32_t linesize;
  28. /* copy the left and right most columns out */
  29. left_src = src;
  30. right_src = src + width - 1;
  31. left_dst_start = src - extend_left;
  32. right_dst_start = src + width;
  33. for (i = height; i--;) {
  34. left_dst = left_dst_start;
  35. right_dst = right_dst_start;
  36. __asm__ __volatile__(
  37. "lb %[left_pix], 0(%[left_src]) \n\t"
  38. "lb %[right_pix], 0(%[right_src]) \n\t"
  39. "replv.qb %[left_pix], %[left_pix] \n\t"
  40. "replv.qb %[right_pix], %[right_pix] \n\t"
  41. : [left_pix] "=&r"(left_pix), [right_pix] "=&r"(right_pix)
  42. : [left_src] "r"(left_src), [right_src] "r"(right_src));
  43. for (j = extend_left / 4; j--;) {
  44. __asm__ __volatile__(
  45. "sw %[left_pix], 0(%[left_dst]) \n\t"
  46. "sw %[right_pix], 0(%[right_dst]) \n\t"
  47. :
  48. : [left_dst] "r"(left_dst), [left_pix] "r"(left_pix),
  49. [right_dst] "r"(right_dst), [right_pix] "r"(right_pix));
  50. left_dst += 4;
  51. right_dst += 4;
  52. }
  53. for (j = extend_left % 4; j--;) {
  54. __asm__ __volatile__(
  55. "sb %[left_pix], 0(%[left_dst]) \n\t"
  56. "sb %[right_pix], 0(%[right_dst]) \n\t"
  57. :
  58. : [left_dst] "r"(left_dst), [left_pix] "r"(left_pix),
  59. [right_dst] "r"(right_dst), [right_pix] "r"(right_pix));
  60. left_dst += 1;
  61. right_dst += 1;
  62. }
  63. left_src += src_stride;
  64. right_src += src_stride;
  65. left_dst_start += src_stride;
  66. right_dst_start += src_stride;
  67. }
  68. /* Now copy the top and bottom lines into each line of the respective
  69. * borders
  70. */
  71. top_src = src - extend_left;
  72. bot_src = src + src_stride * (height - 1) - extend_left;
  73. top_dst = src + src_stride * (-extend_top) - extend_left;
  74. bot_dst = src + src_stride * (height)-extend_left;
  75. linesize = extend_left + extend_right + width;
  76. for (i = 0; i < extend_top; i++) {
  77. memcpy(top_dst, top_src, linesize);
  78. top_dst += src_stride;
  79. }
  80. for (i = 0; i < extend_bottom; i++) {
  81. memcpy(bot_dst, bot_src, linesize);
  82. bot_dst += src_stride;
  83. }
  84. }
  85. static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
  86. const int c_w = ybf->uv_crop_width;
  87. const int c_h = ybf->uv_crop_height;
  88. const int ss_x = ybf->uv_width < ybf->y_width;
  89. const int ss_y = ybf->uv_height < ybf->y_height;
  90. const int c_et = ext_size >> ss_y;
  91. const int c_el = ext_size >> ss_x;
  92. const int c_eb = c_et + ybf->uv_height - ybf->uv_crop_height;
  93. const int c_er = c_el + ybf->uv_width - ybf->uv_crop_width;
  94. assert(ybf->y_height - ybf->y_crop_height < 16);
  95. assert(ybf->y_width - ybf->y_crop_width < 16);
  96. assert(ybf->y_height - ybf->y_crop_height >= 0);
  97. assert(ybf->y_width - ybf->y_crop_width >= 0);
  98. extend_plane(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width,
  99. ybf->y_crop_height, ext_size, ext_size,
  100. ext_size + ybf->y_height - ybf->y_crop_height,
  101. ext_size + ybf->y_width - ybf->y_crop_width);
  102. extend_plane(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er);
  103. extend_plane(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er);
  104. }
  105. void vpx_extend_frame_borders_dspr2(YV12_BUFFER_CONFIG *ybf) {
  106. extend_frame(ybf, ybf->border);
  107. }
  108. void vpx_extend_frame_inner_borders_dspr2(YV12_BUFFER_CONFIG *ybf) {
  109. const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS)
  110. ? VP9INNERBORDERINPIXELS
  111. : ybf->border;
  112. extend_frame(ybf, inner_bw);
  113. }
  114. #endif