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>
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.
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.
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.
21 #include "transition_composite.h"
22 #include <framework/mlt_frame.h>
27 /** Composition class.
32 struct mlt_transition_s parent
;
39 static int transition_get_image( mlt_frame
this, uint8_t **image
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
41 // Get the properties of the a frame
42 mlt_properties a_props
= mlt_frame_properties( this );
44 // Get the b frame from the stack
45 mlt_frame b_frame
= mlt_frame_pop_frame( this );
47 if ( b_frame
!= NULL
)
49 // Get the properties of the b frame
50 mlt_properties b_props
= mlt_frame_properties( b_frame
);
52 // Arbitrary composite defaults
57 // Override from b frame properties if provided
58 if ( mlt_properties_get( b_props
, "x" ) != NULL
)
59 x
= mlt_properties_get_int( b_props
, "x" );
60 if ( mlt_properties_get( b_props
, "y" ) != NULL
)
61 y
= mlt_properties_get_int( b_props
, "y" );
62 if ( mlt_properties_get( b_props
, "mix" ) != NULL
)
63 mix
= mlt_properties_get_double( b_props
, "mix" );
65 // Composite the b_frame on the a_frame
66 mlt_frame_composite_yuv( this, b_frame
, x
, y
, mix
);
68 // Extract the a_frame image info
69 *width
= mlt_properties_get_int( a_props
, "width" );
70 *height
= mlt_properties_get_int( a_props
, "height" );
71 *image
= mlt_properties_get_data( a_props
, "image", NULL
);
73 else if ( a_props
!= NULL
)
75 // Extract the a_frame image info
76 *width
= mlt_properties_get_int( a_props
, "width" );
77 *height
= mlt_properties_get_int( a_props
, "height" );
78 *image
= mlt_properties_get_data( a_props
, "image", NULL
);
84 /** Composition transition processing.
87 static mlt_frame
composite_process( mlt_transition
this, mlt_frame a_frame
, mlt_frame b_frame
)
89 mlt_frame_push_get_image( a_frame
, transition_get_image
);
90 mlt_frame_push_frame( a_frame
, b_frame
);
92 // Propogate the transition properties to the b frame
93 mlt_properties properties
= mlt_transition_properties( this );
94 mlt_properties b_props
= mlt_frame_properties( b_frame
);
95 if ( mlt_properties_get( properties
, "x" ) != NULL
)
96 mlt_properties_set_int( b_props
, "x", mlt_properties_get_int( properties
, "x" ) );
97 if ( mlt_properties_get( properties
, "y" ) != NULL
)
98 mlt_properties_set_int( b_props
, "y", mlt_properties_get_int( properties
, "y" ) );
99 if ( mlt_properties_get( properties
, "mix" ) != NULL
)
100 mlt_properties_set_double( b_props
, "mix", mlt_properties_get_double( properties
, "mix" ) );
105 /** Constructor for the filter.
108 mlt_transition
transition_composite_init( void *arg
)
110 transition_composite
*this = calloc( sizeof( transition_composite
), 1 );
113 mlt_transition transition
= &this->parent
;
114 mlt_transition_init( transition
, this );
115 transition
->process
= composite_process
;
116 return &this->parent
;