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 int error
= mlt_frame_get_image( this, image
, format
, width
, height
, 1 );
33 if ( error
== 0 && *image
&& *format
== mlt_image_yuv422
)
38 int width_line
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "width" );
39 int num
= mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "num" );
40 double maxdarker
= (double)mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "darker" ) ;
41 double maxlighter
=(double)mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "lighter" ) ;
42 //int frame = mlt_properties_get_int( this, "_position" );
46 mlt_position in
= mlt_filter_get_in( filter
);
47 mlt_position out
= mlt_filter_get_out( filter
);
48 mlt_position time
= mlt_frame_get_position( this );
49 double position
= ( double )( time
- in
) / ( double )( out
- in
+ 1 );
50 srand(position
*10000);
55 int type
=(rand()%3)+1;
56 int x1
=(double)w
*rand()/RAND_MAX
;
57 int dx
=rand()%width_line
;
62 sprintf(buf
,"line%d",num
);
63 sprintf(typebuf
,"typeline%d",num
);
64 maxlighter
+=rand()%30-15;
65 maxdarker
+=rand()%30-15;
67 if (mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter
),buf
)==0){
68 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter
),buf
,x1
);
71 if (mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter
),typebuf
)==0 ){
72 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter
),typebuf
,type
);
76 x1
=mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter
),buf
);
77 type
=mlt_properties_get_int(MLT_FILTER_PROPERTIES( filter
),typebuf
);
78 if (position
!=mlt_properties_get_double(MLT_FILTER_PROPERTIES( filter
),"last_oldfilm_line_pos")){
86 for (x
= -dx
; x
< dx
&& dx
!= 0 ; x
++ )
87 for(y
=ystart
;y
<yend
;y
++)
88 if (x
+x1
<w
&& x
+x1
>0){
89 uint8_t* pixel
=(*image
+(y
)*w
*2+(x
+x1
)*2);
90 double diff
=1.0-fabs(x
)/dx
;
93 *pixel
-=((double)*pixel
*diff
*maxdarker
/100.0);
96 *pixel
+=((255.0-(double)*pixel
)*diff
*maxlighter
/100.0);
99 *(pixel
+1)-=((*(pixel
+1))*diff
*maxlighter
/100.0);
104 mlt_properties_set_int(MLT_FILTER_PROPERTIES( filter
),buf
,x1
);
106 mlt_properties_set_double(MLT_FILTER_PROPERTIES( filter
),"last_oldfilm_line_pos",position
);
112 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
115 mlt_frame_push_service( frame
, this );
116 mlt_frame_push_get_image( frame
, filter_get_image
);
120 mlt_filter
filter_lines_init( mlt_profile profile
, mlt_service_type type
, const char *id
, char *arg
)
122 mlt_filter
this = mlt_filter_new( );
125 this->process
= filter_process
;
126 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "width", "2" );
127 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "num", "5" );
128 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "darker" , 40 ) ;
129 mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "lighter" , 40 ) ;