X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=input%2Finput.c;h=fa7f296aa55072a76aaffe93208e8bc7b7fe1e9a;hb=cc652c158c1fa65bfeafb6446b5be855850065d0;hp=78c7a882d928811ebb22d0cedc41d863dc5add6a;hpb=213a99d070ebd4f9aeffe7cb3ed9bd7fe755ec7f;p=x264 diff --git a/input/input.c b/input/input.c index 78c7a882..fa7f296a 100644 --- a/input/input.c +++ b/input/input.c @@ -1,7 +1,7 @@ /***************************************************************************** * input.c: common input functions ***************************************************************************** - * Copyright (C) 2010 x264 project + * Copyright (C) 2010-2015 x264 project * * Authors: Steven Walters * @@ -30,15 +30,28 @@ const x264_cli_csp_t x264_cli_csps[] = { [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 }, [X264_CSP_I444] = { "i444", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 }, [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 }, + [X264_CSP_YV16] = { "yv16", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 }, + [X264_CSP_YV24] = { "yv24", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 }, [X264_CSP_NV12] = { "nv12", 2, { 1, 1 }, { 1, .5 }, 2, 2 }, + [X264_CSP_NV21] = { "nv21", 2, { 1, 1 }, { 1, .5 }, 2, 2 }, + [X264_CSP_NV16] = { "nv16", 2, { 1, 1 }, { 1, 1 }, 2, 1 }, [X264_CSP_BGR] = { "bgr", 1, { 3 }, { 1 }, 1, 1 }, - [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, 1, 1 } + [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, 1, 1 }, + [X264_CSP_RGB] = { "rgb", 1, { 3 }, { 1 }, 1, 1 }, }; int x264_cli_csp_is_invalid( int csp ) { int csp_mask = csp & X264_CSP_MASK; - return csp_mask <= X264_CSP_NONE || csp_mask >= X264_CSP_CLI_MAX || csp & X264_CSP_OTHER; + return csp_mask <= X264_CSP_NONE || csp_mask >= X264_CSP_CLI_MAX || + csp_mask == X264_CSP_V210 || csp & X264_CSP_OTHER; +} + +int x264_cli_csp_depth_factor( int csp ) +{ + if( x264_cli_csp_is_invalid( csp ) ) + return 0; + return (csp & X264_CSP_HIGH_DEPTH) ? 2 : 1; } uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane ) @@ -48,6 +61,7 @@ uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane ) return 0; uint64_t size = (uint64_t)width * height; size *= x264_cli_csps[csp_mask].width[plane] * x264_cli_csps[csp_mask].height[plane]; + size *= x264_cli_csp_depth_factor( csp ); return size; } @@ -62,7 +76,7 @@ uint64_t x264_cli_pic_size( int csp, int width, int height ) return size; } -int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ) +static int x264_cli_pic_alloc_internal( cli_pic_t *pic, int csp, int width, int height, int align ) { memset( pic, 0, sizeof(cli_pic_t) ); int csp_mask = csp & X264_CSP_MASK; @@ -75,15 +89,29 @@ int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ) pic->img.height = height; for( int i = 0; i < pic->img.planes; i++ ) { - pic->img.plane[i] = x264_malloc( x264_cli_pic_plane_size( csp, width, height, i ) ); - if( !pic->img.plane[i] ) - return -1; - pic->img.stride[i] = width * x264_cli_csps[csp_mask].width[i]; + int stride = width * x264_cli_csps[csp_mask].width[i]; + stride *= x264_cli_csp_depth_factor( csp ); + stride = ALIGN( stride, align ); + uint64_t size = (uint64_t)(height * x264_cli_csps[csp_mask].height[i]) * stride; + pic->img.plane[i] = x264_malloc( size ); + if( !pic->img.plane[i] ) + return -1; + pic->img.stride[i] = stride; } return 0; } +int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ) +{ + return x264_cli_pic_alloc_internal( pic, csp, width, height, 1 ); +} + +int x264_cli_pic_alloc_aligned( cli_pic_t *pic, int csp, int width, int height ) +{ + return x264_cli_pic_alloc_internal( pic, csp, width, height, NATIVE_ALIGN ); +} + void x264_cli_pic_clean( cli_pic_t *pic ) { for( int i = 0; i < pic->img.planes; i++ )