]> granicus.if.org Git - libvpx/blob - vpx_scale/generic/yv12extend.c
Merge "Fix potential ioc issue in vp9_get_prob for 4K above sizes"
[libvpx] / vpx_scale / generic / yv12extend.c
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/vpx_integer.h"
14 #include "vpx_mem/vpx_mem.h"
15 #include "vpx_scale/yv12config.h"
16
17 static void extend_plane(uint8_t *const src, int src_stride,
18                          int width, int height,
19                          int extend_top, int extend_left,
20                          int extend_bottom, int extend_right) {
21   int i;
22   const int linesize = extend_left + extend_right + width;
23
24   /* copy the left and right most columns out */
25   uint8_t *src_ptr1 = src;
26   uint8_t *src_ptr2 = src + width - 1;
27   uint8_t *dst_ptr1 = src - extend_left;
28   uint8_t *dst_ptr2 = src + width;
29
30   for (i = 0; i < height; ++i) {
31     vpx_memset(dst_ptr1, src_ptr1[0], extend_left);
32     vpx_memset(dst_ptr2, src_ptr2[0], extend_right);
33     src_ptr1 += src_stride;
34     src_ptr2 += src_stride;
35     dst_ptr1 += src_stride;
36     dst_ptr2 += src_stride;
37   }
38
39   /* Now copy the top and bottom lines into each line of the respective
40    * borders
41    */
42   src_ptr1 = src - extend_left;
43   src_ptr2 = src + src_stride * (height - 1) - extend_left;
44   dst_ptr1 = src + src_stride * -extend_top - extend_left;
45   dst_ptr2 = src + src_stride * height - extend_left;
46
47   for (i = 0; i < extend_top; ++i) {
48     vpx_memcpy(dst_ptr1, src_ptr1, linesize);
49     dst_ptr1 += src_stride;
50   }
51
52   for (i = 0; i < extend_bottom; ++i) {
53     vpx_memcpy(dst_ptr2, src_ptr2, linesize);
54     dst_ptr2 += src_stride;
55   }
56 }
57
58 void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
59   const int uv_border = ybf->border / 2;
60
61   assert(ybf->border % 2 == 0);
62   assert(ybf->y_height - ybf->y_crop_height < 16);
63   assert(ybf->y_width - ybf->y_crop_width < 16);
64   assert(ybf->y_height - ybf->y_crop_height >= 0);
65   assert(ybf->y_width - ybf->y_crop_width >= 0);
66
67   extend_plane(ybf->y_buffer, ybf->y_stride,
68                ybf->y_crop_width, ybf->y_crop_height,
69                ybf->border, ybf->border,
70                ybf->border + ybf->y_height - ybf->y_crop_height,
71                ybf->border + ybf->y_width - ybf->y_crop_width);
72
73   extend_plane(ybf->u_buffer, ybf->uv_stride,
74                ybf->uv_crop_width, ybf->uv_crop_height,
75                uv_border, uv_border,
76                uv_border + ybf->uv_height - ybf->uv_crop_height,
77                uv_border + ybf->uv_width - ybf->uv_crop_width);
78
79   extend_plane(ybf->v_buffer, ybf->uv_stride,
80                ybf->uv_crop_width, ybf->uv_crop_height,
81                uv_border, uv_border,
82                uv_border + ybf->uv_height - ybf->uv_crop_height,
83                uv_border + ybf->uv_width - ybf->uv_crop_width);
84 }
85
86 #if CONFIG_VP9
87 static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
88   const int c_w = ybf->uv_crop_width;
89   const int c_h = ybf->uv_crop_height;
90   const int ss_x = ybf->uv_width < ybf->y_width;
91   const int ss_y = ybf->uv_height < ybf->y_height;
92   const int c_et = ext_size >> ss_y;
93   const int c_el = ext_size >> ss_x;
94   const int c_eb = c_et + ybf->uv_height - ybf->uv_crop_height;
95   const int c_er = c_el + ybf->uv_width - ybf->uv_crop_width;
96
97   assert(ybf->y_height - ybf->y_crop_height < 16);
98   assert(ybf->y_width - ybf->y_crop_width < 16);
99   assert(ybf->y_height - ybf->y_crop_height >= 0);
100   assert(ybf->y_width - ybf->y_crop_width >= 0);
101
102   extend_plane(ybf->y_buffer, ybf->y_stride,
103                ybf->y_crop_width, ybf->y_crop_height,
104                ext_size, ext_size,
105                ext_size + ybf->y_height - ybf->y_crop_height,
106                ext_size + ybf->y_width - ybf->y_crop_width);
107
108   extend_plane(ybf->u_buffer, ybf->uv_stride,
109                c_w, c_h, c_et, c_el, c_eb, c_er);
110
111   extend_plane(ybf->v_buffer, ybf->uv_stride,
112                c_w, c_h, c_et, c_el, c_eb, c_er);
113 }
114
115 void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
116   extend_frame(ybf, ybf->border);
117 }
118
119 void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf) {
120   const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS) ?
121                        VP9INNERBORDERINPIXELS : ybf->border;
122   extend_frame(ybf, inner_bw);
123 }
124 #endif  // CONFIG_VP9
125
126 // Copies the source image into the destination image and updates the
127 // destination's UMV borders.
128 // Note: The frames are assumed to be identical in size.
129 void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc,
130                            YV12_BUFFER_CONFIG *dst_ybc) {
131   int row;
132   const uint8_t *src = src_ybc->y_buffer;
133   uint8_t *dst = dst_ybc->y_buffer;
134
135 #if 0
136   /* These assertions are valid in the codec, but the libvpx-tester uses
137    * this code slightly differently.
138    */
139   assert(src_ybc->y_width == dst_ybc->y_width);
140   assert(src_ybc->y_height == dst_ybc->y_height);
141 #endif
142
143   for (row = 0; row < src_ybc->y_height; ++row) {
144     vpx_memcpy(dst, src, src_ybc->y_width);
145     src += src_ybc->y_stride;
146     dst += dst_ybc->y_stride;
147   }
148
149   src = src_ybc->u_buffer;
150   dst = dst_ybc->u_buffer;
151
152   for (row = 0; row < src_ybc->uv_height; ++row) {
153     vpx_memcpy(dst, src, src_ybc->uv_width);
154     src += src_ybc->uv_stride;
155     dst += dst_ybc->uv_stride;
156   }
157
158   src = src_ybc->v_buffer;
159   dst = dst_ybc->v_buffer;
160
161   for (row = 0; row < src_ybc->uv_height; ++row) {
162     vpx_memcpy(dst, src, src_ybc->uv_width);
163     src += src_ybc->uv_stride;
164     dst += dst_ybc->uv_stride;
165   }
166
167   vp8_yv12_extend_frame_borders_c(dst_ybc);
168 }
169
170 void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
171                        YV12_BUFFER_CONFIG *dst_ybc) {
172   int row;
173   const uint8_t *src = src_ybc->y_buffer;
174   uint8_t *dst = dst_ybc->y_buffer;
175
176   for (row = 0; row < src_ybc->y_height; ++row) {
177     vpx_memcpy(dst, src, src_ybc->y_width);
178     src += src_ybc->y_stride;
179     dst += dst_ybc->y_stride;
180   }
181 }