/src/libvpx/vp9/encoder/vp9_extend.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
11 | | #include "vpx_dsp/vpx_dsp_common.h" |
12 | | #include "vpx_mem/vpx_mem.h" |
13 | | #include "vpx_ports/mem.h" |
14 | | |
15 | | #include "vp9/common/vp9_common.h" |
16 | | #include "vp9/encoder/vp9_extend.h" |
17 | | |
18 | | static void copy_and_extend_plane(const uint8_t *src, int src_pitch, |
19 | | uint8_t *dst, int dst_pitch, int w, int h, |
20 | | int extend_top, int extend_left, |
21 | | int extend_bottom, int extend_right, |
22 | 128k | int interleave_step) { |
23 | 128k | int i, j, linesize; |
24 | 128k | const int step = interleave_step < 1 ? 1 : interleave_step; |
25 | | |
26 | | // copy the left and right most columns out |
27 | 128k | const uint8_t *src_ptr1 = src; |
28 | 128k | const uint8_t *src_ptr2 = src + (w - 1) * step; |
29 | 128k | uint8_t *dst_ptr1 = dst - extend_left; |
30 | 128k | uint8_t *dst_ptr2 = dst + w; |
31 | | |
32 | 5.85M | for (i = 0; i < h; i++) { |
33 | 5.72M | memset(dst_ptr1, src_ptr1[0], extend_left); |
34 | 5.72M | if (step == 1) { |
35 | 5.72M | memcpy(dst_ptr1 + extend_left, src_ptr1, w); |
36 | 5.72M | } else { |
37 | 0 | for (j = 0; j < w; j++) { |
38 | 0 | dst_ptr1[extend_left + j] = src_ptr1[step * j]; |
39 | 0 | } |
40 | 0 | } |
41 | 5.72M | memset(dst_ptr2, src_ptr2[0], extend_right); |
42 | 5.72M | src_ptr1 += src_pitch; |
43 | 5.72M | src_ptr2 += src_pitch; |
44 | 5.72M | dst_ptr1 += dst_pitch; |
45 | 5.72M | dst_ptr2 += dst_pitch; |
46 | 5.72M | } |
47 | | |
48 | | // Now copy the top and bottom lines into each line of the respective |
49 | | // borders |
50 | 128k | src_ptr1 = dst - extend_left; |
51 | 128k | src_ptr2 = dst + dst_pitch * (h - 1) - extend_left; |
52 | 128k | dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left; |
53 | 128k | dst_ptr2 = dst + dst_pitch * (h)-extend_left; |
54 | 128k | linesize = extend_left + extend_right + w; |
55 | | |
56 | 1.52M | for (i = 0; i < extend_top; i++) { |
57 | 1.39M | memcpy(dst_ptr1, src_ptr1, linesize); |
58 | 1.39M | dst_ptr1 += dst_pitch; |
59 | 1.39M | } |
60 | | |
61 | 2.35M | for (i = 0; i < extend_bottom; i++) { |
62 | 2.22M | memcpy(dst_ptr2, src_ptr2, linesize); |
63 | 2.22M | dst_ptr2 += dst_pitch; |
64 | 2.22M | } |
65 | 128k | } |
66 | | |
67 | | #if CONFIG_VP9_HIGHBITDEPTH |
68 | | static void highbd_copy_and_extend_plane(const uint8_t *src8, int src_pitch, |
69 | | uint8_t *dst8, int dst_pitch, int w, |
70 | | int h, int extend_top, int extend_left, |
71 | 0 | int extend_bottom, int extend_right) { |
72 | 0 | int i, linesize; |
73 | 0 | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
74 | 0 | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
75 | | |
76 | | // copy the left and right most columns out |
77 | 0 | const uint16_t *src_ptr1 = src; |
78 | 0 | const uint16_t *src_ptr2 = src + w - 1; |
79 | 0 | uint16_t *dst_ptr1 = dst - extend_left; |
80 | 0 | uint16_t *dst_ptr2 = dst + w; |
81 | |
|
82 | 0 | for (i = 0; i < h; i++) { |
83 | 0 | vpx_memset16(dst_ptr1, src_ptr1[0], extend_left); |
84 | 0 | memcpy(dst_ptr1 + extend_left, src_ptr1, w * sizeof(src_ptr1[0])); |
85 | 0 | vpx_memset16(dst_ptr2, src_ptr2[0], extend_right); |
86 | 0 | src_ptr1 += src_pitch; |
87 | 0 | src_ptr2 += src_pitch; |
88 | 0 | dst_ptr1 += dst_pitch; |
89 | 0 | dst_ptr2 += dst_pitch; |
90 | 0 | } |
91 | | |
92 | | // Now copy the top and bottom lines into each line of the respective |
93 | | // borders |
94 | 0 | src_ptr1 = dst - extend_left; |
95 | 0 | src_ptr2 = dst + dst_pitch * (h - 1) - extend_left; |
96 | 0 | dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left; |
97 | 0 | dst_ptr2 = dst + dst_pitch * (h)-extend_left; |
98 | 0 | linesize = extend_left + extend_right + w; |
99 | |
|
100 | 0 | for (i = 0; i < extend_top; i++) { |
101 | 0 | memcpy(dst_ptr1, src_ptr1, linesize * sizeof(src_ptr1[0])); |
102 | 0 | dst_ptr1 += dst_pitch; |
103 | 0 | } |
104 | |
|
105 | 0 | for (i = 0; i < extend_bottom; i++) { |
106 | 0 | memcpy(dst_ptr2, src_ptr2, linesize * sizeof(src_ptr2[0])); |
107 | 0 | dst_ptr2 += dst_pitch; |
108 | 0 | } |
109 | 0 | } |
110 | | #endif // CONFIG_VP9_HIGHBITDEPTH |
111 | | |
112 | | void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, |
113 | 42.7k | YV12_BUFFER_CONFIG *dst) { |
114 | | // Extend src frame in buffer |
115 | | // Altref filtering assumes 16 pixel extension |
116 | 42.7k | const int et_y = 16; |
117 | 42.7k | const int el_y = 16; |
118 | | // Motion estimation may use src block variance with the block size up |
119 | | // to 64x64, so the right and bottom need to be extended to 64 multiple |
120 | | // or up to 16, whichever is greater. |
121 | 42.7k | const int er_y = |
122 | 42.7k | VPXMAX(src->y_width + 16, ALIGN_POWER_OF_TWO(src->y_width, 6)) - |
123 | 42.7k | src->y_crop_width; |
124 | 42.7k | const int eb_y = |
125 | 42.7k | VPXMAX(src->y_height + 16, ALIGN_POWER_OF_TWO(src->y_height, 6)) - |
126 | 42.7k | src->y_crop_height; |
127 | 42.7k | const int uv_width_subsampling = (src->uv_width != src->y_width); |
128 | 42.7k | const int uv_height_subsampling = (src->uv_height != src->y_height); |
129 | 42.7k | const int et_uv = et_y >> uv_height_subsampling; |
130 | 42.7k | const int el_uv = el_y >> uv_width_subsampling; |
131 | 42.7k | const int eb_uv = eb_y >> uv_height_subsampling; |
132 | 42.7k | const int er_uv = er_y >> uv_width_subsampling; |
133 | | // detect nv12 colorspace |
134 | 42.7k | const int chroma_step = src->v_buffer - src->u_buffer == 1 ? 2 : 1; |
135 | | |
136 | 42.7k | #if CONFIG_VP9_HIGHBITDEPTH |
137 | 42.7k | if (src->flags & YV12_FLAG_HIGHBITDEPTH) { |
138 | 0 | highbd_copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer, |
139 | 0 | dst->y_stride, src->y_crop_width, |
140 | 0 | src->y_crop_height, et_y, el_y, eb_y, er_y); |
141 | |
|
142 | 0 | highbd_copy_and_extend_plane( |
143 | 0 | src->u_buffer, src->uv_stride, dst->u_buffer, dst->uv_stride, |
144 | 0 | src->uv_crop_width, src->uv_crop_height, et_uv, el_uv, eb_uv, er_uv); |
145 | |
|
146 | 0 | highbd_copy_and_extend_plane( |
147 | 0 | src->v_buffer, src->uv_stride, dst->v_buffer, dst->uv_stride, |
148 | 0 | src->uv_crop_width, src->uv_crop_height, et_uv, el_uv, eb_uv, er_uv); |
149 | 0 | return; |
150 | 0 | } |
151 | 42.7k | #endif // CONFIG_VP9_HIGHBITDEPTH |
152 | | |
153 | 42.7k | copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer, |
154 | 42.7k | dst->y_stride, src->y_crop_width, src->y_crop_height, |
155 | 42.7k | et_y, el_y, eb_y, er_y, 1); |
156 | | |
157 | 42.7k | copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer, |
158 | 42.7k | dst->uv_stride, src->uv_crop_width, src->uv_crop_height, |
159 | 42.7k | et_uv, el_uv, eb_uv, er_uv, chroma_step); |
160 | | |
161 | 42.7k | copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer, |
162 | 42.7k | dst->uv_stride, src->uv_crop_width, src->uv_crop_height, |
163 | 42.7k | et_uv, el_uv, eb_uv, er_uv, chroma_step); |
164 | 42.7k | } |