/*
* producer_kdenlivetitle.c -- kdenlive producer
* Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
+ * Copyright (c) 2009 Jean-Baptiste Mardelle <jb@kdenlive.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "kdenlivetitle_wrapper.h"
+
#include <framework/mlt.h>
#include <stdlib.h>
#include <string.h>
-extern void refresh_kdenlivetitle( mlt_producer producer, uint8_t*, int, int, double, int );
-
void read_xml(mlt_properties properties)
{
FILE *f = fopen( mlt_properties_get( properties, "resource" ), "r");
size=fread(infile,1,lSize,f);
infile[size] = '\0';
fclose(f);
- mlt_properties_set(properties, "xmldata", infile);
+ mlt_properties_set(properties, "_xmldata", infile);
mlt_pool_release( infile );
}
}
mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
/* Obtain the producer for this frame */
- mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
-
+ producer_ktitle this = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
+
/* Obtain properties of producer */
- mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
+ mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( &this->parent );
- /* Allocate the image */
- int size = *width * ( *height ) * 4;
-
- *buffer = mlt_pool_alloc( size );
-
- mlt_properties_set_int( properties, "width", *width );
- mlt_properties_set_int( properties, "height", *height );
-
-
+ *width = mlt_properties_get_int( properties, "rescale_width" );
+ *height = mlt_properties_get_int( properties, "rescale_height" );
+
+ mlt_service_lock( MLT_PRODUCER_SERVICE( &this->parent ) );
- /* cache later ?? */
+ /* Allocate the image */
+ *format = mlt_image_rgb24a;
+ mlt_position time = mlt_producer_position( &this->parent ) + mlt_producer_get_in( &this->parent );
+ if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
+ if (mlt_properties_get_int( producer_props, "force_reload" ) > 1) read_xml(producer_props);
+ mlt_properties_set_int( producer_props, "force_reload", 0 );
+ drawKdenliveTitle( this, frame, *width, *height, time, 1);
+ }
+ else drawKdenliveTitle( this, frame, *width, *height, time, 0);
- if ( 1 )
- {
- /* Allocate the image */
- *format = mlt_image_rgb24a;
- mlt_position in = mlt_producer_get_in( producer );
- mlt_position out = mlt_producer_get_out( producer );
- mlt_position time = mlt_producer_position( producer );
- double position = ( double )( time - in ) / ( double )( out - in + 1 );
- if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
- if (mlt_properties_get_int( producer_props, "force_reload" ) > 1) read_xml(producer_props);
- mlt_properties_set_int( producer_props, "force_reload", 0 );
- refresh_kdenlivetitle( producer, *buffer, *width, *height, position, 1);
- }
- else refresh_kdenlivetitle( producer, *buffer, *width, *height, position, 0);
- /* Update the frame */
- mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
+ // Get width and height (may have changed during the refresh)
+ *width = mlt_properties_get_int( properties, "width" );
+ *height = mlt_properties_get_int( properties, "height" );
- mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
+ if ( this->current_image )
+ {
+ // Clone the image and the alpha
+ int image_size = this->current_width * ( this->current_height ) * 4;
+ uint8_t *image_copy = mlt_pool_alloc( image_size );
+ memcpy( image_copy, this->current_image, image_size );
+ // Now update properties so we free the copy after
+ mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
+ // We're going to pass the copy on
+ *buffer = image_copy;
+
+ mlt_log_debug( MLT_PRODUCER_SERVICE( &this->parent ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
}
+ mlt_service_unlock( MLT_PRODUCER_SERVICE( &this->parent ) );
+
return 0;
}
static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
{
+ // Get the real structure for this producer
+ producer_ktitle this = producer->child;
/* Generate a frame */
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
/* Set the producer on the frame properties */
- mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
+ mlt_properties_set_data( properties, "producer_kdenlivetitle", this, 0, NULL, NULL );
/* Update timecode on the frame we're creating */
mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
/* Set producer-specific frame properties */
- mlt_properties_set_int( properties, "progressive", 1 );
+ mlt_profile profile = mlt_service_profile ( MLT_PRODUCER_SERVICE( producer ) ) ;
+ mlt_properties_set_int( properties, "progressive", ( profile ) ? profile->progressive : 1 );
mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
/* Push the get_image method */
{
/* fprintf(stderr, ":::::::::::: CREATE TITLE\n"); */
/* Create a new producer object */
-
- mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
- if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )
+
+ producer_ktitle this = calloc( sizeof( struct producer_ktitle_s ), 1 );
+ if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
{
+ mlt_producer producer = &this->parent;
+
/* Get the properties interface */
mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
/* Callback registration */
producer->get_frame = producer_get_frame;
producer->close = ( mlt_destructor )producer_close;
mlt_properties_set( properties, "resource", filename );
- mlt_properties_set_int( properties, "aspect_ratio", 1 );
+ //mlt_properties_set_int( properties, "aspect_ratio", 1 );
read_xml(properties);
return producer;
}
- free( producer );
+ free( this );
return NULL;
}