1 /*****************************************************************************
2 * input.c: x264 input module common
3 *****************************************************************************
4 * Copyright (C) 2010 Steven Walters <kemuri9@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
19 *****************************************************************************/
23 const x264_cli_csp_t x264_cli_csps[] = {
24 [X264_CSP_I420] = { "i420", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
25 [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 },
26 [X264_CSP_I444] = { "i444", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 },
27 [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
28 [X264_CSP_BGR] = { "bgr", 1, { 3 }, { 1 }, 1, 1 },
29 [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, 1, 1 }
32 int x264_cli_csp_is_invalid( int csp )
34 int csp_mask = csp & X264_CSP_MASK;
35 return csp_mask <= X264_CSP_NONE || csp_mask >= X264_CSP_CLI_MAX || csp & X264_CSP_OTHER;
38 uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane )
40 int csp_mask = csp & X264_CSP_MASK;
41 if( x264_cli_csp_is_invalid( csp ) || plane < 0 || plane >= x264_cli_csps[csp_mask].planes )
43 uint64_t size = (uint64_t)width * height;
44 size *= x264_cli_csps[csp_mask].width[plane] * x264_cli_csps[csp_mask].height[plane];
48 uint64_t x264_cli_pic_size( int csp, int width, int height )
50 if( x264_cli_csp_is_invalid( csp ) )
53 int csp_mask = csp & X264_CSP_MASK;
54 for( int i = 0; i < x264_cli_csps[csp_mask].planes; i++ )
55 size += x264_cli_pic_plane_size( csp, width, height, i );
59 int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height )
61 memset( pic, 0, sizeof(cli_pic_t) );
62 int csp_mask = csp & X264_CSP_MASK;
63 if( x264_cli_csp_is_invalid( csp ) )
66 pic->img.planes = x264_cli_csps[csp_mask].planes;
68 pic->img.width = width;
69 pic->img.height = height;
70 for( int i = 0; i < pic->img.planes; i++ )
72 pic->img.plane[i] = x264_malloc( x264_cli_pic_plane_size( csp, width, height, i ) );
73 if( !pic->img.plane[i] )
75 pic->img.stride[i] = width * x264_cli_csps[csp_mask].width[i];
81 void x264_cli_pic_clean( cli_pic_t *pic )
83 for( int i = 0; i < pic->img.planes; i++ )
84 x264_free( pic->img.plane[i] );
85 memset( pic, 0, sizeof(cli_pic_t) );
88 const x264_cli_csp_t *x264_cli_get_csp( int csp )
90 if( x264_cli_csp_is_invalid( csp ) )
92 return x264_cli_csps + (csp&X264_CSP_MASK);