Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vpx_scale/generic/yv12extend.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <assert.h>
12
#include "./vpx_config.h"
13
#include "./vpx_scale_rtcd.h"
14
#include "vpx/vpx_integer.h"
15
#include "vpx_mem/vpx_mem.h"
16
#include "vpx_ports/mem.h"
17
#include "vpx_scale/yv12config.h"
18
#if CONFIG_VP9_HIGHBITDEPTH
19
#include "vp9/common/vp9_common.h"
20
#endif
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
336k
                         int extend_bottom, int extend_right) {
25
336k
  int i;
26
336k
  const int linesize = extend_left + extend_right + width;
27
28
  /* copy the left and right most columns out */
29
336k
  uint8_t *src_ptr1 = src;
30
336k
  uint8_t *src_ptr2 = src + width - 1;
31
336k
  uint8_t *dst_ptr1 = src - extend_left;
32
336k
  uint8_t *dst_ptr2 = src + width;
33
34
13.0M
  for (i = 0; i < height; ++i) {
35
12.7M
    memset(dst_ptr1, src_ptr1[0], extend_left);
36
12.7M
    memset(dst_ptr2, src_ptr2[0], extend_right);
37
12.7M
    src_ptr1 += src_stride;
38
12.7M
    src_ptr2 += src_stride;
39
12.7M
    dst_ptr1 += src_stride;
40
12.7M
    dst_ptr2 += src_stride;
41
12.7M
  }
42
43
  /* Now copy the top and bottom lines into each line of the respective
44
   * borders
45
   */
46
336k
  src_ptr1 = src - extend_left;
47
336k
  src_ptr2 = src + src_stride * (height - 1) - extend_left;
48
336k
  dst_ptr1 = src + src_stride * -extend_top - extend_left;
49
336k
  dst_ptr2 = src + src_stride * height - extend_left;
50
51
12.9M
  for (i = 0; i < extend_top; ++i) {
52
12.5M
    memcpy(dst_ptr1, src_ptr1, linesize);
53
12.5M
    dst_ptr1 += src_stride;
54
12.5M
  }
55
56
13.0M
  for (i = 0; i < extend_bottom; ++i) {
57
12.6M
    memcpy(dst_ptr2, src_ptr2, linesize);
58
12.6M
    dst_ptr2 += src_stride;
59
12.6M
  }
60
336k
}
61
62
#if CONFIG_VP9_HIGHBITDEPTH
63
static void extend_plane_high(uint8_t *const src8, int src_stride, int width,
64
                              int height, int extend_top, int extend_left,
65
0
                              int extend_bottom, int extend_right) {
66
0
  int i;
67
0
  const int linesize = extend_left + extend_right + width;
68
0
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
69
70
  /* copy the left and right most columns out */
71
0
  uint16_t *src_ptr1 = src;
72
0
  uint16_t *src_ptr2 = src + width - 1;
73
0
  uint16_t *dst_ptr1 = src - extend_left;
74
0
  uint16_t *dst_ptr2 = src + width;
75
76
0
  for (i = 0; i < height; ++i) {
77
0
    vpx_memset16(dst_ptr1, src_ptr1[0], extend_left);
78
0
    vpx_memset16(dst_ptr2, src_ptr2[0], extend_right);
79
0
    src_ptr1 += src_stride;
80
0
    src_ptr2 += src_stride;
81
0
    dst_ptr1 += src_stride;
82
0
    dst_ptr2 += src_stride;
83
0
  }
84
85
  /* Now copy the top and bottom lines into each line of the respective
86
   * borders
87
   */
88
0
  src_ptr1 = src - extend_left;
89
0
  src_ptr2 = src + src_stride * (height - 1) - extend_left;
90
0
  dst_ptr1 = src + src_stride * -extend_top - extend_left;
91
0
  dst_ptr2 = src + src_stride * height - extend_left;
92
93
0
  for (i = 0; i < extend_top; ++i) {
94
0
    memcpy(dst_ptr1, src_ptr1, linesize * sizeof(uint16_t));
95
0
    dst_ptr1 += src_stride;
96
0
  }
97
98
0
  for (i = 0; i < extend_bottom; ++i) {
99
0
    memcpy(dst_ptr2, src_ptr2, linesize * sizeof(uint16_t));
100
0
    dst_ptr2 += src_stride;
101
0
  }
102
0
}
103
#endif
104
105
70.0k
void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
106
70.0k
  const int uv_border = ybf->border / 2;
107
108
70.0k
  assert(ybf->border % 2 == 0);
109
70.0k
  assert(ybf->y_height - ybf->y_crop_height < 16);
110
70.0k
  assert(ybf->y_width - ybf->y_crop_width < 16);
111
70.0k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
112
70.0k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
113
114
70.0k
  extend_plane(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width,
115
70.0k
               ybf->y_crop_height, ybf->border, ybf->border,
116
70.0k
               ybf->border + ybf->y_height - ybf->y_crop_height,
117
70.0k
               ybf->border + ybf->y_width - ybf->y_crop_width);
118
119
70.0k
  extend_plane(ybf->u_buffer, ybf->uv_stride, ybf->uv_crop_width,
120
70.0k
               ybf->uv_crop_height, uv_border, uv_border,
121
70.0k
               uv_border + ybf->uv_height - ybf->uv_crop_height,
122
70.0k
               uv_border + ybf->uv_width - ybf->uv_crop_width);
123
124
70.0k
  extend_plane(ybf->v_buffer, ybf->uv_stride, ybf->uv_crop_width,
125
70.0k
               ybf->uv_crop_height, uv_border, uv_border,
126
70.0k
               uv_border + ybf->uv_height - ybf->uv_crop_height,
127
70.0k
               uv_border + ybf->uv_width - ybf->uv_crop_width);
128
70.0k
}
129
130
#if CONFIG_VP9
131
42.2k
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
132
42.2k
  const int c_w = ybf->uv_crop_width;
133
42.2k
  const int c_h = ybf->uv_crop_height;
134
42.2k
  const int ss_x = ybf->uv_width < ybf->y_width;
135
42.2k
  const int ss_y = ybf->uv_height < ybf->y_height;
136
42.2k
  const int c_et = ext_size >> ss_y;
137
42.2k
  const int c_el = ext_size >> ss_x;
138
42.2k
  const int c_eb = c_et + ybf->uv_height - ybf->uv_crop_height;
139
42.2k
  const int c_er = c_el + ybf->uv_width - ybf->uv_crop_width;
140
141
42.2k
  assert(ybf->y_height - ybf->y_crop_height < 16);
142
42.2k
  assert(ybf->y_width - ybf->y_crop_width < 16);
143
42.2k
  assert(ybf->y_height - ybf->y_crop_height >= 0);
144
42.2k
  assert(ybf->y_width - ybf->y_crop_width >= 0);
145
146
42.2k
#if CONFIG_VP9_HIGHBITDEPTH
147
42.2k
  if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
148
0
    extend_plane_high(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width,
149
0
                      ybf->y_crop_height, ext_size, ext_size,
150
0
                      ext_size + ybf->y_height - ybf->y_crop_height,
151
0
                      ext_size + ybf->y_width - ybf->y_crop_width);
152
0
    extend_plane_high(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb,
153
0
                      c_er);
154
0
    extend_plane_high(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb,
155
0
                      c_er);
156
0
    return;
157
0
  }
158
42.2k
#endif
159
42.2k
  extend_plane(ybf->y_buffer, ybf->y_stride, ybf->y_crop_width,
160
42.2k
               ybf->y_crop_height, ext_size, ext_size,
161
42.2k
               ext_size + ybf->y_height - ybf->y_crop_height,
162
42.2k
               ext_size + ybf->y_width - ybf->y_crop_width);
163
164
42.2k
  extend_plane(ybf->u_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er);
165
166
42.2k
  extend_plane(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er);
167
42.2k
}
168
169
0
void vpx_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
170
0
  extend_frame(ybf, ybf->border);
171
0
}
172
173
42.2k
void vpx_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf) {
174
42.2k
  const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS)
175
42.2k
                           ? VP9INNERBORDERINPIXELS
176
42.2k
                           : ybf->border;
177
42.2k
  extend_frame(ybf, inner_bw);
178
42.2k
}
179
180
#if CONFIG_VP9_HIGHBITDEPTH
181
0
static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
182
0
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
183
0
  uint16_t *src = CONVERT_TO_SHORTPTR(src8);
184
0
  memcpy(dst, src, num * sizeof(uint16_t));
185
0
}
186
#endif  // CONFIG_VP9_HIGHBITDEPTH
187
#endif  // CONFIG_VP9
188
189
// Copies the source image into the destination image and updates the
190
// destination's UMV borders.
191
// Note: The frames are assumed to be identical in size.
192
193
void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc,
194
0
                           YV12_BUFFER_CONFIG *dst_ybc) {
195
0
  int row;
196
0
  const uint8_t *src = src_ybc->y_buffer;
197
0
  uint8_t *dst = dst_ybc->y_buffer;
198
199
#if 0
200
  /* These assertions are valid in the codec, but the libvpx-tester uses
201
   * this code slightly differently.
202
   */
203
  assert(src_ybc->y_width == dst_ybc->y_width);
204
  assert(src_ybc->y_height == dst_ybc->y_height);
205
#endif
206
207
0
  for (row = 0; row < src_ybc->y_height; ++row) {
208
0
    memcpy(dst, src, src_ybc->y_width);
209
0
    src += src_ybc->y_stride;
210
0
    dst += dst_ybc->y_stride;
211
0
  }
212
213
0
  src = src_ybc->u_buffer;
214
0
  dst = dst_ybc->u_buffer;
215
216
0
  for (row = 0; row < src_ybc->uv_height; ++row) {
217
0
    memcpy(dst, src, src_ybc->uv_width);
218
0
    src += src_ybc->uv_stride;
219
0
    dst += dst_ybc->uv_stride;
220
0
  }
221
222
0
  src = src_ybc->v_buffer;
223
0
  dst = dst_ybc->v_buffer;
224
225
0
  for (row = 0; row < src_ybc->uv_height; ++row) {
226
0
    memcpy(dst, src, src_ybc->uv_width);
227
0
    src += src_ybc->uv_stride;
228
0
    dst += dst_ybc->uv_stride;
229
0
  }
230
231
0
  vp8_yv12_extend_frame_borders_c(dst_ybc);
232
0
}
233
234
#if CONFIG_VP9
235
void vpx_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc,
236
0
                           YV12_BUFFER_CONFIG *dst_ybc) {
237
0
  int row;
238
0
  const uint8_t *src = src_ybc->y_buffer;
239
0
  uint8_t *dst = dst_ybc->y_buffer;
240
241
#if 0
242
  /* These assertions are valid in the codec, but the libvpx-tester uses
243
   * this code slightly differently.
244
   */
245
  assert(src_ybc->y_width == dst_ybc->y_width);
246
  assert(src_ybc->y_height == dst_ybc->y_height);
247
#endif
248
249
0
#if CONFIG_VP9_HIGHBITDEPTH
250
0
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
251
0
    assert(dst_ybc->flags & YV12_FLAG_HIGHBITDEPTH);
252
0
    for (row = 0; row < src_ybc->y_height; ++row) {
253
0
      memcpy_short_addr(dst, src, src_ybc->y_width);
254
0
      src += src_ybc->y_stride;
255
0
      dst += dst_ybc->y_stride;
256
0
    }
257
258
0
    src = src_ybc->u_buffer;
259
0
    dst = dst_ybc->u_buffer;
260
261
0
    for (row = 0; row < src_ybc->uv_height; ++row) {
262
0
      memcpy_short_addr(dst, src, src_ybc->uv_width);
263
0
      src += src_ybc->uv_stride;
264
0
      dst += dst_ybc->uv_stride;
265
0
    }
266
267
0
    src = src_ybc->v_buffer;
268
0
    dst = dst_ybc->v_buffer;
269
270
0
    for (row = 0; row < src_ybc->uv_height; ++row) {
271
0
      memcpy_short_addr(dst, src, src_ybc->uv_width);
272
0
      src += src_ybc->uv_stride;
273
0
      dst += dst_ybc->uv_stride;
274
0
    }
275
276
0
    vpx_extend_frame_borders_c(dst_ybc);
277
0
    return;
278
0
  } else {
279
0
    assert(!(dst_ybc->flags & YV12_FLAG_HIGHBITDEPTH));
280
0
  }
281
0
#endif
282
283
0
  for (row = 0; row < src_ybc->y_height; ++row) {
284
0
    memcpy(dst, src, src_ybc->y_width);
285
0
    src += src_ybc->y_stride;
286
0
    dst += dst_ybc->y_stride;
287
0
  }
288
289
0
  src = src_ybc->u_buffer;
290
0
  dst = dst_ybc->u_buffer;
291
292
0
  for (row = 0; row < src_ybc->uv_height; ++row) {
293
0
    memcpy(dst, src, src_ybc->uv_width);
294
0
    src += src_ybc->uv_stride;
295
0
    dst += dst_ybc->uv_stride;
296
0
  }
297
298
0
  src = src_ybc->v_buffer;
299
0
  dst = dst_ybc->v_buffer;
300
301
0
  for (row = 0; row < src_ybc->uv_height; ++row) {
302
0
    memcpy(dst, src, src_ybc->uv_width);
303
0
    src += src_ybc->uv_stride;
304
0
    dst += dst_ybc->uv_stride;
305
0
  }
306
307
0
  vpx_extend_frame_borders_c(dst_ybc);
308
0
}
309
#endif  // CONFIG_VP9
310
311
void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
312
742k
                       YV12_BUFFER_CONFIG *dst_ybc) {
313
742k
  int row;
314
742k
  const uint8_t *src = src_ybc->y_buffer;
315
742k
  uint8_t *dst = dst_ybc->y_buffer;
316
317
742k
#if CONFIG_VP9_HIGHBITDEPTH
318
742k
  if (src_ybc->flags & YV12_FLAG_HIGHBITDEPTH) {
319
0
    const uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
320
0
    uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
321
0
    for (row = 0; row < src_ybc->y_height; ++row) {
322
0
      memcpy(dst16, src16, src_ybc->y_width * sizeof(uint16_t));
323
0
      src16 += src_ybc->y_stride;
324
0
      dst16 += dst_ybc->y_stride;
325
0
    }
326
0
    return;
327
0
  }
328
742k
#endif
329
330
42.4M
  for (row = 0; row < src_ybc->y_height; ++row) {
331
41.6M
    memcpy(dst, src, src_ybc->y_width);
332
41.6M
    src += src_ybc->y_stride;
333
41.6M
    dst += dst_ybc->y_stride;
334
41.6M
  }
335
742k
}