• 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 #include "extend.h"
12 #include "vpx_mem/vpx_mem.h"
13 
copy_and_extend_plane(unsigned char * s,int sp,unsigned char * d,int dp,int h,int w,int et,int el,int eb,int er)14 static void copy_and_extend_plane(unsigned char *s, /* source */
15                                   int sp,           /* source pitch */
16                                   unsigned char *d, /* destination */
17                                   int dp,           /* destination pitch */
18                                   int h,            /* height */
19                                   int w,            /* width */
20                                   int et,           /* extend top border */
21                                   int el,           /* extend left border */
22                                   int eb,           /* extend bottom border */
23                                   int er) {         /* extend right border */
24   int i;
25   unsigned char *src_ptr1, *src_ptr2;
26   unsigned char *dest_ptr1, *dest_ptr2;
27   int linesize;
28 
29   /* copy the left and right most columns out */
30   src_ptr1 = s;
31   src_ptr2 = s + w - 1;
32   dest_ptr1 = d - el;
33   dest_ptr2 = d + w;
34 
35   for (i = 0; i < h; ++i) {
36     memset(dest_ptr1, src_ptr1[0], el);
37     memcpy(dest_ptr1 + el, src_ptr1, w);
38     memset(dest_ptr2, src_ptr2[0], er);
39     src_ptr1 += sp;
40     src_ptr2 += sp;
41     dest_ptr1 += dp;
42     dest_ptr2 += dp;
43   }
44 
45   /* Now copy the top and bottom lines into each line of the respective
46    * borders
47    */
48   src_ptr1 = d - el;
49   src_ptr2 = d + dp * (h - 1) - el;
50   dest_ptr1 = d + dp * (-et) - el;
51   dest_ptr2 = d + dp * (h)-el;
52   linesize = el + er + w;
53 
54   for (i = 0; i < et; ++i) {
55     memcpy(dest_ptr1, src_ptr1, linesize);
56     dest_ptr1 += dp;
57   }
58 
59   for (i = 0; i < eb; ++i) {
60     memcpy(dest_ptr2, src_ptr2, linesize);
61     dest_ptr2 += dp;
62   }
63 }
64 
vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG * src,YV12_BUFFER_CONFIG * dst)65 void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
66                                YV12_BUFFER_CONFIG *dst) {
67   int et = dst->border;
68   int el = dst->border;
69   int eb = dst->border + dst->y_height - src->y_height;
70   int er = dst->border + dst->y_width - src->y_width;
71 
72   copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer,
73                         dst->y_stride, src->y_height, src->y_width, et, el, eb,
74                         er);
75 
76   et = dst->border >> 1;
77   el = dst->border >> 1;
78   eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
79   er = (dst->border >> 1) + dst->uv_width - src->uv_width;
80 
81   copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer,
82                         dst->uv_stride, src->uv_height, src->uv_width, et, el,
83                         eb, er);
84 
85   copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer,
86                         dst->uv_stride, src->uv_height, src->uv_width, et, el,
87                         eb, er);
88 }
89 
vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG * src,YV12_BUFFER_CONFIG * dst,int srcy,int srcx,int srch,int srcw)90 void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src,
91                                          YV12_BUFFER_CONFIG *dst, int srcy,
92                                          int srcx, int srch, int srcw) {
93   int et = dst->border;
94   int el = dst->border;
95   int eb = dst->border + dst->y_height - src->y_height;
96   int er = dst->border + dst->y_width - src->y_width;
97   int src_y_offset = srcy * src->y_stride + srcx;
98   int dst_y_offset = srcy * dst->y_stride + srcx;
99   int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
100   int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
101 
102   /* If the side is not touching the bounder then don't extend. */
103   if (srcy) et = 0;
104   if (srcx) el = 0;
105   if (srcy + srch != src->y_height) eb = 0;
106   if (srcx + srcw != src->y_width) er = 0;
107 
108   copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride,
109                         dst->y_buffer + dst_y_offset, dst->y_stride, srch, srcw,
110                         et, el, eb, er);
111 
112   et = (et + 1) >> 1;
113   el = (el + 1) >> 1;
114   eb = (eb + 1) >> 1;
115   er = (er + 1) >> 1;
116   srch = (srch + 1) >> 1;
117   srcw = (srcw + 1) >> 1;
118 
119   copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride,
120                         dst->u_buffer + dst_uv_offset, dst->uv_stride, srch,
121                         srcw, et, el, eb, er);
122 
123   copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride,
124                         dst->v_buffer + dst_uv_offset, dst->uv_stride, srch,
125                         srcw, et, el, eb, er);
126 }
127 
128 /* 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)129 void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr,
130                        unsigned char *UPtr, unsigned char *VPtr) {
131   int i;
132 
133   YPtr += ybf->y_stride * 14;
134   UPtr += ybf->uv_stride * 6;
135   VPtr += ybf->uv_stride * 6;
136 
137   for (i = 0; i < 4; ++i) {
138     YPtr[i] = YPtr[-1];
139     UPtr[i] = UPtr[-1];
140     VPtr[i] = VPtr[-1];
141   }
142 
143   YPtr += ybf->y_stride;
144   UPtr += ybf->uv_stride;
145   VPtr += ybf->uv_stride;
146 
147   for (i = 0; i < 4; ++i) {
148     YPtr[i] = YPtr[-1];
149     UPtr[i] = UPtr[-1];
150     VPtr[i] = VPtr[-1];
151   }
152 }
153