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