Coverage Report

Created: 2025-07-23 08:18

/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.03k
                         int extend_bottom, int extend_right) {
25
3.03k
  assert(src != NULL);
26
3.03k
  int i;
27
3.03k
  const int linesize = extend_left + extend_right + width;
28
3.03k
  assert(linesize <= src_stride);
29
30
  /* copy the left and right most columns out */
31
3.03k
  uint8_t *src_ptr1 = src;
32
3.03k
  uint8_t *src_ptr2 = src + width - 1;
33
3.03k
  uint8_t *dst_ptr1 = src - extend_left;
34
3.03k
  uint8_t *dst_ptr2 = src + width;
35
36
942k
  for (i = 0; i < height; ++i) {
37
939k
    memset(dst_ptr1, src_ptr1[0], extend_left);
38
939k
    memset(dst_ptr2, src_ptr2[0], extend_right);
39
939k
    src_ptr1 += src_stride;
40
939k
    src_ptr2 += src_stride;
41
939k
    dst_ptr1 += src_stride;
42
939k
    dst_ptr2 += src_stride;
43
939k
  }
44
45
  /* Now copy the top and bottom lines into each line of the respective
46
   * borders
47
   */
48
3.03k
  src_ptr1 = src - extend_left;
49
3.03k
  src_ptr2 = src + src_stride * (height - 1) - extend_left;
50
3.03k
  dst_ptr1 = src + src_stride * -extend_top - extend_left;
51
3.03k
  dst_ptr2 = src + src_stride * height - extend_left;
52
53
700k
  for (i = 0; i < extend_top; ++i) {
54
697k
    memcpy(dst_ptr1, src_ptr1, linesize);
55
697k
    dst_ptr1 += src_stride;
56
697k
  }
57
58
708k
  for (i = 0; i < extend_bottom; ++i) {
59
705k
    memcpy(dst_ptr2, src_ptr2, linesize);
60
705k
    dst_ptr2 += src_stride;
61
705k
  }
62
3.03k
}
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
1.25k
                              int extend_bottom, int extend_right) {
68
1.25k
  int i;
69
1.25k
  const int linesize = extend_left + extend_right + width;
70
1.25k
  assert(linesize <= src_stride);
71
1.25k
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
72
73
  /* copy the left and right most columns out */
74
1.25k
  uint16_t *src_ptr1 = src;
75
1.25k
  uint16_t *src_ptr2 = src + width - 1;
76
1.25k
  uint16_t *dst_ptr1 = src - extend_left;
77
1.25k
  uint16_t *dst_ptr2 = src + width;
78
79
415k
  for (i = 0; i < height; ++i) {
80
414k
    aom_memset16(dst_ptr1, src_ptr1[0], extend_left);
81
414k
    aom_memset16(dst_ptr2, src_ptr2[0], extend_right);
82
414k
    src_ptr1 += src_stride;
83
414k
    src_ptr2 += src_stride;
84
414k
    dst_ptr1 += src_stride;
85
414k
    dst_ptr2 += src_stride;
86
414k
  }
87
88
  /* Now copy the top and bottom lines into each line of the respective
89
   * borders
90
   */
91
1.25k
  src_ptr1 = src - extend_left;
92
1.25k
  src_ptr2 = src + src_stride * (height - 1) - extend_left;
93
1.25k
  dst_ptr1 = src + src_stride * -extend_top - extend_left;
94
1.25k
  dst_ptr2 = src + src_stride * height - extend_left;
95
96
284k
  for (i = 0; i < extend_top; ++i) {
97
283k
    memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t));
98
283k
    dst_ptr1 += src_stride;
99
283k
  }
100
101
287k
  for (i = 0; i < extend_bottom; ++i) {
102
286k
    memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t));
103
286k
    dst_ptr2 += src_stride;
104
286k
  }
105
1.25k
}
106
#endif  // CONFIG_AV1_HIGHBITDEPTH
107
108
void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
109
722
                                     const int num_planes) {
110
722
  assert(ybf->border % 2 == 0);
111
722
  assert(ybf->y_height - ybf->y_crop_height < 16);
112
722
  assert(ybf->y_width - ybf->y_crop_width < 16);
113
722
  assert(ybf->y_height - ybf->y_crop_height >= 0);
114
722
  assert(ybf->y_width - ybf->y_crop_width >= 0);
115
116
722
#if CONFIG_AV1_HIGHBITDEPTH
117
722
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
118
842
    for (int plane = 0; plane < num_planes; ++plane) {
119
628
      const int is_uv = plane > 0;
120
628
      const int plane_border = ybf->border >> is_uv;
121
628
      extend_plane_high(
122
628
          ybf->buffers[plane], ybf->strides[is_uv], ybf->crop_widths[is_uv],
123
628
          ybf->crop_heights[is_uv], plane_border, plane_border,
124
628
          plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
125
628
          plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv]);
126
628
    }
127
214
    return;
128
214
  }
129
508
#endif
130
131
2.02k
  for (int plane = 0; plane < num_planes; ++plane) {
132
1.51k
    const int is_uv = plane > 0;
133
1.51k
    const int plane_border = ybf->border >> is_uv;
134
1.51k
    extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
135
1.51k
                 ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
136
1.51k
                 plane_border, plane_border,
137
1.51k
                 plane_border + ybf->heights[is_uv] - ybf->crop_heights[is_uv],
138
1.51k
                 plane_border + ybf->widths[is_uv] - ybf->crop_widths[is_uv]);
139
1.51k
  }
140
508
}
141
142
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
143
722
                         const int num_planes) {
144
722
  const int ss_x = ybf->subsampling_x;
145
722
  const int ss_y = ybf->subsampling_y;
146
147
722
  assert(ybf->y_height - ybf->y_crop_height < 16);
148
722
  assert(ybf->y_width - ybf->y_crop_width < 16);
149
722
  assert(ybf->y_height - ybf->y_crop_height >= 0);
150
722
  assert(ybf->y_width - ybf->y_crop_width >= 0);
151
152
722
#if CONFIG_AV1_HIGHBITDEPTH
153
722
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
154
842
    for (int plane = 0; plane < num_planes; ++plane) {
155
628
      const int is_uv = plane > 0;
156
628
      const int top = ext_size >> (is_uv ? ss_y : 0);
157
628
      const int left = ext_size >> (is_uv ? ss_x : 0);
158
628
      const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
159
628
      const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
160
628
      extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
161
628
                        ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top,
162
628
                        left, bottom, right);
163
628
    }
164
214
    return;
165
214
  }
166
508
#endif
167
168
2.02k
  for (int plane = 0; plane < num_planes; ++plane) {
169
1.51k
    const int is_uv = plane > 0;
170
1.51k
    const int top = ext_size >> (is_uv ? ss_y : 0);
171
1.51k
    const int left = ext_size >> (is_uv ? ss_x : 0);
172
1.51k
    const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
173
1.51k
    const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
174
1.51k
    extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
175
1.51k
                 ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, left,
176
1.51k
                 bottom, right);
177
1.51k
  }
178
508
}
179
180
722
void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) {
181
722
  extend_frame(ybf, ybf->border, num_planes);
182
722
}
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
209k
static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
215
209k
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
216
209k
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
217
209k
  memcpy(dst, src, num * sizeof(uint16_t));
218
209k
}
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
722
                           YV12_BUFFER_CONFIG *dst_bc, const int num_planes) {
226
722
  assert(src_bc->y_width == dst_bc->y_width);
227
722
  assert(src_bc->y_height == dst_bc->y_height);
228
229
722
#if CONFIG_AV1_HIGHBITDEPTH
230
722
  assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) ==
231
722
         (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
232
233
722
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
234
842
    for (int plane = 0; plane < num_planes; ++plane) {
235
628
      const uint8_t *plane_src = src_bc->buffers[plane];
236
628
      uint8_t *plane_dst = dst_bc->buffers[plane];
237
628
      const int is_uv = plane > 0;
238
239
209k
      for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
240
209k
        memcpy_short_addr(plane_dst, plane_src, src_bc->widths[is_uv]);
241
209k
        plane_src += src_bc->strides[is_uv];
242
209k
        plane_dst += dst_bc->strides[is_uv];
243
209k
      }
244
628
    }
245
214
    aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
246
214
    return;
247
214
  }
248
508
#endif
249
2.02k
  for (int plane = 0; plane < num_planes; ++plane) {
250
1.51k
    const uint8_t *plane_src = src_bc->buffers[plane];
251
1.51k
    uint8_t *plane_dst = dst_bc->buffers[plane];
252
1.51k
    const int is_uv = plane > 0;
253
254
475k
    for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
255
473k
      memcpy(plane_dst, plane_src, src_bc->widths[is_uv]);
256
473k
      plane_src += src_bc->strides[is_uv];
257
473k
      plane_dst += dst_bc->strides[is_uv];
258
473k
    }
259
1.51k
  }
260
508
  aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
261
508
}
262
263
void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
264
0
                       YV12_BUFFER_CONFIG *dst_ybc) {
265
0
  int row;
266
0
  const uint8_t *src = src_ybc->y_buffer;
267
0
  uint8_t *dst = dst_ybc->y_buffer;
268
269
0
#if CONFIG_AV1_HIGHBITDEPTH
270
0
  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
0
#endif
281
282
0
  for (row = 0; row < src_ybc->y_height; ++row) {
283
0
    memcpy(dst, src, src_ybc->y_width);
284
0
    src += src_ybc->y_stride;
285
0
    dst += dst_ybc->y_stride;
286
0
  }
287
0
}
288
289
void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
290
0
                       YV12_BUFFER_CONFIG *dst_bc) {
291
0
  int row;
292
0
  const uint8_t *src = src_bc->u_buffer;
293
0
  uint8_t *dst = dst_bc->u_buffer;
294
0
#if CONFIG_AV1_HIGHBITDEPTH
295
0
  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
0
#endif
306
0
  for (row = 0; row < src_bc->uv_height; ++row) {
307
0
    memcpy(dst, src, src_bc->uv_width);
308
0
    src += src_bc->uv_stride;
309
0
    dst += dst_bc->uv_stride;
310
0
  }
311
0
}
312
313
void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
314
0
                       YV12_BUFFER_CONFIG *dst_bc) {
315
0
  int row;
316
0
  const uint8_t *src = src_bc->v_buffer;
317
0
  uint8_t *dst = dst_bc->v_buffer;
318
0
#if CONFIG_AV1_HIGHBITDEPTH
319
0
  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
0
#endif
330
0
  for (row = 0; row < src_bc->uv_height; ++row) {
331
0
    memcpy(dst, src, src_bc->uv_width);
332
0
    src += src_bc->uv_stride;
333
0
    dst += dst_bc->uv_stride;
334
0
  }
335
0
}
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
786
                               int vstart2) {
341
786
  int row;
342
786
  const uint8_t *src = src_ybc->y_buffer;
343
786
  uint8_t *dst = dst_ybc->y_buffer;
344
786
#if CONFIG_AV1_HIGHBITDEPTH
345
786
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
346
398
    const uint16_t *src16 =
347
398
        CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1);
348
398
    uint16_t *dst16 =
349
398
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_ybc->y_stride + hstart2);
350
351
66.3k
    for (row = vstart1; row < vend1; ++row) {
352
65.9k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
353
65.9k
      src16 += src_ybc->y_stride;
354
65.9k
      dst16 += dst_ybc->y_stride;
355
65.9k
    }
356
398
    return;
357
398
  }
358
388
#endif
359
388
  src = (src + vstart1 * src_ybc->y_stride + hstart1);
360
388
  dst = (dst + vstart2 * dst_ybc->y_stride + hstart2);
361
362
257k
  for (row = vstart1; row < vend1; ++row) {
363
256k
    memcpy(dst, src, (hend1 - hstart1));
364
256k
    src += src_ybc->y_stride;
365
256k
    dst += dst_ybc->y_stride;
366
256k
  }
367
388
}
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
786
                                     int hend, int vstart, int vend) {
372
786
  aom_yv12_partial_copy_y_c(src_ybc, hstart, hend, vstart, vend, dst_ybc,
373
786
                            hstart, vstart);
374
786
}
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
1.16k
                               int vstart2) {
380
1.16k
  int row;
381
1.16k
  const uint8_t *src = src_bc->u_buffer;
382
1.16k
  uint8_t *dst = dst_bc->u_buffer;
383
1.16k
#if CONFIG_AV1_HIGHBITDEPTH
384
1.16k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
385
293
    const uint16_t *src16 =
386
293
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
387
293
    uint16_t *dst16 =
388
293
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
389
72.3k
    for (row = vstart1; row < vend1; ++row) {
390
72.0k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
391
72.0k
      src16 += src_bc->uv_stride;
392
72.0k
      dst16 += dst_bc->uv_stride;
393
72.0k
    }
394
293
    return;
395
293
  }
396
869
#endif
397
869
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
398
869
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
399
400
74.5k
  for (row = vstart1; row < vend1; ++row) {
401
73.6k
    memcpy(dst, src, (hend1 - hstart1));
402
73.6k
    src += src_bc->uv_stride;
403
73.6k
    dst += dst_bc->uv_stride;
404
73.6k
  }
405
869
}
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
1.16k
                                     int hend, int vstart, int vend) {
410
1.16k
  aom_yv12_partial_copy_u_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
411
1.16k
                            vstart);
412
1.16k
}
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
1.45k
                               int vstart2) {
418
1.45k
  int row;
419
1.45k
  const uint8_t *src = src_bc->v_buffer;
420
1.45k
  uint8_t *dst = dst_bc->v_buffer;
421
1.45k
#if CONFIG_AV1_HIGHBITDEPTH
422
1.45k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
423
449
    const uint16_t *src16 =
424
449
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
425
449
    uint16_t *dst16 =
426
449
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
427
72.2k
    for (row = vstart1; row < vend1; ++row) {
428
71.8k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
429
71.8k
      src16 += src_bc->uv_stride;
430
71.8k
      dst16 += dst_bc->uv_stride;
431
71.8k
    }
432
449
    return;
433
449
  }
434
1.00k
#endif
435
1.00k
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
436
1.00k
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
437
438
219k
  for (row = vstart1; row < vend1; ++row) {
439
218k
    memcpy(dst, src, (hend1 - hstart1));
440
218k
    src += src_bc->uv_stride;
441
218k
    dst += dst_bc->uv_stride;
442
218k
  }
443
1.00k
}
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
1.45k
                                     int hend, int vstart, int vend) {
448
1.45k
  aom_yv12_partial_copy_v_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
449
1.45k
                            vstart);
450
1.45k
}
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
}