Commit 6bc63417 authored by Henrik Gramner's avatar Henrik Gramner Committed by Fiona Glaser

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.
parent 008c56ec
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment