OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include "./vpx_config.h" | 12 #include "./vpx_config.h" |
| 13 #include "vpx/vpx_integer.h" |
| 14 #include "vpx_mem/vpx_mem.h" |
13 #include "vpx_scale/yv12config.h" | 15 #include "vpx_scale/yv12config.h" |
14 #include "vpx_mem/vpx_mem.h" | |
15 #include "vpx_scale/vpx_scale.h" | |
16 | 16 |
17 /**************************************************************************** | 17 static void extend_plane(uint8_t *const src, int src_stride, |
18 * Exports | 18 int width, int height, |
19 ****************************************************************************/ | 19 int extend_top, int extend_left, |
20 | 20 int extend_bottom, int extend_right) { |
21 /**************************************************************************** | |
22 * | |
23 ****************************************************************************/ | |
24 static void extend_plane(uint8_t *s, /* source */ | |
25 int sp, /* source pitch */ | |
26 int w, /* width */ | |
27 int h, /* height */ | |
28 int et, /* extend top border */ | |
29 int el, /* extend left border */ | |
30 int eb, /* extend bottom border */ | |
31 int er) { /* extend right border */ | |
32 int i; | 21 int i; |
33 uint8_t *src_ptr1, *src_ptr2; | 22 const int linesize = extend_left + extend_right + width; |
34 uint8_t *dest_ptr1, *dest_ptr2; | |
35 int linesize; | |
36 | 23 |
37 /* copy the left and right most columns out */ | 24 /* copy the left and right most columns out */ |
38 src_ptr1 = s; | 25 uint8_t *src_ptr1 = src; |
39 src_ptr2 = s + w - 1; | 26 uint8_t *src_ptr2 = src + width - 1; |
40 dest_ptr1 = s - el; | 27 uint8_t *dst_ptr1 = src - extend_left; |
41 dest_ptr2 = s + w; | 28 uint8_t *dst_ptr2 = src + width; |
42 | 29 |
43 for (i = 0; i < h; i++) { | 30 for (i = 0; i < height; ++i) { |
44 vpx_memset(dest_ptr1, src_ptr1[0], el); | 31 vpx_memset(dst_ptr1, src_ptr1[0], extend_left); |
45 vpx_memset(dest_ptr2, src_ptr2[0], er); | 32 vpx_memset(dst_ptr2, src_ptr2[0], extend_right); |
46 src_ptr1 += sp; | 33 src_ptr1 += src_stride; |
47 src_ptr2 += sp; | 34 src_ptr2 += src_stride; |
48 dest_ptr1 += sp; | 35 dst_ptr1 += src_stride; |
49 dest_ptr2 += sp; | 36 dst_ptr2 += src_stride; |
50 } | 37 } |
51 | 38 |
52 /* Now copy the top and bottom lines into each line of the respective | 39 /* Now copy the top and bottom lines into each line of the respective |
53 * borders | 40 * borders |
54 */ | 41 */ |
55 src_ptr1 = s - el; | 42 src_ptr1 = src - extend_left; |
56 src_ptr2 = s + sp * (h - 1) - el; | 43 src_ptr2 = src + src_stride * (height - 1) - extend_left; |
57 dest_ptr1 = s + sp * (-et) - el; | 44 dst_ptr1 = src + src_stride * -extend_top - extend_left; |
58 dest_ptr2 = s + sp * (h) - el; | 45 dst_ptr2 = src + src_stride * height - extend_left; |
59 linesize = el + er + w; | |
60 | 46 |
61 for (i = 0; i < et; i++) { | 47 for (i = 0; i < extend_top; ++i) { |
62 vpx_memcpy(dest_ptr1, src_ptr1, linesize); | 48 vpx_memcpy(dst_ptr1, src_ptr1, linesize); |
63 dest_ptr1 += sp; | 49 dst_ptr1 += src_stride; |
64 } | 50 } |
65 | 51 |
66 for (i = 0; i < eb; i++) { | 52 for (i = 0; i < extend_bottom; ++i) { |
67 vpx_memcpy(dest_ptr2, src_ptr2, linesize); | 53 vpx_memcpy(dst_ptr2, src_ptr2, linesize); |
68 dest_ptr2 += sp; | 54 dst_ptr2 += src_stride; |
69 } | 55 } |
70 } | 56 } |
71 | 57 |
72 void | 58 void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { |
73 vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { | |
74 assert(ybf->y_height - ybf->y_crop_height < 16); | 59 assert(ybf->y_height - ybf->y_crop_height < 16); |
75 assert(ybf->y_width - ybf->y_crop_width < 16); | 60 assert(ybf->y_width - ybf->y_crop_width < 16); |
76 assert(ybf->y_height - ybf->y_crop_height >= 0); | 61 assert(ybf->y_height - ybf->y_crop_height >= 0); |
77 assert(ybf->y_width - ybf->y_crop_width >= 0); | 62 assert(ybf->y_width - ybf->y_crop_width >= 0); |
78 | 63 |
79 extend_plane(ybf->y_buffer, ybf->y_stride, | 64 extend_plane(ybf->y_buffer, ybf->y_stride, |
80 ybf->y_crop_width, ybf->y_crop_height, | 65 ybf->y_crop_width, ybf->y_crop_height, |
81 ybf->border, ybf->border, | 66 ybf->border, ybf->border, |
82 ybf->border + ybf->y_height - ybf->y_crop_height, | 67 ybf->border + ybf->y_height - ybf->y_crop_height, |
83 ybf->border + ybf->y_width - ybf->y_crop_width); | 68 ybf->border + ybf->y_width - ybf->y_crop_width); |
84 | 69 |
85 extend_plane(ybf->u_buffer, ybf->uv_stride, | 70 extend_plane(ybf->u_buffer, ybf->uv_stride, |
86 (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, | 71 (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, |
87 ybf->border / 2, ybf->border / 2, | 72 ybf->border / 2, ybf->border / 2, |
88 (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, | 73 (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, |
89 (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); | 74 (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); |
90 | 75 |
91 extend_plane(ybf->v_buffer, ybf->uv_stride, | 76 extend_plane(ybf->v_buffer, ybf->uv_stride, |
92 (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, | 77 (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, |
93 ybf->border / 2, ybf->border / 2, | 78 ybf->border / 2, ybf->border / 2, |
94 (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, | 79 (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, |
95 (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); | 80 (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); |
96 } | 81 } |
97 | 82 |
98 #if CONFIG_VP9 | 83 #if CONFIG_VP9 |
99 static void extend_frame(YV12_BUFFER_CONFIG *ybf, | 84 static void extend_frame(YV12_BUFFER_CONFIG *const ybf, |
100 int subsampling_x, int subsampling_y, | 85 int subsampling_x, int subsampling_y, |
101 int ext_size) { | 86 int ext_size) { |
102 const int c_w = (ybf->y_crop_width + subsampling_x) >> subsampling_x; | 87 const int c_w = (ybf->y_crop_width + subsampling_x) >> subsampling_x; |
103 const int c_h = (ybf->y_crop_height + subsampling_y) >> subsampling_y; | 88 const int c_h = (ybf->y_crop_height + subsampling_y) >> subsampling_y; |
104 const int c_et = ext_size >> subsampling_y; | 89 const int c_et = ext_size >> subsampling_y; |
105 const int c_el = ext_size >> subsampling_x; | 90 const int c_el = ext_size >> subsampling_x; |
106 const int c_eb = (ext_size + ybf->y_height - ybf->y_crop_height + | 91 const int c_eb = (ext_size + ybf->y_height - ybf->y_crop_height + |
107 subsampling_y) >> subsampling_y; | 92 subsampling_y) >> subsampling_y; |
108 const int c_er = (ext_size + ybf->y_width - ybf->y_crop_width + | 93 const int c_er = (ext_size + ybf->y_width - ybf->y_crop_width + |
109 subsampling_x) >> subsampling_x; | 94 subsampling_x) >> subsampling_x; |
110 | 95 |
111 assert(ybf->y_height - ybf->y_crop_height < 16); | 96 assert(ybf->y_height - ybf->y_crop_height < 16); |
112 assert(ybf->y_width - ybf->y_crop_width < 16); | 97 assert(ybf->y_width - ybf->y_crop_width < 16); |
113 assert(ybf->y_height - ybf->y_crop_height >= 0); | 98 assert(ybf->y_height - ybf->y_crop_height >= 0); |
114 assert(ybf->y_width - ybf->y_crop_width >= 0); | 99 assert(ybf->y_width - ybf->y_crop_width >= 0); |
115 | 100 |
116 extend_plane(ybf->y_buffer, ybf->y_stride, | 101 extend_plane(ybf->y_buffer, ybf->y_stride, |
117 ybf->y_crop_width, ybf->y_crop_height, | 102 ybf->y_crop_width, ybf->y_crop_height, |
118 ext_size, ext_size, | 103 ext_size, ext_size, |
119 ext_size + ybf->y_height - ybf->y_crop_height, | 104 ext_size + ybf->y_height - ybf->y_crop_height, |
120 ext_size + ybf->y_width - ybf->y_crop_width); | 105 ext_size + ybf->y_width - ybf->y_crop_width); |
121 | 106 |
122 extend_plane(ybf->u_buffer, ybf->uv_stride, | 107 extend_plane(ybf->u_buffer, ybf->uv_stride, |
123 c_w, c_h, c_et, c_el, c_eb, c_er); | 108 c_w, c_h, c_et, c_el, c_eb, c_er); |
124 | 109 |
125 extend_plane(ybf->v_buffer, ybf->uv_stride, | 110 extend_plane(ybf->v_buffer, ybf->uv_stride, |
126 c_w, c_h, c_et, c_el, c_eb, c_er); | 111 c_w, c_h, c_et, c_el, c_eb, c_er); |
127 } | 112 } |
128 | 113 |
129 | |
130 void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, | 114 void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, |
131 int subsampling_x, int subsampling_y) { | 115 int subsampling_x, int subsampling_y) { |
132 extend_frame(ybf, subsampling_x, subsampling_y, ybf->border); | 116 extend_frame(ybf, subsampling_x, subsampling_y, ybf->border); |
133 } | 117 } |
134 | 118 |
135 void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf, | 119 void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf, |
136 int subsampling_x, int subsampling_y) { | 120 int subsampling_x, int subsampling_y) { |
137 const int inner_bw = ybf->border > VP9INNERBORDERINPIXLES ? | 121 const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS) ? |
138 VP9INNERBORDERINPIXLES : ybf->border; | 122 VP9INNERBORDERINPIXELS : ybf->border; |
139 extend_frame(ybf, subsampling_x, subsampling_y, inner_bw); | 123 extend_frame(ybf, subsampling_x, subsampling_y, inner_bw); |
140 } | 124 } |
141 #endif | 125 #endif // CONFIG_VP9 |
142 | 126 |
143 /**************************************************************************** | 127 // Copies the source image into the destination image and updates the |
144 * | 128 // destination's UMV borders. |
145 * ROUTINE : vp8_yv12_copy_frame | 129 // Note: The frames are assumed to be identical in size. |
146 * | 130 void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc, |
147 * INPUTS : | 131 YV12_BUFFER_CONFIG *dst_ybc) { |
148 * | |
149 * OUTPUTS : None. | |
150 * | |
151 * RETURNS : void | |
152 * | |
153 * FUNCTION : Copies the source image into the destination image and | |
154 * updates the destination's UMV borders. | |
155 * | |
156 * SPECIAL NOTES : The frames are assumed to be identical in size. | |
157 * | |
158 ****************************************************************************/ | |
159 void | |
160 vp8_yv12_copy_frame_c(YV12_BUFFER_CONFIG *src_ybc, | |
161 YV12_BUFFER_CONFIG *dst_ybc) { | |
162 int row; | 132 int row; |
163 unsigned char *source, *dest; | 133 const uint8_t *src = src_ybc->y_buffer; |
| 134 uint8_t *dst = dst_ybc->y_buffer; |
164 | 135 |
165 #if 0 | 136 #if 0 |
166 /* These assertions are valid in the codec, but the libvpx-tester uses | 137 /* These assertions are valid in the codec, but the libvpx-tester uses |
167 * this code slightly differently. | 138 * this code slightly differently. |
168 */ | 139 */ |
169 assert(src_ybc->y_width == dst_ybc->y_width); | 140 assert(src_ybc->y_width == dst_ybc->y_width); |
170 assert(src_ybc->y_height == dst_ybc->y_height); | 141 assert(src_ybc->y_height == dst_ybc->y_height); |
171 #endif | 142 #endif |
172 | 143 |
173 source = src_ybc->y_buffer; | 144 for (row = 0; row < src_ybc->y_height; ++row) { |
174 dest = dst_ybc->y_buffer; | 145 vpx_memcpy(dst, src, src_ybc->y_width); |
175 | 146 src += src_ybc->y_stride; |
176 for (row = 0; row < src_ybc->y_height; row++) { | 147 dst += dst_ybc->y_stride; |
177 vpx_memcpy(dest, source, src_ybc->y_width); | |
178 source += src_ybc->y_stride; | |
179 dest += dst_ybc->y_stride; | |
180 } | 148 } |
181 | 149 |
182 source = src_ybc->u_buffer; | 150 src = src_ybc->u_buffer; |
183 dest = dst_ybc->u_buffer; | 151 dst = dst_ybc->u_buffer; |
184 | 152 |
185 for (row = 0; row < src_ybc->uv_height; row++) { | 153 for (row = 0; row < src_ybc->uv_height; ++row) { |
186 vpx_memcpy(dest, source, src_ybc->uv_width); | 154 vpx_memcpy(dst, src, src_ybc->uv_width); |
187 source += src_ybc->uv_stride; | 155 src += src_ybc->uv_stride; |
188 dest += dst_ybc->uv_stride; | 156 dst += dst_ybc->uv_stride; |
189 } | 157 } |
190 | 158 |
191 source = src_ybc->v_buffer; | 159 src = src_ybc->v_buffer; |
192 dest = dst_ybc->v_buffer; | 160 dst = dst_ybc->v_buffer; |
193 | 161 |
194 for (row = 0; row < src_ybc->uv_height; row++) { | 162 for (row = 0; row < src_ybc->uv_height; ++row) { |
195 vpx_memcpy(dest, source, src_ybc->uv_width); | 163 vpx_memcpy(dst, src, src_ybc->uv_width); |
196 source += src_ybc->uv_stride; | 164 src += src_ybc->uv_stride; |
197 dest += dst_ybc->uv_stride; | 165 dst += dst_ybc->uv_stride; |
198 } | 166 } |
199 | 167 |
200 vp8_yv12_extend_frame_borders_c(dst_ybc); | 168 vp8_yv12_extend_frame_borders_c(dst_ybc); |
201 } | 169 } |
202 | 170 |
203 void vp8_yv12_copy_y_c(YV12_BUFFER_CONFIG *src_ybc, | 171 void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, |
204 YV12_BUFFER_CONFIG *dst_ybc) { | 172 YV12_BUFFER_CONFIG *dst_ybc) { |
205 int row; | 173 int row; |
206 unsigned char *source, *dest; | 174 const uint8_t *src = src_ybc->y_buffer; |
| 175 uint8_t *dst = dst_ybc->y_buffer; |
207 | 176 |
208 | 177 for (row = 0; row < src_ybc->y_height; ++row) { |
209 source = src_ybc->y_buffer; | 178 vpx_memcpy(dst, src, src_ybc->y_width); |
210 dest = dst_ybc->y_buffer; | 179 src += src_ybc->y_stride; |
211 | 180 dst += dst_ybc->y_stride; |
212 for (row = 0; row < src_ybc->y_height; row++) { | |
213 vpx_memcpy(dest, source, src_ybc->y_width); | |
214 source += src_ybc->y_stride; | |
215 dest += dst_ybc->y_stride; | |
216 } | 181 } |
217 } | 182 } |
OLD | NEW |