]> git.sesse.net Git - x264/blob - filters/video/internal.c
78c57b3f536868ef331781d995da2c7270547c7d
[x264] / filters / video / internal.c
1 /*****************************************************************************
2  * internal.c: video filter utilities
3  *****************************************************************************
4  * Copyright (C) 2010-2015 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 "internal.h"
27 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "x264", __VA_ARGS__ )
28
29 void x264_cli_plane_copy( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int w, int h )
30 {
31     while( h-- )
32     {
33         memcpy( dst, src, w );
34         dst += i_dst;
35         src += i_src;
36     }
37 }
38
39 int x264_cli_pic_copy( cli_pic_t *out, cli_pic_t *in )
40 {
41     int csp = in->img.csp & X264_CSP_MASK;
42     FAIL_IF_ERROR( x264_cli_csp_is_invalid( in->img.csp ), "invalid colorspace arg %d\n", in->img.csp )
43     FAIL_IF_ERROR( in->img.csp != out->img.csp || in->img.height != out->img.height
44                 || in->img.width != out->img.width, "incompatible frame properties\n" );
45     /* copy data */
46     out->duration = in->duration;
47     out->pts = in->pts;
48     out->opaque = in->opaque;
49
50     for( int i = 0; i < out->img.planes; i++ )
51     {
52         int height = in->img.height * x264_cli_csps[csp].height[i];
53         int width =  in->img.width  * x264_cli_csps[csp].width[i];
54         width *= x264_cli_csp_depth_factor( in->img.csp );
55         x264_cli_plane_copy( out->img.plane[i], out->img.stride[i], in->img.plane[i],
56                              in->img.stride[i], width, height );
57     }
58     return 0;
59 }