Coverage Report

Created: 2026-06-10 06:30

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
308k
                         int v_end) {
26
308k
  assert(src != NULL);
27
308k
  int i;
28
308k
  const int linesize = extend_left + extend_right + width;
29
308k
  assert(linesize <= src_stride);
30
31
  /* copy the left and right most columns out */
32
308k
  uint8_t *src_ptr1 = src + v_start * src_stride;
33
308k
  uint8_t *src_ptr2 = src + v_start * src_stride + width - 1;
34
308k
  uint8_t *dst_ptr1 = src + v_start * src_stride - extend_left;
35
308k
  uint8_t *dst_ptr2 = src_ptr2 + 1;
36
37
18.1M
  for (i = v_start; i < v_end; ++i) {
38
17.8M
    memset(dst_ptr1, src_ptr1[0], extend_left);
39
17.8M
    memset(dst_ptr2, src_ptr2[0], extend_right);
40
17.8M
    src_ptr1 += src_stride;
41
17.8M
    src_ptr2 += src_stride;
42
17.8M
    dst_ptr1 += src_stride;
43
17.8M
    dst_ptr2 += src_stride;
44
17.8M
  }
45
46
  /* Now copy the top and bottom lines into each line of the respective
47
   * borders
48
   */
49
308k
  src_ptr1 = src - extend_left;
50
308k
  dst_ptr1 = src_ptr1 + src_stride * -extend_top;
51
52
21.2M
  for (i = 0; i < extend_top; ++i) {
53
20.9M
    memcpy(dst_ptr1, src_ptr1, linesize);
54
20.9M
    dst_ptr1 += src_stride;
55
20.9M
  }
56
57
308k
  src_ptr2 = src_ptr1 + src_stride * (height - 1);
58
308k
  dst_ptr2 = src_ptr2;
59
60
22.4M
  for (i = 0; i < extend_bottom; ++i) {
61
22.1M
    dst_ptr2 += src_stride;
62
22.1M
    memcpy(dst_ptr2, src_ptr2, linesize);
63
22.1M
  }
64
308k
}
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
127k
                              int v_end) {
71
127k
  int i;
72
127k
  const int linesize = extend_left + extend_right + width;
73
127k
  assert(linesize <= src_stride);
74
127k
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
75
76
  /* copy the left and right most columns out */
77
127k
  uint16_t *src_ptr1 = src + v_start * src_stride;
78
127k
  uint16_t *src_ptr2 = src + v_start * src_stride + width - 1;
79
127k
  uint16_t *dst_ptr1 = src + v_start * src_stride - extend_left;
80
127k
  uint16_t *dst_ptr2 = src_ptr2 + 1;
81
82
5.20M
  for (i = v_start; i < v_end; ++i) {
83
5.07M
    aom_memset16(dst_ptr1, src_ptr1[0], extend_left);
84
5.07M
    aom_memset16(dst_ptr2, src_ptr2[0], extend_right);
85
5.07M
    src_ptr1 += src_stride;
86
5.07M
    src_ptr2 += src_stride;
87
5.07M
    dst_ptr1 += src_stride;
88
5.07M
    dst_ptr2 += src_stride;
89
5.07M
  }
90
91
  /* Now copy the top and bottom lines into each line of the respective
92
   * borders
93
   */
94
127k
  src_ptr1 = src - extend_left;
95
127k
  dst_ptr1 = src_ptr1 + src_stride * -extend_top;
96
97
9.15M
  for (i = 0; i < extend_top; ++i) {
98
9.02M
    memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t));
99
9.02M
    dst_ptr1 += src_stride;
100
9.02M
  }
101
102
127k
  src_ptr2 = src_ptr1 + src_stride * (height - 1);
103
127k
  dst_ptr2 = src_ptr2;
104
105
9.71M
  for (i = 0; i < extend_bottom; ++i) {
106
9.58M
    dst_ptr2 += src_stride;
107
9.58M
    memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t));
108
9.58M
  }
109
127k
}
110
#endif  // CONFIG_AV1_HIGHBITDEPTH
111
112
void aom_extend_frame_borders_plane_row_c(const YV12_BUFFER_CONFIG *ybf,
113
139k
                                          int plane, int v_start, int v_end) {
114
139k
  const int ext_size = ybf->border;
115
139k
  const int ss_x = ybf->subsampling_x;
116
139k
  const int ss_y = ybf->subsampling_y;
117
118
139k
  assert(ybf->y_height - ybf->y_crop_height < 16);
119
139k
  assert(ybf->y_width - ybf->y_crop_width < 16);
120
139k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
121
139k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
122
123
139k
  const int is_uv = plane > 0;
124
139k
  const int top = ext_size >> (is_uv ? ss_y : 0);
125
139k
  const int left = ext_size >> (is_uv ? ss_x : 0);
126
139k
  const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
127
139k
  const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
128
139k
  const int extend_top_border = (v_start == 0);
129
139k
  const int extend_bottom_border = (v_end == ybf->crop_heights[is_uv]);
130
131
139k
#if CONFIG_AV1_HIGHBITDEPTH
132
139k
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
133
35.6k
    extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
134
35.6k
                      ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
135
35.6k
                      extend_top_border ? top : 0, left,
136
35.6k
                      extend_bottom_border ? bottom : 0, right, v_start, v_end);
137
35.6k
    return;
138
35.6k
  }
139
103k
#endif
140
141
103k
  extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
142
103k
               ybf->crop_widths[is_uv], ybf->crop_heights[is_uv],
143
103k
               extend_top_border ? top : 0, left,
144
103k
               extend_bottom_border ? bottom : 0, right, v_start, v_end);
145
103k
}
146
147
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
148
168k
                         const int num_planes) {
149
168k
  const int ss_x = ybf->subsampling_x;
150
168k
  const int ss_y = ybf->subsampling_y;
151
152
168k
  assert(ybf->y_height - ybf->y_crop_height < 16);
153
168k
  assert(ybf->y_width - ybf->y_crop_width < 16);
154
168k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
155
168k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
156
157
168k
#if CONFIG_AV1_HIGHBITDEPTH
158
168k
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
159
142k
    for (int plane = 0; plane < num_planes; ++plane) {
160
91.6k
      const int is_uv = plane > 0;
161
91.6k
      const int top = ext_size >> (is_uv ? ss_y : 0);
162
91.6k
      const int left = ext_size >> (is_uv ? ss_x : 0);
163
91.6k
      const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
164
91.6k
      const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
165
91.6k
      extend_plane_high(ybf->buffers[plane], ybf->strides[is_uv],
166
91.6k
                        ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top,
167
91.6k
                        left, bottom, right, 0, ybf->crop_heights[is_uv]);
168
91.6k
    }
169
50.6k
    return;
170
50.6k
  }
171
117k
#endif
172
173
322k
  for (int plane = 0; plane < num_planes; ++plane) {
174
204k
    const int is_uv = plane > 0;
175
204k
    const int top = ext_size >> (is_uv ? ss_y : 0);
176
204k
    const int left = ext_size >> (is_uv ? ss_x : 0);
177
204k
    const int bottom = top + ybf->heights[is_uv] - ybf->crop_heights[is_uv];
178
204k
    const int right = left + ybf->widths[is_uv] - ybf->crop_widths[is_uv];
179
204k
    extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
180
204k
                 ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], top, left,
181
204k
                 bottom, right, 0, ybf->crop_heights[is_uv]);
182
204k
  }
183
117k
}
184
185
168k
void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) {
186
168k
  extend_frame(ybf, ybf->border, num_planes);
187
168k
}
188
189
#if CONFIG_AV1_HIGHBITDEPTH
190
3.70M
static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
191
3.70M
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
192
3.70M
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
193
3.70M
  memcpy(dst, src, num * sizeof(uint16_t));
194
3.70M
}
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
122k
                           YV12_BUFFER_CONFIG *dst_bc, const int num_planes) {
202
122k
  assert(src_bc->y_width == dst_bc->y_width);
203
122k
  assert(src_bc->y_height == dst_bc->y_height);
204
205
122k
#if CONFIG_AV1_HIGHBITDEPTH
206
122k
  assert((src_bc->flags & YV12_FLAG_HIGHBITDEPTH) ==
207
122k
         (dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
208
209
122k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
210
104k
    for (int plane = 0; plane < num_planes; ++plane) {
211
68.1k
      const uint8_t *plane_src = src_bc->buffers[plane];
212
68.1k
      uint8_t *plane_dst = dst_bc->buffers[plane];
213
68.1k
      const int is_uv = plane > 0;
214
215
3.77M
      for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
216
3.70M
        memcpy_short_addr(plane_dst, plane_src, src_bc->widths[is_uv]);
217
3.70M
        plane_src += src_bc->strides[is_uv];
218
3.70M
        plane_dst += dst_bc->strides[is_uv];
219
3.70M
      }
220
68.1k
    }
221
36.6k
    aom_extend_frame_borders_c(dst_bc, num_planes);
222
36.6k
    return;
223
36.6k
  }
224
85.7k
#endif
225
238k
  for (int plane = 0; plane < num_planes; ++plane) {
226
152k
    const uint8_t *plane_src = src_bc->buffers[plane];
227
152k
    uint8_t *plane_dst = dst_bc->buffers[plane];
228
152k
    const int is_uv = plane > 0;
229
230
12.3M
    for (int row = 0; row < src_bc->heights[is_uv]; ++row) {
231
12.2M
      memcpy(plane_dst, plane_src, src_bc->widths[is_uv]);
232
12.2M
      plane_src += src_bc->strides[is_uv];
233
12.2M
      plane_dst += dst_bc->strides[is_uv];
234
12.2M
    }
235
152k
  }
236
85.7k
  aom_extend_frame_borders_c(dst_bc, num_planes);
237
85.7k
}
238
239
void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
240
154k
                       YV12_BUFFER_CONFIG *dst_ybc, int use_crop) {
241
154k
  int row;
242
154k
  int width = use_crop ? src_ybc->y_crop_width : src_ybc->y_width;
243
154k
  int height = use_crop ? src_ybc->y_crop_height : src_ybc->y_height;
244
154k
  const uint8_t *src = src_ybc->y_buffer;
245
154k
  uint8_t *dst = dst_ybc->y_buffer;
246
247
154k
#if CONFIG_AV1_HIGHBITDEPTH
248
154k
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
249
50.4k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
250
50.4k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
251
2.49M
    for (row = 0; row < height; ++row) {
252
2.43M
      memcpy(dst16, src16, width * sizeof(uint16_t));
253
2.43M
      src16 += src_ybc->y_stride;
254
2.43M
      dst16 += dst_ybc->y_stride;
255
2.43M
    }
256
50.4k
    return;
257
50.4k
  }
258
103k
#endif
259
260
6.56M
  for (row = 0; row < height; ++row) {
261
6.45M
    memcpy(dst, src, width);
262
6.45M
    src += src_ybc->y_stride;
263
6.45M
    dst += dst_ybc->y_stride;
264
6.45M
  }
265
103k
}
266
267
void aom_yv12_copy_u_c(const YV12_BUFFER_CONFIG *src_bc,
268
61.8k
                       YV12_BUFFER_CONFIG *dst_bc, int use_crop) {
269
61.8k
  int row;
270
61.8k
  int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width;
271
61.8k
  int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height;
272
61.8k
  const uint8_t *src = src_bc->u_buffer;
273
61.8k
  uint8_t *dst = dst_bc->u_buffer;
274
61.8k
#if CONFIG_AV1_HIGHBITDEPTH
275
61.8k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
276
21.5k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
277
21.5k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
278
760k
    for (row = 0; row < height; ++row) {
279
739k
      memcpy(dst16, src16, width * sizeof(uint16_t));
280
739k
      src16 += src_bc->uv_stride;
281
739k
      dst16 += dst_bc->uv_stride;
282
739k
    }
283
21.5k
    return;
284
21.5k
  }
285
40.2k
#endif
286
1.76M
  for (row = 0; row < height; ++row) {
287
1.72M
    memcpy(dst, src, width);
288
1.72M
    src += src_bc->uv_stride;
289
1.72M
    dst += dst_bc->uv_stride;
290
1.72M
  }
291
40.2k
}
292
293
void aom_yv12_copy_v_c(const YV12_BUFFER_CONFIG *src_bc,
294
61.9k
                       YV12_BUFFER_CONFIG *dst_bc, int use_crop) {
295
61.9k
  int row;
296
61.9k
  int width = use_crop ? src_bc->uv_crop_width : src_bc->uv_width;
297
61.9k
  int height = use_crop ? src_bc->uv_crop_height : src_bc->uv_height;
298
61.9k
  const uint8_t *src = src_bc->v_buffer;
299
61.9k
  uint8_t *dst = dst_bc->v_buffer;
300
61.9k
#if CONFIG_AV1_HIGHBITDEPTH
301
61.9k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
302
21.5k
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
303
21.5k
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
304
761k
    for (row = 0; row < height; ++row) {
305
740k
      memcpy(dst16, src16, width * sizeof(uint16_t));
306
740k
      src16 += src_bc->uv_stride;
307
740k
      dst16 += dst_bc->uv_stride;
308
740k
    }
309
21.5k
    return;
310
21.5k
  }
311
40.3k
#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
40.3k
}
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
2.52k
                               int vstart2) {
323
2.52k
  int row;
324
2.52k
  const uint8_t *src = src_ybc->y_buffer;
325
2.52k
  uint8_t *dst = dst_ybc->y_buffer;
326
2.52k
#if CONFIG_AV1_HIGHBITDEPTH
327
2.52k
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
328
930
    const uint16_t *src16 =
329
930
        CONVERT_TO_SHORTPTR(src + vstart1 * src_ybc->y_stride + hstart1);
330
930
    uint16_t *dst16 =
331
930
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_ybc->y_stride + hstart2);
332
333
61.2k
    for (row = vstart1; row < vend1; ++row) {
334
60.2k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
335
60.2k
      src16 += src_ybc->y_stride;
336
60.2k
      dst16 += dst_ybc->y_stride;
337
60.2k
    }
338
930
    return;
339
930
  }
340
1.59k
#endif
341
1.59k
  src = (src + vstart1 * src_ybc->y_stride + hstart1);
342
1.59k
  dst = (dst + vstart2 * dst_ybc->y_stride + hstart2);
343
344
262k
  for (row = vstart1; row < vend1; ++row) {
345
260k
    memcpy(dst, src, (hend1 - hstart1));
346
260k
    src += src_ybc->y_stride;
347
260k
    dst += dst_ybc->y_stride;
348
260k
  }
349
1.59k
}
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
2.52k
                                     int hend, int vstart, int vend) {
354
2.52k
  aom_yv12_partial_copy_y_c(src_ybc, hstart, hend, vstart, vend, dst_ybc,
355
2.52k
                            hstart, vstart);
356
2.52k
}
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
1.84k
                               int vstart2) {
362
1.84k
  int row;
363
1.84k
  const uint8_t *src = src_bc->u_buffer;
364
1.84k
  uint8_t *dst = dst_bc->u_buffer;
365
1.84k
#if CONFIG_AV1_HIGHBITDEPTH
366
1.84k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
367
817
    const uint16_t *src16 =
368
817
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
369
817
    uint16_t *dst16 =
370
817
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
371
48.2k
    for (row = vstart1; row < vend1; ++row) {
372
47.4k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
373
47.4k
      src16 += src_bc->uv_stride;
374
47.4k
      dst16 += dst_bc->uv_stride;
375
47.4k
    }
376
817
    return;
377
817
  }
378
1.03k
#endif
379
1.03k
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
380
1.03k
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
381
382
127k
  for (row = vstart1; row < vend1; ++row) {
383
126k
    memcpy(dst, src, (hend1 - hstart1));
384
126k
    src += src_bc->uv_stride;
385
126k
    dst += dst_bc->uv_stride;
386
126k
  }
387
1.03k
}
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
1.84k
                                     int hend, int vstart, int vend) {
392
1.84k
  aom_yv12_partial_copy_u_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
393
1.84k
                            vstart);
394
1.84k
}
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
2.04k
                               int vstart2) {
400
2.04k
  int row;
401
2.04k
  const uint8_t *src = src_bc->v_buffer;
402
2.04k
  uint8_t *dst = dst_bc->v_buffer;
403
2.04k
#if CONFIG_AV1_HIGHBITDEPTH
404
2.04k
  if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
405
905
    const uint16_t *src16 =
406
905
        CONVERT_TO_SHORTPTR(src + vstart1 * src_bc->uv_stride + hstart1);
407
905
    uint16_t *dst16 =
408
905
        CONVERT_TO_SHORTPTR(dst + vstart2 * dst_bc->uv_stride + hstart2);
409
53.8k
    for (row = vstart1; row < vend1; ++row) {
410
52.9k
      memcpy(dst16, src16, (hend1 - hstart1) * sizeof(uint16_t));
411
52.9k
      src16 += src_bc->uv_stride;
412
52.9k
      dst16 += dst_bc->uv_stride;
413
52.9k
    }
414
905
    return;
415
905
  }
416
1.13k
#endif
417
1.13k
  src = (src + vstart1 * src_bc->uv_stride + hstart1);
418
1.13k
  dst = (dst + vstart2 * dst_bc->uv_stride + hstart2);
419
420
134k
  for (row = vstart1; row < vend1; ++row) {
421
133k
    memcpy(dst, src, (hend1 - hstart1));
422
133k
    src += src_bc->uv_stride;
423
133k
    dst += dst_bc->uv_stride;
424
133k
  }
425
1.13k
}
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
2.04k
                                     int hend, int vstart, int vend) {
430
2.04k
  aom_yv12_partial_copy_v_c(src_bc, hstart, hend, vstart, vend, dst_bc, hstart,
431
2.04k
                            vstart);
432
2.04k
}
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
}