filter_gamma.o \
filter_luma.o \
filter_obscure.o \
+ filter_region.o \
filter_resize.o \
filter_volume.o \
filter_watermark.o \
greyscale libmltcore.so
luma libmltcore.so
obscure libmltcore.so
+region libmltcore.so
resize libmltcore.so
volume libmltcore.so
watermark libmltcore.so
#include "filter_greyscale.h"
#include "filter_obscure.h"
#include "filter_resize.h"
+#include "filter_region.h"
#include "filter_volume.h"
#include "filter_watermark.h"
#include "transition_composite.h"
return filter_luma_init( arg );
if ( !strcmp( id, "obscure" ) )
return filter_obscure_init( arg );
+ if ( !strcmp( id, "region" ) )
+ return filter_region_init( arg );
if ( !strcmp( id, "resize" ) )
return filter_resize_init( arg );
if ( !strcmp( id, "volume" ) )
--- /dev/null
+/*
+ * filter_region.c -- region 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_region.h"
+#include "transition_composite.h"
+
+#include <framework/mlt.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int create_instance( mlt_filter this, char *name, char *value, int count )
+{
+ // Return from this function
+ int error = 0;
+
+ // Duplicate the value
+ char *type = strdup( value );
+
+ // Pointer to filter argument
+ char *arg = type == NULL ? NULL : strchr( type, ':' );
+
+ // New filter being created
+ mlt_filter filter = NULL;
+
+ // Cleanup type and arg
+ if ( arg != NULL )
+ *arg ++ = '\0';
+
+ // Create the filter
+ filter = mlt_factory_filter( type, arg );
+
+ // If we have a filter, then initialise and store it
+ if ( filter != NULL )
+ {
+ // Properties of this
+ mlt_properties properties = mlt_filter_properties( this );
+
+ // String to hold the property name
+ char id[ 256 ];
+
+ // String to hold the passdown key
+ char key[ 256 ];
+
+ // Construct id
+ sprintf( id, "_filter_%d", count );
+
+ // Counstruct key
+ sprintf( key, "%s.", name );
+
+ // Pass all the key properties on the filter down
+ mlt_properties_pass( mlt_filter_properties( filter ), properties, key );
+
+ // Ensure that filter is assigned
+ mlt_properties_set_data( properties, id, filter, 0, ( mlt_destructor )mlt_filter_close, NULL );
+ }
+ else
+ {
+ // Indicate that an error has occurred
+ error = 1;
+ }
+
+ // Cleanup
+ free( type );
+
+ // Return error condition
+ return error;
+}
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ // Error we will return
+ int error = 0;
+
+ // Get the watermark filter object
+ mlt_filter this = mlt_frame_pop_service( frame );
+
+ // Get the properties of the filter
+ mlt_properties properties = mlt_filter_properties( this );
+
+ // Get the composite from the filter
+ mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL );
+
+ // Look for the first filter
+ mlt_filter filter = mlt_properties_get_data( properties, "_filter_0", NULL );
+
+ // Create a composite if we don't have one
+ if ( composite == NULL )
+ {
+ // Create composite via the factory
+ composite = mlt_factory_transition( "composite", NULL );
+
+ // If we have one
+ if ( composite != NULL )
+ {
+ // Get the properties
+ mlt_properties composite_properties = mlt_transition_properties( composite );
+
+ // We want to ensure that we don't get a wobble...
+ mlt_properties_set( composite_properties, "distort", "true" );
+ mlt_properties_set( composite_properties, "progressive", "1" );
+
+ // Pass all the composite. properties on the filter down
+ mlt_properties_pass( composite_properties, properties, "composite." );
+
+ // Register the composite for reuse/destruction
+ mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL );
+ }
+ }
+
+ // Create filters
+ if ( filter == NULL )
+ {
+ // Loop Variable
+ int i = 0;
+
+ // Number of filters created
+ int count = 0;
+
+ // Loop for all properties
+ for ( i = 0; i < mlt_properties_count( properties ); i ++ )
+ {
+ // Get the name of this property
+ char *name = mlt_properties_get_name( properties, i );
+
+ // If the name does not contain a . and matches filter
+ if ( strchr( name, '.' ) == NULL && !strncmp( name, "filter", 6 ) )
+ {
+ // Get the filter constructor
+ char *value = mlt_properties_get_value( properties, i );
+
+ // Create an instance
+ if ( create_instance( this, name, value, count ) == 0 )
+ count ++;
+ }
+ }
+ }
+
+ // Get the image
+ error = mlt_frame_get_image( frame, image, format, width, height, 1 );
+
+ // Only continue if we have both filter and composite
+ if ( composite != NULL && filter != NULL )
+ {
+ // String to hold the filter to query on
+ char id[ 256 ];
+
+ // Index to hold the count
+ int i = 0;
+
+ // We will get the 'b frame' from the composite
+ mlt_frame b_frame = composite_copy_region( composite, frame );
+
+ // Make sure the filter is in the correct position
+ while ( filter != NULL )
+ {
+ // Stack this filter
+ mlt_filter_process( filter, b_frame );
+
+ // Generate the key for the next
+ sprintf( id, "_filter_%d", ++ i );
+
+ // Get the next filter
+ filter = mlt_properties_get_data( properties, id, NULL );
+ }
+
+ // Get the b frame and process with composite if successful
+ mlt_transition_process( composite, frame, b_frame );
+
+ // Get the image
+ error = mlt_frame_get_image( frame, image, format, width, height, 0 );
+
+ // Close the b frame
+ mlt_frame_close( b_frame );
+ }
+
+ return error;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+ // Push the filter on to the frame
+ mlt_frame_push_service( frame, this );
+
+ // Push the filter method
+ mlt_frame_push_get_image( frame, filter_get_image );
+
+ // Return the frame
+ return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_region_init( void *arg )
+{
+ // Create a new filter
+ mlt_filter this = mlt_filter_new( );
+
+ // Further initialisation
+ if ( this != NULL )
+ {
+ // Get the properties from the filter
+ mlt_properties properties = mlt_filter_properties( this );
+
+ // Assign the filter process method
+ this->process = filter_process;
+
+ // Resource defines the shape of the region
+ mlt_properties_set( properties, "resource", arg == NULL ? "rectangle" : arg );
+ }
+
+ // Return the filter
+ return this;
+}
+
--- /dev/null
+/*
+ * filter_region.h -- region 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_REGION_H_
+#define _FILTER_REGION_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_region_init( void *arg );
+
+#endif
/** Do it :-).
*/
-static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
{
+ // Error we will return
int error = 0;
- mlt_filter filter = mlt_frame_pop_service( this );
- mlt_properties properties = mlt_filter_properties( filter );
+
+ // Get the watermark filter object
+ mlt_filter this = mlt_frame_pop_service( frame );
+
+ // Get the properties of the filter
+ mlt_properties properties = mlt_filter_properties( this );
+
+ // Get the producer from the filter
mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
+
+ // Get the composite from the filter
mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL );
- char *name = mlt_properties_get( properties, "_unique_id" );
+ // Create a composite if we don't have one
if ( composite == NULL )
{
+ // Create composite via the factory
composite = mlt_factory_transition( "composite", NULL );
+
+ // If we have one
if ( composite != NULL )
{
+ // Get the properties
mlt_properties composite_properties = mlt_transition_properties( composite );
+
+ // Pass all the composite. properties on the filter down
mlt_properties_pass( composite_properties, properties, "composite." );
+
+ // Register the composite for reuse/destruction
mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL );
}
}
+ // Create a producer if don't have one
if ( producer == NULL )
{
+ // Get the resource to use
char *resource = mlt_properties_get( properties, "resource" );
+
+ // Get the factory producer service
char *factory = mlt_properties_get( properties, "factory" );
+
+ // Create the producer
producer = mlt_factory_producer( factory, resource );
+
+ // If we have one
if ( producer != NULL )
{
+ // Get the producer properties
mlt_properties producer_properties = mlt_producer_properties( producer );
+
+ // Ensure that we loop
mlt_properties_set( producer_properties, "eof", "loop" );
+
+ // Now pass all producer. properties on the filter down
mlt_properties_pass( producer_properties, properties, "producer." );
+
+ // Register the producer for reuse/destruction
mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
}
}
+ // Only continue if we have both producer and composite
if ( composite != NULL && producer != NULL )
{
+ // Get the service of the producer
mlt_service service = mlt_producer_service( producer );
+
+ // We will get the 'b frame' from the producer
mlt_frame b_frame = NULL;
- mlt_properties frame_properties = mlt_frame_properties( this );
- mlt_position position = mlt_properties_get_position( frame_properties, name );
+ // Get the unique id of the filter (used to reacquire the producer position)
+ char *name = mlt_properties_get( properties, "_unique_id" );
+
+ // Get the original producer position
+ mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
+
+ // Make sure the producer is in the correct position
mlt_producer_seek( producer, position );
+
+ // Get the b frame and process with composite if successful
if ( mlt_service_get_frame( service, &b_frame, 0 ) == 0 )
- mlt_transition_process( composite, this, b_frame );
+ mlt_transition_process( composite, frame, b_frame );
- error = mlt_frame_get_image( this, image, format, width, height, 1 );
+ // Get the image
+ error = mlt_frame_get_image( frame, image, format, width, height, 1 );
+ // Close the b frame
mlt_frame_close( b_frame );
}
else
{
- error = mlt_frame_get_image( this, image, format, width, height, 1 );
+ // Get the image from the frame without running fx
+ error = mlt_frame_get_image( frame, image, format, width, height, 1 );
}
return error;
// Calculate this frames geometry
output->nw = in->nw;
output->nh = in->nh;
- output->x = in->x + ( out->x - in->x ) * position + 0.5;
- output->y = in->y + ( out->y - in->y ) * position + 0.5;
+ output->x = in->x + ( out->x - in->x ) * position;
+ output->y = in->y + ( out->y - in->y ) * position;
output->w = in->w + ( out->w - in->w ) * position;
output->h = in->h + ( out->h - in->h ) * position;
+ output->sw = output->w;
+ output->sh = output->h;
output->mix = in->mix + ( out->mix - in->mix ) * position;
output->distort = in->distort;
+
+ output->x = ( int )floor( output->x ) & 0xfffffffe;
+ output->w = ( int )floor( output->w ) & 0xfffffffe;
+ output->sw &= 0xfffffffe;
}
void transition_destroy_keys( void *arg )
static void alignment_calculate( struct geometry_s *geometry )
{
- geometry->x += ( geometry->w - geometry->sw ) * geometry->halign / 2 + 0.5;
- geometry->y += ( geometry->h - geometry->sh ) * geometry->valign / 2 + 0.5;
+ geometry->x += ( geometry->w - geometry->sw ) * geometry->halign / 2;
+ geometry->y += ( geometry->h - geometry->sh ) * geometry->valign / 2;
}
/** Calculate the position for this frame.
*/
-static inline float position_calculate( mlt_transition this, mlt_frame frame )
+static float position_calculate( mlt_transition this, mlt_frame frame )
{
// Get the in and out position
mlt_position in = mlt_transition_get_in( this );
int stride_dest = width_dest * bpp;
// Adjust to consumer scale
- int x = geometry.x * width_dest / geometry.nw + 0.5;
- int y = geometry.y * height_dest / geometry.nh + 0.5;
+ int x = geometry.x * width_dest / geometry.nw;
+ int y = geometry.y * height_dest / geometry.nh;
+
+ x &= 0xfffffffe;
+ width_src &= 0xfffffffe;
- if ( bpp == 2 )
- x -= x % 2;
-
// optimization points - no work to do
if ( width_src <= 0 || height_src <= 0 )
return ret;
mlt_properties b_props = mlt_frame_properties( b_frame );
mlt_properties properties = mlt_transition_properties( this );
- // ???: Not getting the logic of this...
- geometry->sw = geometry->w;
- geometry->sh = geometry->h;
-
if ( mlt_properties_get( properties, "distort" ) == NULL && geometry->distort == 0 )
{
// Adjust b_frame pixel aspect
alignment_calculate( geometry );
// Adjust to consumer scale
- int x = geometry->x * *width / geometry->nw + 0.5;
- int y = geometry->y * *height / geometry->nh + 0.5;
+ int x = geometry->x * *width / geometry->nw;
+ int y = geometry->y * *height / geometry->nh;
*width = geometry->sw * *width / geometry->nw;
*height = geometry->sh * *height / geometry->nh;
return mlt_properties_get_data( properties, "alpha", NULL );
}
+struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transition this, mlt_frame a_frame, float position )
+{
+ // Get the properties from the transition
+ mlt_properties properties = mlt_transition_properties( this );
+
+ // Get the properties from the frame
+ mlt_properties a_props = mlt_frame_properties( a_frame );
+
+ // Structures for geometry
+ struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
+
+ // Now parse the geometries
+ if ( start == NULL )
+ {
+ // Obtain the normalised width and height from the a_frame
+ int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
+ int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
+
+ // Parse the transitions properties
+ start = transition_parse_keys( this, normalised_width, normalised_height );
+ }
+
+ // Do the calculation
+ geometry_calculate( result, start, position );
+
+ // Now parse the alignment
+ result->halign = alignment_parse( mlt_properties_get( properties, "halign" ) );
+ result->valign = alignment_parse( mlt_properties_get( properties, "valign" ) );
+
+ return start;
+}
+
+mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame )
+{
+ // Create a frame to return
+ mlt_frame b_frame = mlt_frame_init( );
+
+ // Get the properties of the a frame
+ mlt_properties a_props = mlt_frame_properties( a_frame );
+
+ // Get the properties of the b frame
+ mlt_properties b_props = mlt_frame_properties( b_frame );
+
+ // Get the position
+ float position = position_calculate( this, a_frame );
+
+ // Destination image
+ uint8_t *dest = NULL;
+
+ // Get the image and dimensions
+ uint8_t *image = mlt_properties_get_data( a_props, "image", NULL );
+ int width = mlt_properties_get_int( a_props, "width" );
+ int height = mlt_properties_get_int( a_props, "height" );
+
+ // Pointers for copy operation
+ uint8_t *p;
+ uint8_t *q;
+ uint8_t *r;
+
+ // Corrdinates
+ int w = 0;
+ int h = 0;
+ int x = 0;
+ int y = 0;
+
+ // Will need to know region to copy
+ struct geometry_s result;
+
+ // Calculate the region now
+ composite_calculate( &result, this, a_frame, position );
+
+ // Need to scale down to actual dimensions
+ x = result.x * width / result.nw ;
+ y = result.y * height / result.nh;
+ w = result.sw * width / result.nw;
+ h = result.sh * height / result.nh;
+
+ x &= 0xfffffffe;
+ w &= 0xfffffffe;
+
+ // Now we need to create a new destination image
+ dest = mlt_pool_alloc( w * h * 2 );
+
+ // Copy the region of the image
+ p = image + y * width * 2 + x * 2;
+ q = dest;
+ r = dest + w * h * 2;
+
+ while ( q < r )
+ {
+ memcpy( q, p, w * 2 );
+ q += w * 2;
+ p += width * 2;
+ }
+
+ // Assign to the new frame
+ mlt_properties_set_data( b_props, "image", dest, w * h * 2, mlt_pool_release, NULL );
+ mlt_properties_set_int( b_props, "width", w );
+ mlt_properties_set_int( b_props, "height", h );
+
+ // Return the frame
+ return b_frame;
+}
+
/** Get the image.
*/
// Get the b frame from the stack
mlt_frame b_frame = mlt_frame_pop_frame( a_frame );
- // This compositer is yuv422 only
- *format = mlt_image_yuv422;
-
// Get the transition from the a frame
mlt_transition this = mlt_frame_pop_service( a_frame );
+ // This compositer is yuv422 only
+ *format = mlt_image_yuv422;
+
// Get the image from the a frame
mlt_frame_get_image( a_frame, image, format, width, height, 1 );
// Structures for geometry
struct geometry_s result;
- struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
// Calculate the position
float position = mlt_properties_get_double( b_props, "relative_position" );
float delta = delta_calculate( this, a_frame );
- // Now parse the geometries
- if ( start == NULL )
- {
- // Obtain the normalised width and height from the a_frame
- int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
- int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
-
- // Parse the transitions properties
- start = transition_parse_keys( this, normalised_width, normalised_height );
- }
+ // Do the calculation
+ struct geometry_s *start = composite_calculate( &result, this, a_frame, position );
// Since we are the consumer of the b_frame, we must pass along these
// consumer properties 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" ) );
- // Do the calculation
- geometry_calculate( &result, start, position );
-
- // Now parse the alignment
- result.halign = alignment_parse( mlt_properties_get( properties, "halign" ) );
- result.valign = alignment_parse( mlt_properties_get( properties, "valign" ) );
-
// Get the image from the b frame
uint8_t *image_b = NULL;
int width_b = *width;
extern mlt_transition transition_composite_init( char *arg );
+// Courtesy functionality - allows regionalised filtering
+extern mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame );
+
#endif