]> git.sesse.net Git - x264/blob - input/input.c
Disable progress for FFMS input with --no-progress
[x264] / input / input.c
1 /*****************************************************************************
2  * input.c: common input functions
3  *****************************************************************************
4  * Copyright (C) 2010-2011 x264 project
5  *
6  * Authors: Steven Walters <kemuri9@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
21  *
22  * This program is also available under a commercial proprietary license.
23  * For more information, contact us at licensing@x264.com.
24  *****************************************************************************/
25
26 #include "input.h"
27
28 const x264_cli_csp_t x264_cli_csps[] = {
29     [X264_CSP_I420] = { "i420", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
30     [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1,  1,  1 }, 2, 1 },
31     [X264_CSP_I444] = { "i444", 3, { 1,  1,  1 }, { 1,  1,  1 }, 1, 1 },
32     [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
33     [X264_CSP_NV12] = { "nv12", 2, { 1,  1 },     { 1, .5 },     2, 2 },
34     [X264_CSP_BGR]  = { "bgr",  1, { 3 },         { 1 },         1, 1 },
35     [X264_CSP_BGRA] = { "bgra", 1, { 4 },         { 1 },         1, 1 },
36     [X264_CSP_RGB]  = { "rgb",  1, { 3 },         { 1 },         1, 1 },
37 };
38
39 int x264_cli_csp_is_invalid( int csp )
40 {
41     int csp_mask = csp & X264_CSP_MASK;
42     return csp_mask <= X264_CSP_NONE || csp_mask >= X264_CSP_CLI_MAX || csp & X264_CSP_OTHER;
43 }
44
45 int x264_cli_csp_depth_factor( int csp )
46 {
47     if( x264_cli_csp_is_invalid( csp ) )
48         return 0;
49     return (csp & X264_CSP_HIGH_DEPTH) ? 2 : 1;
50 }
51
52 uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane )
53 {
54     int csp_mask = csp & X264_CSP_MASK;
55     if( x264_cli_csp_is_invalid( csp ) || plane < 0 || plane >= x264_cli_csps[csp_mask].planes )
56         return 0;
57     uint64_t size = (uint64_t)width * height;
58     size *= x264_cli_csps[csp_mask].width[plane] * x264_cli_csps[csp_mask].height[plane];
59     size *= x264_cli_csp_depth_factor( csp );
60     return size;
61 }
62
63 uint64_t x264_cli_pic_size( int csp, int width, int height )
64 {
65     if( x264_cli_csp_is_invalid( csp ) )
66         return 0;
67     uint64_t size = 0;
68     int csp_mask = csp & X264_CSP_MASK;
69     for( int i = 0; i < x264_cli_csps[csp_mask].planes; i++ )
70         size += x264_cli_pic_plane_size( csp, width, height, i );
71     return size;
72 }
73
74 int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height )
75 {
76     memset( pic, 0, sizeof(cli_pic_t) );
77     int csp_mask = csp & X264_CSP_MASK;
78     if( x264_cli_csp_is_invalid( csp ) )
79         pic->img.planes = 0;
80     else
81         pic->img.planes = x264_cli_csps[csp_mask].planes;
82     pic->img.csp    = csp;
83     pic->img.width  = width;
84     pic->img.height = height;
85     for( int i = 0; i < pic->img.planes; i++ )
86     {
87          pic->img.plane[i] = x264_malloc( x264_cli_pic_plane_size( csp, width, height, i ) );
88          if( !pic->img.plane[i] )
89              return -1;
90          pic->img.stride[i] = width * x264_cli_csps[csp_mask].width[i] * x264_cli_csp_depth_factor( csp );
91     }
92
93     return 0;
94 }
95
96 void x264_cli_pic_clean( cli_pic_t *pic )
97 {
98     for( int i = 0; i < pic->img.planes; i++ )
99         x264_free( pic->img.plane[i] );
100     memset( pic, 0, sizeof(cli_pic_t) );
101 }
102
103 const x264_cli_csp_t *x264_cli_get_csp( int csp )
104 {
105     if( x264_cli_csp_is_invalid( csp ) )
106         return NULL;
107     return x264_cli_csps + (csp&X264_CSP_MASK);
108 }