X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fqimage%2Fproducer_kdenlivetitle.c;h=5e914e25d6a2c4c1724f46e4df772e2ee6781b57;hb=806941f64ad9ef2ebbc223a96a3e6558b0f4d39a;hp=64a8e8710a4ba9a2a0f1cd2c8ddf596a4230f873;hpb=1bfb4a66553f20e8932be69f4387639ea1be1e6e;p=mlt diff --git a/src/modules/qimage/producer_kdenlivetitle.c b/src/modules/qimage/producer_kdenlivetitle.c index 64a8e871..5e914e25 100644 --- a/src/modules/qimage/producer_kdenlivetitle.c +++ b/src/modules/qimage/producer_kdenlivetitle.c @@ -1,6 +1,7 @@ /* * producer_kdenlivetitle.c -- kdenlive producer * Copyright (c) 2009 Marco Gittler + * Copyright (c) 2009 Jean-Baptiste Mardelle * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,102 +18,155 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "kdenlivetitle_wrapper.h" + #include #include #include -extern void init_qt(); -extern void refresh_kdenlivetitle(uint8_t*,int,int,double); -static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) + +void read_xml(mlt_properties properties) { + FILE *f = fopen( mlt_properties_get( properties, "resource" ), "r"); + if ( f != NULL ) + { + int size = 0; + long lSize; + + fseek (f , 0 , SEEK_END); + lSize = ftell (f); + rewind (f); + + char *infile = (char*) mlt_pool_alloc(lSize); + size=fread(infile,1,lSize,f); + infile[size] = '\0'; + fclose(f); + mlt_properties_set(properties, "xmldata", infile); + mlt_pool_release( infile ); + } +} - // Obtain properties of frame - mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); - - // Obtain the producer for this frame - mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL ); - - // Obtain properties of producer - // save extra data - //mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); - // Allocate the image - int size = *width * ( *height ) * 4; - - *buffer = mlt_pool_alloc( size); - // Update the frame - mlt_properties_set_int( properties, "width", *width ); - mlt_properties_set_int( properties, "height", *height ); - - // Update the frame - mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL ); - //cache later ?? - 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_frame_get_position( frame ); - double position = ( double )( time - in ) / ( double )( out - in + 1 ); - refresh_kdenlivetitle(*buffer, *width, *height, position ); - mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "width:%d height:%d %s\n",*width,*height, mlt_image_format_name( *format ) ); - } - return 0; +static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) +{ + /* Obtain properties of frame */ + mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); + + /* Obtain the producer for this frame */ + producer_ktitle this = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL ); + + /* Obtain properties of producer */ + mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( &this->parent ); + + *width = mlt_properties_get_int( properties, "rescale_width" ); + *height = mlt_properties_get_int( properties, "rescale_height" ); + + /* Allocate the image */ + int size = *width * ( *height ) * 4; + + /* Allocate the image */ + *format = mlt_image_rgb24a; + mlt_position in = mlt_producer_get_in( &this->parent ); + mlt_position out = mlt_producer_get_out( &this->parent ); + mlt_position time = mlt_producer_position( &this->parent ); + 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 ); + drawKdenliveTitle( this, frame, *width, *height, position, 1); + } + else drawKdenliveTitle( this, frame, *width, *height, position, 0); + + // Get width and height (may have changed during the refresh) + *width = mlt_properties_get_int( properties, "width" ); + *height = mlt_properties_get_int( properties, "height" ); + + 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_properties_set_data( properties, "image", image_copy, image_size, mlt_pool_release, NULL ); + // We're going to pass the copy on + *buffer = image_copy; + + /* Update the frame */ + mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL ); + + mlt_log_debug( MLT_PRODUCER_SERVICE( &this->parent ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) ); + } + + return 0; } -int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) +static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) + { - // Generate a frame - *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); + // Get the real structure for this producer + producer_ktitle this = producer->child; + + /* Generate a frame */ + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); - if ( *frame != NULL ) - { - // Obtain properties of frame and producer - mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); + if ( *frame != NULL ) + { + /* Obtain properties of frame and producer */ + mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); - // Obtain properties of producer - mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); + /* Obtain properties of 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 ); + /* Set the producer on the frame properties */ + 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 ) ); + /* 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_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) ); + /* Set producer-specific frame properties */ + mlt_properties_set_int( properties, "progressive", 1 ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) ); - // Push the get_image method - mlt_frame_push_get_image( *frame, producer_get_image ); - } + /* Push the get_image method */ + mlt_frame_push_get_image( *frame, producer_get_image ); + } - // Calculate the next timecode - mlt_producer_prepare_next( producer ); + /* Calculate the next timecode */ + mlt_producer_prepare_next( producer ); - return 0; + return 0; } -void producer_close( mlt_producer producer ) +static void producer_close( mlt_producer producer ) { - producer->close = NULL; - mlt_producer_close( producer ); - - free( producer ); + /* fprintf(stderr, ":::::::::::::: CLOSING TITLE\n"); */ + producer->close = NULL; + mlt_producer_close( producer ); + free( producer ); } -mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) + + +mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename ) { - // Create a new producer object - mlt_producer this = mlt_producer_new( ); - - // Initialise the producer - if ( this != NULL ) - { - init_qt(arg); - // Callback registration - this->get_frame = producer_get_frame; - this->close = ( mlt_destructor )producer_close; - } - return this; + /* fprintf(stderr, ":::::::::::: CREATE TITLE\n"); */ + /* Create a new producer object */ + + 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 ); + read_xml(properties); + return producer; + } + free( this ); + return NULL; }