-
Notifications
You must be signed in to change notification settings - Fork 320
Per-Track and Per-Clip Color #1887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jminor
merged 2 commits into
AcademySoftwareFoundation:main
from
dreamworksanimation:clip_color
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the OpenTimelineIO project | ||
|
|
||
| #include <iomanip> | ||
| #include <sstream> | ||
|
|
||
| #include "opentimelineio/color.h" | ||
|
|
||
| namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { | ||
|
|
||
| Color::Color( | ||
| double const r, | ||
| double const g, | ||
| double const b, | ||
| double const a, | ||
| std::string const& name) | ||
| : _name(name), | ||
| _r(r), | ||
| _g(g), | ||
| _b(b), | ||
| _a(a) {} | ||
|
|
||
| Color::Color(Color const& other) : _name(other.name()), | ||
| _r(other.r()), | ||
| _g(other.g()), | ||
| _b(other.b()), | ||
| _a(other.a()) {} | ||
|
|
||
| const Color Color::pink(1.0, 0.0, 1.0, 1.0, "Pink"); | ||
| const Color Color::red(1.0, 0.0, 0.0, 1.0, "Red"); | ||
| const Color Color::orange(1.0, 0.5, 0.0, 1.0, "Orange"); | ||
| const Color Color::yellow(1.0, 1.0, 0.0, 1.0, "Yellow"); | ||
| const Color Color::green(0.0, 1.0, 0.0, 1.0, "Green"); | ||
| const Color Color::cyan(0.0, 1.0, 1.0, 1.0, "Cyan"); | ||
| const Color Color::blue(0.0, 0.0, 1.0, 1.0, "Blue"); | ||
| const Color Color::purple(0.5, 0.0, 0.5, 1.0, "Purple"); | ||
| const Color Color::magenta(1.0, 0.0, 1.0, 1.0, "Magenta"); | ||
| const Color Color::black(0.0, 0.0, 0.0, 1.0, "Black"); | ||
| const Color Color::white(1.0, 1.0, 1.0, 1.0, "White"); | ||
| const Color Color::transparent(1.0, 1.0, 1.0, 0.0, "Transparent"); | ||
|
|
||
| Color* | ||
| Color::from_hex(std::string const& color) | ||
| { | ||
| std::string temp = color; | ||
| if (temp[0] == '#') | ||
| { | ||
| temp = temp.substr(1); | ||
| } | ||
| else if (temp[0] == '0' && (temp[1] == 'x' || temp[1] == 'X')) | ||
| { | ||
| temp = temp.substr(2); | ||
| } | ||
|
|
||
| double _r, _g, _b, _a; | ||
| // 0xFFFFFFFF (rgba, 255) | ||
| int BASE_16 = 16; | ||
| double BASE_16_DIV = 255.0; | ||
| double BASE_8_DIV = 15.0; | ||
| if (temp.length() == 8) | ||
| { | ||
| _r = std::stoi(temp.substr(0, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _g = std::stoi(temp.substr(2, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _b = std::stoi(temp.substr(4, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _a = std::stoi(temp.substr(6, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| } | ||
| // 0xFFFFFF (rgb, 255) | ||
| else if (temp.length() == 6) | ||
| { | ||
| _r = std::stoi(temp.substr(0, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _g = std::stoi(temp.substr(2, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _b = std::stoi(temp.substr(4, 2), nullptr, BASE_16) / BASE_16_DIV; | ||
| _a = 1.0; | ||
| } | ||
| // 0xFFF (rgb, 16) | ||
| else if (temp.length() == 3) | ||
| { | ||
| _r = std::stoi(temp.substr(0, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _g = std::stoi(temp.substr(1, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _b = std::stoi(temp.substr(2, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _a = 1.0; | ||
| } | ||
| // 0xFFFF (rgba, 16) | ||
| else if (temp.length() == 4) | ||
| { | ||
| _r = std::stoi(temp.substr(0, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _g = std::stoi(temp.substr(1, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _b = std::stoi(temp.substr(2, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| _a = std::stoi(temp.substr(3, 1), nullptr, BASE_16) / BASE_8_DIV; | ||
| } | ||
| else { | ||
| throw std::invalid_argument("Invalid hex format"); | ||
| } | ||
| return new Color(_r, _g, _b, _a); | ||
| } | ||
|
|
||
| Color* | ||
| Color::from_int_list(std::vector<int> const& color, int bit_depth) | ||
| { | ||
| double depth = pow(2, bit_depth) - 1.0; // e.g. 8 = 255.0 | ||
| if (color.size() == 3) | ||
| return new Color(color[0] / depth, color[1] / depth, color[2] / depth, 1.0); | ||
| else if (color.size() == 4) | ||
| return new Color(color[0] / depth, color[1] / depth, color[2] / depth, color[3] / depth); | ||
|
|
||
| throw std::invalid_argument("List must have exactly 3 or 4 elements"); | ||
| } | ||
|
|
||
| Color* | ||
| Color::from_agbr_int(unsigned int agbr) noexcept | ||
| { | ||
| auto conv_r = (agbr & 0xFF) / 255.0; | ||
| auto conv_g = ((agbr >> 16) & 0xFF) / 255.0; | ||
| auto conv_b = ((agbr >> 8) & 0xFF) / 255.0; | ||
| auto conv_a = ((agbr >> 24) & 0xFF) / 255.0; | ||
| return new Color(conv_r, conv_g, conv_b, conv_a); | ||
| } | ||
|
|
||
| Color* | ||
| Color::from_float_list(std::vector<double> const& color) | ||
| { | ||
| if (color.size() == 3) | ||
| return new Color(color[0], color[1], color[2], 1.0); | ||
| else if (color.size() == 4) | ||
| return new Color(color[0], color[1], color[2], color[3]); | ||
|
|
||
| throw std::invalid_argument("List must have exactly 3 or 4 elements"); | ||
| } | ||
|
|
||
| std::string | ||
| Color::to_hex() | ||
| { | ||
| auto rgba = to_rgba_int_list(8); | ||
| std::stringstream ss; | ||
| ss << "#"; | ||
|
|
||
| ss << std::hex << std::setfill('0'); | ||
| ss << std::setw(2) << rgba[0]; | ||
| ss << std::setw(2) << rgba[1]; | ||
| ss << std::setw(2) << rgba[2]; | ||
| ss << std::setw(2) << rgba[3]; | ||
| return ss.str(); | ||
| } | ||
|
|
||
| std::vector<int> | ||
| Color::to_rgba_int_list(int base) | ||
| { | ||
| double math_base = pow(2, base) - 1.0; | ||
| return {int(_r * math_base), int(_g * math_base), int(_b * math_base), int(_a * math_base)}; | ||
| } | ||
|
|
||
| unsigned int | ||
| Color::to_agbr_integer() | ||
| { | ||
| auto rgba = to_rgba_int_list(8); | ||
| return (rgba[3] << 24) + (rgba[2] << 16) + (rgba[1] << 8) + rgba[0]; | ||
| } | ||
|
|
||
| std::vector<double> | ||
| Color::to_rgba_float_list() | ||
| { | ||
| return {_r, _g, _b, _a}; | ||
| } | ||
|
|
||
| }} // namespace opentimelineio::OPENTIMELINEIO_VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the OpenTimelineIO project | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cmath> | ||
| #include <vector> | ||
|
|
||
| #include "opentimelineio/version.h" | ||
|
|
||
| namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { | ||
|
|
||
|
|
||
| /// @brief Color consists 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. | ||
| /// This class is meant for use in user interface elements, | ||
| // like marker or clip coloring, NOT for image pixel content. | ||
| class Color | ||
| { | ||
| public: | ||
| struct Schema | ||
| { | ||
| static auto constexpr name = "Color"; | ||
| static int constexpr version = 1; | ||
| }; | ||
|
|
||
| Color( | ||
| double const r = 1.f, | ||
| double const g = 1.f, | ||
| double const b = 1.f, | ||
| double const a = 1.f, | ||
| std::string const& name = ""); | ||
|
|
||
| Color(Color const& other); | ||
|
|
||
| static const Color pink; | ||
| static const Color red; | ||
| static const Color orange; | ||
| static const Color yellow; | ||
| static const Color green; | ||
| static const Color cyan; | ||
| static const Color blue; | ||
| static const Color purple; | ||
| static const Color magenta; | ||
| static const Color black; | ||
| static const Color white; | ||
| static const Color transparent; | ||
semagnum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static Color* from_hex(std::string const& color); | ||
| static Color* from_int_list(std::vector<int> const& color, int bit_depth); | ||
| static Color* from_agbr_int(unsigned int agbr) noexcept; | ||
| static Color* from_float_list(std::vector<double> const& color); | ||
|
|
||
| friend bool | ||
| operator==(Color lhs, Color rhs) noexcept | ||
| { | ||
| return lhs.to_hex() == rhs.to_hex() && lhs.to_agbr_integer() == rhs.to_agbr_integer(); | ||
| } | ||
|
|
||
| std::string to_hex(); | ||
| std::vector<int> to_rgba_int_list(int base); | ||
| unsigned int to_agbr_integer(); | ||
| std::vector<double> to_rgba_float_list(); | ||
|
|
||
| double r() const { return _r; } | ||
| double g() const { return _g; } | ||
| double b() const { return _b; } | ||
| double a() const { return _a; } | ||
| std::string name() const { return _name; } | ||
|
|
||
| void set_r(double r) { _r = r; } | ||
| void set_g(double g) { _g = g; } | ||
| void set_b(double b) { _b = b; } | ||
| void set_a(double a) { _a = a; } | ||
| void set_name(std::string const& name) { _name = name; } | ||
|
|
||
| private: | ||
| double _r; | ||
| double _g; | ||
| double _b; | ||
| double _a; | ||
| std::string _name; | ||
| }; | ||
|
|
||
| }} // namespace opentimelineio::OPENTIMELINEIO_VERSION | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.