2 * producer_kdenlivetitle.c -- kdenlive producer
3 * Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <framework/mlt.h>
21 //#include "frei0r_helper.h"
24 //#include <QtCore/QCoreApplication>
25 //#include <QtGui/QImage>
26 extern void init_qt();
27 extern uint8_t* refresh_kdenlivetitle(uint8_t*,int,int,double);
29 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
32 // Obtain properties of frame
33 mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
35 // Obtain the producer for this frame
36 mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
38 // Obtain properties of producer
39 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
41 int size = *width * ( *height ) * 4;
42 *buffer = mlt_pool_alloc( size);
44 mlt_properties_set_int( properties, "width", *width );
45 mlt_properties_set_int( properties, "height", *height );
46 //printf("%x %x %x\n",*(buffer),*(buffer+1),*(buffer+2));
50 mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
52 // Before we write to the image, make sure we have one
53 if ( *buffer != NULL )
55 // Calculate the end of the buffer
56 uint8_t *p = *buffer + *width * *height * 2;
58 // Value to hold a random number
61 // Generate random noise
62 while ( p != *buffer )
64 value = rand() & 0xff;
66 *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
71 printf("%x %x\n", mlt_properties_get_data(properties,"image",NULL),mlt_properties_get_data(producer_props,"image",NULL));
77 *format = mlt_image_rgb24a;
78 //*format = mlt_image_yuv422;
79 mlt_position in = mlt_producer_get_in( producer );
80 mlt_position out = mlt_producer_get_out( producer );
81 mlt_position time = mlt_frame_get_position( frame );
82 double position = ( double )( time - in ) / ( double )( out - in + 1 );
83 //uint8_t *pic= mlt_pool_alloc( size);
84 uint8_t* pic1=refresh_kdenlivetitle(*buffer, *width, *height, position );
87 memcpy(*buffer,pic1,size);
89 /*uint8_t *p = *buffer + *width * *height * 2;
91 // Value to hold a random number
94 // Generate random noise
95 while ( p != *buffer )
97 value = rand() & 0xff;
99 *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
102 mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "width:%d height:%d %s\n",*width,*height, mlt_image_format_name( *format ) );
108 int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
111 *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
113 if ( *frame != NULL )
115 // Obtain properties of frame and producer
116 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
118 // Obtain properties of producer
119 mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
121 // Set the producer on the frame properties
122 mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
124 // Update timecode on the frame we're creating
125 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
127 // Set producer-specific frame properties
128 mlt_properties_set_int( properties, "progressive", 1 );
129 mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
131 // Push the get_image method
132 mlt_frame_push_get_image( *frame, producer_get_image );
135 // Calculate the next timecode
136 mlt_producer_prepare_next( producer );
141 void producer_close( mlt_producer producer )
143 producer->close = NULL;
144 mlt_producer_close( producer );
148 mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
150 // Create a new producer object
151 mlt_producer this = mlt_producer_new( );
153 // Initialise the producer
157 // Callback registration
158 this->get_frame = producer_get_frame;
159 this->close = ( mlt_destructor )producer_close;