2 * producer_kdenlivetitle.c -- kdenlive producer
3 * Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
4 * Copyright (c) 2009 Jean-Baptiste Mardelle <jb@kdenlive.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "kdenlivetitle_wrapper.h"
23 #include <framework/mlt.h>
28 void read_xml(mlt_properties properties)
30 FILE *f = fopen( mlt_properties_get( properties, "resource" ), "r");
36 if ( fseek (f , 0 , SEEK_END) < 0 )
43 char *infile = (char*) mlt_pool_alloc(lSize);
46 size = fread(infile,1,lSize,f);
50 mlt_properties_set(properties, "_xmldata", infile);
52 mlt_pool_release( infile );
59 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
62 /* Obtain properties of frame */
63 mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
65 /* Obtain the producer for this frame */
66 producer_ktitle this = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
68 /* Obtain properties of producer */
69 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( &this->parent );
71 *width = mlt_properties_get_int( properties, "rescale_width" );
72 *height = mlt_properties_get_int( properties, "rescale_height" );
74 mlt_service_lock( MLT_PRODUCER_SERVICE( &this->parent ) );
76 /* Allocate the image */
77 *format = mlt_image_rgb24a;
78 if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
79 if ( mlt_properties_get_int( producer_props, "force_reload" ) > 1 ) read_xml( producer_props );
80 mlt_properties_set_int( producer_props, "force_reload", 0 );
81 drawKdenliveTitle( this, frame, *width, *height, mlt_frame_original_position( frame ), 1);
83 else drawKdenliveTitle( this, frame, *width, *height, mlt_frame_original_position( frame ), 0);
85 // Get width and height (may have changed during the refresh)
86 *width = mlt_properties_get_int( properties, "width" );
87 *height = mlt_properties_get_int( properties, "height" );
89 if ( this->current_image )
91 // Clone the image and the alpha
92 int image_size = this->current_width * ( this->current_height ) * 4;
93 uint8_t *image_copy = mlt_pool_alloc( image_size );
94 memcpy( image_copy, this->current_image, image_size );
95 // Now update properties so we free the copy after
96 mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
97 // We're going to pass the copy on
100 mlt_log_debug( MLT_PRODUCER_SERVICE( &this->parent ), "width:%d height:%d %s\n", *width, *height, mlt_image_format_name( *format ) );
103 mlt_service_unlock( MLT_PRODUCER_SERVICE( &this->parent ) );
108 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
111 // Get the real structure for this producer
112 producer_ktitle this = producer->child;
114 /* Generate a frame */
115 *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
117 if ( *frame != NULL )
119 /* Obtain properties of frame and producer */
120 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
122 /* Obtain properties of producer */
123 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
125 /* Set the producer on the frame properties */
126 mlt_properties_set_data( properties, "producer_kdenlivetitle", this, 0, NULL, NULL );
128 /* Update timecode on the frame we're creating */
129 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
131 /* Set producer-specific frame properties */
132 mlt_properties_pass_list( properties, producer_props, "progressive, aspect_ratio" );
134 /* Push the get_image method */
135 mlt_frame_push_get_image( *frame, producer_get_image );
138 /* Calculate the next timecode */
139 mlt_producer_prepare_next( producer );
144 static void producer_close( mlt_producer producer )
146 /* fprintf(stderr, ":::::::::::::: CLOSING TITLE\n"); */
147 producer->close = NULL;
148 mlt_producer_close( producer );
153 mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *filename )
155 /* fprintf(stderr, ":::::::::::: CREATE TITLE\n"); */
156 /* Create a new producer object */
158 producer_ktitle this = calloc( 1, sizeof( struct producer_ktitle_s ) );
159 if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
161 mlt_producer producer = &this->parent;
163 /* Get the properties interface */
164 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
165 /* Callback registration */
166 producer->get_frame = producer_get_frame;
167 producer->close = ( mlt_destructor )producer_close;
168 mlt_properties_set( properties, "resource", filename );
169 mlt_properties_set_int( properties, "progressive", 1 );
170 read_xml(properties);