f56c6778a6e9cd968f3a319fd36f8e6abebe9685
[melted] / src / modules / core / transition_composite.c
1 /*
2 * transition_composite.c -- compose one image over another using alpha channel
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
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 "transition_composite.h"
22 #include <framework/mlt_frame.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 /** Composition class.
28 */
29
30 typedef struct
31 {
32 struct mlt_transition_s parent;
33 }
34 transition_composite;
35
36 /** Get the image.
37 */
38
39 static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
40 {
41 // Get the properties of the a frame
42 mlt_properties a_props = mlt_frame_properties( this );
43
44 // Get the b frame from the stack
45 mlt_frame b_frame = mlt_frame_pop_frame( this );
46
47 // Get the properties of the b frame
48 mlt_properties b_props = mlt_frame_properties( b_frame );
49
50 // Arbitrary composite defaults
51 int x = 0;
52 int y = 0;
53 double mix = 1.0;
54
55 // Override from b frame properties if provided
56 if ( mlt_properties_get( b_props, "x" ) != NULL )
57 x = mlt_properties_get_int( b_props, "x" );
58 if ( mlt_properties_get( b_props, "y" ) != NULL )
59 y = mlt_properties_get_int( b_props, "y" );
60 if ( mlt_properties_get( b_props, "mix" ) != NULL )
61 mix = mlt_properties_get_double( b_props, "mix" );
62
63 // Composite the b_frame on the a_frame
64 mlt_frame_composite_yuv( this, b_frame, x, y, mix );
65
66 // Extract the a_frame image info
67 *width = mlt_properties_get_int( a_props, "width" );
68 *height = mlt_properties_get_int( a_props, "height" );
69 *image = mlt_properties_get_data( a_props, "image", NULL );
70
71 // Close the b_frame
72 mlt_frame_close( b_frame );
73
74 return 0;
75 }
76
77 /** Composition transition processing.
78 */
79
80 static mlt_frame composite_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame )
81 {
82 mlt_frame_push_get_image( a_frame, transition_get_image );
83 mlt_frame_push_frame( a_frame, b_frame );
84 return a_frame;
85 }
86
87 /** Constructor for the filter.
88 */
89
90 mlt_transition transition_composite_init( void *arg )
91 {
92 transition_composite *this = calloc( sizeof( transition_composite ), 1 );
93 if ( this != NULL )
94 {
95 mlt_transition transition = &this->parent;
96 mlt_transition_init( transition, this );
97 transition->process = composite_process;
98 return &this->parent;
99 }
100 return NULL;
101 }
102