• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "extend.h"
13 #include "vpx_mem/vpx_mem.h"
14 
15 
extend_plane_borders(unsigned char * s,int sp,int h,int w,int et,int el,int eb,int er)16 static void extend_plane_borders
17 (
18     unsigned char *s, /* source */
19     int sp,           /* pitch */
20     int h,            /* height */
21     int w,            /* width */
22     int et,           /* extend top border */
23     int el,           /* extend left border */
24     int eb,           /* extend bottom border */
25     int er            /* extend right border */
26 )
27 {
28 
29     int i;
30     unsigned char *src_ptr1, *src_ptr2;
31     unsigned char *dest_ptr1, *dest_ptr2;
32     int linesize;
33 
34     /* copy the left and right most columns out */
35     src_ptr1 = s;
36     src_ptr2 = s + w - 1;
37     dest_ptr1 = s - el;
38     dest_ptr2 = s + w;
39 
40     for (i = 0; i < h - 0 + 1; i++)
41     {
42         /* Some linkers will complain if we call vpx_memset with el set to a
43          * constant 0.
44          */
45         if (el)
46             vpx_memset(dest_ptr1, src_ptr1[0], el);
47         vpx_memset(dest_ptr2, src_ptr2[0], er);
48         src_ptr1  += sp;
49         src_ptr2  += sp;
50         dest_ptr1 += sp;
51         dest_ptr2 += sp;
52     }
53 
54     /* Now copy the top and bottom source lines into each line of the respective borders */
55     src_ptr1 = s - el;
56     src_ptr2 = s + sp * (h - 1) - el;
57     dest_ptr1 = s + sp * (-et) - el;
58     dest_ptr2 = s + sp * (h) - el;
59     linesize = el + er + w + 1;
60 
61     for (i = 0; i < (int)et; i++)
62     {
63         vpx_memcpy(dest_ptr1, src_ptr1, linesize);
64         dest_ptr1 += sp;
65     }
66 
67     for (i = 0; i < (int)eb; i++)
68     {
69         vpx_memcpy(dest_ptr2, src_ptr2, linesize);
70         dest_ptr2 += sp;
71     }
72 }
73 
74 
vp8_extend_to_multiple_of16(YV12_BUFFER_CONFIG * ybf,int width,int height)75 void vp8_extend_to_multiple_of16(YV12_BUFFER_CONFIG *ybf, int width, int height)
76 {
77     int er = 0xf & (16 - (width & 0xf));
78     int eb = 0xf & (16 - (height & 0xf));
79 
80     /* check for non multiples of 16 */
81     if (er != 0 || eb != 0)
82     {
83         extend_plane_borders(ybf->y_buffer, ybf->y_stride, height, width, 0, 0, eb, er);
84 
85         /* adjust for uv */
86         height = (height + 1) >> 1;
87         width  = (width  + 1) >> 1;
88         er = 0x7 & (8 - (width  & 0x7));
89         eb = 0x7 & (8 - (height & 0x7));
90 
91         if (er || eb)
92         {
93             extend_plane_borders(ybf->u_buffer, ybf->uv_stride, height, width, 0, 0, eb, er);
94             extend_plane_borders(ybf->v_buffer, ybf->uv_stride, height, width, 0, 0, eb, er);
95         }
96     }
97 }
98 
99 /* note the extension is only for the last row, for intra prediction purpose */
vp8_extend_mb_row(YV12_BUFFER_CONFIG * ybf,unsigned char * YPtr,unsigned char * UPtr,unsigned char * VPtr)100 void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr)
101 {
102     int i;
103 
104     YPtr += ybf->y_stride * 14;
105     UPtr += ybf->uv_stride * 6;
106     VPtr += ybf->uv_stride * 6;
107 
108     for (i = 0; i < 4; i++)
109     {
110         YPtr[i] = YPtr[-1];
111         UPtr[i] = UPtr[-1];
112         VPtr[i] = VPtr[-1];
113     }
114 
115     YPtr += ybf->y_stride;
116     UPtr += ybf->uv_stride;
117     VPtr += ybf->uv_stride;
118 
119     for (i = 0; i < 4; i++)
120     {
121         YPtr[i] = YPtr[-1];
122         UPtr[i] = UPtr[-1];
123         VPtr[i] = VPtr[-1];
124     }
125 }
126