From: lilo_booter Date: Fri, 19 Dec 2003 14:07:35 +0000 (+0000) Subject: Added files rejected by import X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=15934f863eff9ee542f8b65fb7335ad944508f2f;hp=661165812e3410fe2f6f49d7af882b36a0efcf82;p=melted Added files rejected by import git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@6 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/mlt/src/modules/core/Makefile b/mlt/src/modules/core/Makefile new file mode 100644 index 0000000..5b8ac04 --- /dev/null +++ b/mlt/src/modules/core/Makefile @@ -0,0 +1,30 @@ + +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 diff --git a/mlt/src/modules/core/configure b/mlt/src/modules/core/configure new file mode 100755 index 0000000..43f2780 --- /dev/null +++ b/mlt/src/modules/core/configure @@ -0,0 +1,20 @@ +#!/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 + diff --git a/mlt/src/modules/core/factory.c b/mlt/src/modules/core/factory.c new file mode 100644 index 0000000..2f517b8 --- /dev/null +++ b/mlt/src/modules/core/factory.c @@ -0,0 +1,55 @@ +/* + * factory.c -- the factory method interfaces + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#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; +} + diff --git a/mlt/src/modules/core/filter_deinterlace.c b/mlt/src/modules/core/filter_deinterlace.c new file mode 100644 index 0000000..7fc04b6 --- /dev/null +++ b/mlt/src/modules/core/filter_deinterlace.c @@ -0,0 +1,116 @@ +/* + * filter_deinterlace.c -- deinterlace filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/mlt/src/modules/core/filter_deinterlace.h b/mlt/src/modules/core/filter_deinterlace.h new file mode 100644 index 0000000..cfcd2fc --- /dev/null +++ b/mlt/src/modules/core/filter_deinterlace.h @@ -0,0 +1,28 @@ +/* + * filter_deinterlace.h -- deinterlace filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +extern mlt_filter filter_deinterlace_init( void *arg ); + +#endif diff --git a/mlt/src/modules/core/filter_greyscale.c b/mlt/src/modules/core/filter_greyscale.c new file mode 100644 index 0000000..170ff4f --- /dev/null +++ b/mlt/src/modules/core/filter_greyscale.c @@ -0,0 +1,73 @@ +/* + * filter_greyscale.c -- greyscale filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/mlt/src/modules/core/filter_greyscale.h b/mlt/src/modules/core/filter_greyscale.h new file mode 100644 index 0000000..30515f5 --- /dev/null +++ b/mlt/src/modules/core/filter_greyscale.h @@ -0,0 +1,28 @@ +/* + * filter_greyscale.h -- greyscale filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +extern mlt_filter filter_greyscale_init( void *arg ); + +#endif diff --git a/mlt/src/modules/core/producer_ppm.c b/mlt/src/modules/core/producer_ppm.c new file mode 100644 index 0000000..e1357c8 --- /dev/null +++ b/mlt/src/modules/core/producer_ppm.c @@ -0,0 +1,128 @@ +/* + * producer_ppm.c -- simple ppm test case + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 +#include +#include + +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 ); +} + diff --git a/mlt/src/modules/core/producer_ppm.h b/mlt/src/modules/core/producer_ppm.h new file mode 100644 index 0000000..4787b8f --- /dev/null +++ b/mlt/src/modules/core/producer_ppm.h @@ -0,0 +1,38 @@ +/* + * producer_ppm.h -- simple ppm test case + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 +#include + +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 diff --git a/mlt/src/modules/core/transition_composite.c b/mlt/src/modules/core/transition_composite.c new file mode 100644 index 0000000..8418f2f --- /dev/null +++ b/mlt/src/modules/core/transition_composite.c @@ -0,0 +1,102 @@ +/* + * transition_composite.c -- compose one image over another using alpha channel + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/mlt/src/modules/core/transition_composite.h b/mlt/src/modules/core/transition_composite.h new file mode 100644 index 0000000..73fcb30 --- /dev/null +++ b/mlt/src/modules/core/transition_composite.h @@ -0,0 +1,28 @@ +/* + * transition_composite.h -- compose one image over another using alpha channel + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * 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 + +extern mlt_transition transition_composite_init( void *arg ); + +#endif diff --git a/src/modules/core/Makefile b/src/modules/core/Makefile new file mode 100644 index 0000000..5b8ac04 --- /dev/null +++ b/src/modules/core/Makefile @@ -0,0 +1,30 @@ + +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 diff --git a/src/modules/core/configure b/src/modules/core/configure new file mode 100755 index 0000000..43f2780 --- /dev/null +++ b/src/modules/core/configure @@ -0,0 +1,20 @@ +#!/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 + diff --git a/src/modules/core/factory.c b/src/modules/core/factory.c new file mode 100644 index 0000000..2f517b8 --- /dev/null +++ b/src/modules/core/factory.c @@ -0,0 +1,55 @@ +/* + * factory.c -- the factory method interfaces + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#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; +} + diff --git a/src/modules/core/filter_deinterlace.c b/src/modules/core/filter_deinterlace.c new file mode 100644 index 0000000..7fc04b6 --- /dev/null +++ b/src/modules/core/filter_deinterlace.c @@ -0,0 +1,116 @@ +/* + * filter_deinterlace.c -- deinterlace filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/src/modules/core/filter_deinterlace.h b/src/modules/core/filter_deinterlace.h new file mode 100644 index 0000000..cfcd2fc --- /dev/null +++ b/src/modules/core/filter_deinterlace.h @@ -0,0 +1,28 @@ +/* + * filter_deinterlace.h -- deinterlace filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +extern mlt_filter filter_deinterlace_init( void *arg ); + +#endif diff --git a/src/modules/core/filter_greyscale.c b/src/modules/core/filter_greyscale.c new file mode 100644 index 0000000..170ff4f --- /dev/null +++ b/src/modules/core/filter_greyscale.c @@ -0,0 +1,73 @@ +/* + * filter_greyscale.c -- greyscale filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/src/modules/core/filter_greyscale.h b/src/modules/core/filter_greyscale.h new file mode 100644 index 0000000..30515f5 --- /dev/null +++ b/src/modules/core/filter_greyscale.h @@ -0,0 +1,28 @@ +/* + * filter_greyscale.h -- greyscale filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +extern mlt_filter filter_greyscale_init( void *arg ); + +#endif diff --git a/src/modules/core/producer_ppm.c b/src/modules/core/producer_ppm.c new file mode 100644 index 0000000..e1357c8 --- /dev/null +++ b/src/modules/core/producer_ppm.c @@ -0,0 +1,128 @@ +/* + * producer_ppm.c -- simple ppm test case + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 +#include +#include + +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 ); +} + diff --git a/src/modules/core/producer_ppm.h b/src/modules/core/producer_ppm.h new file mode 100644 index 0000000..4787b8f --- /dev/null +++ b/src/modules/core/producer_ppm.h @@ -0,0 +1,38 @@ +/* + * producer_ppm.h -- simple ppm test case + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 +#include + +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 diff --git a/src/modules/core/transition_composite.c b/src/modules/core/transition_composite.c new file mode 100644 index 0000000..8418f2f --- /dev/null +++ b/src/modules/core/transition_composite.c @@ -0,0 +1,102 @@ +/* + * transition_composite.c -- compose one image over another using alpha channel + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * 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 + +#include +#include + +/** 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; +} + diff --git a/src/modules/core/transition_composite.h b/src/modules/core/transition_composite.h new file mode 100644 index 0000000..73fcb30 --- /dev/null +++ b/src/modules/core/transition_composite.h @@ -0,0 +1,28 @@ +/* + * transition_composite.h -- compose one image over another using alpha channel + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * 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 + +extern mlt_transition transition_composite_init( void *arg ); + +#endif