Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Krishna Rapaka | 7319db5 | 2021-09-28 20:35:29 -0700 | [diff] [blame] | 2 | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Vibhoothi | 41c6dd7 | 2021-10-12 18:48:26 +0000 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 3-Clause Clear License |
| 5 | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
| 6 | * License was not distributed with this source code in the LICENSE file, you |
| 7 | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
| 8 | * Alliance for Open Media Patent License 1.0 was not distributed with this |
| 9 | * source code in the PATENTS file, you can obtain it at |
| 10 | * aomedia.org/license/patent-license/. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <assert.h> |
| 14 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 15 | #include "config/aom_config.h" |
| 16 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "aom_scale/yv12config.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "aom_mem/aom_mem.h" |
| 19 | #include "aom_scale/aom_scale.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | |
| 21 | #if HAVE_DSPR2 |
| 22 | static void extend_plane(uint8_t *const src, int src_stride, int width, |
| 23 | int height, int extend_top, int extend_left, |
| 24 | int extend_bottom, int extend_right) { |
| 25 | int i, j; |
| 26 | uint8_t *left_src, *right_src; |
| 27 | uint8_t *left_dst_start, *right_dst_start; |
| 28 | uint8_t *left_dst, *right_dst; |
| 29 | uint8_t *top_src, *bot_src; |
| 30 | uint8_t *top_dst, *bot_dst; |
| 31 | uint32_t left_pix; |
| 32 | uint32_t right_pix; |
| 33 | uint32_t linesize; |
| 34 | |
| 35 | /* copy the left and right most columns out */ |
| 36 | left_src = src; |
| 37 | right_src = src + width - 1; |
| 38 | left_dst_start = src - extend_left; |
| 39 | right_dst_start = src + width; |
| 40 | |
| 41 | for (i = height; i--;) { |
| 42 | left_dst = left_dst_start; |
| 43 | right_dst = right_dst_start; |
| 44 | |
| 45 | __asm__ __volatile__( |
| 46 | "lb %[left_pix], 0(%[left_src]) \n\t" |
| 47 | "lb %[right_pix], 0(%[right_src]) \n\t" |
| 48 | "replv.qb %[left_pix], %[left_pix] \n\t" |
| 49 | "replv.qb %[right_pix], %[right_pix] \n\t" |
| 50 | |
| 51 | : [left_pix] "=&r"(left_pix), [right_pix] "=&r"(right_pix) |
| 52 | : [left_src] "r"(left_src), [right_src] "r"(right_src)); |
| 53 | |
| 54 | for (j = extend_left / 4; j--;) { |
| 55 | __asm__ __volatile__( |
| 56 | "sw %[left_pix], 0(%[left_dst]) \n\t" |
| 57 | "sw %[right_pix], 0(%[right_dst]) \n\t" |
| 58 | |
| 59 | : |
| 60 | : [left_dst] "r"(left_dst), [left_pix] "r"(left_pix), |
| 61 | [right_dst] "r"(right_dst), [right_pix] "r"(right_pix)); |
| 62 | |
| 63 | left_dst += 4; |
| 64 | right_dst += 4; |
| 65 | } |
| 66 | |
| 67 | for (j = extend_left % 4; j--;) { |
| 68 | __asm__ __volatile__( |
| 69 | "sb %[left_pix], 0(%[left_dst]) \n\t" |
| 70 | "sb %[right_pix], 0(%[right_dst]) \n\t" |
| 71 | |
| 72 | : |
| 73 | : [left_dst] "r"(left_dst), [left_pix] "r"(left_pix), |
| 74 | [right_dst] "r"(right_dst), [right_pix] "r"(right_pix)); |
| 75 | |
| 76 | left_dst += 1; |
| 77 | right_dst += 1; |
| 78 | } |
| 79 | |
| 80 | left_src += src_stride; |
| 81 | right_src += src_stride; |
| 82 | left_dst_start += src_stride; |
| 83 | right_dst_start += src_stride; |
| 84 | } |
| 85 | |
| 86 | /* Now copy the top and bottom lines into each line of the respective |
| 87 | * borders |
| 88 | */ |
| 89 | top_src = src - extend_left; |
| 90 | bot_src = src + src_stride * (height - 1) - extend_left; |
| 91 | top_dst = src + src_stride * (-extend_top) - extend_left; |
| 92 | bot_dst = src + src_stride * (height)-extend_left; |
| 93 | linesize = extend_left + extend_right + width; |
| 94 | |
| 95 | for (i = 0; i < extend_top; i++) { |
| 96 | memcpy(top_dst, top_src, linesize); |
| 97 | top_dst += src_stride; |
| 98 | } |
| 99 | |
| 100 | for (i = 0; i < extend_bottom; i++) { |
| 101 | memcpy(bot_dst, bot_src, linesize); |
| 102 | bot_dst += src_stride; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) { |
| 107 | const int c_w = ybf->uv_crop_width; |
| 108 | const int c_h = ybf->uv_crop_height; |
| 109 | const int ss_x = ybf->uv_width < ybf->y_width; |
| 110 | const int ss_y = ybf->uv_height < ybf->y_height; |
| 111 | const int c_et = ext_size >> ss_y; |
| 112 | const int c_el = ext_size >> ss_x; |
| 113 | const int c_eb = c_et + ybf->uv_height - ybf->uv_crop_height; |
| 114 | const int c_er = c_el + ybf->uv_width - ybf->uv_crop_width; |
| 115 | |
| 116 | assert(ybf->y_height - ybf->y_crop_height < 16); |
| 117 | assert(ybf->y_width - ybf->y_crop_width < 16); |
| 118 | assert(ybf->y_height - ybf->y_crop_height >= 0); |
| 119 | assert(ybf->y_width - ybf->y_crop_width >= 0); |
| 120 | |
| 121 | extend_plane(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width, |
| 122 | ybf->y_crop_height, ext_size, ext_size, |
| 123 | ext_size + ybf->y_height - ybf->y_crop_height, |
| 124 | ext_size + ybf->y_width - ybf->y_crop_width); |
| 125 | |
| 126 | extend_plane(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er); |
| 127 | |
| 128 | extend_plane(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er); |
| 129 | } |
| 130 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 131 | void aom_extend_frame_borders_dspr2(YV12_BUFFER_CONFIG *ybf, |
| 132 | const int num_planes) { |
| 133 | extend_frame(ybf, ybf->border, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 136 | void aom_extend_frame_inner_borders_dspr2(YV12_BUFFER_CONFIG *ybf, |
| 137 | const int num_planes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 138 | const int inner_bw = (ybf->border > AOMINNERBORDERINPIXELS) |
| 139 | ? AOMINNERBORDERINPIXELS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | : ybf->border; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 141 | extend_frame(ybf, inner_bw, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | } |
| 143 | #endif |