producer_framebuffer.c: interpret negative speed as reverse
[melted] / src / modules / core / producer_colour.c
index 9f504f7..ac42001 100644 (file)
@@ -3,22 +3,22 @@
  * 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 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser 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.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; 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_producer.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_pool.h>
 
@@ -35,7 +35,7 @@ typedef struct
 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_colour_init( mlt_profile profile, mlt_service_type type, const char *id, char *colour )
 {
        mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
        if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )
@@ -58,23 +58,11 @@ mlt_producer producer_colour_init( char *colour )
        return NULL;
 }
 
-rgba_color parse_color( char *color )
+rgba_color parse_color( char *color, unsigned int color_int )
 {
        rgba_color result = { 0xff, 0xff, 0xff, 0xff };
 
-       if ( strchr( color, '/' ) )
-               color = strrchr( color, '/' ) + 1;
-
-       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" ) )
+       if ( !strcmp( color, "red" ) )
        {
                result.r = 0xff;
                result.g = 0x00;
@@ -94,12 +82,10 @@ rgba_color parse_color( char *color )
        }
        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;
+               result.r = ( color_int >> 24 ) & 0xff;
+               result.g = ( color_int >> 16 ) & 0xff;
+               result.b = ( color_int >> 8 ) & 0xff;
+               result.a = ( color_int ) & 0xff;
        }
 
        return result;
@@ -129,7 +115,12 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        int current_height = mlt_properties_get_int( producer_props, "_height" );
 
        // Parse the colour
-       rgba_color color = parse_color( now );
+       if ( now && strchr( now, '/' ) )
+       {
+               now = strrchr( now, '/' ) + 1;
+               mlt_properties_set( producer_props, "resource", now );
+       }
+       rgba_color color = parse_color( now, mlt_properties_get_int( producer_props, "resource" ) );
 
        // See if we need to regenerate
        if ( strcmp( now, then ) || *width != current_width || *height != current_height )
@@ -198,6 +189,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                // Now update properties so we free the copy after
                mlt_properties_set_data( properties, "image", copy, size, mlt_pool_release, NULL );
                mlt_properties_set_data( properties, "alpha", alpha, size >> 1, mlt_pool_release, NULL );
+               mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_props, "aspect_ratio" ) );
        }
 
        // Pass on the image
@@ -210,7 +202,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
 {
        // Generate a frame
-       *frame = mlt_frame_init( );
+       *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
 
        if ( *frame != NULL )
        {