[vlc-devel] [PATCH 2/2] lib: media: Allow thumbnails to be cropped

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Jun 20 10:13:29 CEST 2019


---
 include/vlc/libvlc_media.h |  4 ++--
 lib/media.c                | 10 +++++++---
 lib/picture.c              |  5 +++--
 lib/picture_internal.h     |  4 +++-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index c2ae654b04..aab025ae28 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -847,7 +847,7 @@ libvlc_media_thumbnail_request_by_time( libvlc_media_t *md,
                                         libvlc_time_t time,
                                         libvlc_thumbnailer_seek_speed_t speed,
                                         unsigned int width, unsigned int height,
-                                        libvlc_picture_type_t picture_type,
+                                        bool crop, libvlc_picture_type_t picture_type,
                                         libvlc_time_t timeout );
 
 /**
@@ -877,7 +877,7 @@ libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md,
                                        float pos,
                                        libvlc_thumbnailer_seek_speed_t speed,
                                        unsigned int width, unsigned int height,
-                                       libvlc_picture_type_t picture_type,
+                                       bool crop, libvlc_picture_type_t picture_type,
                                        libvlc_time_t timeout );
 
 /**
diff --git a/lib/media.c b/lib/media.c
index 02759d5b42..06d02bad8d 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -1096,6 +1096,7 @@ struct libvlc_media_thumbnail_request_t
     libvlc_media_t *md;
     unsigned int width;
     unsigned int height;
+    bool crop;
     libvlc_picture_type_t type;
     vlc_thumbnailer_request_t* req;
 };
@@ -1109,7 +1110,8 @@ static void media_on_thumbnail_ready( void* data, picture_t* thumbnail )
     libvlc_picture_t* pic = NULL;
     if ( thumbnail != NULL )
         pic = libvlc_picture_new( VLC_OBJECT(p_media->p_libvlc_instance->p_libvlc_int),
-                                    thumbnail, req->type, req->width, req->height );
+                                    thumbnail, req->type, req->width, req->height,
+                                    req->crop );
     event.u.media_thumbnail_generated.p_thumbnail = pic;
     libvlc_event_send( &p_media->event_manager, &event );
     if ( pic != NULL )
@@ -1122,7 +1124,7 @@ libvlc_media_thumbnail_request_t*
 libvlc_media_thumbnail_request_by_time( libvlc_media_t *md, libvlc_time_t time,
                                         libvlc_thumbnailer_seek_speed_t speed,
                                         unsigned int width, unsigned int height,
-                                        libvlc_picture_type_t picture_type,
+                                        bool crop, libvlc_picture_type_t picture_type,
                                         libvlc_time_t timeout )
 {
     assert( md );
@@ -1137,6 +1139,7 @@ libvlc_media_thumbnail_request_by_time( libvlc_media_t *md, libvlc_time_t time,
     req->width = width;
     req->height = height;
     req->type = picture_type;
+    req->crop = crop;
     libvlc_media_retain( md );
     req->req = vlc_thumbnailer_RequestByTime( p_priv->p_thumbnailer,
         VLC_TICK_FROM_MS( time ),
@@ -1158,7 +1161,7 @@ libvlc_media_thumbnail_request_t*
 libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md, float pos,
                                        libvlc_thumbnailer_seek_speed_t speed,
                                        unsigned int width, unsigned int height,
-                                       libvlc_picture_type_t picture_type,
+                                       bool crop, libvlc_picture_type_t picture_type,
                                        libvlc_time_t timeout )
 {
     assert( md );
@@ -1172,6 +1175,7 @@ libvlc_media_thumbnail_request_by_pos( libvlc_media_t *md, float pos,
     req->md = md;
     req->width = width;
     req->height = height;
+    req->crop = crop;
     req->type = picture_type;
     libvlc_media_retain( md );
     req->req = vlc_thumbnailer_RequestByPos( priv->p_thumbnailer, pos,
diff --git a/lib/picture.c b/lib/picture.c
index 5a7d9cb6e6..fc8b769b2a 100644
--- a/lib/picture.c
+++ b/lib/picture.c
@@ -45,7 +45,8 @@ struct libvlc_picture_t
 
 libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t* input,
                                       libvlc_picture_type_t type,
-                                      unsigned int width, unsigned int height )
+                                      unsigned int width, unsigned int height,
+                                      bool crop )
 {
     libvlc_picture_t *pic = malloc( sizeof( *pic ) );
     if ( unlikely( pic == NULL ) )
@@ -69,7 +70,7 @@ libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t* input,
             vlc_assert_unreachable();
     }
     if ( picture_Export( p_obj, &pic->converted, &pic->fmt,
-                         input, format, width, height, false ) != VLC_SUCCESS )
+                         input, format, width, height, crop ) != VLC_SUCCESS )
     {
         free( pic );
         return NULL;
diff --git a/lib/picture_internal.h b/lib/picture_internal.h
index 83b913f0f3..aeb1e3f505 100644
--- a/lib/picture_internal.h
+++ b/lib/picture_internal.h
@@ -32,6 +32,7 @@
  * \param i_type Desired converted picture type
  * \param i_width Converted picture width
  * \param i_height Converted picture height
+ * \param b_crop Should the picture be cropped to preserve aspect ratio
  * \return An opaque libvlc_picture_t
  *
  * The picture refcount is left untouched by this function, but is converted to
@@ -40,6 +41,7 @@
  */
 libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t* p_pic,
                                       libvlc_picture_type_t i_format,
-                                      unsigned int i_width, unsigned int i_height );
+                                      unsigned int i_width, unsigned int i_height,
+                                      bool b_crop );
 
 #endif /* PICTURE_INTERNAL_H */
-- 
2.20.1



More information about the vlc-devel mailing list