]> git.sesse.net Git - vlc/blob - src/misc/filter.c
7ced511d9d532e564628243fb6412daa5c756b91
[vlc] / src / misc / filter.c
1 /*****************************************************************************
2  * filter.c : filter_t helpers.
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include <libvlc.h>
30 #include <vlc_filter.h>
31
32 filter_t *filter_NewBlend( vlc_object_t *p_this,
33                            vlc_fourcc_t i_chroma_dst )
34 {
35     filter_t *p_blend = vlc_custom_create( p_this, sizeof(*p_blend),
36                                            VLC_OBJECT_GENERIC, "blend" );
37     if( !p_blend )
38         return NULL;
39
40     es_format_Init( &p_blend->fmt_in, VIDEO_ES, 0 );
41
42     es_format_Init( &p_blend->fmt_out, VIDEO_ES, 0 );
43
44     p_blend->fmt_out.i_codec        = 
45     p_blend->fmt_out.video.i_chroma = i_chroma_dst;
46
47     /* The blend module will be loaded when needed with the real
48     * input format */
49     p_blend->p_module = NULL;
50
51     /* */
52     vlc_object_attach( p_blend, p_this );
53
54     return p_blend;
55 }
56
57 int filter_ConfigureBlend( filter_t *p_blend,
58                            int i_dst_width, int i_dst_height,
59                            const video_format_t *p_src )
60 {
61     /* */
62     if( p_blend->p_module &&
63         p_blend->fmt_in.video.i_chroma != p_src->i_chroma )
64     {
65         /* The chroma is not the same, we need to reload the blend module */
66         module_unneed( p_blend, p_blend->p_module );
67         p_blend->p_module = NULL;
68     }
69
70     /* */
71
72     p_blend->fmt_in.i_codec = p_src->i_chroma;
73     p_blend->fmt_in.video   = *p_src;
74
75     /* */
76     p_blend->fmt_out.video.i_width          =
77     p_blend->fmt_out.video.i_visible_width  = i_dst_width;
78     p_blend->fmt_out.video.i_height         =
79     p_blend->fmt_out.video.i_visible_height = i_dst_height;
80
81     /* */
82     if( !p_blend->p_module )
83         p_blend->p_module = module_need( p_blend, "video blending", NULL, false );
84     if( !p_blend->p_module )
85         return VLC_EGENERIC;
86     return VLC_SUCCESS;
87 }
88
89 int filter_Blend( filter_t *p_blend,
90                   picture_t *p_dst, int i_dst_x, int i_dst_y,
91                   const picture_t *p_src, int i_alpha )
92 {
93     if( !p_blend->p_module )
94         return VLC_EGENERIC;
95
96     p_blend->pf_video_blend( p_blend, p_dst, p_src, i_dst_x, i_dst_y, i_alpha );
97     return VLC_SUCCESS;
98 }
99
100 void filter_DeleteBlend( filter_t *p_blend )
101 {
102     if( p_blend->p_module )
103         module_unneed( p_blend, p_blend->p_module );
104
105     vlc_object_detach( p_blend );
106     vlc_object_release( p_blend );
107 }
108
109 /* */
110 #include <vlc_video_splitter.h>
111
112 video_splitter_t *video_splitter_New( vlc_object_t *p_this,
113                                       const char *psz_name,
114                                       const video_format_t *p_fmt )
115 {
116     video_splitter_t *p_splitter = vlc_custom_create( p_this, sizeof(*p_splitter),
117                                            VLC_OBJECT_GENERIC, "video splitter" );
118     if( !p_splitter )
119         return NULL;
120
121     video_format_Copy( &p_splitter->fmt, p_fmt );
122
123     /* */
124     vlc_object_attach( p_splitter, p_this );
125
126     p_splitter->p_module = module_need( p_splitter, "video splitter", psz_name, true );
127     if( ! p_splitter->p_module )
128     {
129         video_splitter_Delete( p_splitter );
130         return NULL;
131     }
132
133     return p_splitter;
134 }
135
136 void video_splitter_Delete( video_splitter_t *p_splitter )
137 {
138     if( p_splitter->p_module )
139         module_unneed( p_splitter, p_splitter->p_module );
140
141     video_format_Clean( &p_splitter->fmt );
142
143     vlc_object_detach( p_splitter );
144     vlc_object_release( p_splitter );
145 }
146