From e7a173f826e52501125c04a93218870f34427699 Mon Sep 17 00:00:00 2001 From: Diego Mateos Date: Wed, 15 Nov 2023 09:27:03 +0100 Subject: [PATCH 1/2] Restrict use of color vec components to XYZW - Be able to compile using GLM_FORCE_XYZW_ONLY --- include/cinder/Color.h | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/include/cinder/Color.h b/include/cinder/Color.h index 73b5902c54..042fd40976 100644 --- a/include/cinder/Color.h +++ b/include/cinder/Color.h @@ -51,9 +51,8 @@ class CI_API ColorT : r( src.r ), g( src.g ), b( src.b ) {} ColorT( const vec3 &src ) - : r( CHANTRAIT::convert( src.r ) ), g( CHANTRAIT::convert( src.g ) ), b( CHANTRAIT::convert( src.b ) ) + : r( CHANTRAIT::convert( src.x ) ), g( CHANTRAIT::convert( src.y ) ), b( CHANTRAIT::convert( src.z ) ) {} - ColorT( const char *svgColorName ); ColorT( ColorModel cm, const vec3 &v ); @@ -93,21 +92,21 @@ class CI_API ColorT T* ptr() const { return &(const_cast( this )->r); } ColorT operator+( const ColorT &rhs ) const { return ColorT( r + rhs.r, g + rhs.g, b + rhs.b ); } - ColorT operator+( const glm::vec3 &rhs ) const { return ColorT( r + CHANTRAIT::convert( rhs.r ), g + CHANTRAIT::convert( rhs.g ), b + CHANTRAIT::convert( rhs.b ) ); } + ColorT operator+( const glm::vec3 &rhs ) const { return ColorT( r + CHANTRAIT::convert( rhs.x ), g + CHANTRAIT::convert( rhs.y ), b + CHANTRAIT::convert( rhs.z ) ); } ColorT operator-( const ColorT &rhs ) const { return ColorT( r - rhs.r, g - rhs.g, b - rhs.b ); } - ColorT operator-( const glm::vec3 &rhs ) const { return ColorT( r - CHANTRAIT::convert( rhs.r ), g - CHANTRAIT::convert( rhs.g ), b - CHANTRAIT::convert( rhs.b ) ); } + ColorT operator-( const glm::vec3 &rhs ) const { return ColorT( r - CHANTRAIT::convert( rhs.x ), g - CHANTRAIT::convert( rhs.y ), b - CHANTRAIT::convert( rhs.z ) ); } ColorT operator*( const ColorT &rhs ) const { return ColorT( r * rhs.r, g * rhs.g, b * rhs.b ); } - ColorT operator*( const glm::vec3 &rhs ) const { return ColorT( r * CHANTRAIT::convert( rhs.r ), g * CHANTRAIT::convert( rhs.g ), b * CHANTRAIT::convert( rhs.b ) ); } + ColorT operator*( const glm::vec3 &rhs ) const { return ColorT( r * CHANTRAIT::convert( rhs.x ), g * CHANTRAIT::convert( rhs.y ), b * CHANTRAIT::convert( rhs.z ) ); } ColorT operator/( const ColorT &rhs ) const { return ColorT( r / rhs.r, g / rhs.g, b / rhs.b ); } - ColorT operator/( const glm::vec3 &rhs ) const { return ColorT( r / CHANTRAIT::convert( rhs.r ), g / CHANTRAIT::convert( rhs.g ), b / CHANTRAIT::convert( rhs.b ) ); } + ColorT operator/( const glm::vec3 &rhs ) const { return ColorT( r / CHANTRAIT::convert( rhs.x ), g / CHANTRAIT::convert( rhs.y ), b / CHANTRAIT::convert( rhs.z ) ); } const ColorT& operator+=( const ColorT &rhs ) { r += rhs.r; g += rhs.g; b += rhs.b; return *this; } - const ColorT& operator+=( const glm::vec3 &rhs ) { r += CHANTRAIT::convert( rhs.r ); g += CHANTRAIT::convert( rhs.g ); b += CHANTRAIT::convert( rhs.b ); return *this; } + const ColorT& operator+=( const glm::vec3 &rhs ) { r += CHANTRAIT::convert( rhs.x ); g += CHANTRAIT::convert( rhs.y ); b += CHANTRAIT::convert( rhs.z ); return *this; } const ColorT& operator-=( const ColorT &rhs ) { r -= rhs.r; g -= rhs.g; b -= rhs.b; return *this; } - const ColorT& operator-=( const glm::vec3 &rhs ) { r -= CHANTRAIT::convert( rhs.r ); g -= CHANTRAIT::convert( rhs.g ); b -= CHANTRAIT::convert( rhs.b ); return *this; } + const ColorT& operator-=( const glm::vec3 &rhs ) { r -= CHANTRAIT::convert( rhs.x ); g -= CHANTRAIT::convert( rhs.y ); b -= CHANTRAIT::convert( rhs.z ); return *this; } const ColorT& operator*=( const ColorT &rhs ) { r *= rhs.r; g *= rhs.g; b *= rhs.b; return *this; } - const ColorT& operator*=( const glm::vec3 &rhs ) { r *= CHANTRAIT::convert( rhs.r ); g *= CHANTRAIT::convert( rhs.g ); b *= CHANTRAIT::convert( rhs.b ); return *this; } + const ColorT& operator*=( const glm::vec3 &rhs ) { r *= CHANTRAIT::convert( rhs.x ); g *= CHANTRAIT::convert( rhs.y ); b *= CHANTRAIT::convert( rhs.z ); return *this; } const ColorT& operator/=( const ColorT &rhs ) { r /= rhs.r; g /= rhs.g; b /= rhs.b; return *this; } - const ColorT& operator/=( const glm::vec3 &rhs ) { r /= CHANTRAIT::convert( rhs.r ); g /= CHANTRAIT::convert( rhs.g ); b /= CHANTRAIT::convert( rhs.b ); return *this; } + const ColorT& operator/=( const glm::vec3 &rhs ) { r /= CHANTRAIT::convert( rhs.x ); g /= CHANTRAIT::convert( rhs.y ); b /= CHANTRAIT::convert( rhs.z ); return *this; } ColorT operator+( T rhs ) const { return ColorT( r + rhs, g + rhs, b + rhs ); } ColorT operator-( T rhs ) const { return ColorT( r - rhs, g - rhs, b - rhs ); } ColorT operator*( T rhs ) const { return ColorT( r * rhs, g * rhs, b * rhs ); } @@ -199,7 +198,7 @@ class CI_API ColorAT { {} ColorAT( const vec4 &src ) - : r( CHANTRAIT::convert( src.r ) ), g( CHANTRAIT::convert( src.g ) ), b( CHANTRAIT::convert( src.b ) ), a( CHANTRAIT::convert( src.a ) ) + : r( CHANTRAIT::convert( src.x ) ), g( CHANTRAIT::convert( src.y ) ), b( CHANTRAIT::convert( src.z ) ), a( CHANTRAIT::convert( src.w ) ) { } @@ -238,27 +237,27 @@ class CI_API ColorAT { T* ptr() const { return &(const_cast( this )->r); } ColorAT operator+( const ColorAT &rhs ) const { return ColorAT( r + rhs.r, g + rhs.g, b + rhs.b, a + rhs.a ); } - ColorAT operator+( const glm::vec4 &rhs ) const { return ColorAT( r + CHANTRAIT::convert( rhs.r ), g + CHANTRAIT::convert( rhs.g ), b + CHANTRAIT::convert( rhs.b ), a + CHANTRAIT::convert( rhs.a ) ); } + ColorAT operator+( const glm::vec4 &rhs ) const { return ColorAT( r + CHANTRAIT::convert( rhs.x ), g + CHANTRAIT::convert( rhs.y ), b + CHANTRAIT::convert( rhs.z ), a + CHANTRAIT::convert( rhs.w ) ); } ColorAT operator-( const ColorAT &rhs ) const { return ColorAT( r - rhs.r, g - rhs.g, b - rhs.b, a - rhs.a ); } - ColorAT operator-( const glm::vec4 &rhs ) const { return ColorAT( r - CHANTRAIT::convert( rhs.r ), g - CHANTRAIT::convert( rhs.g ), b - CHANTRAIT::convert( rhs.b ), a - CHANTRAIT::convert( rhs.a ) ); } + ColorAT operator-( const glm::vec4 &rhs ) const { return ColorAT( r - CHANTRAIT::convert( rhs.x ), g - CHANTRAIT::convert( rhs.y ), b - CHANTRAIT::convert( rhs.z ), a - CHANTRAIT::convert( rhs.w ) ); } ColorAT operator*( const ColorAT &rhs ) const { return ColorAT( r * rhs.r, g * rhs.g, b * rhs.b, a * rhs.a ); } - ColorAT operator*( const glm::vec4 &rhs ) const { return ColorAT( r * CHANTRAIT::convert( rhs.r ), g * CHANTRAIT::convert( rhs.g ), b * CHANTRAIT::convert( rhs.b ), a * CHANTRAIT::convert( rhs.a ) ); } + ColorAT operator*( const glm::vec4 &rhs ) const { return ColorAT( r * CHANTRAIT::convert( rhs.x ), g * CHANTRAIT::convert( rhs.y ), b * CHANTRAIT::convert( rhs.z ), a * CHANTRAIT::convert( rhs.w ) ); } ColorAT operator/( const ColorAT &rhs ) const { return ColorAT( r / rhs.r, g / rhs.g, b / rhs.b, a / rhs.a ); } - ColorAT operator/( const glm::vec4 &rhs ) const { return ColorAT( r / CHANTRAIT::convert( rhs.r ), g / CHANTRAIT::convert( rhs.g ), b / CHANTRAIT::convert( rhs.b ), a / CHANTRAIT::convert( rhs.a ) ); } + ColorAT operator/( const glm::vec4 &rhs ) const { return ColorAT( r / CHANTRAIT::convert( rhs.x ), g / CHANTRAIT::convert( rhs.y ), b / CHANTRAIT::convert( rhs.z ), a / CHANTRAIT::convert( rhs.w ) ); } const ColorAT& operator+=( const ColorAT &rhs ) { r += rhs.r; g += rhs.g; b += rhs.b; a += rhs.a; return *this; } - const ColorAT& operator+=( const glm::vec4 &rhs ) { r += CHANTRAIT::convert( rhs.r ); g += CHANTRAIT::convert( rhs.g ); b += CHANTRAIT::convert( rhs.b ); a += CHANTRAIT::convert( rhs.a ); return *this; } + const ColorAT& operator+=( const glm::vec4 &rhs ) { r += CHANTRAIT::convert( rhs.x ); g += CHANTRAIT::convert( rhs.y ); b += CHANTRAIT::convert( rhs.z ); a += CHANTRAIT::convert( rhs.w ); return *this; } const ColorAT& operator-=( const ColorAT &rhs ) { r -= rhs.r; g -= rhs.g; b -= rhs.b; a -= rhs.a; return *this; } - const ColorAT& operator-=( const glm::vec4 &rhs ) { r -= CHANTRAIT::convert( rhs.r ); g -= CHANTRAIT::convert( rhs.g ); b -= CHANTRAIT::convert( rhs.b ); a -= CHANTRAIT::convert( rhs.a ); return *this; } + const ColorAT& operator-=( const glm::vec4 &rhs ) { r -= CHANTRAIT::convert( rhs.x ); g -= CHANTRAIT::convert( rhs.y ); b -= CHANTRAIT::convert( rhs.z ); a -= CHANTRAIT::convert( rhs.w ); return *this; } const ColorAT& operator*=( const ColorAT &rhs ) { r *= rhs.r; g *= rhs.g; b *= rhs.b; a *= rhs.a; return *this; } - const ColorAT& operator*=( const glm::vec4 &rhs ) { r *= CHANTRAIT::convert( rhs.r ); g *= CHANTRAIT::convert( rhs.g ); b *= CHANTRAIT::convert( rhs.b ); a *= CHANTRAIT::convert( rhs.a ); return *this; } + const ColorAT& operator*=( const glm::vec4 &rhs ) { r *= CHANTRAIT::convert( rhs.x ); g *= CHANTRAIT::convert( rhs.y ); b *= CHANTRAIT::convert( rhs.z ); a *= CHANTRAIT::convert( rhs.w ); return *this; } const ColorAT& operator/=( const ColorAT &rhs ) { r /= rhs.r; g /= rhs.g; b /= rhs.b; a /= rhs.a; return *this; } - const ColorAT& operator/=( const vec4 &rhs ) { r /= CHANTRAIT::convert( rhs.r ); g /= CHANTRAIT::convert( rhs.g ); b /= CHANTRAIT::convert( rhs.b ); a /= CHANTRAIT::convert( rhs.a ); return *this; } + const ColorAT& operator/=( const vec4 &rhs ) { r /= CHANTRAIT::convert( rhs.x ); g /= CHANTRAIT::convert( rhs.y ); b /= CHANTRAIT::convert( rhs.z ); a /= CHANTRAIT::convert( rhs.w ); return *this; } ColorAT operator+( T rhs ) const { return ColorAT( r + rhs, g + rhs, b + rhs, a + rhs ); } ColorAT operator-( T rhs ) const { return ColorAT( r - rhs, g - rhs, b - rhs, a - rhs ); } ColorAT operator*( T rhs ) const { return ColorAT( r * rhs, g * rhs, b * rhs, a * rhs ); } ColorAT operator/( T rhs ) const { return ColorAT( r / rhs, g / rhs, b / rhs, a / rhs ); } - const ColorAT& operator+=( T rhs ) { r += rhs; g += rhs; b += rhs; a += rhs; return *this; } - const ColorAT& operator-=( T rhs ) { r -= rhs; g -= rhs; b -= rhs; a -= rhs; return * this; } + const ColorAT& operator+=( T rhs ) { r += rhs; g += rhs; b += rhs; a += rhs; return *this; } + const ColorAT& operator-=( T rhs ) { r -= rhs; g -= rhs; b -= rhs; a -= rhs; return * this; } const ColorAT& operator*=( T rhs ) { r *= rhs; g *= rhs; b *= rhs; a *= rhs; return * this; } const ColorAT& operator/=( T rhs ) { r /= rhs; g /= rhs; b /= rhs; a /= rhs; return * this; } @@ -307,7 +306,7 @@ class CI_API ColorAT { { uint8_t red = ( hexValue >> 16 ) & 255; uint8_t green = ( hexValue >> 8 ) & 255; - uint8_t blue = hexValue & 255; + uint8_t blue = hexValue & 255; return ColorAT( CHANTRAIT::convert( red ), CHANTRAIT::convert( green ), CHANTRAIT::convert( blue ), CHANTRAIT::max() ); } From 78a11898bfe3b2f2516a6adccfe7dd876620464e Mon Sep 17 00:00:00 2001 From: Diego Mateos Date: Wed, 15 Nov 2023 10:11:30 +0100 Subject: [PATCH 2/2] Restrict to XYZW in cpp too... --- src/cinder/Color.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cinder/Color.cpp b/src/cinder/Color.cpp index 818b318230..c741ca8c53 100644 --- a/src/cinder/Color.cpp +++ b/src/cinder/Color.cpp @@ -192,9 +192,9 @@ void ColorAT::set( ColorModel cm, const vec4 &v ) } break; case CM_RGB: - r = CHANTRAIT::convert( v.r ); - g = CHANTRAIT::convert( v.g ); - b = CHANTRAIT::convert( v.b ); + r = CHANTRAIT::convert( v.x ); + g = CHANTRAIT::convert( v.y ); + b = CHANTRAIT::convert( v.z ); break; default: throw ImageIoExceptionIllegalColorModel();