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 :
12 : #include "vpx_scale/yv12config.h"
13 : #include "vpx_mem/vpx_mem.h"
14 : #include "vpx_scale/vpxscale.h"
15 :
16 : /****************************************************************************
17 : * Exports
18 : ****************************************************************************/
19 :
20 : /****************************************************************************
21 : *
22 : ****************************************************************************/
23 : void
24 0 : vp8_yv12_extend_frame_borders(YV12_BUFFER_CONFIG *ybf)
25 : {
26 : int i;
27 : unsigned char *src_ptr1, *src_ptr2;
28 : unsigned char *dest_ptr1, *dest_ptr2;
29 :
30 : unsigned int Border;
31 : int plane_stride;
32 : int plane_height;
33 : int plane_width;
34 :
35 : /***********/
36 : /* Y Plane */
37 : /***********/
38 0 : Border = ybf->border;
39 0 : plane_stride = ybf->y_stride;
40 0 : plane_height = ybf->y_height;
41 0 : plane_width = ybf->y_width;
42 :
43 : /* copy the left and right most columns out */
44 0 : src_ptr1 = ybf->y_buffer;
45 0 : src_ptr2 = src_ptr1 + plane_width - 1;
46 0 : dest_ptr1 = src_ptr1 - Border;
47 0 : dest_ptr2 = src_ptr2 + 1;
48 :
49 0 : for (i = 0; i < plane_height; i++)
50 : {
51 0 : vpx_memset(dest_ptr1, src_ptr1[0], Border);
52 0 : vpx_memset(dest_ptr2, src_ptr2[0], Border);
53 0 : src_ptr1 += plane_stride;
54 0 : src_ptr2 += plane_stride;
55 0 : dest_ptr1 += plane_stride;
56 0 : dest_ptr2 += plane_stride;
57 : }
58 :
59 : /* Now copy the top and bottom source lines into each line of the respective borders */
60 0 : src_ptr1 = ybf->y_buffer - Border;
61 0 : src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
62 0 : dest_ptr1 = src_ptr1 - (Border * plane_stride);
63 0 : dest_ptr2 = src_ptr2 + plane_stride;
64 :
65 0 : for (i = 0; i < (int)Border; i++)
66 : {
67 0 : vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
68 0 : vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
69 0 : dest_ptr1 += plane_stride;
70 0 : dest_ptr2 += plane_stride;
71 : }
72 :
73 :
74 : /***********/
75 : /* U Plane */
76 : /***********/
77 0 : plane_stride = ybf->uv_stride;
78 0 : plane_height = ybf->uv_height;
79 0 : plane_width = ybf->uv_width;
80 0 : Border /= 2;
81 :
82 : /* copy the left and right most columns out */
83 0 : src_ptr1 = ybf->u_buffer;
84 0 : src_ptr2 = src_ptr1 + plane_width - 1;
85 0 : dest_ptr1 = src_ptr1 - Border;
86 0 : dest_ptr2 = src_ptr2 + 1;
87 :
88 0 : for (i = 0; i < plane_height; i++)
89 : {
90 0 : vpx_memset(dest_ptr1, src_ptr1[0], Border);
91 0 : vpx_memset(dest_ptr2, src_ptr2[0], Border);
92 0 : src_ptr1 += plane_stride;
93 0 : src_ptr2 += plane_stride;
94 0 : dest_ptr1 += plane_stride;
95 0 : dest_ptr2 += plane_stride;
96 : }
97 :
98 : /* Now copy the top and bottom source lines into each line of the respective borders */
99 0 : src_ptr1 = ybf->u_buffer - Border;
100 0 : src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
101 0 : dest_ptr1 = src_ptr1 - (Border * plane_stride);
102 0 : dest_ptr2 = src_ptr2 + plane_stride;
103 :
104 0 : for (i = 0; i < (int)(Border); i++)
105 : {
106 0 : vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
107 0 : vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
108 0 : dest_ptr1 += plane_stride;
109 0 : dest_ptr2 += plane_stride;
110 : }
111 :
112 : /***********/
113 : /* V Plane */
114 : /***********/
115 :
116 : /* copy the left and right most columns out */
117 0 : src_ptr1 = ybf->v_buffer;
118 0 : src_ptr2 = src_ptr1 + plane_width - 1;
119 0 : dest_ptr1 = src_ptr1 - Border;
120 0 : dest_ptr2 = src_ptr2 + 1;
121 :
122 0 : for (i = 0; i < plane_height; i++)
123 : {
124 0 : vpx_memset(dest_ptr1, src_ptr1[0], Border);
125 0 : vpx_memset(dest_ptr2, src_ptr2[0], Border);
126 0 : src_ptr1 += plane_stride;
127 0 : src_ptr2 += plane_stride;
128 0 : dest_ptr1 += plane_stride;
129 0 : dest_ptr2 += plane_stride;
130 : }
131 :
132 : /* Now copy the top and bottom source lines into each line of the respective borders */
133 0 : src_ptr1 = ybf->v_buffer - Border;
134 0 : src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
135 0 : dest_ptr1 = src_ptr1 - (Border * plane_stride);
136 0 : dest_ptr2 = src_ptr2 + plane_stride;
137 :
138 0 : for (i = 0; i < (int)(Border); i++)
139 : {
140 0 : vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
141 0 : vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
142 0 : dest_ptr1 += plane_stride;
143 0 : dest_ptr2 += plane_stride;
144 : }
145 0 : }
146 :
147 :
148 : static void
149 0 : extend_frame_borders_yonly(YV12_BUFFER_CONFIG *ybf)
150 : {
151 : int i;
152 : unsigned char *src_ptr1, *src_ptr2;
153 : unsigned char *dest_ptr1, *dest_ptr2;
154 :
155 : unsigned int Border;
156 : int plane_stride;
157 : int plane_height;
158 : int plane_width;
159 :
160 : /***********/
161 : /* Y Plane */
162 : /***********/
163 0 : Border = ybf->border;
164 0 : plane_stride = ybf->y_stride;
165 0 : plane_height = ybf->y_height;
166 0 : plane_width = ybf->y_width;
167 :
168 : /* copy the left and right most columns out */
169 0 : src_ptr1 = ybf->y_buffer;
170 0 : src_ptr2 = src_ptr1 + plane_width - 1;
171 0 : dest_ptr1 = src_ptr1 - Border;
172 0 : dest_ptr2 = src_ptr2 + 1;
173 :
174 0 : for (i = 0; i < plane_height; i++)
175 : {
176 0 : vpx_memset(dest_ptr1, src_ptr1[0], Border);
177 0 : vpx_memset(dest_ptr2, src_ptr2[0], Border);
178 0 : src_ptr1 += plane_stride;
179 0 : src_ptr2 += plane_stride;
180 0 : dest_ptr1 += plane_stride;
181 0 : dest_ptr2 += plane_stride;
182 : }
183 :
184 : /* Now copy the top and bottom source lines into each line of the respective borders */
185 0 : src_ptr1 = ybf->y_buffer - Border;
186 0 : src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride;
187 0 : dest_ptr1 = src_ptr1 - (Border * plane_stride);
188 0 : dest_ptr2 = src_ptr2 + plane_stride;
189 :
190 0 : for (i = 0; i < (int)Border; i++)
191 : {
192 0 : vpx_memcpy(dest_ptr1, src_ptr1, plane_stride);
193 0 : vpx_memcpy(dest_ptr2, src_ptr2, plane_stride);
194 0 : dest_ptr1 += plane_stride;
195 0 : dest_ptr2 += plane_stride;
196 : }
197 :
198 0 : plane_stride /= 2;
199 0 : plane_height /= 2;
200 0 : plane_width /= 2;
201 0 : Border /= 2;
202 :
203 0 : }
204 :
205 :
206 :
207 : /****************************************************************************
208 : *
209 : * ROUTINE : vp8_yv12_copy_frame
210 : *
211 : * INPUTS :
212 : *
213 : * OUTPUTS : None.
214 : *
215 : * RETURNS : void
216 : *
217 : * FUNCTION : Copies the source image into the destination image and
218 : * updates the destination's UMV borders.
219 : *
220 : * SPECIAL NOTES : The frames are assumed to be identical in size.
221 : *
222 : ****************************************************************************/
223 : void
224 0 : vp8_yv12_copy_frame(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc)
225 : {
226 : int row;
227 : unsigned char *source, *dest;
228 :
229 0 : source = src_ybc->y_buffer;
230 0 : dest = dst_ybc->y_buffer;
231 :
232 0 : for (row = 0; row < src_ybc->y_height; row++)
233 : {
234 0 : vpx_memcpy(dest, source, src_ybc->y_width);
235 0 : source += src_ybc->y_stride;
236 0 : dest += dst_ybc->y_stride;
237 : }
238 :
239 0 : source = src_ybc->u_buffer;
240 0 : dest = dst_ybc->u_buffer;
241 :
242 0 : for (row = 0; row < src_ybc->uv_height; row++)
243 : {
244 0 : vpx_memcpy(dest, source, src_ybc->uv_width);
245 0 : source += src_ybc->uv_stride;
246 0 : dest += dst_ybc->uv_stride;
247 : }
248 :
249 0 : source = src_ybc->v_buffer;
250 0 : dest = dst_ybc->v_buffer;
251 :
252 0 : for (row = 0; row < src_ybc->uv_height; row++)
253 : {
254 0 : vpx_memcpy(dest, source, src_ybc->uv_width);
255 0 : source += src_ybc->uv_stride;
256 0 : dest += dst_ybc->uv_stride;
257 : }
258 :
259 0 : vp8_yv12_extend_frame_borders_ptr(dst_ybc);
260 0 : }
261 :
262 : void
263 0 : vp8_yv12_copy_frame_yonly(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc)
264 : {
265 : int row;
266 : unsigned char *source, *dest;
267 :
268 :
269 0 : source = src_ybc->y_buffer;
270 0 : dest = dst_ybc->y_buffer;
271 :
272 0 : for (row = 0; row < src_ybc->y_height; row++)
273 : {
274 0 : vpx_memcpy(dest, source, src_ybc->y_width);
275 0 : source += src_ybc->y_stride;
276 0 : dest += dst_ybc->y_stride;
277 : }
278 :
279 0 : extend_frame_borders_yonly(dst_ybc);
280 0 : }
|