From: Dan Dennedy Date: Tue, 28 May 2013 04:17:20 +0000 (-0700) Subject: Add mlt_color and mlt_properties_get_color(). X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6e2455d36714aacd635a1a297501d5501c9834f2;p=mlt Add mlt_color and mlt_properties_get_color(). --- diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index a8cef7d1..705ccdf6 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -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 diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index 8c0d0a3c..ec790687 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -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 ); diff --git a/src/framework/mlt_types.h b/src/framework/mlt_types.h index fbd41900..bf1c1c47 100644 --- a/src/framework/mlt_types.h +++ b/src/framework/mlt_types.h @@ -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 */ diff --git a/src/mlt++/MltProperties.cpp b/src/mlt++/MltProperties.cpp index e493a36c..b037025d 100644 --- a/src/mlt++/MltProperties.cpp +++ b/src/mlt++/MltProperties.cpp @@ -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 ); diff --git a/src/mlt++/MltProperties.h b/src/mlt++/MltProperties.h index 6a710e4b..78e3405c 100644 --- a/src/mlt++/MltProperties.h +++ b/src/mlt++/MltProperties.h @@ -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 ); diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index db02688c..8e04e706 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -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)