]> git.sesse.net Git - mlt/blob - src/modules/oldfilm/filter_lines.c
c840ae0eb6fc01b983c263b7c87826fb88da48f4
[mlt] / src / modules / oldfilm / filter_lines.c
1 /*
2  * filter_lines.c -- lines filter
3  * Copyright (c) 2007 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
20 #include "filter_lines.h"
21
22 #include <framework/mlt_frame.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27
28
29 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
30 {
31
32         mlt_filter filter = mlt_frame_pop_service( this );
33         int error = mlt_frame_get_image( this, image, format, width, height, 1 );
34
35         if ( error == 0 && *image && *format == mlt_image_yuv422 )
36         {
37                 int h = *height;
38                 int w = *width;
39
40                 int width = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "width" );
41                 int num = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "num" );
42                 //int frame = mlt_properties_get_int( this, "_position" );
43                 char buf[1024];
44                 
45                 while (num--){
46                         sprintf(buf,"line%d",num);
47                         
48                         int type=rand()%2;
49                         int x1=rand()%w;;
50                         int dx=rand()%width;
51                         /*int xx=mlt_properties_get_int(MLT_PRODUCER_PROPERTIES(mlt_frame_get_original_producer( this ),buf);
52                         if (xx==0){
53                                 mlt_properties_set_int(this,buf,x1);
54                                 //x1=100;
55                         }
56                         x1=mlt_properties_get_int(this,buf)+5;
57                         */
58                         int x=0,y=0,pix=0;
59                         for (x=-dx;x<dx;x++)
60                                 for(y=0;y<h;y++)
61                                         if (x+x1<w && x+x1>0){
62                                                 uint8_t* pixel=(*image+(y)*w*2+(x+x1)*2);
63                                                 switch(type){
64                                                         case 0:
65                                                                 pix=(*pixel)*abs(x)/dx;
66                                                                 *pixel=pix;
67                                                                 break;
68                                                         case 1:
69                                                                 pix=(*pixel)+((255-*pixel)*abs(x)/dx);
70                                                                 *pixel=pix;
71                                                                 break;
72                                                 }
73                                                         
74                                 }
75                 }
76         }
77
78         return error;
79 }
80
81 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
82 {
83
84         mlt_frame_push_service( frame, this );
85         mlt_frame_push_get_image( frame, filter_get_image );
86         return frame;
87 }
88
89 mlt_filter filter_lines_init( char *arg )
90 {
91         mlt_filter this = mlt_filter_new( );
92         if ( this != NULL )
93         {
94                 this->process = filter_process;
95                 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "width", "2" );
96                 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "num", "5" );
97         }
98         return this;
99 }
100
101