Skip to content

Commit

Permalink
libgui|Image: Color mixing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent e83aa94 commit 0eddee8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doomsday/libs/gui/include/de/graphics/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class LIBGUI_PUBLIC Image : public ISerializable
}
static Vec4f hsv(Color color); // normalized HSV
static Color fromHsv(const Vec4f &hsv); // normalized HSV
static Color mix(Color a, Color b, Color m);

public:
Image();
Expand Down
15 changes: 15 additions & 0 deletions doomsday/libs/gui/src/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,4 +1465,19 @@ Image::Color Image::fromHsv(const Vec4f &hsv)
return (rgb.min(Vec4f(1, 1, 1, 1)).max(Vec4f()) * 255.f + Vec4f(.5f, .5f, .5f, .5f)).toVec4ub();
}

Image::Color Image::mix(Color a, Color b, Color m)
{
const duint mr = m.x;
const duint mg = m.y;
const duint mb = m.z;
const duint ma = m.w;

int red = (b.x * mr + a.x * (255u - mr)) / 255u;
int green = (b.y * mg + a.y * (255u - mg)) / 255u;
int blue = (b.z * mb + a.z * (255u - mb)) / 255u;
int alpha = (b.w * ma + a.w * (255u - ma)) / 255u;

return makeColor(red, green, blue, alpha);
}

} // namespace de

0 comments on commit 0eddee8

Please sign in to comment.