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