]> git.sesse.net Git - mlt/commitdiff
producer_colour
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 3 Mar 2004 22:07:25 +0000 (22:07 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 3 Mar 2004 22:07:25 +0000 (22:07 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@186 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_frame.c
src/framework/mlt_frame.h
src/modules/core/Makefile
src/modules/core/configure
src/modules/core/factory.c
src/modules/core/producer_colour.c [new file with mode: 0644]
src/modules/core/producer_colour.h [new file with mode: 0644]

index 09eb6f078ddd6dae00250f9caa67392ad9efe745..544bea3ee5888405d33a9fd1ab6f06ad5b95e01f 100644 (file)
@@ -323,30 +323,6 @@ void mlt_frame_close( mlt_frame this )
 
 /***** convenience functions *****/
 
-/* this macro scales rgb into the yuv gamut, y is scaled by 219/255 and uv by 224/255 */
-#define RGB2YUV(r, g, b, y, u, v)\
-  y = ((257*r + 504*g + 98*b) >> 10) + 16;\
-  u = ((-148*r - 291*g + 439*b) >> 10) + 128;\
-  v = ((439*r - 368*g - 71*b) >> 10) + 128;\
-  y = y < 16 ? 16 : y;\
-  u = u < 16 ? 16 : u;\
-  v = v < 16 ? 16 : v;\
-  y = y > 235 ? 235 : y;\
-  u = u > 240 ? 240 : u;\
-  v = v > 240 ? 240 : v
-
-/* this macro assumes the user has already scaled their rgb down into the broadcast limits */
-#define RGB2YUV_UNSCALED(r, g, b, y, u, v)\
-  y = (299*r + 587*g + 114*b) >> 10;\
-  u = ((-169*r - 331*g + 500*b) >> 10) + 128;\
-  v = ((500*r - 419*g - 81*b) >> 10) + 128;\
-  y = y < 16 ? 16 : y;\
-  u = u < 16 ? 16 : u;\
-  v = v < 16 ? 16 : v;\
-  y = y > 235 ? 235 : y;\
-  u = u > 240 ? 240 : u;\
-  v = v > 240 ? 240 : v
-  
 int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
 {
        int ret = 0;
index 915a707c1059fec35ef5815ce26b461975f153a5..a35086ed8db004f6e385b8e03b2adf41b3995427 100644 (file)
@@ -96,5 +96,29 @@ extern void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t
 extern int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight_start, float weight_end, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples  );
 extern int mlt_sample_calculator( float fps, int frequency, int64_t position );
 
+/* this macro scales rgb into the yuv gamut, y is scaled by 219/255 and uv by 224/255 */
+#define RGB2YUV(r, g, b, y, u, v)\
+  y = ((257*r + 504*g + 98*b) >> 10) + 16;\
+  u = ((-148*r - 291*g + 439*b) >> 10) + 128;\
+  v = ((439*r - 368*g - 71*b) >> 10) + 128;\
+  y = y < 16 ? 16 : y;\
+  u = u < 16 ? 16 : u;\
+  v = v < 16 ? 16 : v;\
+  y = y > 235 ? 235 : y;\
+  u = u > 240 ? 240 : u;\
+  v = v > 240 ? 240 : v
+
+/* this macro assumes the user has already scaled their rgb down into the broadcast limits */
+#define RGB2YUV_UNSCALED(r, g, b, y, u, v)\
+  y = (299*r + 587*g + 114*b) >> 10;\
+  u = ((-169*r - 331*g + 500*b) >> 10) + 128;\
+  v = ((500*r - 419*g - 81*b) >> 10) + 128;\
+  y = y < 16 ? 16 : y;\
+  u = u < 16 ? 16 : u;\
+  v = v < 16 ? 16 : v;\
+  y = y > 235 ? 235 : y;\
+  u = u > 240 ? 240 : u;\
+  v = v > 240 ? 240 : v
+
 #endif
 
index ad00a6bc8a536c7ff9d8b3bc53e0f58238b18aa4..379abf8ebf485c0c05b31427d01ef212d20d78c2 100644 (file)
@@ -15,7 +15,8 @@ OBJS = factory.o \
           filter_watermark.o \
           transition_composite.o \
           transition_luma.o \
-          transition_mix.o 
+          transition_mix.o \
+          producer_colour.o 
 
 CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
 
index 252b719a733329123f8213e6889605ced4e46594..54af3ea35d7d62be05b65078630b0de22467233e 100755 (executable)
@@ -5,6 +5,7 @@ then
 
 cat << EOF >> ../producers.dat
 ppm                            libmltcore.so
+colour                 libmltcore.so
 EOF
 
 cat << EOF >> ../filters.dat
index 624ec32c0da91711276480672cd768d0a74da29c..6812dfbbf94831e2f65ced198e11e534eafbbba6 100644 (file)
 #include "transition_composite.h"
 #include "transition_luma.h"
 #include "transition_mix.h"
+#include "producer_colour.h"
 
 void *mlt_create_producer( char *id, void *arg )
 {
+       if ( !strcmp( id, "colour" ) )
+               return producer_colour_init( arg );
        if ( !strcmp( id, "ppm" ) )
                return producer_ppm_init( arg );
        return NULL;
diff --git a/src/modules/core/producer_colour.c b/src/modules/core/producer_colour.c
new file mode 100644 (file)
index 0000000..6ff180f
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * producer_colour.c -- raster image loader based upon gdk-pixbuf
+ * 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 "producer_colour.h"
+#include <framework/mlt_frame.h>
+#include <framework/mlt_pool.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+typedef struct
+{
+       uint8_t r, g, b, a;
+} rgba_color;
+
+static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
+static void producer_close( mlt_producer parent );
+
+mlt_producer producer_colour_init( char *colour )
+{
+       mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
+       if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )
+       {
+               // Get the properties interface
+               mlt_properties properties = mlt_producer_properties( producer );
+       
+               // Callback registration
+               producer->get_frame = producer_get_frame;
+               producer->close = producer_close;
+
+               // Set the default properties
+               if ( colour == NULL )
+                       colour = "0x000000ff";
+               mlt_properties_set( properties, "resource", colour );
+               
+               return producer;
+       }
+       free( producer );
+       return NULL;
+}
+
+rgba_color parse_color( char *color )
+{
+       rgba_color result = { 0xff, 0xff, 0xff, 0xff };
+
+       if ( !strncmp( color, "0x", 2 ) )
+       {
+               unsigned int temp = 0;
+               sscanf( color + 2, "%x", &temp );
+               result.r = ( temp >> 24 ) & 0xff;
+               result.g = ( temp >> 16 ) & 0xff;
+               result.b = ( temp >> 8 ) & 0xff;
+               result.a = ( temp ) & 0xff;
+       }
+       else if ( !strcmp( color, "red" ) )
+       {
+               result.r = 0xff;
+               result.g = 0x00;
+               result.b = 0x00;
+       }
+       else if ( !strcmp( color, "green" ) )
+       {
+               result.r = 0x00;
+               result.g = 0xff;
+               result.b = 0x00;
+       }
+       else if ( !strcmp( color, "blue" ) )
+       {
+               result.r = 0x00;
+               result.g = 0x00;
+               result.b = 0xff;
+       }
+       else if ( strcmp( color, "white" ) )
+       {
+               unsigned int temp = 0;
+               sscanf( color, "%d", &temp );
+               result.r = ( temp >> 24 ) & 0xff;
+               result.g = ( temp >> 16 ) & 0xff;
+               result.b = ( temp >> 8 ) & 0xff;
+               result.a = ( temp ) & 0xff;
+       }
+
+       return result;
+}
+
+static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
+{
+       // May need to know the size of the image to clone it
+       int size = 0;
+       
+       // Obtain properties of frame
+       mlt_properties properties = mlt_frame_properties( frame );
+
+       // Obtain the producer for this frame
+       mlt_producer producer = mlt_properties_get_data( properties, "producer_colour", NULL );
+
+       // Obtain properties of producer
+       mlt_properties producer_props = mlt_producer_properties( producer );
+
+       // Get the current image and dimensions cached in the producer
+       uint8_t *image = mlt_properties_get_data( producer_props, "image", &size );
+       int current_width = mlt_properties_get_int( producer_props, "width" );
+       int current_height = mlt_properties_get_int( producer_props, "height" );
+
+       // See if we need to regenerate
+       if ( *width != current_width || *height != current_height )
+       {
+       fprintf( stderr, "%dx%d\n", *width, *height );
+               // Allocate the image
+               size = *width * *height * 2;
+               image = mlt_pool_alloc( size );
+
+               // Update the producer
+               mlt_properties_set_data( producer_props, "image", image, size, mlt_pool_release, NULL );
+               mlt_properties_set_int( producer_props, "width", *width );
+               mlt_properties_set_int( producer_props, "height", *height );
+
+               // Color the image
+               rgba_color color = parse_color( mlt_properties_get( producer_props, "resource" ) );
+               uint8_t y, u, v;
+               int i;
+               RGB2YUV( color.r, color.g, color.b, y, u, v );
+               color.r = y;
+               color.g = u;
+               color.b = y;
+               color.a = v;
+               for ( i = 0; i < size; i += 4 )
+                       memcpy( &image[ i ], &color, 4 );
+       }
+
+       // Update the frame
+       mlt_properties_set_data( properties, "image", image, size, NULL, NULL );
+       mlt_properties_set_int( properties, "width", *width );
+       mlt_properties_set_int( properties, "height", *height );
+       
+       // Clone if necessary
+       if ( writable )
+       {
+               // Clone our image
+               uint8_t *copy = mlt_pool_alloc( size );
+               memcpy( copy, image, size );
+
+               // We're going to pass the copy on
+               image = copy;
+
+               // Now update properties so we free the copy after
+               mlt_properties_set_data( properties, "image", copy, size, mlt_pool_release, NULL );
+       }
+
+       // Pass on the image
+       *buffer = image;
+       *format = mlt_image_yuv422;
+
+       return 0;
+}
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+{
+       // Generate a frame
+       *frame = mlt_frame_init( );
+
+       if ( *frame != NULL )
+       {
+               // Obtain properties of frame and producer
+               mlt_properties properties = mlt_frame_properties( *frame );
+
+               // Obtain properties of producer
+               mlt_properties producer_props = mlt_producer_properties( producer );
+
+               // Set the producer on the frame properties
+               mlt_properties_set_data( properties, "producer_colour", producer, 0, NULL, NULL );
+
+               // Update timecode on the frame we're creating
+               mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
+
+               // Set producer-specific frame properties
+               mlt_properties_set_int( properties, "progressive", 1 );
+
+               // colour is an alias for resource
+               if ( mlt_properties_get( producer_props, "colour" ) != NULL )
+                       mlt_properties_set( producer_props, "resource", mlt_properties_get( producer_props, "colour" ) );
+               
+               // Push the get_image method
+               mlt_frame_push_get_image( *frame, producer_get_image );
+       }
+
+       // Calculate the next timecode
+       mlt_producer_prepare_next( producer );
+
+       return 0;
+}
+
+static void producer_close( mlt_producer producer )
+{
+       producer->close = NULL;
+       mlt_producer_close( producer );
+       free( producer );
+}
+
diff --git a/src/modules/core/producer_colour.h b/src/modules/core/producer_colour.h
new file mode 100644 (file)
index 0000000..fe120f9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * producer_colour.h -- raster image loader based upon gdk-pixbuf
+ * 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 _PRODUCER_COLOUR_H_
+#define _PRODUCER_COLOUR_H_
+
+#include <framework/mlt_producer.h>
+
+extern mlt_producer producer_colour_init( char *filename );
+
+#endif