]> git.sesse.net Git - x264/blob - filters/video/internal.c
Add video filtering system to x264cli
[x264] / filters / video / internal.c
1 /*****************************************************************************
2  * internal.c: x264 video filter internal utilities
3  *****************************************************************************
4  * Copyright (C) 2010 Steven Walters <kemuri9@gmail.com>
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #include "internal.h"
22 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "x264", __VA_ARGS__ )
23
24 void x264_cli_plane_copy( pixel *dst, int i_dst, uint8_t *src, int i_src, int w, int h )
25 {
26     while( h-- )
27     {
28         memcpy( dst, src, w );
29         dst += i_dst;
30         src += i_src;
31     }
32 }
33
34 int x264_cli_pic_copy( cli_pic_t *out, cli_pic_t *in )
35 {
36     int csp = in->img.csp & X264_CSP_MASK;
37     FAIL_IF_ERROR( x264_cli_csp_is_invalid( in->img.csp ), "invalid colorspace arg %d\n", in->img.csp )
38     FAIL_IF_ERROR( in->img.csp != out->img.csp || in->img.height != out->img.height
39                 || in->img.width != out->img.width, "incompatible frame properties\n" );
40     /* copy data */
41     out->duration = in->duration;
42     out->pts = in->pts;
43     out->opaque = in->opaque;
44
45     for( int i = 0; i < out->img.planes; i++ )
46     {
47         int height = in->img.height * x264_cli_csps[csp].height[i];
48         int width =  in->img.width  * x264_cli_csps[csp].width[i];
49         x264_cli_plane_copy( out->img.plane[i], out->img.stride[i], in->img.plane[i],
50                              in->img.stride[i], width, height );
51     }
52     return 0;
53 }