]> git.sesse.net Git - mlt/blob - src/modules/qimage/producer_kdenlivetitle.c
memhandling changed
[mlt] / src / modules / qimage / producer_kdenlivetitle.c
1 /*
2  * producer_kdenlivetitle.c -- kdenlive producer
3  * Copyright (c) 2009 Marco Gittler <g.marco@freenet.de>
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <framework/mlt.h>
21 //#include "frei0r_helper.h"
22 #include <stdlib.h>
23 #include <string.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);
28
29 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
30 {
31
32     // Obtain properties of frame
33     mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
34
35     // Obtain the producer for this frame
36     mlt_producer producer = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
37
38     // Obtain properties of producer
39     mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
40     // Allocate the image
41     int size = *width * ( *height  ) * 4;
42     *buffer = mlt_pool_alloc( size);
43     // Update the frame
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));
47     
48     //######### noise
49     // Update the frame
50     mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
51 #if 0
52     // Before we write to the image, make sure we have one
53     if ( *buffer != NULL )
54     {
55         // Calculate the end of the buffer
56         uint8_t *p = *buffer + *width * *height * 2;
57
58         // Value to hold a random number
59         uint32_t value;
60
61         // Generate random noise
62         while ( p != *buffer )
63         {
64             value = rand() & 0xff;
65             *( -- p ) = 128;
66             *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
67         }
68     }
69
70
71     printf("%x %x\n", mlt_properties_get_data(properties,"image",NULL),mlt_properties_get_data(producer_props,"image",NULL));
72     //unchached now
73 #else
74     if ( 1 )
75     {
76         // Allocate the image
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 );
85         
86         
87         memcpy(*buffer,pic1,size); 
88         
89         /*uint8_t *p = *buffer + *width * *height * 2;
90
91         // Value to hold a random number
92         uint32_t value;
93
94         // Generate random noise
95         while ( p != *buffer )
96         {
97             value = rand() & 0xff;
98             *( -- p ) = 128;
99             *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value;
100         }
101         */
102         mlt_log_debug( MLT_PRODUCER_SERVICE(producer), "width:%d height:%d %s\n",*width,*height, mlt_image_format_name( *format ) );
103     }   
104 #endif
105     return 0;
106 }
107
108 int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
109 {
110     // Generate a frame
111     *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
112
113     if ( *frame != NULL )
114     {
115         // Obtain properties of frame and producer
116         mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
117
118         // Obtain properties of producer
119         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
120
121         // Set the producer on the frame properties
122         mlt_properties_set_data( properties, "producer_kdenlivetitle", producer, 0, NULL, NULL );
123
124         // Update timecode on the frame we're creating
125         mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
126
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" ) );
130
131         // Push the get_image method
132         mlt_frame_push_get_image( *frame, producer_get_image );
133     }
134
135     // Calculate the next timecode
136     mlt_producer_prepare_next( producer );
137
138     return 0;
139 }
140
141 void producer_close( mlt_producer producer )
142 {
143     producer->close = NULL;
144     mlt_producer_close( producer );    
145
146     free( producer );
147 }
148 mlt_producer producer_kdenlivetitle_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
149 {
150     // Create a new producer object
151     mlt_producer this = mlt_producer_new( );
152
153     // Initialise the producer
154     if ( this != NULL )
155     {
156         init_qt(arg);
157         // Callback registration
158         this->get_frame = producer_get_frame;
159         this->close = ( mlt_destructor )producer_close;
160     }
161     return this;
162 }
163