9935c70c0844b7c12eb6653dbe2989ea6e0dd9ea
[melted] / src / modules / oldfilm / filter_oldfilm.c
1 /*
2 * filter_oldfilm.c -- oldfilm 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_oldfilm.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 x=0;
41 int y=0;
42 // Get u and v values
43 int delta = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "delta" );
44 int every = mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "every" );
45 int diffpic=rand()%delta*2-delta;
46 if (rand()%100>every)
47 diffpic=0;
48 int yend,ydiff;
49 if (diffpic<=0){
50 y=h;
51 yend=0;
52 ydiff=-1;
53 }else{
54 y=0;
55 yend=h;
56 ydiff=1;
57 }
58 while(y!=yend){
59 for (x=0;x<w;x++){
60 uint8_t* pic=(*image+y*w*2+x*2);
61 if (y+diffpic>0 && y+diffpic<h){
62 *pic=*(pic+diffpic*w*2);
63 *(pic+1)=*(pic+diffpic*w*2+1);
64 }else{
65 *pic=0;
66 *(pic+1)=127;
67 }
68 }
69 y+=ydiff;
70 }
71 }
72
73 return error;
74 }
75
76 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
77 {
78
79 mlt_frame_push_service( frame, this );
80 mlt_frame_push_get_image( frame, filter_get_image );
81 return frame;
82 }
83
84 mlt_filter filter_oldfilm_init( char *arg )
85 {
86 mlt_filter this = mlt_filter_new( );
87 if ( this != NULL )
88 {
89 this->process = filter_process;
90 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "delta", "20" );
91 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "every", "80" );
92 }
93 return this;
94 }
95