示例#1
0
文件: picture.c 项目: Annovae/vlc
picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_resource_t *p_resource )
{
    video_format_t fmt = *p_fmt;

    /* It is needed to be sure all information are filled */
    video_format_Setup( &fmt, p_fmt->i_chroma,
                              p_fmt->i_width, p_fmt->i_height,
                              p_fmt->i_visible_width, p_fmt->i_visible_height,
                              p_fmt->i_sar_num, p_fmt->i_sar_den );
    if( p_fmt->i_x_offset < p_fmt->i_width &&
        p_fmt->i_y_offset < p_fmt->i_height &&
        p_fmt->i_visible_width  > 0 && p_fmt->i_x_offset + p_fmt->i_visible_width  <= p_fmt->i_width &&
        p_fmt->i_visible_height > 0 && p_fmt->i_y_offset + p_fmt->i_visible_height <= p_fmt->i_height )
        video_format_CopyCrop( &fmt, p_fmt );

    /* */
    picture_t *p_picture = calloc( 1, sizeof(*p_picture) );
    if( !p_picture )
        return NULL;

    /* Make sure the real dimensions are a multiple of 16 */
    if( picture_Setup( p_picture, &fmt ) )
    {
        free( p_picture );
        return NULL;
    }

    if( p_resource )
    {
        p_picture->p_sys = p_resource->p_sys;
        p_picture->gc.pf_destroy = p_resource->pf_destroy;
        assert( p_picture->gc.p_sys == NULL );

        for( int i = 0; i < p_picture->i_planes; i++ )
        {
            p_picture->p[i].p_pixels = p_resource->p[i].p_pixels;
            p_picture->p[i].i_lines  = p_resource->p[i].i_lines;
            p_picture->p[i].i_pitch  = p_resource->p[i].i_pitch;
        }
    }
    else
    {
        if( AllocatePicture( p_picture ) )
        {
            free( p_picture );
            return NULL;
        }
    }

    /* */
    p_picture->format = fmt;

    atomic_init( &p_picture->gc.refcount, 1 );
    if( p_picture->gc.pf_destroy == NULL )
        p_picture->gc.pf_destroy = PictureDestroy;

    return p_picture;
}
示例#2
0
bool CPixelConverterRBP::Decode(const uint8_t* pData, unsigned int size)
{
  if (pData == nullptr || size == 0 || m_swsContext == nullptr)
    return false;

  if (m_buf)
    FreePicture(m_buf);

  m_buf = AllocatePicture(m_width, m_height);
  if (!m_buf)
  {
    CLog::Log(LOGERROR, "%s: Failed to allocate picture of dimensions %dx%d", __FUNCTION__, m_width, m_height);
    return false;
  }

  uint8_t* dataMutable = const_cast<uint8_t*>(pData);

  int bpp;
  if (m_mmal_format == MMAL_ENCODING_ARGB ||
      m_mmal_format == MMAL_ENCODING_RGBA ||
      m_mmal_format == MMAL_ENCODING_ABGR ||
      m_mmal_format == MMAL_ENCODING_BGRA)
    bpp = 4;
  else if (m_mmal_format == MMAL_ENCODING_RGB24 ||
           m_mmal_format == MMAL_ENCODING_BGR24)
    bpp = 4;
  else if (m_mmal_format == MMAL_ENCODING_RGB16 ||
           m_mmal_format == MMAL_ENCODING_BGR16)
    bpp = 2;
  else
  {
    CLog::Log(LOGERROR, "CPixelConverter::AllocatePicture, unknown format:%.4s", (char *)&m_mmal_format);
    return false;
  }

  MMAL::CMMALYUVBuffer *omvb = static_cast<MMAL::CMMALYUVBuffer*>(m_buf->hwPic);

  const int stride = size / m_height;

  uint8_t* src[] =       { dataMutable,                       0, 0, 0 };
  int      srcStride[] = { stride,                            0, 0, 0 };
  uint8_t* dst[] =       { (uint8_t *)omvb->gmem->m_arm,      0, 0, 0 };
  int      dstStride[] = { (int)omvb->m_aligned_width * bpp,  0, 0, 0 };

  sws_scale(m_swsContext, src, srcStride, 0, m_height, dst, dstStride);

  return true;
}