PageRenderTime 43ms CodeModel.GetById 20ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/media/libvpx/vp8/common/extend.c

http://github.com/zpao/v8monkey
C | 131 lines | 96 code | 21 blank | 14 comment | 5 complexity | 7e7d5945601c344967254c9c30fd8e81 MD5 | raw file
  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
 16static void copy_and_extend_plane
 17(
 18    unsigned char *s, /* source */
 19    int sp,           /* source pitch */
 20    unsigned char *d, /* destination */
 21    int dp,           /* destination pitch */
 22    int h,            /* height */
 23    int w,            /* width */
 24    int et,           /* extend top border */
 25    int el,           /* extend left border */
 26    int eb,           /* extend bottom border */
 27    int er            /* extend right border */
 28)
 29{
 30    int i;
 31    unsigned char *src_ptr1, *src_ptr2;
 32    unsigned char *dest_ptr1, *dest_ptr2;
 33    int linesize;
 34
 35    /* copy the left and right most columns out */
 36    src_ptr1 = s;
 37    src_ptr2 = s + w - 1;
 38    dest_ptr1 = d - el;
 39    dest_ptr2 = d + w;
 40
 41    for (i = 0; i < h; i++)
 42    {
 43        vpx_memset(dest_ptr1, src_ptr1[0], el);
 44        vpx_memcpy(dest_ptr1 + el, src_ptr1, w);
 45        vpx_memset(dest_ptr2, src_ptr2[0], er);
 46        src_ptr1  += sp;
 47        src_ptr2  += sp;
 48        dest_ptr1 += dp;
 49        dest_ptr2 += dp;
 50    }
 51
 52    /* Now copy the top and bottom lines into each line of the respective
 53     * borders
 54     */
 55    src_ptr1 = d - el;
 56    src_ptr2 = d + dp * (h - 1) - el;
 57    dest_ptr1 = d + dp * (-et) - el;
 58    dest_ptr2 = d + dp * (h) - el;
 59    linesize = el + er + w;
 60
 61    for (i = 0; i < et; i++)
 62    {
 63        vpx_memcpy(dest_ptr1, src_ptr1, linesize);
 64        dest_ptr1 += dp;
 65    }
 66
 67    for (i = 0; i < eb; i++)
 68    {
 69        vpx_memcpy(dest_ptr2, src_ptr2, linesize);
 70        dest_ptr2 += dp;
 71    }
 72}
 73
 74
 75void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src,
 76                               YV12_BUFFER_CONFIG *dst)
 77{
 78    int et = dst->border;
 79    int el = dst->border;
 80    int eb = dst->border + dst->y_height - src->y_height;
 81    int er = dst->border + dst->y_width - src->y_width;
 82
 83    copy_and_extend_plane(src->y_buffer, src->y_stride,
 84                          dst->y_buffer, dst->y_stride,
 85                          src->y_height, src->y_width,
 86                          et, el, eb, er);
 87
 88    et = dst->border >> 1;
 89    el = dst->border >> 1;
 90    eb = (dst->border >> 1) + dst->uv_height - src->uv_height;
 91    er = (dst->border >> 1) + dst->uv_width - src->uv_width;
 92
 93    copy_and_extend_plane(src->u_buffer, src->uv_stride,
 94                          dst->u_buffer, dst->uv_stride,
 95                          src->uv_height, src->uv_width,
 96                          et, el, eb, er);
 97
 98    copy_and_extend_plane(src->v_buffer, src->uv_stride,
 99                          dst->v_buffer, dst->uv_stride,
100                          src->uv_height, src->uv_width,
101                          et, el, eb, er);
102}
103
104
105/* note the extension is only for the last row, for intra prediction purpose */
106void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr)
107{
108    int i;
109
110    YPtr += ybf->y_stride * 14;
111    UPtr += ybf->uv_stride * 6;
112    VPtr += ybf->uv_stride * 6;
113
114    for (i = 0; i < 4; i++)
115    {
116        YPtr[i] = YPtr[-1];
117        UPtr[i] = UPtr[-1];
118        VPtr[i] = VPtr[-1];
119    }
120
121    YPtr += ybf->y_stride;
122    UPtr += ybf->uv_stride;
123    VPtr += ybf->uv_stride;
124
125    for (i = 0; i < 4; i++)
126    {
127        YPtr[i] = YPtr[-1];
128        UPtr[i] = UPtr[-1];
129        VPtr[i] = VPtr[-1];
130    }
131}