Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vp8/common/extend.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 "extend.h"
12
#include "vpx_mem/vpx_mem.h"
13
14
static void copy_and_extend_plane(
15
    unsigned char *s,      /* source */
16
    int sp,                /* source pitch */
17
    unsigned char *d,      /* destination */
18
    int dp,                /* destination pitch */
19
    int h,                 /* height */
20
    int w,                 /* width */
21
    int et,                /* extend top border */
22
    int el,                /* extend left border */
23
    int eb,                /* extend bottom border */
24
    int er,                /* extend right border */
25
210k
    int interleave_step) { /* step between pixels of the current plane */
26
210k
  int i, j;
27
210k
  unsigned char *src_ptr1, *src_ptr2;
28
210k
  unsigned char *dest_ptr1, *dest_ptr2;
29
210k
  int linesize;
30
31
210k
  if (interleave_step < 1) interleave_step = 1;
32
33
  /* copy the left and right most columns out */
34
210k
  src_ptr1 = s;
35
210k
  src_ptr2 = s + (w - 1) * interleave_step;
36
210k
  dest_ptr1 = d - el;
37
210k
  dest_ptr2 = d + w;
38
39
6.42M
  for (i = 0; i < h; ++i) {
40
6.21M
    memset(dest_ptr1, src_ptr1[0], el);
41
6.21M
    if (interleave_step == 1) {
42
6.21M
      memcpy(dest_ptr1 + el, src_ptr1, w);
43
6.21M
    } else {
44
0
      for (j = 0; j < w; j++) {
45
0
        dest_ptr1[el + j] = src_ptr1[interleave_step * j];
46
0
      }
47
0
    }
48
6.21M
    memset(dest_ptr2, src_ptr2[0], er);
49
6.21M
    src_ptr1 += sp;
50
6.21M
    src_ptr2 += sp;
51
6.21M
    dest_ptr1 += dp;
52
6.21M
    dest_ptr2 += dp;
53
6.21M
  }
54
55
  /* Now copy the top and bottom lines into each line of the respective
56
   * borders
57
   */
58
210k
  src_ptr1 = d - el;
59
210k
  src_ptr2 = d + dp * (h - 1) - el;
60
210k
  dest_ptr1 = d + dp * (-et) - el;
61
210k
  dest_ptr2 = d + dp * (h)-el;
62
210k
  linesize = el + er + w;
63
64
4.69M
  for (i = 0; i < et; ++i) {
65
4.48M
    memcpy(dest_ptr1, src_ptr1, linesize);
66
4.48M
    dest_ptr1 += dp;
67
4.48M
  }
68
69
5.55M
  for (i = 0; i < eb; ++i) {
70
5.34M
    memcpy(dest_ptr2, src_ptr2, linesize);
71
5.34M
    dest_ptr2 += dp;
72
5.34M
  }
73
210k
}
74
75
void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
76
70.0k
                               YV12_BUFFER_CONFIG *dst) {
77
70.0k
  int et = dst->border;
78
70.0k
  int el = dst->border;
79
70.0k
  int eb = dst->border + dst->y_height - src->y_height;
80
70.0k
  int er = dst->border + dst->y_width - src->y_width;
81
82
  // detect nv12 colorspace
83
70.0k
  int chroma_step = src->v_buffer - src->u_buffer == 1 ? 2 : 1;
84
85
70.0k
  copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer,
86
70.0k
                        dst->y_stride, src->y_height, src->y_width, et, el, eb,
87
70.0k
                        er, 1);
88
89
70.0k
  et = dst->border >> 1;
90
70.0k
  el = dst->border >> 1;
91
70.0k
  eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
92
70.0k
  er = (dst->border >> 1) + dst->uv_width - src->uv_width;
93
94
70.0k
  copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer,
95
70.0k
                        dst->uv_stride, src->uv_height, src->uv_width, et, el,
96
70.0k
                        eb, er, chroma_step);
97
98
70.0k
  copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer,
99
70.0k
                        dst->uv_stride, src->uv_height, src->uv_width, et, el,
100
70.0k
                        eb, er, chroma_step);
101
70.0k
}
102
103
void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
104
                                         YV12_BUFFER_CONFIG *dst, int srcy,
105
0
                                         int srcx, int srch, int srcw) {
106
0
  int et = dst->border;
107
0
  int el = dst->border;
108
0
  int eb = dst->border + dst->y_height - src->y_height;
109
0
  int er = dst->border + dst->y_width - src->y_width;
110
0
  int src_y_offset = srcy * src->y_stride + srcx;
111
0
  int dst_y_offset = srcy * dst->y_stride + srcx;
112
0
  int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
113
0
  int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
114
  // detect nv12 colorspace
115
0
  int chroma_step = src->v_buffer - src->u_buffer == 1 ? 2 : 1;
116
117
  /* If the side is not touching the bounder then don't extend. */
118
0
  if (srcy) et = 0;
119
0
  if (srcx) el = 0;
120
0
  if (srcy + srch != src->y_height) eb = 0;
121
0
  if (srcx + srcw != src->y_width) er = 0;
122
123
0
  copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride,
124
0
                        dst->y_buffer + dst_y_offset, dst->y_stride, srch, srcw,
125
0
                        et, el, eb, er, 1);
126
127
0
  et = (et + 1) >> 1;
128
0
  el = (el + 1) >> 1;
129
0
  eb = (eb + 1) >> 1;
130
0
  er = (er + 1) >> 1;
131
0
  srch = (srch + 1) >> 1;
132
0
  srcw = (srcw + 1) >> 1;
133
134
0
  copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride,
135
0
                        dst->u_buffer + dst_uv_offset, dst->uv_stride, srch,
136
0
                        srcw, et, el, eb, er, chroma_step);
137
138
0
  copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride,
139
0
                        dst->v_buffer + dst_uv_offset, dst->uv_stride, srch,
140
0
                        srcw, et, el, eb, er, chroma_step);
141
0
}
142
143
/* note the extension is only for the last row, for intra prediction purpose */
144
void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr,
145
328k
                       unsigned char *UPtr, unsigned char *VPtr) {
146
328k
  int i;
147
148
328k
  YPtr += ybf->y_stride * 14;
149
328k
  UPtr += ybf->uv_stride * 6;
150
328k
  VPtr += ybf->uv_stride * 6;
151
152
1.64M
  for (i = 0; i < 4; ++i) {
153
1.31M
    YPtr[i] = YPtr[-1];
154
1.31M
    UPtr[i] = UPtr[-1];
155
1.31M
    VPtr[i] = VPtr[-1];
156
1.31M
  }
157
158
328k
  YPtr += ybf->y_stride;
159
328k
  UPtr += ybf->uv_stride;
160
328k
  VPtr += ybf->uv_stride;
161
162
1.64M
  for (i = 0; i < 4; ++i) {
163
1.31M
    YPtr[i] = YPtr[-1];
164
1.31M
    UPtr[i] = UPtr[-1];
165
1.31M
    VPtr[i] = VPtr[-1];
166
1.31M
  }
167
328k
}