[vlc-devel] commit: Added picture_New/picture_Delete/picture_CopyPixels/picture_Copy ( Laurent Aimar )

git version control git at videolan.org
Sun Jul 20 12:51:46 CEST 2008


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Jul 20 12:45:20 2008 +0200| [a4270c7dc8ac4e35ecdfe320c2a78142e3170905]

Added picture_New/picture_Delete/picture_CopyPixels/picture_Copy
helpers.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a4270c7dc8ac4e35ecdfe320c2a78142e3170905
---

 include/vlc_vout.h               |   34 ++++++++++++++++
 src/libvlccore.sym               |    3 +
 src/video_output/vout_pictures.c |   79 +++++++++++++++++++++++++++++++++-----
 3 files changed, 106 insertions(+), 10 deletions(-)

diff --git a/include/vlc_vout.h b/include/vlc_vout.h
index d5e7469..635434f 100644
--- a/include/vlc_vout.h
+++ b/include/vlc_vout.h
@@ -116,6 +116,23 @@ struct picture_t
 };
 
 /**
+ * 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
  */
@@ -149,6 +166,23 @@ static inline void picture_CopyProperties( picture_t *p_dst, const picture_t *p_
 }
 
 /**
+ * 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)
  */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index e3c6a4b..0d4039d 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -236,6 +236,9 @@ osd_ShowTextRelative
 osd_Slider
 __osd_Volume
 path_sanitize
+picture_CopyPixels
+picture_Delete
+picture_New
 playlist_Add
 playlist_AddExt
 playlist_AddInput
diff --git a/src/video_output/vout_pictures.c b/src/video_output/vout_pictures.c
index de9464f..e19d9b6 100644
--- a/src/video_output/vout_pictures.c
+++ b/src/video_output/vout_pictures.c
@@ -849,8 +849,9 @@ int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
             break;
 
         default:
-            msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
-                             i_chroma, (char*)&i_chroma );
+            if( p_this )
+                msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
+                                 i_chroma, (char*)&i_chroma );
             p_pic->i_planes = 0;
             return VLC_EGENERIC;
     }
@@ -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 );
 }
 
+/*****************************************************************************
+ *
+ *****************************************************************************/
+
+




More information about the vlc-devel mailing list