watermark added, minor mods to mlt framework required
[melted] / src / modules / core / filter_watermark.c
1 /*
2 * filter_watermark.c -- watermark filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
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 Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "filter_watermark.h"
22
23 #include <framework/mlt_factory.h>
24 #include <framework/mlt_frame.h>
25 #include <framework/mlt_producer.h>
26 #include <framework/mlt_transition.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 /** Do it :-).
32 */
33
34 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
35 {
36 int error = 0;
37 mlt_properties frame_properties = mlt_frame_properties( this );
38 mlt_filter filter = mlt_properties_get_data( frame_properties, "watermark", NULL );
39 mlt_properties properties = mlt_filter_properties( filter );
40 mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
41 mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL );
42
43 if ( composite == NULL )
44 {
45 char *geometry = mlt_properties_get( properties, "geometry" );
46 composite = mlt_factory_transition( "composite", geometry == NULL ? "85%,5%:10%x10%" : geometry );
47 if ( composite != NULL )
48 {
49 mlt_properties composite_properties = mlt_transition_properties( composite );
50 char *distort = mlt_properties_get( properties, "distort" );
51 if ( distort != NULL )
52 mlt_properties_set( composite_properties, "distort", distort );
53 mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL );
54 }
55 }
56
57 if ( producer == NULL )
58 {
59 char *resource = mlt_properties_get( properties, "resource" );
60 char *factory = mlt_properties_get( properties, "factory" );
61 producer = mlt_factory_producer( factory, resource );
62 if ( producer != NULL )
63 {
64 mlt_properties producer_properties = mlt_producer_properties( producer );
65 mlt_properties_set( producer_properties, "eof", "loop" );
66 mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
67 }
68 }
69
70 if ( composite != NULL && producer != NULL )
71 {
72 mlt_service service = mlt_producer_service( producer );
73 mlt_frame b_frame = NULL;
74
75 if ( mlt_service_get_frame( service, &b_frame, 0 ) == 0 )
76 mlt_transition_process( composite, this, b_frame );
77
78 error = mlt_frame_get_image( this, image, format, width, height, 1 );
79
80 mlt_frame_close( b_frame );
81 }
82 else
83 {
84 error = mlt_frame_get_image( this, image, format, width, height, 1 );
85 }
86
87 return error;
88 }
89
90 /** Filter processing.
91 */
92
93 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
94 {
95 mlt_properties properties = mlt_frame_properties( frame );
96 mlt_properties_set_data( properties, "watermark", this, 0, NULL, NULL );
97 mlt_frame_push_get_image( frame, filter_get_image );
98 return frame;
99 }
100
101 /** Constructor for the filter.
102 */
103
104 mlt_filter filter_watermark_init( void *arg )
105 {
106 mlt_filter this = mlt_filter_new( );
107 if ( this != NULL )
108 {
109 mlt_properties properties = mlt_filter_properties( this );
110 this->process = filter_process;
111 mlt_properties_set( properties, "factory", "fezzik" );
112 if ( arg != NULL )
113 mlt_properties_set( properties, "resource", arg );
114 }
115 return this;
116 }
117