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
*/
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 );
// 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
{
filter_deinterlace.o \
filter_greyscale.o \
filter_gamma.o \
+ filter_luma.o \
filter_obscure.o \
filter_resize.o \
filter_volume.o \
deinterlace libmltcore.so
gamma libmltcore.so
greyscale libmltcore.so
+luma libmltcore.so
obscure libmltcore.so
resize libmltcore.so
volume libmltcore.so
#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"
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" ) )
--- /dev/null
+/*
+ * 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;
+}
+
--- /dev/null
+/*
+ * 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
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 );
}
}
{
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 );
}
}
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
+#include <math.h>
/** Geometry struct.
*/
// 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 )
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.
*/
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 );
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 )
{
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...
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.
*/
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;
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
+#include <math.h>
/** Luma class.
*/
// 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;
}
// 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 );