From: Henrik Gramner Date: Fri, 20 Dec 2013 21:44:28 +0000 (+0100) Subject: CLI: Avoid redundant 16-bit upconversions in piped raw input X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bc63417e10e135d8cd881495c71be72d322e1d3;p=libx264 CLI: Avoid redundant 16-bit upconversions in piped raw input It's not possible to seek in pipes, so if we want to skip frames we have to read and discard unused ones. It's pointless to do bit-depth upconversions in those frames. --- diff --git a/input/raw.c b/input/raw.c index 32134358..9d21c596 100644 --- a/input/raw.c +++ b/input/raw.c @@ -99,14 +99,14 @@ 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, raw_hnd_t *h ) +static int read_frame_internal( cli_pic_t *pic, raw_hnd_t *h, int bit_depth_uc ) { int error = 0; int pixel_depth = x264_cli_csp_depth_factor( pic->img.csp ); for( int 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. */ @@ -131,13 +131,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; diff --git a/input/y4m.c b/input/y4m.c index da8f9803..bf62e837 100644 --- a/input/y4m.c +++ b/input/y4m.c @@ -223,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 ); @@ -249,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. */ @@ -274,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;