/src/aom/aom_scale/generic/yv12extend.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #include <assert.h> |
13 | | |
14 | | #include "config/aom_config.h" |
15 | | #include "config/aom_scale_rtcd.h" |
16 | | |
17 | | #include "aom/aom_integer.h" |
18 | | #include "aom_mem/aom_mem.h" |
19 | | #include "aom_ports/mem.h" |
20 | | #include "aom_scale/yv12config.h" |
21 | | |
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, int v_start, |
25 | 13.4k | int v_end) { |
26 | 13.4k | assert(src != NULL); |
27 | 13.4k | int i; |
28 | 13.4k | const int linesize = extend_left + extend_right + width; |
29 | 13.4k | assert(linesize <= src_stride); |
30 | | |
31 | | /* copy the left and right most columns out */ |
32 | 13.4k | uint8_t *src_ptr1 = src + v_start * src_stride; |
33 | 13.4k | uint8_t *src_ptr2 = src + v_start * src_stride + width - 1; |
34 | 13.4k | uint8_t *dst_ptr1 = src + v_start * src_stride - extend_left; |
35 | 13.4k | uint8_t *dst_ptr2 = src_ptr2 + 1; |
36 | | |
37 | 1.12M | for (i = v_start; i < v_end; ++i) { |
38 | 1.11M | memset(dst_ptr1, src_ptr1[0], extend_left); |
39 | 1.11M | memset(dst_ptr2, src_ptr2[0], extend_right); |
40 | 1.11M | src_ptr1 += src_stride; |
41 | 1.11M | src_ptr2 += src_stride; |
42 | 1.11M | dst_ptr1 += src_stride; |
43 | 1.11M | dst_ptr2 += src_stride; |
44 | 1.11M | } |
45 | | |
46 | | /* Now copy the top and bottom lines into each line of the respective |
47 | | * borders |
48 | | */ |
49 | 13.4k | src_ptr1 = src - extend_left; |
50 | 13.4k | dst_ptr1 = src_ptr1 + src_stride * -extend_top; |
51 | | |
52 | 2.79M | for (i = 0; i < extend_top; ++i) { |
53 | 2.78M | memcpy(dst_ptr1, src_ptr1, linesize); |
54 | 2.78M | dst_ptr1 += src_stride; |
55 | 2.78M | } |
56 | | |
57 | 13.4k | src_ptr2 = src_ptr1 + src_stride * (height - 1); |
58 | 13.4k | dst_ptr2 = src_ptr2; |
59 | | |
60 | 2.84M | for (i = 0; i < extend_bottom; ++i) { |
61 | 2.83M | dst_ptr2 += src_stride; |
62 | 2.83M | memcpy(dst_ptr2, src_ptr2, linesize); |
63 | 2.83M | } |
64 | 13.4k | } |
65 | | |
66 | | #if CONFIG_AV1_HIGHBITDEPTH |
67 | | static void extend_plane_high(uint8_t *const src8, int src_stride, int width, |
68 | | int height, int extend_top, int extend_left, |
69 | | int extend_bottom, int extend_right, int v_start, |
70 | 21.4k | int v_end) { |
71 | 21.4k | int i; |
72 | 21.4k | const int linesize = extend_left + extend_right + width; |
73 | 21.4k | assert(linesize <= src_stride); |
74 | 21.4k | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
75 | | |
76 | | /* copy the left and right most columns out */ |
77 | 21.4k | uint16_t *src_ptr1 = src + v_start * src_stride; |
78 | 21.4k | uint16_t *src_ptr2 = src + v_start * src_stride + width - 1; |
79 | 21.4k | uint16_t *dst_ptr1 = src + v_start * src_stride - extend_left; |
80 | 21.4k | uint16_t *dst_ptr2 = src_ptr2 + 1; |
81 | | |
82 | 2.99M | for (i = v_start; i < v_end; ++i) { |
83 | 2.97M | aom_memset16(dst_ptr1, src_ptr1[0], extend_left); |
84 | 2.97M | aom_memset16(dst_ptr2, src_ptr2[0], extend_right); |
85 | 2.97M | src_ptr1 += src_stride; |
86 | 2.97M | src_ptr2 += src_stride; |
87 | 2.97M | dst_ptr1 += src_stride; |
88 | 2.97M | dst_ptr2 += src_stride; |
89 | 2.97M | } |
90 | | |
91 | | /* Now copy the top and bottom lines into each line of the respective |
92 | | * borders |
93 | | */ |
94 | 21.4k | src_ptr1 = src - extend_left; |
95 | 21.4k | dst_ptr1 = src_ptr1 + src_stride * -extend_top; |
96 | | |
97 | 5.40M | for (i = 0; i < extend_top; ++i) { |
98 | 5.38M | memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t)); |
99 | 5.38M | dst_ptr1 += src_stride; |
100 | 5.38M | } |
101 | | |
102 | 21.4k | src_ptr2 = src_ptr1 + src_stride * (height - 1); |
103 | 21.4k | dst_ptr2 = src_ptr2; |
104 | | |
105 | 5.47M | for (i = 0; i < extend_bottom; ++i) { |
106 | 5.45M | dst_ptr2 += src_stride; |
107 | 5.45M | memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t)); |
108 | 5.45M | } |
109 | 21.4k | } |
110 | | #endif // CONFIG_AV1_HIGHBITDEPTH |
111 | | |
112 | | void aom_extend_frame_borders_plane_row_c(const YV12_BUFFER_CONFIG *ybf, |
113 | 0 | int plane, int v_start, int v_end) { |
114 | 0 | const int ext_size = ybf->border; |
115 | 0 | const int ss_x = ybf->subsampling_x; |
116 | 0 | const int ss_y = ybf->subsampling_y; |
117 | |
|
118 | 0 | assert(ybf->y_height - ybf->y_crop_height < 16); |
119 | 0 | assert(ybf->y_width - ybf->y_crop_width < 16); |
120 | 0 | assert(ybf->y_height - ybf->y_crop_height >= 0); |
121 | 0 | assert(ybf->y_width - ybf->y_crop_width >= 0); |
122 | | |
123 | 0 | const int is_uv = plane > 0; |
124 | 0 | const int top = ext_size >> (is_uv ? ss_y : 0); |
125 | 0 | const int left = ext_size >> (is_uv ? ss_x : 0); |
126 | 0 | const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv]; |
127 | 0 | const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv]; |
128 | 0 | const int extend_top_border = (v_start == 0); |
129 | 0 | const int extend_bottom_border = (v_end == ybf->crop_heights[is_uv]); |
130 | |
|
131 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
132 | 0 | if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) { |
133 | 0 | extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv], |
134 | 0 | ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], |
135 | 0 | extend_top_border ? top : 0, left, |
136 | 0 | extend_bottom_border ? bottom : 0, right, v_start, v_end); |
137 | 0 | return; |
138 | 0 | } |
139 | 0 | #endif |
140 | | |
141 | 0 | extend_plane(ybf->buffers[plane], ybf->strides[is_uv], |
142 | 0 | ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], |
143 | 0 | extend_top_border ? top : 0, left, |
144 | 0 | extend_bottom_border ? bottom : 0, right, v_start, v_end); |
145 | 0 | } |
146 | | |
147 | | void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, |
148 | 9.88k | const int num_planes) { |
149 | 9.88k | assert(ybf->border % 2 == 0); |
150 | 9.88k | assert(ybf->y_height - ybf->y_crop_height < 16); |
151 | 9.88k | assert(ybf->y_width - ybf->y_crop_width < 16); |
152 | 9.88k | assert(ybf->y_height - ybf->y_crop_height >= 0); |
153 | 9.88k | assert(ybf->y_width - ybf->y_crop_width >= 0); |
154 | | |
155 | 9.88k | #if CONFIG_AV1_HIGHBITDEPTH |
156 | 9.88k | if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) { |
157 | 18.1k | for (int plane = 0; plane < num_planes; ++plane) { |
158 | 10.7k | const int is_uv = plane > 0; |
159 | 10.7k | const int plane_border = ybf->border >> is_uv; |
160 | 10.7k | extend_plane_high( |
161 | 10.7k | ybf->buffers[plane], ybf->strides[is_uv], ybf->crop_widths[is_uv], |
162 | 10.7k | ybf->crop_heights[is_uv], plane_border, plane_border, |
163 | 10.7k | plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv], |
164 | 10.7k | plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0, |
165 | 10.7k | ybf->crop_heights[is_uv]); |
166 | 10.7k | } |
167 | 7.43k | return; |
168 | 7.43k | } |
169 | 2.44k | #endif |
170 | | |
171 | 9.17k | for (int plane = 0; plane < num_planes; ++plane) { |
172 | 6.72k | const int is_uv = plane > 0; |
173 | 6.72k | const int plane_border = ybf->border >> is_uv; |
174 | 6.72k | extend_plane(ybf->buffers[plane], ybf->strides[is_uv], |
175 | 6.72k | ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], |
176 | 6.72k | plane_border, plane_border, |
177 | 6.72k | plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv], |
178 | 6.72k | plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0, |
179 | 6.72k | ybf->crop_heights[is_uv]); |
180 | 6.72k | } |
181 | 2.44k | } |
182 | | |
183 | | static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size, |
184 | 9.88k | const int num_planes) { |
185 | 9.88k | const int ss_x = ybf->subsampling_x; |
186 | 9.88k | const int ss_y = ybf->subsampling_y; |
187 | | |
188 | 9.88k | assert(ybf->y_height - ybf->y_crop_height < 16); |
189 | 9.88k | assert(ybf->y_width - ybf->y_crop_width < 16); |
190 | 9.88k | assert(ybf->y_height - ybf->y_crop_height >= 0); |
191 | 9.88k | assert(ybf->y_width - ybf->y_crop_width >= 0); |
192 | | |
193 | 9.88k | #if CONFIG_AV1_HIGHBITDEPTH |
194 | 9.88k | if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) { |
195 | 18.1k | for (int plane = 0; plane < num_planes; ++plane) { |
196 | 10.7k | const int is_uv = plane > 0; |
197 | 10.7k | const int top = ext_size >> (is_uv ? ss_y : 0); |
198 | 10.7k | const int left = ext_size >> (is_uv ? ss_x : 0); |
199 | 10.7k | const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv]; |
200 | 10.7k | const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv]; |
201 | 10.7k | extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv], |
202 | 10.7k | ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, |
203 | 10.7k | left, bottom, right, 0, ybf->crop_heights[is_uv]); |
204 | 10.7k | } |
205 | 7.43k | return; |
206 | 7.43k | } |
207 | 2.44k | #endif |
208 | | |
209 | 9.17k | for (int plane = 0; plane < num_planes; ++plane) { |
210 | 6.72k | const int is_uv = plane > 0; |
211 | 6.72k | const int top = ext_size >> (is_uv ? ss_y : 0); |
212 | 6.72k | const int left = ext_size >> (is_uv ? ss_x : 0); |
213 | 6.72k | const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv]; |
214 | 6.72k | const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv]; |
215 | 6.72k | extend_plane(ybf->buffers[plane], ybf->strides[is_uv], |
216 | 6.72k | ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, left, |
217 | 6.72k | bottom, right, 0, ybf->crop_heights[is_uv]); |
218 | 6.72k | } |
219 | 2.44k | } |
220 | | |
221 | 9.88k | void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) { |
222 | 9.88k | extend_frame(ybf, ybf->border, num_planes); |
223 | 9.88k | } |
224 | | |
225 | | #if CONFIG_AV1_HIGHBITDEPTH |
226 | 1.52M | static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) { |
227 | 1.52M | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
228 | 1.52M | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
229 | 1.52M | memcpy(dst, src, num * sizeof(uint16_t)); |
230 | 1.52M | } |
231 | | #endif |
232 | | |
233 | | // Copies the source image into the destination image and updates the |
234 | | // destination's UMV borders. |
235 | | // Note: The frames are assumed to be identical in size. |
236 | | void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc, |
237 | 9.88k | YV12_BUFFER_CONFIG *dst_bc, const int num_planes) { |
238 | 9.88k | assert(src_bc->y_width == dst_bc->y_width); |
239 | 9.88k | assert(src_bc->y_height == dst_bc->y_height); |
240 | | |
241 | 9.88k | #if CONFIG_AV1_HIGHBITDEPTH |
242 | 9.88k | assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) == |
243 | 9.88k | (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH)); |
244 | | |
245 | 9.88k | if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { |
246 | 18.1k | for (int plane = 0; plane < num_planes; ++plane) { |
247 | 10.7k | const uint8_t *plane_src = src_bc->buffers[plane]; |
248 | 10.7k | uint8_t *plane_dst = dst_bc->buffers[plane]; |
249 | 10.7k | const int is_uv = plane > 0; |
250 | | |
251 | 1.53M | for (int row = 0; row < src_bc->heights[is_uv]; ++row) { |
252 | 1.52M | memcpy_short_addr(plane_dst, plane_src, src_bc->widths[is_uv]); |
253 | 1.52M | plane_src += src_bc->strides[is_uv]; |
254 | 1.52M | plane_dst += dst_bc->strides[is_uv]; |
255 | 1.52M | } |
256 | 10.7k | } |
257 | 7.43k | aom_yv12_extend_frame_borders_c(dst_bc, num_planes); |
258 | 7.43k | return; |
259 | 7.43k | } |
260 | 2.44k | #endif |
261 | 9.17k | for (int plane = 0; plane < num_planes; ++plane) { |
262 | 6.72k | const uint8_t *plane_src = src_bc->buffers[plane]; |
263 | 6.72k | uint8_t *plane_dst = dst_bc->buffers[plane]; |
264 | 6.72k | const int is_uv = plane > 0; |
265 | | |
266 | 590k | for (int row = 0; row < src_bc->heights[is_uv]; ++row) { |
267 | 584k | memcpy(plane_dst, plane_src, src_bc->widths[is_uv]); |
268 | 584k | plane_src += src_bc->strides[is_uv]; |
269 | 584k | plane_dst += dst_bc->strides[is_uv]; |
270 | 584k | } |
271 | 6.72k | } |
272 | 2.44k | aom_yv12_extend_frame_borders_c(dst_bc, num_planes); |
273 | 2.44k | } |
274 | | |
275 | | void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, |
276 | 0 | YV12_BUFFER_CONFIG *dst_ybc, int use_crop) { |
277 | 0 | int row; |
278 | 0 | int width = use_crop ? src_ybc->y_crop_width : src_ybc->y_width; |
279 | 0 | int height = use_crop ? src_ybc->y_crop_height : src_ybc->y_height; |
280 | 0 | const uint8_t *src = src_ybc->y_buffer; |
281 | 0 | uint8_t *dst = dst_ybc->y_buffer; |
282 | |
|
283 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
284 | 0 | if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) { |
285 | 0 | const uint16_t *src16 = CONVERT_TO_SHORTPTR(src); |
286 | 0 | uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst); |
287 | 0 | for (row = 0; row < height; ++row) { |
288 | 0 | memcpy(dst16, src16, width * sizeof(uint16_t)); |
289 | 0 | src16 += src_ybc->y_stride; |
290 | 0 | dst16 += dst_ybc->y_stride; |
291 | 0 | } |
292 | 0 | return; |
293 | 0 | } |
294 | 0 | #endif |
295 | | |
296 | 0 | for (row = 0; row < height; ++row) { |
297 | 0 | memcpy(dst, src, width); |
298 | 0 | src += src_ybc->y_stride; |
299 | 0 | dst += dst_ybc->y_stride; |
300 | 0 | } |
301 | 0 | } |
302 | | |
303 | | void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc, |
304 | 0 | YV12_BUFFER_CONFIG *dst_bc, int use_crop) { |
305 | 0 | int row; |
306 | 0 | int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width; |
307 | 0 | int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height; |
308 | 0 | const uint8_t *src = src_bc->u_buffer; |
309 | 0 | uint8_t *dst = dst_bc->u_buffer; |
310 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
311 | 0 | if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { |
312 | 0 | const uint16_t *src16 = CONVERT_TO_SHORTPTR(src); |
313 | 0 | uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst); |
314 | 0 | for (row = 0; row < height; ++row) { |
315 | 0 | memcpy(dst16, src16, width * sizeof(uint16_t)); |
316 | 0 | src16 += src_bc->uv_stride; |
317 | 0 | dst16 += dst_bc->uv_stride; |
318 | 0 | } |
319 | 0 | return; |
320 | 0 | } |
321 | 0 | #endif |
322 | 0 | for (row = 0; row < height; ++row) { |
323 | 0 | memcpy(dst, src, width); |
324 | 0 | src += src_bc->uv_stride; |
325 | 0 | dst += dst_bc->uv_stride; |
326 | 0 | } |
327 | 0 | } |
328 | | |
329 | | void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc, |
330 | 0 | YV12_BUFFER_CONFIG *dst_bc, int use_crop) { |
331 | 0 | int row; |
332 | 0 | int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width; |
333 | 0 | int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height; |
334 | 0 | const uint8_t *src = src_bc->v_buffer; |
335 | 0 | uint8_t *dst = dst_bc->v_buffer; |
336 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
337 | 0 | if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { |
338 | 0 | const uint16_t *src16 = CONVERT_TO_SHORTPTR(src); |
339 | 0 | uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst); |
340 | 0 | for (row = 0; row < height; ++row) { |
341 | 0 | memcpy(dst16, src16, width * sizeof(uint16_t)); |
342 | 0 | src16 += src_bc->uv_stride; |
343 | 0 | dst16 += dst_bc->uv_stride; |
344 | 0 | } |
345 | 0 | return; |
346 | 0 | } |
347 | 0 | #endif |
348 | 0 | for (row = 0; row < height; ++row) { |
349 | 0 | memcpy(dst, src, width); |
350 | 0 | src += src_bc->uv_stride; |
351 | 0 | dst += dst_bc->uv_stride; |
352 | 0 | } |
353 | 0 | } |
354 | | |
355 | | void aom_yv12_partial_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, int hstart1, |
356 | | int hend1, int vstart1, int vend1, |
357 | | YV12_BUFFER_CONFIG *dst_ybc, int hstart2, |
358 | 29.0k | int vstart2) { |
359 | 29.0k | int row; |
360 | 29.0k | const uint8_t *src = src_ybc->y_buffer; |
361 | 29.0k | uint8_t *dst = dst_ybc->y_buffer; |
362 | 29.0k | #if CONFIG_AV1_HIGHBITDEPTH |
363 | 29.0k | if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) { |
364 | 17.6k | const uint16_t *src16 = |
365 | 17.6k | CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1); |
366 | 17.6k | uint16_t *dst16 = |
367 | 17.6k | CONVERT_TO_SHORTPTR(dst + vstart2 * dst_ybc->y_stride + hstart2); |
368 | | |
369 | 2.13M | for (row = vstart1; row < vend1; ++row) { |
370 | 2.11M | memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t)); |
371 | 2.11M | src16 += src_ybc->y_stride; |
372 | 2.11M | dst16 += dst_ybc->y_stride; |
373 | 2.11M | } |
374 | 17.6k | return; |
375 | 17.6k | } |
376 | 11.3k | #endif |
377 | 11.3k | src = (src + vstart1 * src_ybc->y_stride + hstart1); |
378 | 11.3k | dst = (dst + vstart2 * dst_ybc->y_stride + hstart2); |
379 | | |
380 | 1.37M | for (row = vstart1; row < vend1; ++row) { |
381 | 1.35M | memcpy(dst, src, (hend1 - hstart1)); |
382 | 1.35M | src += src_ybc->y_stride; |
383 | 1.35M | dst += dst_ybc->y_stride; |
384 | 1.35M | } |
385 | 11.3k | } |
386 | | |
387 | | void aom_yv12_partial_coloc_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, |
388 | | YV12_BUFFER_CONFIG *dst_ybc, int hstart, |
389 | 29.0k | int hend, int vstart, int vend) { |
390 | 29.0k | aom_yv12_partial_copy_y_c(src_ybc, hstart, hend, vstart, vend, dst_ybc, |
391 | 29.0k | hstart, vstart); |
392 | 29.0k | } |
393 | | |
394 | | void aom_yv12_partial_copy_u_c(const YV12_BUFFER_CONFIG *src_bc, int hstart1, |
395 | | int hend1, int vstart1, int vend1, |
396 | | YV12_BUFFER_CONFIG *dst_bc, int hstart2, |
397 | 24.1k | int vstart2) { |
398 | 24.1k | int row; |
399 | 24.1k | const uint8_t *src = src_bc->u_buffer; |
400 | 24.1k | uint8_t *dst = dst_bc->u_buffer; |
401 | 24.1k | #if CONFIG_AV1_HIGHBITDEPTH |
402 | 24.1k | if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { |
403 | 13.1k | const uint16_t *src16 = |
404 | 13.1k | CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1); |
405 | 13.1k | uint16_t *dst16 = |
406 | 13.1k | CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2); |
407 | 860k | for (row = vstart1; row < vend1; ++row) { |
408 | 847k | memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t)); |
409 | 847k | src16 += src_bc->uv_stride; |
410 | 847k | dst16 += dst_bc->uv_stride; |
411 | 847k | } |
412 | 13.1k | return; |
413 | 13.1k | } |
414 | 10.9k | #endif |
415 | 10.9k | src = (src + vstart1 * src_bc->uv_stride + hstart1); |
416 | 10.9k | dst = (dst + vstart2 * dst_bc->uv_stride + hstart2); |
417 | | |
418 | 724k | for (row = vstart1; row < vend1; ++row) { |
419 | 713k | memcpy(dst, src, (hend1 - hstart1)); |
420 | 713k | src += src_bc->uv_stride; |
421 | 713k | dst += dst_bc->uv_stride; |
422 | 713k | } |
423 | 10.9k | } |
424 | | |
425 | | void aom_yv12_partial_coloc_copy_u_c(const YV12_BUFFER_CONFIG *src_bc, |
426 | | YV12_BUFFER_CONFIG *dst_bc, int hstart, |
427 | 24.1k | int hend, int vstart, int vend) { |
428 | 24.1k | aom_yv12_partial_copy_u_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart, |
429 | 24.1k | vstart); |
430 | 24.1k | } |
431 | | |
432 | | void aom_yv12_partial_copy_v_c(const YV12_BUFFER_CONFIG *src_bc, int hstart1, |
433 | | int hend1, int vstart1, int vend1, |
434 | | YV12_BUFFER_CONFIG *dst_bc, int hstart2, |
435 | 9.73k | int vstart2) { |
436 | 9.73k | int row; |
437 | 9.73k | const uint8_t *src = src_bc->v_buffer; |
438 | 9.73k | uint8_t *dst = dst_bc->v_buffer; |
439 | 9.73k | #if CONFIG_AV1_HIGHBITDEPTH |
440 | 9.73k | if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) { |
441 | 4.72k | const uint16_t *src16 = |
442 | 4.72k | CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1); |
443 | 4.72k | uint16_t *dst16 = |
444 | 4.72k | CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2); |
445 | 412k | for (row = vstart1; row < vend1; ++row) { |
446 | 407k | memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t)); |
447 | 407k | src16 += src_bc->uv_stride; |
448 | 407k | dst16 += dst_bc->uv_stride; |
449 | 407k | } |
450 | 4.72k | return; |
451 | 4.72k | } |
452 | 5.00k | #endif |
453 | 5.00k | src = (src + vstart1 * src_bc->uv_stride + hstart1); |
454 | 5.00k | dst = (dst + vstart2 * dst_bc->uv_stride + hstart2); |
455 | | |
456 | 289k | for (row = vstart1; row < vend1; ++row) { |
457 | 284k | memcpy(dst, src, (hend1 - hstart1)); |
458 | 284k | src += src_bc->uv_stride; |
459 | 284k | dst += dst_bc->uv_stride; |
460 | 284k | } |
461 | 5.00k | } |
462 | | |
463 | | void aom_yv12_partial_coloc_copy_v_c(const YV12_BUFFER_CONFIG *src_bc, |
464 | | YV12_BUFFER_CONFIG *dst_bc, int hstart, |
465 | 9.73k | int hend, int vstart, int vend) { |
466 | 9.73k | aom_yv12_partial_copy_v_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart, |
467 | 9.73k | vstart); |
468 | 9.73k | } |
469 | | |
470 | | int aom_yv12_realloc_with_new_border_c(YV12_BUFFER_CONFIG *ybf, int new_border, |
471 | | int byte_alignment, bool alloc_pyramid, |
472 | 0 | int num_planes) { |
473 | 0 | if (ybf) { |
474 | 0 | if (new_border == ybf->border) return 0; |
475 | 0 | YV12_BUFFER_CONFIG new_buf; |
476 | 0 | memset(&new_buf, 0, sizeof(new_buf)); |
477 | 0 | const int error = aom_alloc_frame_buffer( |
478 | 0 | &new_buf, ybf->y_crop_width, ybf->y_crop_height, ybf->subsampling_x, |
479 | 0 | ybf->subsampling_y, ybf->flags & YV12_FLAG_HIGHBITDEPTH, new_border, |
480 | 0 | byte_alignment, alloc_pyramid, 0); |
481 | 0 | if (error) return error; |
482 | | // Copy image buffer |
483 | 0 | aom_yv12_copy_frame(ybf, &new_buf, num_planes); |
484 | | |
485 | | // Extend up to new border |
486 | 0 | aom_extend_frame_borders(&new_buf, num_planes); |
487 | | |
488 | | // Now free the old buffer and replace with the new |
489 | 0 | aom_free_frame_buffer(ybf); |
490 | 0 | *ybf = new_buf; |
491 | 0 | return 0; |
492 | 0 | } |
493 | 0 | return -2; |
494 | 0 | } |