Skip to content

Commit

Permalink
Add RGB minus operator
Browse files Browse the repository at this point in the history
  • Loading branch information
SnijderC authored and yaqwsx committed Feb 1, 2023
1 parent d546c82 commit 832939c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ Rgb& Rgb::operator+=( Rgb in ) {
return *this;
}

Rgb Rgb::operator-( Rgb in ) const {
auto copy = *this;
copy -= in;
return copy;
}

Rgb& Rgb::operator-=( Rgb in ) {
r = ( in.r > r ) ? 0 : r - in.r;
g = ( in.g > g ) ? 0 : g - in.g;
b = ( in.b > b ) ? 0 : b - in.b;
return *this;
}

Rgb& Rgb::blend( Rgb in ) {
unsigned int inAlpha = in.a * ( 255 - a );
unsigned int alpha = a + inAlpha;
Expand Down
2 changes: 2 additions & 0 deletions src/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ union Rgb {
Rgb& operator=( Hsv hsv );
Rgb operator+( Rgb in ) const;
Rgb& operator+=( Rgb in );
Rgb operator-(Rgb in) const;
Rgb &operator-=(Rgb in);
bool operator==( Rgb in ) const { return in.value == value; }
Rgb& blend( Rgb in );
void swap( Rgb& o ) { value = o.value; }
Expand Down

0 comments on commit 832939c

Please sign in to comment.