Commit a4270c7d authored by Laurent Aimar's avatar Laurent Aimar

Added picture_New/picture_Delete/picture_CopyPixels/picture_Copy

helpers.
parent 71c4969b
......@@ -115,6 +115,23 @@ struct picture_t
struct picture_t *p_next;
};
/**
* This function will create a new picture.
* The picture created will implement a default release management compatible
* with picture_Yield and picture_Release. This default management will release
* picture_sys_t *p_sys field if non NULL.
*/
VLC_EXPORT( picture_t *, picture_New, ( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect ) );
/**
* This function will force the destruction a picture.
* The value of the picture reference count should be 0 before entering this
* function.
* Unless used for reimplementing pf_release, you should not use this
* function but picture_Release.
*/
VLC_EXPORT( void, picture_Delete, ( picture_t * ) );
/**
* This function will increase the picture reference count.
* It will not have any effect on picture obtained from vout
......@@ -148,6 +165,23 @@ static inline void picture_CopyProperties( picture_t *p_dst, const picture_t *p_
p_dst->b_top_field_first = p_src->b_top_field_first;
}
/**
* This function will copy the picture pixels.
*/
VLC_EXPORT( void, picture_CopyPixels, ( picture_t *p_dst, const picture_t *p_src ) );
/**
* This function will copy both picture dynamic properties and pixels.
* You have to notice that sometime a simple picture_Yield may do what
* you want without the copy overhead.
* Provided for convenience.
*/
static inline void picture_Copy( picture_t *p_dst, const picture_t *p_src )
{
picture_CopyPixels( p_dst, p_src );
picture_CopyProperties( p_dst, p_src );
}
/**
* Video picture heap, either render (to store pictures used
* by the decoder) or output (to store pictures displayed by the vout plugin)
......
......@@ -236,6 +236,9 @@ osd_ShowTextRelative
osd_Slider
__osd_Volume
path_sanitize
picture_CopyPixels
picture_Delete
picture_New
playlist_Add
playlist_AddExt
playlist_AddInput
......
......@@ -849,6 +849,7 @@ int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
break;
default:
if( p_this )
msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
i_chroma, (char*)&i_chroma );
p_pic->i_planes = 0;
......@@ -944,35 +945,93 @@ int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
void __vout_CopyPicture( vlc_object_t *p_this,
picture_t *p_dest, picture_t *p_src )
{
VLC_UNUSED( p_this );
VLC_UNUSED(p_this);
picture_Copy( p_dest, p_src );
}
/*****************************************************************************
*
*****************************************************************************/
static void PictureReleaseCallback( picture_t *p_picture )
{
if( --p_picture->i_refcount > 0 )
return;
picture_Delete( p_picture );
}
/*****************************************************************************
*
*****************************************************************************/
picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
{
picture_t *p_picture = malloc( sizeof(*p_picture) );
if( !p_picture )
return NULL;
memset( p_picture, 0, sizeof(*p_picture) );
if( __vout_AllocatePicture( NULL, p_picture,
i_chroma, i_width, i_height, i_aspect ) )
{
free( p_picture );
return NULL;
}
p_picture->i_refcount = 1;
p_picture->pf_release = PictureReleaseCallback;
p_picture->i_status = RESERVED_PICTURE;
return p_picture;
}
/*****************************************************************************
*
*****************************************************************************/
void picture_Delete( picture_t *p_picture )
{
assert( p_picture && p_picture->i_refcount == 0 );
free( p_picture->p_data_orig );
free( p_picture->p_sys );
free( p_picture );
}
/*****************************************************************************
*
*****************************************************************************/
void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
{
int i;
for( i = 0; i < p_src->i_planes ; i++ )
{
if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
if( p_src->p[i].i_pitch == p_dst->p[i].i_pitch )
{
/* There are margins, but with the same width : perfect ! */
vlc_memcpy( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
vlc_memcpy( p_dst->p[i].p_pixels, p_src->p[i].p_pixels,
p_src->p[i].i_pitch * p_src->p[i].i_visible_lines );
}
else
{
/* We need to proceed line by line */
uint8_t *p_in = p_src->p[i].p_pixels;
uint8_t *p_out = p_dst->p[i].p_pixels;
int i_line;
assert( p_in );
uint8_t *p_out = p_dest->p[i].p_pixels;
assert( p_out );
int i_line;
for( i_line = p_src->p[i].i_visible_lines; i_line--; )
{
vlc_memcpy( p_out, p_in, p_src->p[i].i_visible_pitch );
p_in += p_src->p[i].i_pitch;
p_out += p_dest->p[i].i_pitch;
p_out += p_dst->p[i].i_pitch;
}
}
}
picture_CopyProperties( p_dest, p_src );
}
/*****************************************************************************
*
*****************************************************************************/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment