]> git.sesse.net Git - mlt/commitdiff
Add mlt_color and mlt_properties_get_color().
authorDan Dennedy <dan@dennedy.org>
Tue, 28 May 2013 04:17:20 +0000 (21:17 -0700)
committerDan Dennedy <dan@dennedy.org>
Fri, 31 May 2013 23:58:13 +0000 (16:58 -0700)
src/framework/mlt_properties.c
src/framework/mlt_properties.h
src/framework/mlt_types.h
src/mlt++/MltProperties.cpp
src/mlt++/MltProperties.h
src/tests/test_properties/test_properties.cpp

index a8cef7d163a88e7c5196664e3af52a8786dc95b0..705ccdf67a217d7d909850deb269a8d266d77638 100644 (file)
@@ -2067,6 +2067,54 @@ char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_f
        return NULL;
 }
 
+mlt_color mlt_properties_get_color( mlt_properties self, const char* name )
+{
+       mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
+       double fps = mlt_profile_fps( profile );
+       property_list *list = self->local;
+       mlt_property value = mlt_properties_find( self, name );
+       mlt_color result = { 0xff, 0xff, 0xff, 0xff };
+       if ( value )
+       {
+               const char *color = mlt_property_get_string_l( value, list->locale );
+               unsigned int color_int = mlt_property_get_int( value, fps, list->locale );
+
+               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, "black" ) )
+               {
+                       result.r = 0x00;
+                       result.g = 0x00;
+                       result.b = 0x00;
+               }
+               else if ( strcmp( color, "white" ) )
+               {
+                       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;
+}
+
+
 /** Get a string value by name.
  *
  * Do not free the returned string. It's lifetime is controlled by the property
index 8c0d0a3c945530df590e11a9ae2fb2c4879e1d07..ec79068789e447e4bd851b3c9f1aa7cf68364254 100644 (file)
@@ -89,6 +89,7 @@ extern char *mlt_properties_serialise_yaml( mlt_properties self );
 extern void mlt_properties_lock( mlt_properties self );
 extern void mlt_properties_unlock( mlt_properties self );
 extern char *mlt_properties_get_time( mlt_properties, const char* name, mlt_time_format );
+extern mlt_color mlt_properties_get_color( mlt_properties, const char* name );
 
 extern char* mlt_properties_anim_get( mlt_properties self, const char *name, int position, int length );
 extern int mlt_properties_anim_set( mlt_properties self, const char *name, const char *value, int position, int length );
index fbd41900b30fbd8c465614b6237e591117d320eb..bf1c1c476a8dfcdca9eab8118240df971c61670c 100644 (file)
@@ -129,7 +129,16 @@ typedef struct {
        double w; /**< width */
        double h; /**< height */
        double o; /**< opacity / mix-level */
-} mlt_rect;
+}
+mlt_rect;
+
+typedef struct {
+       uint8_t r;
+       uint8_t g;
+       uint8_t b;
+       uint8_t a;
+}
+mlt_color;
 
 typedef struct mlt_frame_s *mlt_frame, **mlt_frame_ptr; /**< pointer to Frame object */
 typedef struct mlt_property_s *mlt_property;            /**< pointer to Property object */
index e493a36cc6856b870dd6e6029bb15cb82ce048c5..b037025d97a265fd89e5a374d53dd52c297a398d 100644 (file)
@@ -337,6 +337,11 @@ char *Properties::get_time( const char *name, mlt_time_format format )
        return mlt_properties_get_time( get_properties(), name, format );
 }
 
+mlt_color Properties::get_color( const char *name )
+{
+       return mlt_properties_get_color( get_properties(), name );
+}
+
 char *Properties::anim_get( const char *name, int position, int length )
 {
        return mlt_properties_anim_get( get_properties(), name, position, length );
index 6a710e4bf03f419a79c5b64ee827696e892957c2..78e3405cf9fecf383b1a090e80e7f98f27c4effd 100644 (file)
@@ -97,6 +97,7 @@ namespace Mlt
                        int set_lcnumeric( const char *locale );
                        const char *get_lcnumeric( );
                        char *get_time( const char *name, mlt_time_format = mlt_time_smpte );
+                       mlt_color get_color( const char *name );
 
                        char* anim_get( const char *name, int position, int length );
                        int anim_set( const char *name, const char *value, int position, int length );
index db02688cd02f7a83fef706889cbccf0c9c13bd68..8e04e7061a991cda98638b1c39a8652e43c738af 100644 (file)
@@ -836,6 +836,37 @@ private Q_SLOTS:
         QCOMPARE(p.anim_get_rect("key", 25, len).y, 1.0);
     }
 
+    void ColorFromInt()
+    {
+        Properties p;
+        p.set_lcnumeric("POSIX");
+        p.set("key", (int) 0xaabbccdd);
+        mlt_color color = p.get_color("key");
+        QCOMPARE(color.r, quint8(0xaa));
+        QCOMPARE(color.g, quint8(0xbb));
+        QCOMPARE(color.b, quint8(0xcc));
+        QCOMPARE(color.a, quint8(0xdd));
+        p.set("key", *((int*) &color));
+        QCOMPARE(p.get_int("key"), int(0xddccbbaa));
+    }
+
+    void ColorFromString()
+    {
+        Properties p;
+        p.set_lcnumeric("POSIX");
+        p.set("key", "red");
+        mlt_color color = p.get_color("key");
+        QCOMPARE(color.r, quint8(0xff));
+        QCOMPARE(color.g, quint8(0x00));
+        QCOMPARE(color.b, quint8(0x00));
+        QCOMPARE(color.a, quint8(0xff));
+        p.set("key", "#deadd00d");
+        color = p.get_color("key");
+        QCOMPARE(color.r, quint8(0xad));
+        QCOMPARE(color.g, quint8(0xd0));
+        QCOMPARE(color.b, quint8(0x0d));
+        QCOMPARE(color.a, quint8(0xde));
+    }
 };
 
 QTEST_APPLESS_MAIN(TestProperties)