Skip to content

Instantly share code, notes, and snippets.

@RomiTT
Created August 12, 2019 15:45
Show Gist options
  • Save RomiTT/657e6a24b847307b994f60e2b2b551f7 to your computer and use it in GitHub Desktop.
Save RomiTT/657e6a24b847307b994f60e2b2b551f7 to your computer and use it in GitHub Desktop.
vlc functions.
void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
{
for( int i = 0; i < p_src->i_planes ; i++ )
plane_CopyPixels( p_dst->p+i, p_src->p+i );
assert( p_dst->context == NULL );
if( p_src->context != NULL )
p_dst->context = p_src->context->copy( p_src->context );
}
void picture_Copy( picture_t *p_dst, const picture_t *p_src )
{
picture_CopyPixels( p_dst, p_src );
picture_CopyProperties( p_dst, p_src );
}
int picture_UpdatePlanes(picture_t *picture, uint8_t *data, unsigned pitch)
{
/* fill in buffer info in first plane */
picture->p->p_pixels = data;
picture->p->i_pitch = pitch;
picture->p->i_lines = picture->format.i_height;
assert(picture->p->i_visible_pitch <= picture->p->i_pitch);
assert(picture->p->i_visible_lines <= picture->p->i_lines);
/* Fill chroma planes for biplanar YUV */
if (picture->format.i_chroma == VLC_CODEC_NV12 ||
picture->format.i_chroma == VLC_CODEC_NV21 ||
picture->format.i_chroma == VLC_CODEC_P010) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch;
p->i_lines = picture->format.i_height / 2;
assert(p->i_visible_pitch <= p->i_pitch);
assert(p->i_visible_lines <= p->i_lines);
}
/* The dx/d3d buffer is always allocated as NV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
/* TODO : Swap NV21 UV planes to match NV12 */
return VLC_EGENERIC;
}
}
/* Fill chroma planes for planar YUV */
else
if (picture->format.i_chroma == VLC_CODEC_I420 ||
picture->format.i_chroma == VLC_CODEC_J420 ||
picture->format.i_chroma == VLC_CODEC_YV12) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch / 2;
p->i_lines = picture->format.i_height / 2;
}
/* The dx/d3d buffer is always allocated as YV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12))
picture_SwapUV( picture );
}
return VLC_SUCCESS;
}
void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
{
const unsigned i_width = __MIN( p_dst->i_visible_pitch,
p_src->i_visible_pitch );
const unsigned i_height = __MIN( p_dst->i_visible_lines,
p_src->i_visible_lines );
/* The 2x visible pitch check does two things:
1) Makes field plane_t's work correctly (see the deinterlacer module)
2) Moves less data if the pitch and visible pitch differ much.
*/
if( p_src->i_pitch == p_dst->i_pitch &&
p_src->i_pitch < 2*p_src->i_visible_pitch )
{
/* There are margins, but with the same width : perfect ! */
memcpy( p_dst->p_pixels, p_src->p_pixels,
p_src->i_pitch * i_height );
}
else
{
/* We need to proceed line by line */
uint8_t *p_in = p_src->p_pixels;
uint8_t *p_out = p_dst->p_pixels;
assert( p_in );
assert( p_out );
for( int i_line = i_height; i_line--; )
{
memcpy( p_out, p_in, i_width );
p_in += p_src->i_pitch;
p_out += p_dst->i_pitch;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment