composite aspect ratio fix (again ;-)), added fill compositing test case, filter...
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 26 Feb 2004 13:09:28 +0000 (13:09 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 26 Feb 2004 13:09:28 +0000 (13:09 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@170 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_properties.c
src/framework/mlt_properties.h
src/modules/avformat/producer_avformat.c
src/modules/core/Makefile
src/modules/core/configure
src/modules/core/factory.c
src/modules/core/filter_luma.c [new file with mode: 0644]
src/modules/core/filter_luma.h [new file with mode: 0644]
src/modules/core/filter_watermark.c
src/modules/core/transition_composite.c
src/modules/core/transition_luma.c

index d830e44..a774ca1 100644 (file)
@@ -105,18 +105,40 @@ void mlt_properties_mirror( mlt_properties this, mlt_properties that )
 int mlt_properties_inherit( mlt_properties this, mlt_properties that )
 {
        int count = mlt_properties_count( that );
-       while ( count -- )
+       int i = 0;
+       for ( i = 0; i < count; i ++ )
        {
-               char *value = mlt_properties_get_value( that, count );
+               char *value = mlt_properties_get_value( that, i );
                if ( value != NULL )
                {
-                       char *name = mlt_properties_get_name( that, count );
+                       char *name = mlt_properties_get_name( that, i );
                        mlt_properties_set( this, name, value );
                }
        }
        return 0;
 }
 
+/** Pass all properties from 'that' that match the prefix to 'this' (excluding the prefix).
+*/
+
+int mlt_properties_pass( mlt_properties this, mlt_properties that, char *prefix )
+{
+       int count = mlt_properties_count( that );
+       int length = strlen( prefix );
+       int i = 0;
+       for ( i = 0; i < count; i ++ )
+       {
+               char *name = mlt_properties_get_name( that, i );
+               if ( !strncmp( name, prefix, length ) )
+               {
+                       char *value = mlt_properties_get_value( that, i );
+                       if ( value != NULL )
+                               mlt_properties_set( this, name + length, value );
+               }
+       }
+       return 0;
+}
+
 /** Locate a property by name
 */
 
index e6e956b..df66146 100644 (file)
@@ -41,6 +41,7 @@ extern int mlt_properties_init( mlt_properties, void *child );
 extern mlt_properties mlt_properties_new( );
 extern void mlt_properties_mirror( mlt_properties this, mlt_properties that );
 extern int mlt_properties_inherit( mlt_properties this, mlt_properties that );
+extern int mlt_properties_pass( mlt_properties this, mlt_properties that, char *prefix );
 extern int mlt_properties_set( mlt_properties this, char *name, char *value );
 extern int mlt_properties_parse( mlt_properties this, char *namevalue );
 extern char *mlt_properties_get( mlt_properties this, char *name );
index 67a66df..78aeb51 100644 (file)
@@ -583,9 +583,6 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame )
 
                                // Now store the codec with its destructor
                                mlt_properties_set_data( properties, "video_codec", codec_context, 0, producer_codec_close, NULL );
-
-                               // Set to the real timecode
-                               av_seek_frame( context, -1, 0 );
                        }
                        else
                        {
index 41f7b34..2fdb469 100644 (file)
@@ -7,6 +7,7 @@ OBJS = factory.o \
           filter_deinterlace.o \
           filter_greyscale.o \
           filter_gamma.o \
+          filter_luma.o \
           filter_obscure.o \
           filter_resize.o \
           filter_volume.o \
index dec3e77..66dcf3e 100755 (executable)
@@ -12,6 +12,7 @@ brightness            libmltcore.so
 deinterlace            libmltcore.so
 gamma                  libmltcore.so
 greyscale              libmltcore.so
+luma                   libmltcore.so
 obscure                        libmltcore.so
 resize                 libmltcore.so
 volume                 libmltcore.so
index 650cca8..d29ac3a 100644 (file)
@@ -24,6 +24,7 @@
 #include "filter_brightness.h"
 #include "filter_deinterlace.h"
 #include "filter_gamma.h"
+#include "filter_luma.h"
 #include "filter_greyscale.h"
 #include "filter_obscure.h"
 #include "filter_resize.h"
@@ -50,6 +51,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, "luma" ) )
+               return filter_luma_init( arg );
        if ( !strcmp( id, "obscure" ) )
                return filter_obscure_init( arg );
        if ( !strcmp( id, "resize" ) )
diff --git a/src/modules/core/filter_luma.c b/src/modules/core/filter_luma.c
new file mode 100644 (file)
index 0000000..b1b27d6
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * filter_luma.c -- luma 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_luma.h"
+
+#include <framework/mlt_factory.h>
+#include <framework/mlt_frame.h>
+#include <framework/mlt_producer.h>
+#include <framework/mlt_transition.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+       int error = 0;
+       mlt_filter filter = mlt_frame_pop_service( this );
+       mlt_properties properties = mlt_filter_properties( filter );
+       mlt_transition luma = mlt_properties_get_data( properties, "luma", NULL );
+       mlt_frame b_frame = mlt_properties_get_data( properties, "frame", NULL );
+       int out = 24;
+
+       if ( luma == NULL )
+       {
+               char *resource = mlt_properties_get( properties, "resource" );
+               luma = mlt_factory_transition( "luma", resource );
+               if ( luma != NULL )
+               {
+                       mlt_properties luma_properties = mlt_transition_properties( luma );
+                       mlt_properties_set_int( luma_properties, "in", 0 );
+                       mlt_properties_set_int( luma_properties, "out", out );
+                       mlt_properties_set_int( luma_properties, "reverse", 1 );
+                       mlt_properties_pass( luma_properties, properties, "luma." );
+                       mlt_properties_set_data( properties, "luma", luma, 0, ( mlt_destructor )mlt_transition_close, NULL );
+                       out = mlt_properties_get_int( luma_properties, "out" );
+               }
+       }
+
+       if ( b_frame == NULL )
+       {
+               b_frame = mlt_frame_init( );
+               mlt_properties_set_data( properties, "frame", b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
+       }
+
+       if ( luma != NULL && 
+               ( mlt_properties_get( properties, "blur" ) != NULL || 
+                 mlt_frame_get_position( this ) % ( out + 1 ) != out ) )
+               mlt_transition_process( luma, this, b_frame );
+
+       error = mlt_frame_get_image( this, image, format, width, height, 1 );
+
+       if ( error == 0 )
+       {
+               mlt_properties a_props = mlt_frame_properties( this );
+               int size = 0;
+               uint8_t *src = mlt_properties_get_data( a_props, "image", &size );
+               uint8_t *dst = mlt_pool_alloc( size );
+
+               if ( dst != NULL )
+               {
+                       mlt_properties b_props = mlt_frame_properties( b_frame );
+                       memcpy( dst, src, size );
+                       mlt_properties_set_data( b_props, "image", dst, size, mlt_pool_release, NULL );
+                       mlt_properties_set_int( b_props, "width", *width );
+                       mlt_properties_set_int( b_props, "height", *height );
+               }
+       }
+
+       return error;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+       // Push the filter on to the stack
+       mlt_frame_push_service( frame, this );
+
+       // Push the get_image on to the stack
+       mlt_frame_push_get_image( frame, filter_get_image );
+
+       return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_luma_init( void *arg )
+{
+       mlt_filter this = mlt_filter_new( );
+       if ( this != NULL )
+       {
+               mlt_properties properties = mlt_filter_properties( this );
+               this->process = filter_process;
+               if ( arg != NULL )
+                       mlt_properties_set( properties, "resource", arg );
+       }
+       return this;
+}
+
diff --git a/src/modules/core/filter_luma.h b/src/modules/core/filter_luma.h
new file mode 100644 (file)
index 0000000..4862d68
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * filter_luma.h -- luma 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_LUMA_H_
+#define _FILTER_LUMA_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_luma_init( void *arg );
+
+#endif
index a22bac3..1b343c3 100644 (file)
@@ -41,14 +41,11 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        if ( composite == NULL )
        {
-               char *geometry = mlt_properties_get( properties, "geometry" );
-               composite = mlt_factory_transition( "composite", geometry == NULL ? "85%,5%:10%x10%" : geometry );
+               composite = mlt_factory_transition( "composite", NULL );
                if ( composite != NULL )
                {
                        mlt_properties composite_properties = mlt_transition_properties( composite );
-                       char *distort = mlt_properties_get( properties, "distort" );
-                       if ( distort != NULL )
-                               mlt_properties_set( composite_properties, "distort", distort );
+                       mlt_properties_pass( composite_properties, properties, "composite." );
                        mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL );
                }
        }
@@ -62,6 +59,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                {
                        mlt_properties producer_properties = mlt_producer_properties( producer );
                        mlt_properties_set( producer_properties, "eof", "loop" );
+                       mlt_properties_pass( producer_properties, properties, "producer." );
                        mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
                }
        }
index 4bd3d41..3ea3ec0 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <math.h>
 
 /** Geometry struct.
 */
@@ -125,6 +126,14 @@ static void geometry_calculate( struct geometry_s *output, struct geometry_s *in
        // Search in for position
        struct geometry_s *out = in->next;
 
+       if ( position >= 1.0 )
+       {
+               int section = floor( position );
+               position -= section;
+               if ( section % 2 == 1 )
+                       position = 1.0 - position;
+       }
+
        while ( out->next != NULL )
        {
                if ( position >= in->position && position < out->position )
@@ -144,9 +153,106 @@ static void geometry_calculate( struct geometry_s *output, struct geometry_s *in
        output->w = in->w + ( out->w - in->w ) * position;
        output->h = in->h + ( out->h - in->h ) * position;
        output->mix = in->mix + ( out->mix - in->mix ) * position;
+       output->sw = output->w;
+       output->sh = output->h;
        output->distort = in->distort;
 }
 
+void transition_destroy_keys( void *arg )
+{
+       struct geometry_s *ptr = arg;
+       struct geometry_s *next = NULL;
+
+       while ( ptr != NULL )
+       {
+               next = ptr->next;
+               free( ptr );
+               ptr = next;
+       }
+}
+
+static struct geometry_s *transition_parse_keys( mlt_transition this,  int normalised_width, int normalised_height )
+{
+       // Loop variable for property interrogation
+       int i = 0;
+
+       // Get the properties of the transition
+       mlt_properties properties = mlt_transition_properties( this );
+
+       // Get the in and out position
+       mlt_position in = mlt_transition_get_in( this );
+       mlt_position out = mlt_transition_get_out( this );
+
+       // Create the start
+       struct geometry_s *start = calloc( 1, sizeof( struct geometry_s ) );
+
+       // Create the end (we always need two entries)
+       struct geometry_s *end = calloc( 1, sizeof( struct geometry_s ) );
+
+       // Pointer
+       struct geometry_s *ptr = start;
+
+       // Parse the start property
+       geometry_parse( start, NULL, mlt_properties_get( properties, "start" ), normalised_width, normalised_height );
+
+       // Parse the keys in between
+       for ( i = 0; i < mlt_properties_count( properties ); i ++ )
+       {
+               // Get the name of the property
+               char *name = mlt_properties_get_name( properties, i );
+
+               // Check that it's valid
+               if ( !strncmp( name, "key[", 4 ) )
+               {
+                       // Get the value of the property
+                       char *value = mlt_properties_get_value( properties, i );
+
+                       // Determine the frame number
+                       int frame = atoi( name + 4 );
+
+                       // Determine the position
+                       float position = 0;
+                       
+                       if ( frame >= 0 && frame < ( out - in ) )
+                               position = ( float )frame / ( float )( out - in + 1 );
+                       else if ( frame < 0 && - frame < ( out - in ) )
+                               position = ( float )( out - in + frame ) / ( float )( out - in + 1 );
+
+                       // For now, we'll exclude all keys received out of order
+                       if ( position > ptr->position )
+                       {
+                               // Create a new geometry
+                               struct geometry_s *temp = calloc( 1, sizeof( struct geometry_s ) );
+
+                               // Parse and add to the list
+                               geometry_parse( temp, ptr, value, normalised_width, normalised_height );
+
+                               // Assign the position
+                               temp->position = position;
+
+                               // Allow the next to be appended after this one
+                               ptr = temp;
+                       }
+                       else
+                       {
+                               fprintf( stderr, "Key out of order - skipping %s\n", name );
+                       }
+               }
+       }
+       
+       // Parse the end
+       geometry_parse( end, ptr, mlt_properties_get( properties, "end" ), normalised_width, normalised_height );
+       if ( out > 0 )
+               end->position = ( float )( out - in ) / ( float )( out - in + 1 );
+       else
+               end->position = 1;
+
+       // Assign to properties to ensure we get destroyed
+       mlt_properties_set_data( properties, "geometries", start, 0, transition_destroy_keys, NULL );
+
+       return start;
+}
+
 /** Parse the alignment properties into the geometry.
 */
 
@@ -344,11 +450,7 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
        int ret = 0;
        mlt_image_format format = mlt_image_yuv422;
 
-       // Initialise the scaled dimensions from the computed
-       geometry->sw = geometry->w;
-       geometry->sh = geometry->h;
-
-       // Compute the dimensioning rectangle
+       // Get the properties objects
        mlt_properties b_props = mlt_frame_properties( b_frame );
        mlt_properties properties = mlt_transition_properties( this );
 
@@ -359,9 +461,16 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
                int normalised_height = geometry->h;
                int real_width = get_value( b_props, "real_width", "width" );
                int real_height = get_value( b_props, "real_height", "height" );
+               double input_ar = mlt_frame_get_aspect_ratio( b_frame );
+               double output_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" );
                int scaled_width = real_width;
                int scaled_height = real_height;
+               double output_sar = ( double ) geometry->nw / geometry->nh / output_ar;
 
+               // If the output is fat pixels (NTSC) then stretch our input horizontally
+               // derived from: output_sar / input_sar * real_width
+               scaled_width = output_sar * real_height * input_ar;
+                       
                // Now ensure that our images fit in the normalised frame
                if ( scaled_width > normalised_width )
                {
@@ -374,13 +483,17 @@ static int get_b_frame_image( mlt_transition this, mlt_frame b_frame, uint8_t **
                        scaled_height = normalised_height;
                }
 
-               // Now we need to align to the geometry
-               if ( scaled_width <= geometry->w && scaled_height <= geometry->h )
+               // Now apply the fill
+               // TODO: Should combine fill/distort in one property
+               if ( mlt_properties_get( properties, "fill" ) != NULL )
                {
-                       // Save the new scaled dimensions
-                       geometry->sw = scaled_width;
-                       geometry->sh = scaled_height;
+                       scaled_width = ( geometry->w / scaled_width ) * scaled_width;
+                       scaled_height = ( geometry->h / scaled_height ) * scaled_height;
                }
+
+               // Save the new scaled dimensions
+               geometry->sw = scaled_width;
+               geometry->sh = scaled_height;
        }
 
        // We want to ensure that we bypass resize now...
@@ -419,98 +532,6 @@ static uint8_t *transition_get_alpha_mask( mlt_frame this )
        return mlt_properties_get_data( properties, "alpha", NULL );
 }
 
-void transition_destroy_keys( void *arg )
-{
-       struct geometry_s *ptr = arg;
-       struct geometry_s *next = NULL;
-
-       while ( ptr != NULL )
-       {
-               next = ptr->next;
-               free( ptr );
-               ptr = next;
-       }
-}
-
-static struct geometry_s *transition_parse_keys( mlt_transition this,  int normalised_width, int normalised_height )
-{
-       // Loop variable for property interrogation
-       int i = 0;
-
-       // Get the properties of the transition
-       mlt_properties properties = mlt_transition_properties( this );
-
-       // Get the in and out position
-       mlt_position in = mlt_transition_get_in( this );
-       mlt_position out = mlt_transition_get_out( this );
-
-       // Create the start
-       struct geometry_s *start = calloc( 1, sizeof( struct geometry_s ) );
-
-       // Create the end (we always need two entries)
-       struct geometry_s *end = calloc( 1, sizeof( struct geometry_s ) );
-
-       // Pointer
-       struct geometry_s *ptr = start;
-
-       // Parse the start property
-       geometry_parse( start, NULL, mlt_properties_get( properties, "start" ), normalised_width, normalised_height );
-
-       // Parse the keys in between
-       for ( i = 0; i < mlt_properties_count( properties ); i ++ )
-       {
-               // Get the name of the property
-               char *name = mlt_properties_get_name( properties, i );
-
-               // Check that it's valid
-               if ( !strncmp( name, "key[", 4 ) )
-               {
-                       // Get the value of the property
-                       char *value = mlt_properties_get_value( properties, i );
-
-                       // Determine the frame number
-                       int frame = atoi( name + 4 );
-
-                       // Determine the position
-                       float position = 0;
-                       
-                       if ( frame >= 0 && frame < ( out - in ) )
-                               position = ( float )frame / ( float )( out - in + 1 );
-                       else if ( frame < 0 && - frame < ( out - in ) )
-                               position = ( float )( out - in + frame ) / ( float )( out - in + 1 );
-
-                       // For now, we'll exclude all keys received out of order
-                       if ( position > ptr->position )
-                       {
-                               // Create a new geometry
-                               struct geometry_s *temp = calloc( 1, sizeof( struct geometry_s ) );
-
-                               // Parse and add to the list
-                               geometry_parse( temp, ptr, value, normalised_width, normalised_height );
-
-                               // Assign the position
-                               temp->position = position;
-
-                               // Allow the next to be appended after this one
-                               ptr = temp;
-                       }
-                       else
-                       {
-                               fprintf( stderr, "Key out of order - skipping %s\n", name );
-                       }
-               }
-       }
-       
-       // Parse the end
-       geometry_parse( end, ptr, mlt_properties_get( properties, "end" ), normalised_width, normalised_height );
-       end->position = ( float )( out - in ) / ( float )( out - in + 1 );
-
-       // Assign to properties to ensure we get destroyed
-       mlt_properties_set_data( properties, "geometries", start, 0, transition_destroy_keys, NULL );
-
-       return start;
-}
-
 /** Get the image.
 */
 
@@ -571,7 +592,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                result.valign = alignment_parse( mlt_properties_get( properties, "valign" ) );
 
                // Get the image from the b frame
-               uint8_t *image_b;
+               uint8_t *image_b = NULL;
                int width_b = *width;
                int height_b = *height;
                
index 6e58f26..bb44d29 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <math.h>
 
 /** Luma class.
 */
@@ -240,8 +241,11 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        // consumer property from the a_frame
        mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
        mlt_properties_set_double( b_props, "consumer_scale", mlt_properties_get_double( a_props, "consumer_scale" ) );
-               
+
        // Honour the reverse here
+       if ( mix >= 1.0 )
+               mix -= floor( mix );
+
        mix = reverse ? 1 - mix : mix;
        frame_delta *= reverse ? -1.0 : 1.0;
 
@@ -379,8 +383,8 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram
        }
 
        // Set the b frame properties
-       mlt_properties_set_double( b_props, "image.mix", position_calculate( transition, b_frame ) );
-       mlt_properties_set_double( b_props, "luma.delta", delta_calculate( transition, b_frame ) );
+       mlt_properties_set_double( b_props, "image.mix", position_calculate( transition, a_frame ) );
+       mlt_properties_set_double( b_props, "luma.delta", delta_calculate( transition, a_frame ) );
        mlt_properties_set_int( b_props, "luma.width", this->width );
        mlt_properties_set_int( b_props, "luma.height", this->height );
        mlt_properties_set_data( b_props, "luma.bitmap", this->bitmap, 0, NULL, NULL );