X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ftransition_region.c;h=b75a2904329e2cb2d06a66dc9c5a0d57f7a6af8b;hb=bb52b9f3ce843820aca77ca7bc18adf1dcd61122;hp=41fce2fd087a9951d38df4ed287763f290e11289;hpb=52b7a4fb7a6e8745ac40153cd18c1fb5555a82f2;p=melted diff --git a/src/modules/core/transition_region.c b/src/modules/core/transition_region.c index 41fce2f..b75a290 100644 --- a/src/modules/core/transition_region.c +++ b/src/modules/core/transition_region.c @@ -3,19 +3,19 @@ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited * Author: Charles Yates * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "transition_region.h" @@ -46,13 +46,14 @@ static int create_instance( mlt_transition this, char *name, char *value, int co *arg ++ = '\0'; // Create the filter - filter = mlt_factory_filter( type, arg ); + mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( this ) ); + filter = mlt_factory_filter( profile, type, arg ); // If we have a filter, then initialise and store it if ( filter != NULL ) { // Properties of this - mlt_properties properties = mlt_transition_properties( this ); + mlt_properties properties = MLT_TRANSITION_PROPERTIES( this ); // String to hold the property name char id[ 256 ]; @@ -67,11 +68,11 @@ static int create_instance( mlt_transition this, char *name, char *value, int co sprintf( key, "%s.", name ); // Just in case, let's assume that the filter here has a composite - mlt_properties_set( mlt_filter_properties( filter ), "composite.start", "0%,0%:100%x100%" ); - mlt_properties_set( mlt_filter_properties( filter ), "composite.fill", "true" ); + //mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "composite.geometry", "0%,0%:100%x100%" ); + //mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "composite.fill", 1 ); // Pass all the key properties on the filter down - mlt_properties_pass( mlt_filter_properties( filter ), properties, key ); + mlt_properties_pass( MLT_FILTER_PROPERTIES( filter ), properties, key ); // Ensure that filter is assigned mlt_properties_set_data( properties, id, filter, 0, ( mlt_destructor )mlt_filter_close, NULL ); @@ -91,23 +92,47 @@ static int create_instance( mlt_transition this, char *name, char *value, int co static uint8_t *filter_get_alpha_mask( mlt_frame this ) { + uint8_t *alpha = NULL; + // Obtain properties of frame - mlt_properties properties = mlt_frame_properties( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); // Get the shape frame mlt_frame shape_frame = mlt_properties_get_data( properties, "shape_frame", NULL ); // Get the width and height of the image - int region_width = mlt_properties_get_int( mlt_frame_properties( this ), "width" ); - int region_height = mlt_properties_get_int( mlt_frame_properties( this ), "height" ); + int region_width = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "width" ); + int region_height = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "height" ); uint8_t *image = NULL; mlt_image_format format = mlt_image_yuv422; // Get the shape image to trigger alpha creation - mlt_properties_set( mlt_frame_properties( shape_frame ), "distort", "true" ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( shape_frame ), "distort", 1 ); mlt_frame_get_image( shape_frame, &image, &format, ®ion_width, ®ion_height, 0 ); - return mlt_frame_get_alpha_mask( shape_frame ); + alpha = mlt_frame_get_alpha_mask( shape_frame ); + + // Generate from the Y component of the image if no alpha available + if ( alpha == NULL ) + { + int size = region_width * region_height; + uint8_t *p = mlt_pool_alloc( size ); + alpha = p; + while ( size -- ) + { + *p ++ = ( int )( ( ( *image ++ - 16 ) * 299 ) / 255 ); + image ++; + } + mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", alpha, region_width * region_height, mlt_pool_release, NULL ); + } + else + { + mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", alpha, region_width * region_height, NULL, NULL ); + } + + this->get_alpha_mask = NULL; + + return alpha; } /** Do it :-). @@ -125,7 +150,7 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for mlt_transition this = mlt_frame_pop_service( frame ); // Get the properties of the transition - mlt_properties properties = mlt_transition_properties( this ); + mlt_properties properties = MLT_TRANSITION_PROPERTIES( this ); // Get the composite from the transition mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL ); @@ -137,23 +162,24 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for char *name = mlt_properties_get( properties, "_unique_id" ); // Get the original producer position - mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name ); + mlt_position position = mlt_properties_get_position( MLT_FRAME_PROPERTIES( frame ), name ); // Create a composite if we don't have one if ( composite == NULL ) { // Create composite via the factory - composite = mlt_factory_transition( "composite", NULL ); + mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( this ) ); + composite = mlt_factory_transition( profile, "composite", NULL ); // If we have one if ( composite != NULL ) { // Get the properties - mlt_properties composite_properties = mlt_transition_properties( composite ); + mlt_properties composite_properties = MLT_TRANSITION_PROPERTIES( composite ); // We want to ensure that we don't get a wobble... - mlt_properties_set( composite_properties, "distort", "true" ); - mlt_properties_set( composite_properties, "progressive", "1" ); + //mlt_properties_set_int( composite_properties, "distort", 1 ); + mlt_properties_set_int( composite_properties, "progressive", 1 ); // Pass all the composite. properties on the transition down mlt_properties_pass( composite_properties, properties, "composite." ); @@ -162,6 +188,12 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL ); } } + else + { + // Pass all current properties down + mlt_properties composite_properties = MLT_TRANSITION_PROPERTIES( composite ); + mlt_properties_pass( composite_properties, properties, "composite." ); + } // Create filters if ( filter == NULL ) @@ -189,6 +221,48 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for count ++; } } + + // Look for the first filter again + filter = mlt_properties_get_data( properties, "_filter_0", NULL ); + } + else + { + // Pass all properties down + mlt_filter temp = NULL; + + // Loop Variable + int i = 0; + + // Number of filters found + int count = 0; + + // Loop for all properties + for ( i = 0; i < mlt_properties_count( properties ); i ++ ) + { + // Get the name of this property + char *name = mlt_properties_get_name( properties, i ); + + // If the name does not contain a . and matches filter + if ( strchr( name, '.' ) == NULL && !strncmp( name, "filter", 6 ) ) + { + // Strings to hold the id and pass down key + char id[ 256 ]; + char key[ 256 ]; + + // Construct id and key + sprintf( id, "_filter_%d", count ); + sprintf( key, "%s.", name ); + + // Get the filter + temp = mlt_properties_get_data( properties, id, NULL ); + + if ( temp != NULL ) + { + mlt_properties_pass( MLT_FILTER_PROPERTIES( temp ), properties, key ); + count ++; + } + } + } } // Get the image @@ -200,6 +274,9 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for // Get the resource of this filter (could be a shape [rectangle/circle] or an alpha provider of choice char *resource = mlt_properties_get( properties, "resource" ); + // Get the old resource in case it's changed + char *old_resource = mlt_properties_get( properties, "_old_resource" ); + // String to hold the filter to query on char id[ 256 ]; @@ -213,14 +290,18 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for b_frame = composite_copy_region( composite, frame, position ); // Ensure a destructor - mlt_properties_set_data( mlt_frame_properties( frame ), name, b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); + mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), name, b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); } + // Set the position of the b_frame + mlt_frame_set_position( b_frame, position ); + // Make sure the filter is in the correct position while ( filter != NULL ) { // Stack this filter - mlt_filter_process( filter, b_frame ); + if ( mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "off" ) == 0 ) + mlt_filter_process( filter, b_frame ); // Generate the key for the next sprintf( id, "_filter_%d", ++ i ); @@ -229,6 +310,11 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for filter = mlt_properties_get_data( properties, id, NULL ); } + // Allow filters to be attached to a region filter + filter = mlt_properties_get_data( properties, "_region_filter", NULL ); + if ( filter != NULL ) + mlt_service_apply_filters( MLT_FILTER_SERVICE( filter ), b_frame, 0 ); + // Hmm - this is probably going to go wrong.... mlt_frame_set_position( frame, position ); @@ -242,29 +328,27 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); // If We have no producer then create one - if ( producer == NULL ) + if ( producer == NULL || ( old_resource != NULL && strcmp( resource, old_resource ) ) ) { // Get the factory producer service char *factory = mlt_properties_get( properties, "factory" ); + // Store the old resource + mlt_properties_set( properties, "_old_resource", resource ); + // Special case circle resource if ( strcmp( resource, "circle" ) == 0 ) - { - // Special case to ensure that fezzik produces a pixbuf with a NULL constructor - resource = "pixbuf"; + resource = "pixbuf:"; - // Specify the svg circle - mlt_properties_set( properties, "producer.resource", "" ); - } - - // Create the producer - producer = mlt_factory_producer( factory, resource ); + // Create the producer + mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( this ) ); + producer = mlt_factory_producer( profile, factory, resource ); // If we have one if ( producer != NULL ) { // Get the producer properties - mlt_properties producer_properties = mlt_producer_properties( producer ); + mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); // Ensure that we loop mlt_properties_set( producer_properties, "eof", "loop" ); @@ -287,10 +371,10 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for mlt_producer_seek( producer, position ); // Get the shape frame - if ( mlt_service_get_frame( mlt_producer_service( producer ), &shape_frame, 0 ) == 0 ) + if ( mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &shape_frame, 0 ) == 0 ) { // Ensure that the shape frame will be closed - mlt_properties_set_data( mlt_frame_properties( b_frame ), "shape_frame", shape_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); + mlt_properties_set_data( MLT_FRAME_PROPERTIES( b_frame ), "shape_frame", shape_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); // Specify the callback for evaluation b_frame->get_alpha_mask = filter_get_alpha_mask; @@ -311,10 +395,10 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame ) { // Get the properties of the frame - mlt_properties properties = mlt_frame_properties( a_frame ); + mlt_properties properties = MLT_FRAME_PROPERTIES( a_frame ); // Get a unique name to store the frame position - char *name = mlt_properties_get( mlt_transition_properties( this ), "_unique_id" ); + char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( this ), "_unique_id" ); // Assign the current position to the name mlt_properties_set_position( properties, name, mlt_frame_get_position( a_frame ) ); @@ -335,7 +419,7 @@ static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt /** Constructor for the transition. */ -mlt_transition transition_region_init( void *arg ) +mlt_transition transition_region_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { // Create a new transition mlt_transition this = mlt_transition_new( ); @@ -344,7 +428,7 @@ mlt_transition transition_region_init( void *arg ) if ( this != NULL ) { // Get the properties from the transition - mlt_properties properties = mlt_transition_properties( this ); + mlt_properties properties = MLT_TRANSITION_PROPERTIES( this ); // Assign the transition process method this->process = transition_process; @@ -354,6 +438,9 @@ mlt_transition transition_region_init( void *arg ) // Resource defines the shape of the region mlt_properties_set( properties, "resource", arg == NULL ? "rectangle" : arg ); + + // Inform apps and framework that this is a video only transition + mlt_properties_set_int( properties, "_transition_type", 1 ); } // Return the transition