Coverage Report

Created: 2025-10-13 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
170k
                         int v_end) {
26
170k
  assert(src != NULL);
27
170k
  int i;
28
170k
  const int linesize = extend_left + extend_right + width;
29
170k
  assert(linesize <= src_stride);
30
31
  /* copy the left and right most columns out */
32
170k
  uint8_t *src_ptr1 = src + v_start * src_stride;
33
170k
  uint8_t *src_ptr2 = src + v_start * src_stride + width - 1;
34
170k
  uint8_t *dst_ptr1 = src + v_start * src_stride - extend_left;
35
170k
  uint8_t *dst_ptr2 = src_ptr2 + 1;
36
37
7.18M
  for (i = v_start; i < v_end; ++i) {
38
7.01M
    memset(dst_ptr1, src_ptr1[0], extend_left);
39
7.01M
    memset(dst_ptr2, src_ptr2[0], extend_right);
40
7.01M
    src_ptr1 += src_stride;
41
7.01M
    src_ptr2 += src_stride;
42
7.01M
    dst_ptr1 += src_stride;
43
7.01M
    dst_ptr2 += src_stride;
44
7.01M
  }
45
46
  /* Now copy the top and bottom lines into each line of the respective
47
   * borders
48
   */
49
170k
  src_ptr1 = src - extend_left;
50
170k
  dst_ptr1 = src_ptr1 + src_stride * -extend_top;
51
52
11.3M
  for (i = 0; i < extend_top; ++i) {
53
11.2M
    memcpy(dst_ptr1, src_ptr1, linesize);
54
11.2M
    dst_ptr1 += src_stride;
55
11.2M
  }
56
57
170k
  src_ptr2 = src_ptr1 + src_stride * (height - 1);
58
170k
  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
170k
}
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
67.7k
                              int v_end) {
71
67.7k
  int i;
72
67.7k
  const int linesize = extend_left + extend_right + width;
73
67.7k
  assert(linesize <= src_stride);
74
67.7k
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
75
76
  /* copy the left and right most columns out */
77
67.7k
  uint16_t *src_ptr1 = src + v_start * src_stride;
78
67.7k
  uint16_t *src_ptr2 = src + v_start * src_stride + width - 1;
79
67.7k
  uint16_t *dst_ptr1 = src + v_start * src_stride - extend_left;
80
67.7k
  uint16_t *dst_ptr2 = src_ptr2 + 1;
81
82
2.65M
  for (i = v_start; i < v_end; ++i) {
83
2.58M
    aom_memset16(dst_ptr1, src_ptr1[0], extend_left);
84
2.58M
    aom_memset16(dst_ptr2, src_ptr2[0], extend_right);
85
2.58M
    src_ptr1 += src_stride;
86
2.58M
    src_ptr2 += src_stride;
87
2.58M
    dst_ptr1 += src_stride;
88
2.58M
    dst_ptr2 += src_stride;
89
2.58M
  }
90
91
  /* Now copy the top and bottom lines into each line of the respective
92
   * borders
93
   */
94
67.7k
  src_ptr1 = src - extend_left;
95
67.7k
  dst_ptr1 = src_ptr1 + src_stride * -extend_top;
96
97
5.23M
  for (i = 0; i < extend_top; ++i) {
98
5.16M
    memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t));
99
5.16M
    dst_ptr1 += src_stride;
100
5.16M
  }
101
102
67.7k
  src_ptr2 = src_ptr1 + src_stride * (height - 1);
103
67.7k
  dst_ptr2 = src_ptr2;
104
105
5.51M
  for (i = 0; i < extend_bottom; ++i) {
106
5.44M
    dst_ptr2 += src_stride;
107
5.44M
    memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t));
108
5.44M
  }
109
67.7k
}
110
#endif  // CONFIG_AV1_HIGHBITDEPTH
111
112
void aom_extend_frame_borders_plane_row_c(const YV12_BUFFER_CONFIG *ybf,
113
154k
                                          int plane, int v_start, int v_end) {
114
154k
  const int ext_size = ybf->border;
115
154k
  const int ss_x = ybf->subsampling_x;
116
154k
  const int ss_y = ybf->subsampling_y;
117
118
154k
  assert(ybf->y_height - ybf->y_crop_height < 16);
119
154k
  assert(ybf->y_width - ybf->y_crop_width < 16);
120
154k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
121
154k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
122
123
154k
  const int is_uv = plane > 0;
124
154k
  const int top = ext_size >> (is_uv ? ss_y : 0);
125
154k
  const int left = ext_size >> (is_uv ? ss_x : 0);
126
154k
  const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
127
154k
  const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
128
154k
  const int extend_top_border = (v_start == 0);
129
154k
  const int extend_bottom_border = (v_end == ybf->crop_heights[is_uv]);
130
131
154k
#if CONFIG_AV1_HIGHBITDEPTH
132
154k
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
133
40.4k
    extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
134
40.4k
                      ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
135
40.4k
                      extend_top_border ? top : 0, left,
136
40.4k
                      extend_bottom_border ? bottom : 0, right, v_start, v_end);
137
40.4k
    return;
138
40.4k
  }
139
114k
#endif
140
141
114k
  extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
142
114k
               ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
143
114k
               extend_top_border ? top : 0, left,
144
114k
               extend_bottom_border ? bottom : 0, right, v_start, v_end);
145
114k
}
146
147
void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
148
450
                                     const int num_planes) {
149
450
  assert(ybf->border % 2 == 0);
150
450
  assert(ybf->y_height - ybf->y_crop_height < 16);
151
450
  assert(ybf->y_width - ybf->y_crop_width < 16);
152
450
  assert(ybf->y_height - ybf->y_crop_height >= 0);
153
450
  assert(ybf->y_width - ybf->y_crop_width >= 0);
154
155
450
#if CONFIG_AV1_HIGHBITDEPTH
156
450
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
157
1.05k
    for (int plane = 0; plane < num_planes; ++plane) {
158
756
      const int is_uv = plane > 0;
159
756
      const int plane_border = ybf->border >> is_uv;
160
756
      extend_plane_high(
161
756
          ybf->buffers[plane], ybf->strides[is_uv], ybf->crop_widths[is_uv],
162
756
          ybf->crop_heights[is_uv], plane_border, plane_border,
163
756
          plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
164
756
          plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0,
165
756
          ybf->crop_heights[is_uv]);
166
756
    }
167
298
    return;
168
298
  }
169
152
#endif
170
171
528
  for (int plane = 0; plane < num_planes; ++plane) {
172
376
    const int is_uv = plane > 0;
173
376
    const int plane_border = ybf->border >> is_uv;
174
376
    extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
175
376
                 ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
176
376
                 plane_border, plane_border,
177
376
                 plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
178
376
                 plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv], 0,
179
376
                 ybf->crop_heights[is_uv]);
180
376
  }
181
152
}
182
183
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
184
49.8k
                         const int num_planes) {
185
49.8k
  const int ss_x = ybf->subsampling_x;
186
49.8k
  const int ss_y = ybf->subsampling_y;
187
188
49.8k
  assert(ybf->y_height - ybf->y_crop_height < 16);
189
49.8k
  assert(ybf->y_width - ybf->y_crop_width < 16);
190
49.8k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
191
49.8k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
192
193
49.8k
#if CONFIG_AV1_HIGHBITDEPTH
194
49.8k
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
195
42.3k
    for (int plane = 0; plane < num_planes; ++plane) {
196
26.6k
      const int is_uv = plane > 0;
197
26.6k
      const int top = ext_size >> (is_uv ? ss_y : 0);
198
26.6k
      const int left = ext_size >> (is_uv ? ss_x : 0);
199
26.6k
      const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
200
26.6k
      const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
201
26.6k
      extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
202
26.6k
                        ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top,
203
26.6k
                        left, bottom, right, 0, ybf->crop_heights[is_uv]);
204
26.6k
    }
205
15.7k
    return;
206
15.7k
  }
207
34.0k
#endif
208
209
90.0k
  for (int plane = 0; plane < num_planes; ++plane) {
210
55.9k
    const int is_uv = plane > 0;
211
55.9k
    const int top = ext_size >> (is_uv ? ss_y : 0);
212
55.9k
    const int left = ext_size >> (is_uv ? ss_x : 0);
213
55.9k
    const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
214
55.9k
    const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
215
55.9k
    extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
216
55.9k
                 ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, left,
217
55.9k
                 bottom, right, 0, ybf->crop_heights[is_uv]);
218
55.9k
  }
219
34.0k
}
220
221
49.8k
void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) {
222
49.8k
  extend_frame(ybf, ybf->border, num_planes);
223
49.8k
}
224
225
#if CONFIG_AV1_HIGHBITDEPTH
226
404k
static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
227
404k
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
228
404k
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
229
404k
  memcpy(dst, src, num * sizeof(uint16_t));
230
404k
}
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
450
                           YV12_BUFFER_CONFIG *dst_bc, const int num_planes) {
238
450
  assert(src_bc->y_width == dst_bc->y_width);
239
450
  assert(src_bc->y_height == dst_bc->y_height);
240
241
450
#if CONFIG_AV1_HIGHBITDEPTH
242
450
  assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) ==
243
450
         (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
244
245
450
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
246
1.05k
    for (int plane = 0; plane < num_planes; ++plane) {
247
756
      const uint8_t *plane_src = src_bc->buffers[plane];
248
756
      uint8_t *plane_dst = dst_bc->buffers[plane];
249
756
      const int is_uv = plane > 0;
250
251
405k
      for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
252
404k
        memcpy_short_addr(plane_dst, plane_src, src_bc->widths[is_uv]);
253
404k
        plane_src += src_bc->strides[is_uv];
254
404k
        plane_dst += dst_bc->strides[is_uv];
255
404k
      }
256
756
    }
257
298
    aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
258
298
    return;
259
298
  }
260
152
#endif
261
528
  for (int plane = 0; plane < num_planes; ++plane) {
262
376
    const uint8_t *plane_src = src_bc->buffers[plane];
263
376
    uint8_t *plane_dst = dst_bc->buffers[plane];
264
376
    const int is_uv = plane > 0;
265
266
177k
    for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
267
176k
      memcpy(plane_dst, plane_src, src_bc->widths[is_uv]);
268
176k
      plane_src += src_bc->strides[is_uv];
269
176k
      plane_dst += dst_bc->strides[is_uv];
270
176k
    }
271
376
  }
272
152
  aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
273
152
}
274
275
void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
276
184k
                       YV12_BUFFER_CONFIG *dst_ybc, int use_crop) {
277
184k
  int row;
278
184k
  int width = use_crop ? src_ybc->y_crop_width : src_ybc->y_width;
279
184k
  int height = use_crop ? src_ybc->y_crop_height : src_ybc->y_height;
280
184k
  const uint8_t *src = src_ybc->y_buffer;
281
184k
  uint8_t *dst = dst_ybc->y_buffer;
282
283
184k
#if CONFIG_AV1_HIGHBITDEPTH
284
184k
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
285
61.9k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
286
61.9k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
287
2.76M
    for (row = 0; row < height; ++row) {
288
2.70M
      memcpy(dst16, src16, width * sizeof(uint16_t));
289
2.70M
      src16 += src_ybc->y_stride;
290
2.70M
      dst16 += dst_ybc->y_stride;
291
2.70M
    }
292
61.9k
    return;
293
61.9k
  }
294
122k
#endif
295
296
7.64M
  for (row = 0; row < height; ++row) {
297
7.52M
    memcpy(dst, src, width);
298
7.52M
    src += src_ybc->y_stride;
299
7.52M
    dst += dst_ybc->y_stride;
300
7.52M
  }
301
122k
}
302
303
void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
304
73.5k
                       YV12_BUFFER_CONFIG *dst_bc, int use_crop) {
305
73.5k
  int row;
306
73.5k
  int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width;
307
73.5k
  int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height;
308
73.5k
  const uint8_t *src = src_bc->u_buffer;
309
73.5k
  uint8_t *dst = dst_bc->u_buffer;
310
73.5k
#if CONFIG_AV1_HIGHBITDEPTH
311
73.5k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
312
25.7k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
313
25.7k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
314
865k
    for (row = 0; row < height; ++row) {
315
839k
      memcpy(dst16, src16, width * sizeof(uint16_t));
316
839k
      src16 += src_bc->uv_stride;
317
839k
      dst16 += dst_bc->uv_stride;
318
839k
    }
319
25.7k
    return;
320
25.7k
  }
321
47.7k
#endif
322
2.00M
  for (row = 0; row < height; ++row) {
323
1.95M
    memcpy(dst, src, width);
324
1.95M
    src += src_bc->uv_stride;
325
1.95M
    dst += dst_bc->uv_stride;
326
1.95M
  }
327
47.7k
}
328
329
void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
330
73.5k
                       YV12_BUFFER_CONFIG *dst_bc, int use_crop) {
331
73.5k
  int row;
332
73.5k
  int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width;
333
73.5k
  int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height;
334
73.5k
  const uint8_t *src = src_bc->v_buffer;
335
73.5k
  uint8_t *dst = dst_bc->v_buffer;
336
73.5k
#if CONFIG_AV1_HIGHBITDEPTH
337
73.5k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
338
25.7k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
339
25.7k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
340
860k
    for (row = 0; row < height; ++row) {
341
835k
      memcpy(dst16, src16, width * sizeof(uint16_t));
342
835k
      src16 += src_bc->uv_stride;
343
835k
      dst16 += dst_bc->uv_stride;
344
835k
    }
345
25.7k
    return;
346
25.7k
  }
347
47.7k
#endif
348
2.00M
  for (row = 0; row < height; ++row) {
349
1.95M
    memcpy(dst, src, width);
350
1.95M
    src += src_bc->uv_stride;
351
1.95M
    dst += dst_bc->uv_stride;
352
1.95M
  }
353
47.7k
}
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
5.41k
                               int vstart2) {
359
5.41k
  int row;
360
5.41k
  const uint8_t *src = src_ybc->y_buffer;
361
5.41k
  uint8_t *dst = dst_ybc->y_buffer;
362
5.41k
#if CONFIG_AV1_HIGHBITDEPTH
363
5.41k
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
364
2.45k
    const uint16_t *src16 =
365
2.45k
        CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1);
366
2.45k
    uint16_t *dst16 =
367
2.45k
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_ybc->y_stride + hstart2);
368
369
399k
    for (row = vstart1; row < vend1; ++row) {
370
397k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
371
397k
      src16 += src_ybc->y_stride;
372
397k
      dst16 += dst_ybc->y_stride;
373
397k
    }
374
2.45k
    return;
375
2.45k
  }
376
2.95k
#endif
377
2.95k
  src = (src + vstart1 * src_ybc->y_stride + hstart1);
378
2.95k
  dst = (dst + vstart2 * dst_ybc->y_stride + hstart2);
379
380
413k
  for (row = vstart1; row < vend1; ++row) {
381
410k
    memcpy(dst, src, (hend1 - hstart1));
382
410k
    src += src_ybc->y_stride;
383
410k
    dst += dst_ybc->y_stride;
384
410k
  }
385
2.95k
}
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
5.42k
                                     int hend, int vstart, int vend) {
390
5.42k
  aom_yv12_partial_copy_y_c(src_ybc, hstart, hend, vstart, vend, dst_ybc,
391
5.42k
                            hstart, vstart);
392
5.42k
}
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
3.61k
                               int vstart2) {
398
3.61k
  int row;
399
3.61k
  const uint8_t *src = src_bc->u_buffer;
400
3.61k
  uint8_t *dst = dst_bc->u_buffer;
401
3.61k
#if CONFIG_AV1_HIGHBITDEPTH
402
3.61k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
403
1.61k
    const uint16_t *src16 =
404
1.61k
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
405
1.61k
    uint16_t *dst16 =
406
1.61k
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
407
270k
    for (row = vstart1; row < vend1; ++row) {
408
269k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
409
269k
      src16 += src_bc->uv_stride;
410
269k
      dst16 += dst_bc->uv_stride;
411
269k
    }
412
1.61k
    return;
413
1.61k
  }
414
1.99k
#endif
415
1.99k
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
416
1.99k
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
417
418
269k
  for (row = vstart1; row < vend1; ++row) {
419
267k
    memcpy(dst, src, (hend1 - hstart1));
420
267k
    src += src_bc->uv_stride;
421
267k
    dst += dst_bc->uv_stride;
422
267k
  }
423
1.99k
}
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
3.61k
                                     int hend, int vstart, int vend) {
428
3.61k
  aom_yv12_partial_copy_u_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
429
3.61k
                            vstart);
430
3.61k
}
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
3.67k
                               int vstart2) {
436
3.67k
  int row;
437
3.67k
  const uint8_t *src = src_bc->v_buffer;
438
3.67k
  uint8_t *dst = dst_bc->v_buffer;
439
3.67k
#if CONFIG_AV1_HIGHBITDEPTH
440
3.67k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
441
2.17k
    const uint16_t *src16 =
442
2.17k
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
443
2.17k
    uint16_t *dst16 =
444
2.17k
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
445
344k
    for (row = vstart1; row < vend1; ++row) {
446
341k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
447
341k
      src16 += src_bc->uv_stride;
448
341k
      dst16 += dst_bc->uv_stride;
449
341k
    }
450
2.17k
    return;
451
2.17k
  }
452
1.49k
#endif
453
1.49k
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
454
1.49k
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
455
456
212k
  for (row = vstart1; row < vend1; ++row) {
457
211k
    memcpy(dst, src, (hend1 - hstart1));
458
211k
    src += src_bc->uv_stride;
459
211k
    dst += dst_bc->uv_stride;
460
211k
  }
461
1.49k
}
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
3.67k
                                     int hend, int vstart, int vend) {
466
3.67k
  aom_yv12_partial_copy_v_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
467
3.67k
                            vstart);
468
3.67k
}
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
}