Coverage Report

Created: 2023-06-07 06:31

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