Merge "vp8_rd_pick_best_mbsegmentation code restructure"
[libvpx.git] / vp8 / common / extend.c
blob47207fa790032656b397bdef3ac1ba2542f5e6c1
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
12 #include "extend.h"
13 #include "vpx_mem/vpx_mem.h"
16 static void extend_plane_borders
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 */
29 int i;
30 unsigned char *src_ptr1, *src_ptr2;
31 unsigned char *dest_ptr1, *dest_ptr2;
32 int linesize;
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;
40 for (i = 0; i < h - 0 + 1; i++)
42 /* Some linkers will complain if we call vpx_memset with el set to a
43 * constant 0.
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;
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;
61 for (i = 0; i < (int)et; i++)
63 vpx_memcpy(dest_ptr1, src_ptr1, linesize);
64 dest_ptr1 += sp;
67 for (i = 0; i < (int)eb; i++)
69 vpx_memcpy(dest_ptr2, src_ptr2, linesize);
70 dest_ptr2 += sp;
75 void vp8_extend_to_multiple_of16(YV12_BUFFER_CONFIG *ybf, int width, int height)
77 int er = 0xf & (16 - (width & 0xf));
78 int eb = 0xf & (16 - (height & 0xf));
80 /* check for non multiples of 16 */
81 if (er != 0 || eb != 0)
83 extend_plane_borders(ybf->y_buffer, ybf->y_stride, height, width, 0, 0, eb, er);
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));
91 if (er || eb)
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);
99 /* note the extension is only for the last row, for intra prediction purpose */
100 void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr)
102 int i;
104 YPtr += ybf->y_stride * 14;
105 UPtr += ybf->uv_stride * 6;
106 VPtr += ybf->uv_stride * 6;
108 for (i = 0; i < 4; i++)
110 YPtr[i] = YPtr[-1];
111 UPtr[i] = UPtr[-1];
112 VPtr[i] = VPtr[-1];
115 YPtr += ybf->y_stride;
116 UPtr += ybf->uv_stride;
117 VPtr += ybf->uv_stride;
119 for (i = 0; i < 4; i++)
121 YPtr[i] = YPtr[-1];
122 UPtr[i] = UPtr[-1];
123 VPtr[i] = VPtr[-1];