Skip to content

ofColor: new getHsb() to retrieve values as glm::vec3 #8006

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
merged 5 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion libs/openFrameworks/types/ofColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ class ofColor_{
float saturation,
float brightness,
float alpha = limit());

void setHsb(glm::vec3 hsb) {
setHsb(hsb.x, hsb.y, hsb.z);
}
void setNormalizedHsb(glm::vec3 hsb) {
hsb *= limit();
setHsb(hsb.x, hsb.y, hsb.z);
}
/// \}

/// \name Modifiers
Expand Down Expand Up @@ -303,6 +309,22 @@ class ofColor_{
/// \param brightness A reference to the brightness to fill. Will be in the
/// range of 0 - limit().
void getHsb(float& hue, float& saturation, float& brightness) const;

/// \brief Extract the hue, saturation and brightness (HSB) from this color.
///
/// \returns the 3 color-native values in a glm::vec3
glm::vec3 getHsb() const {
float h, s, b;
getHsb(h,s,b);
return { h, s, b };
}

/// \brief Extract the hue, saturation and brightness (HSB) from this color.
///
/// \returns the 3 values normalized 0-1 in a glm::vec3
glm::vec3 getNormalizedHsb() const {
return getHsb()/limit();
}

/// \brief Get the maximum value of a color component.
///
Expand Down