2 * filter_lines.c -- lines filter
3 * Copyright (c) 2007 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
20 #include <framework/mlt_filter.h>
21 #include <framework/mlt_frame.h>
27 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
30 mlt_filter filter = mlt_frame_pop_service( this );
31 *format = mlt_image_yuv422;
32 int error = mlt_frame_get_image( this, image, format, width, height, 1 );
34 if ( error == 0 && *image )
39 int width_line = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "width" );
40 int num = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "num" );
41 double maxdarker= (double)mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "darker" ) ;
42 double maxlighter=(double)mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "lighter" ) ;
43 //int frame = mlt_properties_get_int( this, "_position" );
47 mlt_position in = mlt_filter_get_in( filter );
48 mlt_position out = mlt_filter_get_out( filter );
49 mlt_position time = mlt_frame_get_position( this );
50 double position = ( double )( time - in ) / ( double )( out - in + 1 );
51 srand(position*10000);
55 mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
58 int type=(rand()%3)+1;
59 int x1=(double)w*rand()/RAND_MAX;
60 int dx=rand()%width_line;
65 sprintf(buf,"line%d",num);
66 sprintf(typebuf,"typeline%d",num);
67 maxlighter+=rand()%30-15;
68 maxdarker+=rand()%30-15;
70 if (mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter ),buf)==0){
71 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter ),buf,x1);
74 if (mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter ),typebuf)==0 ){
75 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter ),typebuf,type);
79 x1=mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter ),buf);
80 type=mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter ),typebuf);
81 if (position!=mlt_properties_get_double(MLT_FILTER_PROPERTIES( filter ),"last_oldfilm_line_pos")){
89 for (x = -dx ; x < dx && dx != 0 ; x++ )
90 for(y=ystart;y<yend;y++)
91 if (x+x1<w && x+x1>0){
92 uint8_t* pixel=(*image+(y)*w*2+(x+x1)*2);
93 double diff=1.0-fabs(x)/dx;
96 *pixel-=((double)*pixel*diff*maxdarker/100.0);
99 *pixel+=((255.0-(double)*pixel)*diff*maxlighter/100.0);
102 *(pixel+1)-=((*(pixel+1))*diff*maxlighter/100.0);
107 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter ),buf,x1);
109 mlt_properties_set_double(MLT_FILTER_PROPERTIES( filter ),"last_oldfilm_line_pos",position);
110 mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
116 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
119 mlt_frame_push_service( frame, this );
120 mlt_frame_push_get_image( frame, filter_get_image );
124 mlt_filter filter_lines_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
126 mlt_filter this = mlt_filter_new( );
129 this->process = filter_process;
130 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "width", "2" );
131 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "num", "5" );
132 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "darker" , 40 ) ;
133 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "lighter" , 40 ) ;