[vlc-commits] [Git][videolan/vlc][master] 3 commits: demux: mkv: apply the stretching of visible area after cropping

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Tue Feb 22 14:54:33 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
32f4a992 by Steve Lhomme at 2022-02-22T14:08:16+00:00
demux: mkv: apply the stretching of visible area after cropping

We can also apply the pixel cropping no matter what, if the value is 0 it will
have no side effect.

Ref. #26501

- - - - -
cc4faf0c by Steve Lhomme at 2022-02-22T14:08:16+00:00
demux: mkv: set the video format SAR based on the DisplayUnit of the track

We can apply the SAR once we know the cropped pixels dimensions and the actual
display dimension requested.

Apply the DAR when DisplayUnit is 3 [1].

[1] https://www.ietf.org/archive/id/draft-ietf-cellar-matroska-08.html#name-displayunit-element

- - - - -
267cf709 by Steve Lhomme at 2022-02-22T14:08:16+00:00
demux: mkv: set the default display width/height when DisplayUnit is 0

As specified in the format [1].

> If the DisplayUnit of the same TrackEntry is 0, then the default value for
> DisplayWidth is equal toPixelWidth - PixelCropLeft - PixelCropRight,
> else there is no default value.

[1] https://www.ietf.org/archive/id/draft-ietf-cellar-matroska-08.html#section-8.1.4.1.31.11

- - - - -


1 changed file:

- modules/demux/mkv/matroska_segment_parse.cpp


Changes:

=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -487,7 +487,7 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
             unsigned int i_crop_bottom = vars.track_video_info.i_crop_bottom;
             unsigned int i_crop_left   = vars.track_video_info.i_crop_left;
 
-            unsigned int i_display_unit   = vars.track_video_info.i_display_unit; VLC_UNUSED(i_display_unit);
+            unsigned int i_display_unit   = vars.track_video_info.i_display_unit;
             unsigned int i_display_width  = vars.track_video_info.i_display_width;
             unsigned int i_display_height = vars.track_video_info.i_display_height;
 
@@ -519,24 +519,66 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
                 }
             }
 
-            if( i_display_height && i_display_width )
+            unsigned int h_crop;
+            if (!add_overflow(i_crop_left, i_crop_right, &h_crop))
             {
-                tk->fmt.video.i_sar_num = i_display_width  * tk->fmt.video.i_height;
-                tk->fmt.video.i_sar_den = i_display_height * tk->fmt.video.i_width;
+                debug( vars, "invalid horizontal crop %u+%u",
+                              i_crop_left, i_crop_right );
+                i_crop_left = i_crop_right = 0;
             }
+            else if (unlikely(h_crop >= tk->fmt.video.i_width))
+            {
+                debug( vars, "Horizontal crop (left=%u, right=%u) "
+                             "greater than the picture width (%u)",
+                              i_crop_left, i_crop_right, tk->fmt.video.i_width );
+                i_crop_left = i_crop_right = 0;
+            }
+
+            unsigned int v_crop;
+            if (!add_overflow(i_crop_top, i_crop_bottom, &v_crop))
+            {
+                debug( vars, "invalid vertical crop %u+%u",
+                              i_crop_top, i_crop_bottom);
+                i_crop_top = i_crop_bottom = 0;
+            }
+            if (unlikely(v_crop >= tk->fmt.video.i_height))
+            {
+                debug( vars, "Vertical crop (top=%u, bottom=%u) "
+                             "greater than the picture height (%u)",
+                              i_crop_top, i_crop_bottom, tk->fmt.video.i_height );
+                i_crop_top = i_crop_bottom = 0;
+            }
+
+            tk->fmt.video.i_x_offset      = i_crop_left;
+            tk->fmt.video.i_y_offset      = i_crop_top;
+            tk->fmt.video.i_visible_width = tk->fmt.video.i_width -
+                                            (i_crop_left + i_crop_right);
+            tk->fmt.video.i_visible_height = tk->fmt.video.i_height -
+                                            (i_crop_top + i_crop_bottom);
 
-            tk->fmt.video.i_visible_width   = tk->fmt.video.i_width;
-            tk->fmt.video.i_visible_height  = tk->fmt.video.i_height;
+            if (i_display_unit == 0 && i_display_width == 0)
+                i_display_width = tk->fmt.video.i_width;
+            if (i_display_unit == 0 && i_display_height == 0)
+                i_display_height = tk->fmt.video.i_height;
 
-            if( i_crop_left || i_crop_right || i_crop_top || i_crop_bottom )
+            if (i_display_height && i_display_width)
             {
-                tk->fmt.video.i_x_offset        = i_crop_left;
-                tk->fmt.video.i_y_offset        = i_crop_top;
-                tk->fmt.video.i_visible_width  -= i_crop_left + i_crop_right;
-                tk->fmt.video.i_visible_height -= i_crop_top + i_crop_bottom;
+                switch (i_display_unit)
+                {
+                    case 0: // pixels
+                    case 1: // centimeters
+                    case 2: // inches
+                        vlc_ureduce( &tk->fmt.video.i_sar_num, &tk->fmt.video.i_sar_den,
+                                     i_display_width * tk->fmt.video.i_visible_height,
+                                     i_display_height * tk->fmt.video.i_visible_width, 0);
+                        break;
+                    case 3: // display aspect ratio
+                        vlc_ureduce( &tk->fmt.video.i_sar_num, &tk->fmt.video.i_sar_den,
+                                     i_display_height * tk->fmt.video.i_visible_width,
+                                     i_display_width * tk->fmt.video.i_visible_height, 0);
+                        break;
+                }
             }
-            /* FIXME: i_display_* allows you to not only set DAR, but also a zoom factor.
-               we do not support this atm */
         }
 #if LIBMATROSKA_VERSION >= 0x010406
         E_CASE( KaxVideoProjection, proj )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/35ec60b58050f777c3c3bbdcad470dcc35382f89...267cf709fb0b31716ff558c7e739b2e8d9ba09d6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/35ec60b58050f777c3c3bbdcad470dcc35382f89...267cf709fb0b31716ff558c7e739b2e8d9ba09d6
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list