]> git.sesse.net Git - x264/blobdiff - input/y4m.c
checkasm: aarch64: Check register clobbering
[x264] / input / y4m.c
index 009afa6d7604f1ff2ab32ee924175402e490c2f6..f32cc9b6704d923e5407463b440e1b36be230248 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * y4m.c: y4m input
  *****************************************************************************
- * Copyright (C) 2003-2013 x264 project
+ * Copyright (C) 2003-2015 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
@@ -46,7 +46,6 @@ typedef struct
 static int parse_csp_and_depth( char *csp_name, int *bit_depth )
 {
     int csp    = X264_CSP_MAX;
-    *bit_depth = 8;
 
     /* Set colorspace from known variants */
     if( !strncmp( "420", csp_name, 3 ) )
@@ -57,8 +56,8 @@ static int parse_csp_and_depth( char *csp_name, int *bit_depth )
         csp = X264_CSP_I444;
 
     /* Set high bit depth from known extensions */
-    if( !strncmp( "p", csp_name + 3, 1 ) )
-        *bit_depth = strtol( csp_name + 4, NULL, 10 );
+    if( sscanf( csp_name, "%*d%*[pP]%d", bit_depth ) != 1 )
+        *bit_depth = 8;
 
     return csp;
 }
@@ -82,7 +81,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     if( !strcmp( psz_filename, "-" ) )
         h->fh = stdin;
     else
-        h->fh = fopen(psz_filename, "rb");
+        h->fh = x264_fopen(psz_filename, "rb");
     if( h->fh == NULL )
         return -1;
 
@@ -224,7 +223,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     return 0;
 }
 
-static int read_frame_internal( cli_pic_t *pic, y4m_hnd_t *h )
+static int read_frame_internal( cli_pic_t *pic, y4m_hnd_t *h, int bit_depth_uc )
 {
     size_t slen = strlen( Y4M_FRAME_MAGIC );
     int pixel_depth = x264_cli_csp_depth_factor( pic->img.csp );
@@ -250,7 +249,7 @@ static int read_frame_internal( cli_pic_t *pic, y4m_hnd_t *h )
     for( i = 0; i < pic->img.planes && !error; i++ )
     {
         error |= fread( pic->img.plane[i], pixel_depth, h->plane_size[i], h->fh ) != h->plane_size[i];
-        if( h->bit_depth & 7 )
+        if( bit_depth_uc )
         {
             /* upconvert non 16bit high depth planes to 16bit using the same
              * algorithm as used in the depth filter. */
@@ -275,13 +274,13 @@ static int read_frame( cli_pic_t *pic, hnd_t handle, int i_frame )
         else
             while( i_frame > h->next_frame )
             {
-                if( read_frame_internal( pic, h ) )
+                if( read_frame_internal( pic, h, 0 ) )
                     return -1;
                 h->next_frame++;
             }
     }
 
-    if( read_frame_internal( pic, h ) )
+    if( read_frame_internal( pic, h, h->bit_depth & 7 ) )
         return -1;
 
     h->next_frame = i_frame+1;