X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fqimage%2Fproducer_kdenlivetitle.c;h=5c37d3a348f4d9994ef5d8b46b0fdf27998129b6;hb=b592fda161e4a3388e8841cda2d0ff33589a64e9;hp=f1db7e70e7a70b91587b1d01ea60341816bf3886;hpb=1afe84bb87bc902dab9254fe1efc82b5a78b69bc;p=mlt diff --git a/src/modules/qimage/producer_kdenlivetitle.c b/src/modules/qimage/producer_kdenlivetitle.c index f1db7e70..5c37d3a3 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,13 +18,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "kdenlivetitle_wrapper.h" + #include #include #include -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"); @@ -40,7 +41,7 @@ void read_xml(mlt_properties properties) 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 ); } } @@ -51,50 +52,54 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form 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 ); - *width = mlt_properties_get_int( properties, "width" ); - *height = mlt_properties_get_int( properties, "height" ); + *width = mlt_properties_get_int( properties, "rescale_width" ); + *height = mlt_properties_get_int( properties, "rescale_height" ); - /* 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 ); + 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 ) + // 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 ) { - /* 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 ); - - mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) ); + // 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 ) ); @@ -108,13 +113,14 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i 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 */ @@ -140,10 +146,12 @@ mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type { /* 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 */ @@ -154,7 +162,7 @@ mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type read_xml(properties); return producer; } - free( producer ); + free( this ); return NULL; }