2 * frei0r_helper.c -- frei0r helper
3 * Copyright (c) 2008 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "frei0r_helper.h"
24 static void parse_color( int color, f0r_param_color_t *fcolor )
26 fcolor->r = ( color >> 24 ) & 0xff;
28 fcolor->g = ( color >> 16 ) & 0xff;
30 fcolor->b = ( color >> 8 ) & 0xff;
34 static void rgba_bgra( uint8_t *src, uint8_t* dst, int width, int height )
36 int n = width * height + 1;
48 int process_frei0r_item( mlt_service service, double position, double time, mlt_properties prop, mlt_frame this, uint8_t **image, int *width, int *height )
51 f0r_instance_t ( *f0r_construct ) ( unsigned int , unsigned int ) = mlt_properties_get_data( prop , "f0r_construct" ,NULL);
52 void (*f0r_update)(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe)=mlt_properties_get_data( prop , "f0r_update" ,NULL);
53 void (*f0r_destruct)(f0r_instance_t instance)=mlt_properties_get_data( prop , "f0r_destruct" ,NULL);
55 void (*f0r_get_plugin_info)(f0r_plugin_info_t*)=mlt_properties_get_data( prop, "f0r_get_plugin_info" ,NULL);
56 void (*f0r_get_param_info)(f0r_param_info_t* info, int param_index)=mlt_properties_get_data( prop , "f0r_get_param_info" ,NULL);
57 void (*f0r_set_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index)=mlt_properties_get_data( prop , "f0r_set_param_value" ,NULL);
58 void (*f0r_update2) (f0r_instance_t instance, double time,
59 const uint32_t* inframe1,const uint32_t* inframe2,const uint32_t* inframe3,
60 uint32_t* outframe)=mlt_properties_get_data( prop , "f0r_update2" ,NULL);
61 mlt_service_type type = mlt_service_identify( service );
62 int not_thread_safe = mlt_properties_get_int( prop, "_not_thread_safe" );
64 //use as name the width and height
66 f0r_plugin_info_t info;
67 char ctorname[1024]="";
68 sprintf(ctorname,"ctor-%dx%d",*width,*height);
70 mlt_service_lock( service );
72 void* neu=mlt_properties_get_data( prop , ctorname ,NULL );
74 //printf("no ctor\n");
78 inst= f0r_construct(*width,*height);
79 mlt_properties_set_data( prop , ctorname , inst, sizeof( inst ) , f0r_destruct , NULL );;
81 inst=mlt_properties_get_data( prop , ctorname , NULL );
84 if ( !not_thread_safe )
85 mlt_service_unlock( service );
87 if (f0r_get_plugin_info){
88 f0r_get_plugin_info(&info);
89 for (i=0;i<info.num_params;i++){
90 f0r_param_info_t pinfo;
91 f0r_get_param_info(&pinfo,i);
93 snprintf( index, sizeof(index), "%d", i );
94 char *val = mlt_properties_get( prop , index );
96 val = mlt_properties_get( prop , pinfo.name );
98 // Use the backwards-compatibility param name map.
99 mlt_properties map = mlt_properties_get_data( prop, "_param_name_map", NULL );
102 for ( j = 0; !val && j < mlt_properties_count(map); j++ ) {
103 if ( !strcmp(mlt_properties_get_value(map, j), index) )
104 val = mlt_properties_get( prop , mlt_properties_get_name(map, j) );
109 switch (pinfo.type) {
110 case F0R_PARAM_DOUBLE:
113 mlt_geometry geom=mlt_geometry_init();
114 struct mlt_geometry_item_s item;
115 mlt_geometry_parse(geom,val,-1,-1,-1);
116 mlt_geometry_fetch(geom,&item,position);
118 f0r_set_param_value(inst,&t,i);
119 mlt_geometry_close(geom);
122 case F0R_PARAM_COLOR:
124 f0r_param_color_t color;
125 int int_color = mlt_properties_get(prop, index) ?
126 mlt_properties_get_int(prop, index) : mlt_properties_get_int(prop, pinfo.name);
127 parse_color(int_color, &color);
128 f0r_set_param_value(inst, &color, i);
131 case F0R_PARAM_STRING:
133 f0r_set_param_value(inst, &val, i);
141 int video_area = *width * *height;
142 uint32_t *result = mlt_pool_alloc( video_area * sizeof(uint32_t) );
143 uint32_t *extra = NULL;
144 uint32_t *source[2] = { (uint32_t*) image[0], (uint32_t*) image[1] };
145 uint32_t *dest = result;
147 if (info.color_model == F0R_COLOR_MODEL_BGRA8888) {
148 rgba_bgra(image[0], (uint8_t*) result, *width, *height);
150 dest = (uint32_t*) image[0];
151 if (type == producer_type) {
152 extra = mlt_pool_alloc( video_area * sizeof(uint32_t) );
155 else if (type == transition_type && f0r_update2) {
156 extra = mlt_pool_alloc( video_area * sizeof(uint32_t) );
157 rgba_bgra(image[1], (uint8_t*) extra, *width, *height);
161 if (type==producer_type) {
162 f0r_update (inst, time, NULL, dest );
163 } else if (type==filter_type) {
164 f0r_update ( inst, time, source[0], dest );
165 } else if (type==transition_type && f0r_update2 ){
166 f0r_update2 ( inst, time, source[0], source[1], NULL, dest );
168 if ( not_thread_safe )
169 mlt_service_unlock( service );
170 if (info.color_model == F0R_COLOR_MODEL_BGRA8888) {
171 rgba_bgra((uint8_t*) dest, (uint8_t*) result, *width, *height);
173 *image = (uint8_t*) result;
174 mlt_frame_set_image(this, (uint8_t*) result, video_area * sizeof(uint32_t), mlt_pool_release);
176 mlt_pool_release(extra);
181 void destruct (mlt_properties prop ) {
183 void (*f0r_destruct)(f0r_instance_t instance)=mlt_properties_get_data( prop , "f0r_destruct" , NULL );
184 void (*f0r_deinit)(void)=mlt_properties_get_data ( prop , "f0r_deinit" , NULL);
187 if ( f0r_deinit != NULL )
190 for ( i=0 ; i < mlt_properties_count ( prop ) ; i++ ){
191 if ( strstr ( mlt_properties_get_name ( prop , i ) , "ctor-" ) != NULL ){
192 void * inst=mlt_properties_get_data( prop , mlt_properties_get_name ( prop , i ) , NULL );
194 f0r_destruct( (f0r_instance_t) inst);
198 void (*dlclose)(void*)=mlt_properties_get_data ( prop , "_dlclose" , NULL);
199 void *handle=mlt_properties_get_data ( prop , "_dlclose_handle" , NULL);
201 if (handle && dlclose ){