8b21d8f7b0ce104f56a2086e2cc87c4f8146e4a0
[melted] / src / modules / frei0r / frei0r_helper.c
1 /*
2 * frei0r_helper.c -- frei0r helper
3 * Copyright (c) 2008 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #include "frei0r_helper.h"
20 #include <frei0r.h>
21 #include <string.h>
22
23 int process_frei0r_item( mlt_service_type type, double position , mlt_properties prop , mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ){
24
25 int i=0;
26 f0r_instance_t ( *f0r_construct ) ( unsigned int , unsigned int ) = mlt_properties_get_data( prop , "f0r_construct" ,NULL);
27 void (*f0r_update)(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe)=mlt_properties_get_data( prop , "f0r_update" ,NULL);
28 void (*f0r_destruct)(f0r_instance_t instance)=mlt_properties_get_data( prop , "f0r_destruct" ,NULL);
29
30 void (*f0r_get_plugin_info)(f0r_plugin_info_t*)=mlt_properties_get_data( prop, "f0r_get_plugin_info" ,NULL);
31 void (*f0r_get_param_info)(f0r_param_info_t* info, int param_index)=mlt_properties_get_data( prop , "f0r_get_param_info" ,NULL);
32 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);
33 void (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index)=mlt_properties_get_data( prop , "f0r_get_param_value" ,NULL);
34 void (*f0r_update2) (f0r_instance_t instance, double time,
35 const uint32_t* inframe1,const uint32_t* inframe2,const uint32_t* inframe3,
36 uint32_t* outframe)=mlt_properties_get_data( prop , "f0r_update2" ,NULL);
37
38
39 //use as name the width and height
40 f0r_instance_t inst;
41 char ctorname[1024]="";
42 sprintf(ctorname,"ctor-%dx%d",*width,*height);
43
44 void* neu=mlt_properties_get_data( prop , ctorname ,NULL );
45 if (!f0r_construct){
46 //printf("no ctor\n");
47 return -1;
48 }
49 if ( neu == 0 ){
50 inst= f0r_construct(*width,*height);
51 mlt_properties_set_data( prop , ctorname , inst, sizeof(void*) , f0r_destruct , NULL );;
52 }else{
53 inst=mlt_properties_get_data( prop , ctorname , NULL );
54 }
55 if (f0r_get_plugin_info){
56 f0r_plugin_info_t info;
57 f0r_get_plugin_info(&info);
58 for (i=0;i<info.num_params;i++){
59 f0r_param_info_t pinfo;
60 f0r_get_param_info(&pinfo,i);
61 mlt_geometry geom=mlt_geometry_init();
62 struct mlt_geometry_item_s item;
63 //set param if found
64
65 double t=0.0;
66 f0r_get_param_value(inst,&t,i);
67 char *val;
68 if (mlt_properties_get( prop , pinfo.name ) !=NULL ){
69 switch (pinfo.type) {
70 case F0R_PARAM_DOUBLE:
71 case F0R_PARAM_BOOL:
72 val=mlt_properties_get(prop, pinfo.name );
73 mlt_geometry_parse(geom,val,-1,-1,-1);
74 mlt_geometry_fetch(geom,&item,position);
75 t=item.x;
76 f0r_set_param_value(inst,&t,i);
77 break;
78 //case F0R_PARAM_COLOR:
79 // t=mlt_properties_get_double( prop , pinfo.name );
80
81 }
82 }
83
84 mlt_geometry_close(geom);
85 }
86 }
87
88 int video_area = *width * *height;
89 uint32_t *img_a = mlt_pool_alloc( video_area * sizeof(uint32_t) );
90 uint32_t *img_b = mlt_pool_alloc( video_area * sizeof(uint32_t) );
91
92 if (type==filter_type){
93 mlt_convert_yuv422_to_rgb24a(*image, (uint8_t *)img_a, video_area);
94 f0r_update ( inst , position , img_a , img_b );
95 mlt_convert_rgb24a_to_yuv422((uint8_t *)img_b , *width, *height, *width * sizeof(uint32_t),
96 *image, NULL );
97 }else if (type==transition_type && f0r_update2 ){
98 uint32_t *result = mlt_pool_alloc( video_area * sizeof(uint32_t) );
99
100 mlt_convert_yuv422_to_rgb24a ( image[0] , (uint8_t *)img_a , video_area );
101 mlt_convert_yuv422_to_rgb24a ( image[1] , (uint8_t *)img_b , video_area );
102 f0r_update2 ( inst , position , img_a , img_b , NULL , result );
103
104 uint8_t * image_ptr=mlt_properties_get_data(MLT_FRAME_PROPERTIES(this), "image", NULL );
105 if (image_ptr)
106 mlt_convert_rgb24a_to_yuv422((uint8_t *)result, *width, *height, *width * sizeof(uint32_t), image_ptr , NULL );
107
108 mlt_pool_release(result);
109 }
110 mlt_pool_release(img_a);
111 mlt_pool_release(img_b);
112
113 return 0;
114 }
115
116 void destruct (mlt_properties prop ) {
117
118 void (*f0r_destruct)(f0r_instance_t instance)=mlt_properties_get_data( prop , "f0r_destruct" , NULL );
119 void (*f0r_deinit)(void)=mlt_properties_get_data ( prop , "f0r_deinit" , NULL);
120 int i=0;
121
122 if ( f0r_deinit != NULL )
123 f0r_deinit();
124
125 for ( i=0 ; i < mlt_properties_count ( prop ) ; i++ ){
126 if ( strstr ( mlt_properties_get_name ( prop , i ) , "ctor-" ) != NULL ){
127 void * inst=mlt_properties_get_data( prop , mlt_properties_get_name ( prop , i ) , NULL );
128 if ( inst != NULL ){
129 f0r_destruct( (f0r_instance_t) inst);
130 }
131 }
132 }
133 void (*dlclose)(void*)=mlt_properties_get_data ( prop , "_dlclose" , NULL);
134 void *handle=mlt_properties_get_data ( prop , "_dlclose_handle" , NULL);
135
136 if (handle && dlclose ){
137 dlclose ( handle );
138 }
139
140 }