--- /dev/null
+
+TARGET=libmltcore.so
+
+OBJS = factory.o \
+ producer_ppm.o \
+ filter_deinterlace.o \
+ filter_greyscale.o \
+ transition_composite.o
+
+CFLAGS=-I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
+
+SRCS := $(OBJS:.o=.c)
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ $(CC) -shared -o $@ $(OBJS) $(LDFLAGS)
+
+depend: $(SRCS)
+ $(CC) -MM $(CFLAGS) $^ 1>.depend
+
+dist-clean: clean
+ rm -f .depend
+
+clean:
+ rm -f $(OBJS) $(TARGET)
+
+ifneq ($(wildcard .depend),)
+include .depend
+endif
--- /dev/null
+#!/bin/bash
+
+if [ "$help" != "1" ]
+then
+
+cat << EOF >> ../producers.dat
+ppm libmltcore.so
+EOF
+
+cat << EOF >> ../filters.dat
+deinterlace libmltcore.so
+greyscale libmltcore.so
+EOF
+
+cat << EOF >> ../transitions.dat
+composite libmltcore.so
+EOF
+
+fi
+
--- /dev/null
+/*
+ * factory.c -- the factory method interfaces
+ * 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 <string.h>
+
+#include "filter_deinterlace.h"
+#include "filter_greyscale.h"
+#include "producer_ppm.h"
+#include "transition_composite.h"
+
+void *mlt_create_producer( char *id, void *arg )
+{
+ if ( !strcmp( id, "ppm" ) )
+ return producer_ppm_init( arg );
+ return NULL;
+}
+
+void *mlt_create_filter( char *id, void *arg )
+{
+ if ( !strcmp( id, "deinterlace" ) )
+ return filter_deinterlace_init( arg );
+ if ( !strcmp( id, "greyscale" ) )
+ return filter_greyscale_init( arg );
+ return NULL;
+}
+
+void *mlt_create_transition( char *id, void *arg )
+{
+ if ( !strcmp( id, "composite" ) )
+ return transition_composite_init( arg );
+ return NULL;
+}
+
+void *mlt_create_consumer( char *id, void *arg )
+{
+ return NULL;
+}
+
--- /dev/null
+/*
+ * filter_deinterlace.c -- deinterlace 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_deinterlace.h"
+
+#include <framework/mlt_frame.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+/** Deinterlace class.
+*/
+
+typedef struct
+{
+ struct mlt_filter_s parent;
+}
+filter_deinterlace;
+
+/* Linear Blend filter - C version contributed by Rogerio Brito.
+ This algorithm has the same interface as the other functions.
+
+ The destination "screen" (pdst) is constructed from the source
+ screen (psrc[0]) line by line.
+
+ The i-th line of the destination screen is the average of 3 lines
+ from the source screen: the (i-1)-th, i-th and (i+1)-th lines, with
+ the i-th line having weight 2 in the computation.
+
+ Remarks:
+ * each line on pdst doesn't depend on previous lines;
+ * due to the way the algorithm is defined, the first & last lines of the
+ screen aren't deinterlaced.
+
+*/
+static void deinterlace_yuv( uint8_t *pdst, uint8_t *psrc, int width, int height )
+{
+ register int x, y;
+ register uint8_t *l0, *l1, *l2, *l3;
+
+ l0 = pdst; /* target line */
+ l1 = psrc; /* 1st source line */
+ l2 = l1 + width; /* 2nd source line = line that follows l1 */
+ l3 = l2 + width; /* 3rd source line = line that follows l2 */
+
+ /* Copy the first line */
+ memcpy(l0, l1, width);
+ l0 += width;
+
+ for (y = 1; y < height-1; ++y)
+ {
+ /* computes avg of: l1 + 2*l2 + l3 */
+ for (x = 0; x < width; ++x)
+ l0[x] = (l1[x] + (l2[x]<<1) + l3[x]) >> 2;
+
+ /* updates the line pointers */
+ l1 = l2; l2 = l3; l3 += width;
+ l0 += width;
+ }
+
+ /* Copy the last line */
+ memcpy(l0, l1, width);
+}
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ mlt_frame_get_image( this, image, format, width, height, 1 );
+ deinterlace_yuv( *image, *image, *width * 2, *height );
+ return 0;
+}
+
+/** Deinterlace filter processing - this should be lazy evaluation here...
+*/
+
+static mlt_frame deinterlace_process( mlt_filter this, mlt_frame frame )
+{
+ mlt_frame_push_get_image( frame, filter_get_image );
+ return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_deinterlace_init( void *arg )
+{
+ filter_deinterlace *this = calloc( sizeof( filter_deinterlace ), 1 );
+ if ( this != NULL )
+ {
+ mlt_filter filter = &this->parent;
+ mlt_filter_init( filter, this );
+ filter->process = deinterlace_process;
+ return &this->parent;
+ }
+ return NULL;
+}
+
--- /dev/null
+/*
+ * filter_deinterlace.h -- deinterlace 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_DEINTERLACE_H_
+#define _FILTER_DEINTERLACE_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_deinterlace_init( void *arg );
+
+#endif
--- /dev/null
+/*
+ * filter_greyscale.c -- greyscale 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_greyscale.h"
+
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Greyscale class.
+*/
+
+typedef struct
+{
+ struct mlt_filter_s parent;
+}
+filter_greyscale;
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ mlt_frame_get_image( this, image, format, width, height, 1 );
+ uint8_t *p = *image;
+ uint8_t *q = *image + *width * *height * 2;
+ while ( p ++ != q )
+ *p ++ = 128;
+ return 0;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+ mlt_frame_push_get_image( frame, filter_get_image );
+ return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_greyscale_init( void *arg )
+{
+ filter_greyscale *this = calloc( sizeof( filter_greyscale ), 1 );
+ if ( this != NULL )
+ {
+ mlt_filter filter = &this->parent;
+ mlt_filter_init( filter, this );
+ filter->process = filter_process;
+ }
+ return ( mlt_filter )this;
+}
+
--- /dev/null
+/*
+ * filter_greyscale.h -- greyscale 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_GREYSCALE_H_
+#define _FILTER_GREYSCALE_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_greyscale_init( void *arg );
+
+#endif
--- /dev/null
+/*
+ * producer_ppm.c -- simple ppm test case
+ * 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 "producer_ppm.h"
+#include <framework/mlt_frame.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
+static void producer_close( mlt_producer parent );
+
+mlt_producer producer_ppm_init( void *command )
+{
+ producer_ppm this = calloc( sizeof( struct producer_ppm_s ), 1 );
+ if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
+ {
+ mlt_producer producer = &this->parent;
+
+ producer->get_frame = producer_get_frame;
+ producer->close = producer_close;
+
+ if ( command == NULL )
+ this->command = strdup( "image2raw -n -a -r 3 -ppm /usr/share/pixmaps/*.png" );
+ else
+ this->command = strdup( command );
+
+ this->pipe = popen( this->command, "r" );
+
+ return producer;
+ }
+ free( this );
+ return NULL;
+}
+
+static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
+{
+ // Get the frames properties
+ mlt_properties properties = mlt_frame_properties( this );
+
+ // Get the RGB image
+ uint8_t *rgb = mlt_properties_get_data( properties, "image", NULL );
+
+ // Get width and height
+ *width = mlt_properties_get_int( properties, "width" );
+ *height = mlt_properties_get_int( properties, "height" );
+
+ // Convert to requested format
+ if ( *format == mlt_image_yuv422 )
+ {
+ uint8_t *image = malloc( *width * *height * 2 );
+ mlt_convert_rgb24_to_yuv422( rgb, *width, *height, *width * 3, image );
+ mlt_properties_set_data( properties, "image", image, *width * *height * 2, free, NULL );
+ *buffer = image;
+ }
+ else if ( *format == mlt_image_rgb24 )
+ {
+ *buffer = rgb;
+ }
+
+ return 0;
+}
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+{
+ producer_ppm this = producer->child;
+ int width;
+ int height;
+
+ // Construct a test frame
+ *frame = mlt_frame_init( );
+
+ // Scan the header
+ if ( fscanf( this->pipe, "P6\n%d %d\n255\n", &width, &height ) == 2 )
+ {
+ // Get the frames properties
+ mlt_properties properties = mlt_frame_properties( *frame );
+
+ // Allocate an image
+ uint8_t *image = malloc( width * height * 3 );
+
+ // Read it
+ fread( image, width * height * 3, 1, this->pipe );
+
+ // Pass the data on the frame properties
+ mlt_properties_set_data( properties, "image", image, width * height * 3, free, NULL );
+ mlt_properties_set_int( properties, "width", width );
+ mlt_properties_set_int( properties, "height", height );
+
+ // Push the image callback
+ mlt_frame_push_get_image( *frame, producer_get_image );
+ }
+
+ // Update timecode on the frame we're creating
+ mlt_frame_set_timecode( *frame, mlt_producer_position( producer ) );
+
+ // Calculate the next timecode
+ mlt_producer_prepare_next( producer );
+
+ return 0;
+}
+
+static void producer_close( mlt_producer parent )
+{
+ producer_ppm this = parent->child;
+ pclose( this->pipe );
+ free( this->command );
+ parent->close = NULL;
+ mlt_producer_close( parent );
+ free( this );
+}
+
--- /dev/null
+/*
+ * producer_ppm.h -- simple ppm test case
+ * 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 _PRODUCER_PPM_H_
+#define _PRODUCER_PPM_H_
+
+#include <framework/mlt_producer.h>
+#include <stdio.h>
+
+typedef struct producer_ppm_s *producer_ppm;
+
+struct producer_ppm_s
+{
+ struct mlt_producer_s parent;
+ char *command;
+ FILE *pipe;
+};
+
+extern mlt_producer producer_ppm_init( void *command );
+
+#endif
--- /dev/null
+/*
+ * transition_composite.c -- compose one image over another using alpha channel
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * 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 "transition_composite.h"
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Composition class.
+*/
+
+typedef struct
+{
+ struct mlt_transition_s parent;
+}
+transition_composite;
+
+/** Get the image.
+*/
+
+static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ // Get the properties of the a frame
+ mlt_properties a_props = mlt_frame_properties( this );
+
+ // Get the b frame from the stack
+ mlt_frame b_frame = mlt_frame_pop_frame( this );
+
+ // Get the properties of the b frame
+ mlt_properties b_props = mlt_frame_properties( b_frame );
+
+ // Arbitrary composite defaults
+ int x = 50;
+ int y = 50;
+ double weight = 1.0;
+
+ // Override from b frame properties if provided
+ if ( mlt_properties_get( b_props, "x" ) != NULL )
+ x = mlt_properties_get_int( b_props, "x" );
+ if ( mlt_properties_get( b_props, "y" ) != NULL )
+ y = mlt_properties_get_int( b_props, "y" );
+ if ( mlt_properties_get( b_props, "weight" ) != NULL )
+ weight = mlt_properties_get_double( b_props, "weight" );
+
+ // Composite the b_frame on the a_frame
+ mlt_frame_composite_yuv( this, b_frame, x, y, weight );
+
+ // Extract the a_frame image info
+ *width = mlt_properties_get_int( a_props, "width" );
+ *height = mlt_properties_get_int( a_props, "height" );
+ *image = mlt_properties_get_data( a_props, "image", NULL );
+
+ // Close the b_frame
+ mlt_frame_close( b_frame );
+
+ return 0;
+}
+
+/** Composition transition processing.
+*/
+
+static mlt_frame composite_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame )
+{
+ mlt_frame_push_get_image( a_frame, transition_get_image );
+ mlt_frame_push_frame( a_frame, b_frame );
+ return a_frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_transition transition_composite_init( void *arg )
+{
+ transition_composite *this = calloc( sizeof( transition_composite ), 1 );
+ if ( this != NULL )
+ {
+ mlt_transition transition = &this->parent;
+ mlt_transition_init( transition, this );
+ transition->process = composite_process;
+ return &this->parent;
+ }
+ return NULL;
+}
+
--- /dev/null
+/*
+ * transition_composite.h -- compose one image over another using alpha channel
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * 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 _TRANSITION_COMPOSITE_H_
+#define _TRANSITION_COMPOSITE_H_
+
+#include <framework/mlt_transition.h>
+
+extern mlt_transition transition_composite_init( void *arg );
+
+#endif
--- /dev/null
+
+TARGET=libmltcore.so
+
+OBJS = factory.o \
+ producer_ppm.o \
+ filter_deinterlace.o \
+ filter_greyscale.o \
+ transition_composite.o
+
+CFLAGS=-I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
+
+SRCS := $(OBJS:.o=.c)
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ $(CC) -shared -o $@ $(OBJS) $(LDFLAGS)
+
+depend: $(SRCS)
+ $(CC) -MM $(CFLAGS) $^ 1>.depend
+
+dist-clean: clean
+ rm -f .depend
+
+clean:
+ rm -f $(OBJS) $(TARGET)
+
+ifneq ($(wildcard .depend),)
+include .depend
+endif
--- /dev/null
+#!/bin/bash
+
+if [ "$help" != "1" ]
+then
+
+cat << EOF >> ../producers.dat
+ppm libmltcore.so
+EOF
+
+cat << EOF >> ../filters.dat
+deinterlace libmltcore.so
+greyscale libmltcore.so
+EOF
+
+cat << EOF >> ../transitions.dat
+composite libmltcore.so
+EOF
+
+fi
+
--- /dev/null
+/*
+ * factory.c -- the factory method interfaces
+ * 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 <string.h>
+
+#include "filter_deinterlace.h"
+#include "filter_greyscale.h"
+#include "producer_ppm.h"
+#include "transition_composite.h"
+
+void *mlt_create_producer( char *id, void *arg )
+{
+ if ( !strcmp( id, "ppm" ) )
+ return producer_ppm_init( arg );
+ return NULL;
+}
+
+void *mlt_create_filter( char *id, void *arg )
+{
+ if ( !strcmp( id, "deinterlace" ) )
+ return filter_deinterlace_init( arg );
+ if ( !strcmp( id, "greyscale" ) )
+ return filter_greyscale_init( arg );
+ return NULL;
+}
+
+void *mlt_create_transition( char *id, void *arg )
+{
+ if ( !strcmp( id, "composite" ) )
+ return transition_composite_init( arg );
+ return NULL;
+}
+
+void *mlt_create_consumer( char *id, void *arg )
+{
+ return NULL;
+}
+
--- /dev/null
+/*
+ * filter_deinterlace.c -- deinterlace 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_deinterlace.h"
+
+#include <framework/mlt_frame.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+/** Deinterlace class.
+*/
+
+typedef struct
+{
+ struct mlt_filter_s parent;
+}
+filter_deinterlace;
+
+/* Linear Blend filter - C version contributed by Rogerio Brito.
+ This algorithm has the same interface as the other functions.
+
+ The destination "screen" (pdst) is constructed from the source
+ screen (psrc[0]) line by line.
+
+ The i-th line of the destination screen is the average of 3 lines
+ from the source screen: the (i-1)-th, i-th and (i+1)-th lines, with
+ the i-th line having weight 2 in the computation.
+
+ Remarks:
+ * each line on pdst doesn't depend on previous lines;
+ * due to the way the algorithm is defined, the first & last lines of the
+ screen aren't deinterlaced.
+
+*/
+static void deinterlace_yuv( uint8_t *pdst, uint8_t *psrc, int width, int height )
+{
+ register int x, y;
+ register uint8_t *l0, *l1, *l2, *l3;
+
+ l0 = pdst; /* target line */
+ l1 = psrc; /* 1st source line */
+ l2 = l1 + width; /* 2nd source line = line that follows l1 */
+ l3 = l2 + width; /* 3rd source line = line that follows l2 */
+
+ /* Copy the first line */
+ memcpy(l0, l1, width);
+ l0 += width;
+
+ for (y = 1; y < height-1; ++y)
+ {
+ /* computes avg of: l1 + 2*l2 + l3 */
+ for (x = 0; x < width; ++x)
+ l0[x] = (l1[x] + (l2[x]<<1) + l3[x]) >> 2;
+
+ /* updates the line pointers */
+ l1 = l2; l2 = l3; l3 += width;
+ l0 += width;
+ }
+
+ /* Copy the last line */
+ memcpy(l0, l1, width);
+}
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ mlt_frame_get_image( this, image, format, width, height, 1 );
+ deinterlace_yuv( *image, *image, *width * 2, *height );
+ return 0;
+}
+
+/** Deinterlace filter processing - this should be lazy evaluation here...
+*/
+
+static mlt_frame deinterlace_process( mlt_filter this, mlt_frame frame )
+{
+ mlt_frame_push_get_image( frame, filter_get_image );
+ return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_deinterlace_init( void *arg )
+{
+ filter_deinterlace *this = calloc( sizeof( filter_deinterlace ), 1 );
+ if ( this != NULL )
+ {
+ mlt_filter filter = &this->parent;
+ mlt_filter_init( filter, this );
+ filter->process = deinterlace_process;
+ return &this->parent;
+ }
+ return NULL;
+}
+
--- /dev/null
+/*
+ * filter_deinterlace.h -- deinterlace 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_DEINTERLACE_H_
+#define _FILTER_DEINTERLACE_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_deinterlace_init( void *arg );
+
+#endif
--- /dev/null
+/*
+ * filter_greyscale.c -- greyscale 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_greyscale.h"
+
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Greyscale class.
+*/
+
+typedef struct
+{
+ struct mlt_filter_s parent;
+}
+filter_greyscale;
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ mlt_frame_get_image( this, image, format, width, height, 1 );
+ uint8_t *p = *image;
+ uint8_t *q = *image + *width * *height * 2;
+ while ( p ++ != q )
+ *p ++ = 128;
+ return 0;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+ mlt_frame_push_get_image( frame, filter_get_image );
+ return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_greyscale_init( void *arg )
+{
+ filter_greyscale *this = calloc( sizeof( filter_greyscale ), 1 );
+ if ( this != NULL )
+ {
+ mlt_filter filter = &this->parent;
+ mlt_filter_init( filter, this );
+ filter->process = filter_process;
+ }
+ return ( mlt_filter )this;
+}
+
--- /dev/null
+/*
+ * filter_greyscale.h -- greyscale 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_GREYSCALE_H_
+#define _FILTER_GREYSCALE_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_greyscale_init( void *arg );
+
+#endif
--- /dev/null
+/*
+ * producer_ppm.c -- simple ppm test case
+ * 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 "producer_ppm.h"
+#include <framework/mlt_frame.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
+static void producer_close( mlt_producer parent );
+
+mlt_producer producer_ppm_init( void *command )
+{
+ producer_ppm this = calloc( sizeof( struct producer_ppm_s ), 1 );
+ if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
+ {
+ mlt_producer producer = &this->parent;
+
+ producer->get_frame = producer_get_frame;
+ producer->close = producer_close;
+
+ if ( command == NULL )
+ this->command = strdup( "image2raw -n -a -r 3 -ppm /usr/share/pixmaps/*.png" );
+ else
+ this->command = strdup( command );
+
+ this->pipe = popen( this->command, "r" );
+
+ return producer;
+ }
+ free( this );
+ return NULL;
+}
+
+static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
+{
+ // Get the frames properties
+ mlt_properties properties = mlt_frame_properties( this );
+
+ // Get the RGB image
+ uint8_t *rgb = mlt_properties_get_data( properties, "image", NULL );
+
+ // Get width and height
+ *width = mlt_properties_get_int( properties, "width" );
+ *height = mlt_properties_get_int( properties, "height" );
+
+ // Convert to requested format
+ if ( *format == mlt_image_yuv422 )
+ {
+ uint8_t *image = malloc( *width * *height * 2 );
+ mlt_convert_rgb24_to_yuv422( rgb, *width, *height, *width * 3, image );
+ mlt_properties_set_data( properties, "image", image, *width * *height * 2, free, NULL );
+ *buffer = image;
+ }
+ else if ( *format == mlt_image_rgb24 )
+ {
+ *buffer = rgb;
+ }
+
+ return 0;
+}
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+{
+ producer_ppm this = producer->child;
+ int width;
+ int height;
+
+ // Construct a test frame
+ *frame = mlt_frame_init( );
+
+ // Scan the header
+ if ( fscanf( this->pipe, "P6\n%d %d\n255\n", &width, &height ) == 2 )
+ {
+ // Get the frames properties
+ mlt_properties properties = mlt_frame_properties( *frame );
+
+ // Allocate an image
+ uint8_t *image = malloc( width * height * 3 );
+
+ // Read it
+ fread( image, width * height * 3, 1, this->pipe );
+
+ // Pass the data on the frame properties
+ mlt_properties_set_data( properties, "image", image, width * height * 3, free, NULL );
+ mlt_properties_set_int( properties, "width", width );
+ mlt_properties_set_int( properties, "height", height );
+
+ // Push the image callback
+ mlt_frame_push_get_image( *frame, producer_get_image );
+ }
+
+ // Update timecode on the frame we're creating
+ mlt_frame_set_timecode( *frame, mlt_producer_position( producer ) );
+
+ // Calculate the next timecode
+ mlt_producer_prepare_next( producer );
+
+ return 0;
+}
+
+static void producer_close( mlt_producer parent )
+{
+ producer_ppm this = parent->child;
+ pclose( this->pipe );
+ free( this->command );
+ parent->close = NULL;
+ mlt_producer_close( parent );
+ free( this );
+}
+
--- /dev/null
+/*
+ * producer_ppm.h -- simple ppm test case
+ * 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 _PRODUCER_PPM_H_
+#define _PRODUCER_PPM_H_
+
+#include <framework/mlt_producer.h>
+#include <stdio.h>
+
+typedef struct producer_ppm_s *producer_ppm;
+
+struct producer_ppm_s
+{
+ struct mlt_producer_s parent;
+ char *command;
+ FILE *pipe;
+};
+
+extern mlt_producer producer_ppm_init( void *command );
+
+#endif
--- /dev/null
+/*
+ * transition_composite.c -- compose one image over another using alpha channel
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * 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 "transition_composite.h"
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/** Composition class.
+*/
+
+typedef struct
+{
+ struct mlt_transition_s parent;
+}
+transition_composite;
+
+/** Get the image.
+*/
+
+static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+ // Get the properties of the a frame
+ mlt_properties a_props = mlt_frame_properties( this );
+
+ // Get the b frame from the stack
+ mlt_frame b_frame = mlt_frame_pop_frame( this );
+
+ // Get the properties of the b frame
+ mlt_properties b_props = mlt_frame_properties( b_frame );
+
+ // Arbitrary composite defaults
+ int x = 50;
+ int y = 50;
+ double weight = 1.0;
+
+ // Override from b frame properties if provided
+ if ( mlt_properties_get( b_props, "x" ) != NULL )
+ x = mlt_properties_get_int( b_props, "x" );
+ if ( mlt_properties_get( b_props, "y" ) != NULL )
+ y = mlt_properties_get_int( b_props, "y" );
+ if ( mlt_properties_get( b_props, "weight" ) != NULL )
+ weight = mlt_properties_get_double( b_props, "weight" );
+
+ // Composite the b_frame on the a_frame
+ mlt_frame_composite_yuv( this, b_frame, x, y, weight );
+
+ // Extract the a_frame image info
+ *width = mlt_properties_get_int( a_props, "width" );
+ *height = mlt_properties_get_int( a_props, "height" );
+ *image = mlt_properties_get_data( a_props, "image", NULL );
+
+ // Close the b_frame
+ mlt_frame_close( b_frame );
+
+ return 0;
+}
+
+/** Composition transition processing.
+*/
+
+static mlt_frame composite_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame )
+{
+ mlt_frame_push_get_image( a_frame, transition_get_image );
+ mlt_frame_push_frame( a_frame, b_frame );
+ return a_frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_transition transition_composite_init( void *arg )
+{
+ transition_composite *this = calloc( sizeof( transition_composite ), 1 );
+ if ( this != NULL )
+ {
+ mlt_transition transition = &this->parent;
+ mlt_transition_init( transition, this );
+ transition->process = composite_process;
+ return &this->parent;
+ }
+ return NULL;
+}
+
--- /dev/null
+/*
+ * transition_composite.h -- compose one image over another using alpha channel
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * 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 _TRANSITION_COMPOSITE_H_
+#define _TRANSITION_COMPOSITE_H_
+
+#include <framework/mlt_transition.h>
+
+extern mlt_transition transition_composite_init( void *arg );
+
+#endif