obscurer filter, consistency mods and bug fixes
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 2 Feb 2004 23:23:58 +0000 (23:23 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 2 Feb 2004 23:23:58 +0000 (23:23 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@106 d19143bc-622f-0410-bfdd-b5b2a6649095

src/inigo/inigo.c
src/modules/avformat/producer_avformat.c
src/modules/core/Makefile
src/modules/core/configure
src/modules/core/factory.c
src/modules/core/filter_obscure.c [new file with mode: 0644]
src/modules/core/filter_obscure.h [new file with mode: 0644]
src/modules/inigo/Makefile
src/modules/inigo/configure
src/modules/inigo/producer_inigo.c
src/modules/vorbis/Makefile

index 40c99b4..76edbc9 100644 (file)
@@ -11,6 +11,8 @@ static void transport_action( mlt_producer producer, char *value )
        mlt_properties properties = mlt_producer_properties( producer );
        mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
 
+       mlt_properties_set_int( properties, "stats_off", 0 );
+
        if ( strlen( value ) == 1 )
        {
                switch( value[ 0 ] )
@@ -55,6 +57,7 @@ static void transport_action( mlt_producer producer, char *value )
                                {
                                        int i = 0;
                                        mlt_position last = -1;
+                                       fprintf( stderr, "\n" );
                                        for ( i = 0; 1; i ++ )
                                        {
                                                mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
@@ -63,7 +66,6 @@ static void transport_action( mlt_producer producer, char *value )
                                                last = time;
                                                fprintf( stderr, "%d: %lld\n", i, time );
                                        }
-                                       fprintf( stderr, "Current Position: %lld\n", mlt_producer_position( producer ) );
                                }
                                break;
 
@@ -120,6 +122,8 @@ static void transport_action( mlt_producer producer, char *value )
                                break;
                }
        }
+
+       mlt_properties_set_int( properties, "stats_off", 0 );
 }
 
 static mlt_consumer create_consumer( char *id, mlt_producer producer )
@@ -162,7 +166,12 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                int value = term_read( );
                if ( value != -1 )
                        transport_action( producer, ( char * )&value );
+
+               if ( mlt_properties_get_int( properties, "stats_off" ) == 0 )
+                       fprintf( stderr, "Current Position: %10lld\r", mlt_producer_position( producer ) );
        }
+
+       fprintf( stderr, "\n" );
 }
 
 int main( int argc, char **argv )
index bbefd2a..d5e6c7e 100644 (file)
@@ -204,8 +204,8 @@ static int producer_open( mlt_producer this, char *file )
                        {
                                // This isn't going to be accurate for all formats
                                mlt_position frames = ( mlt_position )( ( ( double )context->duration / ( double )AV_TIME_BASE ) * fps );
-                               mlt_properties_set_position( properties, "out", frames - 1 );
-                               mlt_properties_set_position( properties, "length", frames );
+                               mlt_properties_set_position( properties, "out", frames - 2 );
+                               mlt_properties_set_position( properties, "length", frames - 1 );
                        }
 
                        // Find default audio and video streams
index 4c458d1..3c02842 100644 (file)
@@ -6,11 +6,12 @@ OBJS = factory.o \
           filter_deinterlace.o \
           filter_greyscale.o \
           filter_gamma.o \
+          filter_obscure.o \
           filter_resize.o \
+          filter_volume.o \
           transition_composite.o \
           transition_luma.o \
-          transition_mix.o \
-          filter_volume.o
+          transition_mix.o
 
 CFLAGS = -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
 
index baedbae..e993214 100755 (executable)
@@ -13,6 +13,7 @@ gamma                 libmltcore.so
 greyscale              libmltcore.so
 resize                 libmltcore.so
 volume                 libmltcore.so
+obscure                        libmltcore.so
 EOF
 
 cat << EOF >> ../transitions.dat
index 5353ac2..5a1cc83 100644 (file)
 
 #include "producer_ppm.h"
 #include "filter_deinterlace.h"
+#include "filter_gamma.h"
 #include "filter_greyscale.h"
+#include "filter_obscure.h"
 #include "filter_resize.h"
-#include "filter_gamma.h"
+#include "filter_volume.h"
 #include "transition_composite.h"
 #include "transition_luma.h"
 #include "transition_mix.h"
-#include "filter_volume.h"
 
 void *mlt_create_producer( char *id, void *arg )
 {
@@ -45,6 +46,8 @@ void *mlt_create_filter( char *id, void *arg )
                return filter_gamma_init( arg );
        if ( !strcmp( id, "greyscale" ) )
                return filter_greyscale_init( arg );
+       if ( !strcmp( id, "obscure" ) )
+               return filter_obscure_init( arg );
        if ( !strcmp( id, "resize" ) )
                return filter_resize_init( arg );
        if ( !strcmp( id, "volume" ) )
diff --git a/src/modules/core/filter_obscure.c b/src/modules/core/filter_obscure.c
new file mode 100644 (file)
index 0000000..1867a41
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * filter_obscure.c -- obscure filter
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "filter_obscure.h"
+
+#include <framework/mlt_frame.h>
+#include <framework/mlt_deque.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Geometry struct.
+*/
+
+struct geometry_s
+{
+       float x;
+       float y;
+       float w;
+       float h;
+       int mask_w;
+       int mask_h;
+};
+
+/** Parse a geometry property string.
+*/
+
+static void geometry_parse( struct geometry_s *geometry, struct geometry_s *defaults, char *property )
+{
+       // Assign from defaults if available
+       if ( defaults != NULL )
+       {
+               geometry->x = defaults->x;
+               geometry->y = defaults->y;
+               geometry->w = defaults->w;
+               geometry->h = defaults->h;
+               geometry->mask_w = defaults->mask_w;
+               geometry->mask_h = defaults->mask_h;
+       }
+       else
+       {
+               geometry->mask_w = 20;
+               geometry->mask_h = 20;
+       }
+
+       // Parse the geomtry string
+       if ( property != NULL )
+               sscanf( property, "%f,%f:%fx%f:%dx%d", &geometry->x, &geometry->y, &geometry->w, &geometry->h, &geometry->mask_w, &geometry->mask_h );
+}
+
+/** A Timism but not as clean ;-).
+*/
+
+static float lerp( float value, float lower, float upper )
+{
+       if ( value < lower )
+               return lower;
+       else if ( value > upper )
+               return upper;
+       return value;
+}
+
+/** Calculate real geometry.
+*/
+
+static void geometry_calculate( struct geometry_s *output, struct geometry_s *in, struct geometry_s *out, float position )
+{
+       // Calculate this frames geometry
+       output->x = lerp( in->x + ( out->x - in->x ) * position, 0, 100 );
+       output->y = lerp( in->y + ( out->y - in->y ) * position, 0, 100 );
+       output->w = lerp( in->w + ( out->w - in->w ) * position, 0, 100 - output->x );
+       output->h = lerp( in->h + ( out->h - in->h ) * position, 0, 100 - output->y );
+       output->mask_w = in->mask_w + ( out->mask_w - in->mask_w ) * position;
+       output->mask_h = in->mask_h + ( out->mask_h - in->mask_h ) * position;
+}
+
+/** Calculate the position for this frame.
+*/
+
+static float position_calculate( mlt_filter this, mlt_frame frame )
+{
+       // Get the in and out position
+       mlt_position in = mlt_filter_get_in( this );
+       mlt_position out = mlt_filter_get_out( this );
+
+       // Get the position of the frame
+       mlt_position position = mlt_frame_get_position( frame );
+
+       // Now do the calcs
+       return ( float )( position - in ) / ( float )( out - in + 1 );
+}
+
+/** The averaging function...
+*/
+
+void obscure_average( uint8_t *start, int width, int height, int stride )
+{
+       int y;
+       int x;
+       int Y = ( *start + *( start + 2 ) ) / 2;
+       int U = *( start + 1 );
+       int V = *( start + 3 );
+
+       for ( y = 0; y < height; y ++ )
+       {
+               uint8_t *p = start + y * stride;
+               for ( x = 0; x < width / 2; x ++ )
+               {
+                       Y = ( Y + *p ++ ) / 2;
+                       U = ( U + *p ++ ) / 2;
+                       Y = ( Y + *p ++ ) / 2;
+                       V = ( V + *p ++ ) / 2;
+               }
+       }
+
+       for ( y = 0; y < height; y ++ )
+       {
+               uint8_t *p = start + y * stride;
+               for ( x = 0; x < width / 2; x ++ )
+               {
+                       *p ++ = Y;
+                       *p ++ = U;
+                       *p ++ = Y;
+                       *p ++ = V;
+               }
+       }
+}
+
+
+/** The obscurer rendering function...
+*/
+
+static void obscure_render( uint8_t *image, int width, int height, struct geometry_s result )
+{
+       int area_x = ( result.x / 100 ) * width;
+       int area_y = ( result.y / 100 ) * height;
+       int area_w = ( result.w / 100 ) * width;
+       int area_h = ( result.h / 100 ) * height;
+
+       int mw = result.mask_w;
+       int mh = result.mask_h;
+       int w;
+       int h;
+
+       uint8_t *p = image + area_y * width * 2 + area_x * 2;
+
+       for ( w = 0; w < area_w; w += mw )
+       {
+               for ( h = 0; h < area_h; h += mh )
+               {
+                       int aw = w + mw > area_w ? mw - ( w + mw - area_w ) : mw;
+                       int ah = h + mh > area_h ? mh - ( h + mh - area_h ) : mh;
+                       if ( aw > 1 && ah > 1 );
+                               obscure_average( p + h * width * 2 + w * 2, aw, ah, width * 2 );
+               }
+       }
+}
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+       // Get the frame properties
+       mlt_properties frame_properties = mlt_frame_properties( frame );
+
+       // Fetch the obscure stack for this frame
+       mlt_deque deque = mlt_properties_get_data( frame_properties, "filter_obscure", NULL );
+
+       // Pop the top of stack now
+       mlt_filter this = mlt_deque_pop_back( deque );
+
+       // Get the image from the frame
+       if ( mlt_frame_get_image( frame, image, format, width, height, 1 ) == 0 )
+       {
+               if ( this != NULL )
+               {
+                       // Get the filter properties
+                       mlt_properties properties = mlt_filter_properties( this );
+
+                       // Structures for geometry
+                       struct geometry_s result;
+                       struct geometry_s start;
+                       struct geometry_s end;
+
+                       // Calculate the position
+                       float position = position_calculate( this, frame );
+
+                       // Now parse the geometries
+                       geometry_parse( &start, NULL, mlt_properties_get( properties, "start" ) );
+                       geometry_parse( &end, &start, mlt_properties_get( properties, "end" ) );
+
+                       // Do the calculation
+                       geometry_calculate( &result, &start, &end, position );
+
+                       // Now actually render it
+                       obscure_render( *image, *width, *height, result );
+               }
+       }
+
+       return 0;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+       // Get the frame properties
+       mlt_properties frame_properties = mlt_frame_properties( frame );
+
+       // Fetch the obscure stack for this frame
+       mlt_deque deque = mlt_properties_get_data( frame_properties, "filter_obscure", NULL );
+
+       // Create stack if necessary
+       if ( deque == NULL )
+       {
+               // Create the deque
+               deque = mlt_deque_init( );
+
+               // Assign to the frame
+               mlt_properties_set_data( frame_properties, "filter_obscure", deque, 0, ( mlt_destructor )mlt_deque_close, NULL );
+       }
+
+       // Push this on to the obscure stack
+       mlt_deque_push_back( deque, this );
+       
+       // Push the get image call
+       mlt_frame_push_get_image( frame, filter_get_image );
+
+       return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_obscure_init( void *arg )
+{
+       mlt_filter this = calloc( 1, sizeof( struct mlt_filter_s ) );
+       mlt_properties properties = mlt_filter_properties( this );
+       mlt_filter_init( this, NULL );
+       this->process = filter_process;
+       mlt_properties_set( properties, "start", "40,40:20x20" );
+       mlt_properties_set( properties, "end", "" );
+       return this;
+}
+
diff --git a/src/modules/core/filter_obscure.h b/src/modules/core/filter_obscure.h
new file mode 100644 (file)
index 0000000..ec21dcf
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * filter_obscure.h -- obscure filter
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _FILTER_OBSCURE_H_
+#define _FILTER_OBSCURE_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_obscure_init( void *arg );
+
+#endif
index c52ae1d..527e49c 100644 (file)
@@ -1,5 +1,5 @@
 
-TARGET = ../libinigo.so
+TARGET = ../libmltinigo.so
 
 OBJS = factory.o \
           producer_inigo.o 
index 617ee0a..1e75d7c 100755 (executable)
@@ -4,7 +4,7 @@ if [ "$help" != "1" ]
 then
 
 cat << EOF >> ../producers.dat
-inigo                  libinigo.so
+inigo                  libmltinigo.so
 EOF
 
 fi
index 313e8d5..1b82b94 100644 (file)
@@ -48,9 +48,7 @@ static mlt_producer parse_inigo( char *file )
        if ( result != NULL )
        {
                mlt_properties properties = mlt_producer_properties( result );
-               fprintf( stderr, "resource = %s\n", mlt_properties_get( properties, "resource" ) );
                mlt_properties_set( properties, "resource", file );
-               fprintf( stderr, "resource = %s\n", mlt_properties_get( properties, "resource" ) );
        }
 
        while( count -- )
@@ -248,9 +246,9 @@ mlt_producer producer_inigo_init( char **argv )
        mlt_tractor tractor = mlt_field_tractor( field );
        mlt_producer prod = mlt_tractor_producer( tractor );
        mlt_properties props = mlt_tractor_properties( tractor );
-       mlt_properties_set_data( props, "multitrack", multitrack, 0, NULL, NULL );
-       mlt_properties_set_data( props, "field", field, 0, NULL, NULL );
-       mlt_properties_set_data( props, "group", group, 0, NULL, NULL );
+       mlt_properties_set_data( props, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
+       mlt_properties_set_data( props, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
+       mlt_properties_set_data( props, "group", group, 0, ( mlt_destructor )mlt_properties_close, NULL );
        mlt_properties_set_position( props, "length", mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) + 1 );
        mlt_producer_set_in_and_out( prod, 0, mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) );
        mlt_properties_set_double( props, "fps", mlt_producer_get_fps( mlt_multitrack_producer( multitrack ) ) );
index 6e28934..fd8f129 100644 (file)
@@ -6,7 +6,7 @@ OBJS = factory.o \
 
 CFLAGS = -I../../ -Wall -g -D_FILE_OFFSET_BITS=64
 
-LDFLAGS = -lvorbis -lvorbisfile
+LDFLAGS = -lvorbisfile -lvorbis
 
 SRCS := $(OBJS:.o=.c)