浏览代码

LibGfx: Add Color::from_cmyk

Matthew Olsson 4 年之前
父节点
当前提交
f4941f5940
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      Userland/Libraries/LibGfx/Color.h

+ 9 - 0
Userland/Libraries/LibGfx/Color.h

@@ -71,6 +71,15 @@ public:
     static constexpr Color from_rgb(unsigned rgb) { return Color(rgb | 0xff000000); }
     static constexpr Color from_rgba(unsigned rgba) { return Color(rgba); }
 
+    static constexpr Color from_cmyk(float c, float m, float y, float k)
+    {
+        auto r = static_cast<u8>(255.0f * (1.0f - c) * (1.0f - k));
+        auto g = static_cast<u8>(255.0f * (1.0f - m) * (1.0f - k));
+        auto b = static_cast<u8>(255.0f * (1.0f - y) * (1.0f - k));
+
+        return Color(r, g, b);
+    }
+
     constexpr u8 red() const { return (m_value >> 16) & 0xff; }
     constexpr u8 green() const { return (m_value >> 8) & 0xff; }
     constexpr u8 blue() const { return m_value & 0xff; }