]> git.sesse.net Git - vlc/commitdiff
snapshot core : correct aspect ratio issue (trac #2705)
authorErwan Tulou <brezhoneg1@yahoo.fr>
Mon, 25 May 2009 11:40:16 +0000 (13:40 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 25 May 2009 23:52:11 +0000 (01:52 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
src/video_output/video_output.c
src/video_output/vout_pictures.c

index 3c932f69856ca7315c1a3db263b412f0b4a616e0..825e1d6f25ac2e92877e12460fd713f1696b754c 100644 (file)
@@ -1213,6 +1213,9 @@ static void* RunThread( void *p_this )
 
                 picture_Copy( p_pic, p_directbuffer );
 
+                p_pic->format.i_sar_num = p_vout->fmt_out.i_sar_num;
+                p_pic->format.i_sar_den = p_vout->fmt_out.i_sar_den;
+
                 p_pic->p_next = p_vout->p->snapshot.p_picture;
                 p_vout->p->snapshot.p_picture = p_pic;
                 p_vout->p->snapshot.i_request--;
index d0da611c43180080ebb1bfdf89019cfe995a8111..0f408f864187ca89dcded5e2eada7a9134fd5c01 100644 (file)
@@ -1114,30 +1114,37 @@ int picture_Export( vlc_object_t *p_obj,
     fmt_out.i_sar_num =
     fmt_out.i_sar_den = 1;
     fmt_out.i_chroma  = i_format;
-    fmt_out.i_width   = i_override_width;
-    fmt_out.i_height  = i_override_height;
 
-    if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
+    /* compute original width/height */
+    unsigned int i_original_width;
+    unsigned int i_original_height;
+    if( fmt_in.i_sar_num >= fmt_in.i_sar_den )
     {
-        fmt_out.i_height = fmt_in.i_height * fmt_out.i_width / fmt_in.i_width;
-        const int i_height = fmt_out.i_height * fmt_in.i_sar_den / fmt_in.i_sar_num;
-        if( i_height > 0 )
-            fmt_out.i_height = i_height;
+        i_original_width = fmt_in.i_width * fmt_in.i_sar_num / fmt_in.i_sar_den;
+        i_original_height = fmt_in.i_height;
     }
     else
     {
-        if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
-        {
-            fmt_out.i_width = fmt_in.i_width * fmt_out.i_height / fmt_in.i_height;
-        }
-        else
-        {
-            fmt_out.i_width = fmt_in.i_width;
-            fmt_out.i_height = fmt_in.i_height;
-        }
-        const int i_width = fmt_out.i_width * fmt_in.i_sar_num / fmt_in.i_sar_den;
-        if( i_width > 0 )
-            fmt_out.i_width = i_width;
+        i_original_width =  fmt_in.i_width;
+        i_original_height = fmt_in.i_height * fmt_in.i_sar_den / fmt_in.i_sar_num;
+    }
+
+    /* */
+    fmt_out.i_width  = ( i_override_width < 0 ) ?
+                       i_original_width : i_override_width;
+    fmt_out.i_height = ( i_override_height < 0 ) ?
+                       i_original_height : i_override_height;
+
+    /* scale if only one direction is provided */
+    if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
+    {
+        fmt_out.i_height = fmt_in.i_height * fmt_out.i_width
+                     * fmt_in.i_sar_den / fmt_in.i_width / fmt_in.i_sar_num;
+    }
+    else if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
+    {
+        fmt_out.i_width  = fmt_in.i_width * fmt_out.i_height
+                     * fmt_in.i_sar_num / fmt_in.i_height / fmt_in.i_sar_den;
     }
 
     image_handler_t *p_image = image_HandlerCreate( p_obj );