2 * filter_luma.c -- luma filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "filter_luma.h"
23 #include <framework/mlt_factory.h>
24 #include <framework/mlt_frame.h>
25 #include <framework/mlt_producer.h>
26 #include <framework/mlt_transition.h>
35 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
38 mlt_filter filter = mlt_frame_pop_service( this );
39 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
40 mlt_transition luma = mlt_properties_get_data( properties, "luma", NULL );
41 mlt_frame b_frame = mlt_properties_get_data( properties, "frame", NULL );
42 mlt_properties b_frame_props = b_frame ? MLT_FRAME_PROPERTIES( b_frame ) : NULL;
43 int out = mlt_properties_get_int( properties, "period" );
50 char *resource = mlt_properties_get( properties, "resource" );
51 luma = mlt_factory_transition( "luma", resource );
54 mlt_properties luma_properties = MLT_TRANSITION_PROPERTIES( luma );
55 mlt_properties_set_int( luma_properties, "in", 0 );
56 mlt_properties_set_int( luma_properties, "out", out );
57 mlt_properties_set_int( luma_properties, "reverse", 1 );
58 mlt_properties_set_data( properties, "luma", luma, 0, ( mlt_destructor )mlt_transition_close, NULL );
62 if ( b_frame == NULL || mlt_properties_get_int( b_frame_props, "width" ) != *width || mlt_properties_get_int( b_frame_props, "height" ) != *height )
64 b_frame = mlt_frame_init( );
65 mlt_properties_set_data( properties, "frame", b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
69 ( mlt_properties_get( properties, "blur" ) != NULL ||
70 (int)mlt_frame_get_position( this ) % ( out + 1 ) != out ) )
72 mlt_properties luma_properties = MLT_TRANSITION_PROPERTIES( luma );
73 mlt_properties_pass( luma_properties, properties, "luma." );
74 mlt_transition_process( luma, this, b_frame );
77 error = mlt_frame_get_image( this, image, format, width, height, 1 );
81 mlt_properties a_props = MLT_FRAME_PROPERTIES( this );
83 uint8_t *src = mlt_properties_get_data( a_props, "image", &size );
84 uint8_t *dst = mlt_pool_alloc( size );
88 mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
89 memcpy( dst, src, size );
90 mlt_properties_set_data( b_props, "image", dst, size, mlt_pool_release, NULL );
91 mlt_properties_set_int( b_props, "width", *width );
92 mlt_properties_set_int( b_props, "height", *height );
93 mlt_properties_set_int( b_props, "format", *format );
100 /** Filter processing.
103 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
105 // Push the filter on to the stack
106 mlt_frame_push_service( frame, this );
108 // Push the get_image on to the stack
109 mlt_frame_push_get_image( frame, filter_get_image );
114 /** Constructor for the filter.
117 mlt_filter filter_luma_init( void *arg )
119 mlt_filter this = mlt_filter_new( );
122 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
123 this->process = filter_process;
125 mlt_properties_set( properties, "resource", arg );