media/libvpx/vp9/vp9_iface_common.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/vp9_iface_common.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +#ifndef VP9_VP9_IFACE_COMMON_H_
    1.14 +#define VP9_VP9_IFACE_COMMON_H_
    1.15 +
    1.16 +static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG  *yv12,
    1.17 +                            void *user_priv) {
    1.18 +  /** vpx_img_wrap() doesn't allow specifying independent strides for
    1.19 +    * the Y, U, and V planes, nor other alignment adjustments that
    1.20 +    * might be representable by a YV12_BUFFER_CONFIG, so we just
    1.21 +    * initialize all the fields.*/
    1.22 +  int bps = 12;
    1.23 +  if (yv12->uv_height == yv12->y_height) {
    1.24 +    if (yv12->uv_width == yv12->y_width) {
    1.25 +      img->fmt = VPX_IMG_FMT_I444;
    1.26 +      bps = 24;
    1.27 +    } else {
    1.28 +      img->fmt = VPX_IMG_FMT_I422;
    1.29 +      bps = 16;
    1.30 +    }
    1.31 +  } else {
    1.32 +    img->fmt = VPX_IMG_FMT_I420;
    1.33 +  }
    1.34 +  img->w = yv12->y_stride;
    1.35 +  img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9BORDERINPIXELS, 3);
    1.36 +  img->d_w = yv12->y_crop_width;
    1.37 +  img->d_h = yv12->y_crop_height;
    1.38 +  img->x_chroma_shift = yv12->uv_width < yv12->y_width;
    1.39 +  img->y_chroma_shift = yv12->uv_height < yv12->y_height;
    1.40 +  img->planes[VPX_PLANE_Y] = yv12->y_buffer;
    1.41 +  img->planes[VPX_PLANE_U] = yv12->u_buffer;
    1.42 +  img->planes[VPX_PLANE_V] = yv12->v_buffer;
    1.43 +  img->planes[VPX_PLANE_ALPHA] = yv12->alpha_buffer;
    1.44 +  img->stride[VPX_PLANE_Y] = yv12->y_stride;
    1.45 +  img->stride[VPX_PLANE_U] = yv12->uv_stride;
    1.46 +  img->stride[VPX_PLANE_V] = yv12->uv_stride;
    1.47 +  img->stride[VPX_PLANE_ALPHA] = yv12->alpha_stride;
    1.48 +  img->bps = bps;
    1.49 +  img->user_priv = user_priv;
    1.50 +  img->img_data = yv12->buffer_alloc;
    1.51 +  img->img_data_owner = 0;
    1.52 +  img->self_allocd = 0;
    1.53 +}
    1.54 +
    1.55 +static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
    1.56 +                                       YV12_BUFFER_CONFIG *yv12) {
    1.57 +  yv12->y_buffer = img->planes[VPX_PLANE_Y];
    1.58 +  yv12->u_buffer = img->planes[VPX_PLANE_U];
    1.59 +  yv12->v_buffer = img->planes[VPX_PLANE_V];
    1.60 +  yv12->alpha_buffer = img->planes[VPX_PLANE_ALPHA];
    1.61 +
    1.62 +  yv12->y_crop_width  = img->d_w;
    1.63 +  yv12->y_crop_height = img->d_h;
    1.64 +  yv12->y_width  = img->d_w;
    1.65 +  yv12->y_height = img->d_h;
    1.66 +
    1.67 +  yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
    1.68 +                                            : yv12->y_width;
    1.69 +  yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
    1.70 +                                             : yv12->y_height;
    1.71 +
    1.72 +  yv12->alpha_width = yv12->alpha_buffer ? img->d_w : 0;
    1.73 +  yv12->alpha_height = yv12->alpha_buffer ? img->d_h : 0;
    1.74 +
    1.75 +  yv12->y_stride = img->stride[VPX_PLANE_Y];
    1.76 +  yv12->uv_stride = img->stride[VPX_PLANE_U];
    1.77 +  yv12->alpha_stride = yv12->alpha_buffer ? img->stride[VPX_PLANE_ALPHA] : 0;
    1.78 +
    1.79 +  yv12->border  = (img->stride[VPX_PLANE_Y] - img->w) / 2;
    1.80 +#if CONFIG_ALPHA
    1.81 +  // For development purposes, force alpha to hold the same data a Y for now.
    1.82 +  yv12->alpha_buffer = yv12->y_buffer;
    1.83 +  yv12->alpha_width = yv12->y_width;
    1.84 +  yv12->alpha_height = yv12->y_height;
    1.85 +  yv12->alpha_stride = yv12->y_stride;
    1.86 +#endif
    1.87 +  return VPX_CODEC_OK;
    1.88 +}
    1.89 +
    1.90 +#endif  // VP9_VP9_IFACE_COMMON_H_

mercurial