Skip to content

Commit ffb9b6f

Browse files
committed
Add name and metadata explicitly
Signed-off-by: Spencer Magnusson <spencer.magnusson@dreamworks.com>
1 parent 710eadc commit ffb9b6f

4 files changed

Lines changed: 42 additions & 27 deletions

File tree

src/opentimelineio/color.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,36 @@
99
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
1010

1111
Color::Color(
12-
double const r,
13-
double const g,
14-
double const b,
15-
double const a)
16-
: _r(r),
12+
double const r,
13+
double const g,
14+
double const b,
15+
double const a,
16+
std::string const& name,
17+
AnyDictionary const& metadata)
18+
: Parent(name, metadata),
19+
_r(r),
1720
_g(g),
1821
_b(b),
1922
_a(a) {}
2023

21-
Color::Color(Color const& other) : _r(other.r()),
24+
Color::Color(Color const& other) : Parent(other.name(), other.metadata()),
25+
_r(other.r()),
2226
_g(other.g()),
2327
_b(other.b()),
2428
_a(other.a()) {}
2529

26-
const Color Color::pink(1.0, 0.0, 1.0, 1.0);
27-
const Color Color::red(1.0, 0.0, 0.0, 1.0);
28-
const Color Color::orange(1.0, 0.5, 0.0, 1.0);
29-
const Color Color::yellow(1.0, 1.0, 0.0, 1.0);
30-
const Color Color::green(0.0, 1.0, 0.0, 1.0);
31-
const Color Color::cyan(0.0, 1.0, 1.0, 1.0);
32-
const Color Color::blue(0.0, 0.0, 1.0, 1.0);
33-
const Color Color::purple(0.5, 0.0, 0.5, 1.0);
34-
const Color Color::magenta(1.0, 0.0, 1.0, 1.0);
35-
const Color Color::black(0.0, 0.0, 0.0, 1.0);
36-
const Color Color::white(1.0, 1.0, 1.0, 1.0);
37-
const Color Color::transparent(0.0, 0.0, 0.0, 0.0);
30+
const Color Color::pink(1.0, 0.0, 1.0, 1.0, "Pink");
31+
const Color Color::red(1.0, 0.0, 0.0, 1.0, "Red");
32+
const Color Color::orange(1.0, 0.5, 0.0, 1.0, "Orange");
33+
const Color Color::yellow(1.0, 1.0, 0.0, 1.0, "Yellow");
34+
const Color Color::green(0.0, 1.0, 0.0, 1.0, "Green");
35+
const Color Color::cyan(0.0, 1.0, 1.0, 1.0, "Cyan");
36+
const Color Color::blue(0.0, 0.0, 1.0, 1.0, "Blue");
37+
const Color Color::purple(0.5, 0.0, 0.5, 1.0, "Purple");
38+
const Color Color::magenta(1.0, 0.0, 1.0, 1.0, "Magenta");
39+
const Color Color::black(0.0, 0.0, 0.0, 1.0, "Black");
40+
const Color Color::white(1.0, 1.0, 1.0, 1.0, "White");
41+
const Color Color::transparent(0.0, 0.0, 0.0, 0.0, "Transparent");
3842

3943
std::string
4044
Color::to_hex()

src/opentimelineio/color.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ class Color: public SerializableObjectWithMetadata
2323

2424
using Parent = SerializableObjectWithMetadata;
2525

26-
Color(double const r = 1.f,
27-
double const g = 1.f,
28-
double const b = 1.f,
29-
double const a = 1.f);
26+
Color(
27+
double const r = 1.f,
28+
double const g = 1.f,
29+
double const b = 1.f,
30+
double const a = 1.f,
31+
std::string const& name = "Color",
32+
AnyDictionary const& metadata = AnyDictionary());
3033

3134
Color(Color const& other);
3235

src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ static void define_bases2(py::module m) {
206206
EffectVectorProxy::define_py_class(m, "EffectVector");
207207

208208
py::class_<Color, SOWithMetadata, managing_ptr<Color>>(m, "Color", py::dynamic_attr(), R"docstring(:class:`Color` is a definition of red, green, blue, and alpha double floating point values, allowing conversion between different formats. To be considered interoperable, the sRGB transfer function encoded values, ranging between zero and one, are expected to be accurate to within 1/255 of the intended value. Round-trip conversions may not be guaranteed outside that.)docstring")
209-
.def(py::init([](double r, double g, double b, double a) {
210-
return new Color(r, g, b, a);
211-
}), "r"_a = 1.0, "g"_a = 1.0, "b"_a = 1.0, "a"_a = 1.0)
209+
.def(py::init([](double r, double g, double b, double a, std::string name, py::object metadata) {
210+
return new Color(r, g, b, a, name, py_to_any_dictionary(metadata));
211+
}), "r"_a = 1.0, "g"_a = 1.0, "b"_a = 1.0, "a"_a = 1.0,
212+
py::arg_v("name"_a = std::string()),
213+
py::arg_v("metadata"_a = py::none()))
212214
.def_property("r", &Color::r, &Color::set_r)
213215
.def_property("g", &Color::g, &Color::set_g)
214216
.def_property("b", &Color::b, &Color::set_b)

src/py-opentimelineio/opentimelineio/schema/color.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,31 @@
77

88
@add_method(_otio.Color)
99
def __str__(self):
10-
return 'Color({}, {}, {}, {})'.format(
10+
return 'Color({}, ({}, {}, {}, {}), {})'.format(
11+
repr(self.name),
1112
self.r,
1213
self.g,
1314
self.b,
1415
self.a,
16+
str(self.metadata)
1517
)
1618

1719

1820
@add_method(_otio.Color)
1921
def __repr__(self):
2022
return (
2123
'otio.schema.Color('
24+
'name={}, '
2225
'r={}, '
2326
'g={}, '
2427
'b={}, '
25-
'a={})'.format(
28+
'a={}, '
29+
'metadata={})'.format(
30+
repr(self.name),
2631
repr(self.r),
2732
repr(self.g),
2833
repr(self.b),
2934
repr(self.a),
35+
repr(self.metadata)
3036
)
3137
)

0 commit comments

Comments
 (0)