X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcolor.h;h=e57689bffe559d8f411670f910cceaa2ed94ead0;hp=d3710a9d64c745fb85d87a4216222854e4c08730;hb=4a1e2b6a68095e6bb7c212be57abb5a1509739b9;hpb=cea3c333797cadd9629aefaa5b82243173a02d16 diff --git a/source/color.h b/source/color.h index d3710a9d..e57689bf 100644 --- a/source/color.h +++ b/source/color.h @@ -1,18 +1,17 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_GL_COLOR_H_ #define MSP_GL_COLOR_H_ -#include +#include namespace Msp { namespace GL { +inline float to_srgb(float c) +{ return (c<=0.0031308f ? 12.92f*c : 1.055f*std::pow(c, 1/2.4f)-0.055f); } + +inline float to_linear(float c) +{ return (c<=0.04045 ? c/12.92f : std::pow((c+0.055f)/1.055f, 2.4f)); } + struct Color { float r, g, b, a; @@ -22,9 +21,12 @@ struct Color Color(float r_, float g_, float b_): r(r_), g(g_), b(b_), a(1) { } Color(float r_, float g_, float b_, float a_): r(r_), g(g_), b(b_), a(a_) { } Color operator*(float f) const { return Color(r*f, g*f, b*f, a); } - Color operator+(const Color &c) const { return Color(r+c.r, g+c.g, b+c.g, 1-(1-a)*(1-c.a)); } - bool operator==(const Color &c) const { return (r==c.r && b==c.b && g==c.g && a==c.a); } + Color operator+(const Color &c) const { return Color(r+c.r, g+c.g, b+c.b, 1-(1-a)*(1-c.a)); } + bool operator==(const Color &c) const { return (r==c.r && g==c.g && b==c.b && a==c.a); } bool operator!=(const Color &c) const { return !operator==(c); } + + Color to_srgb() const { return Color(GL::to_srgb(r), GL::to_srgb(g), GL::to_srgb(b), a); } + Color to_linear() const { return Color(GL::to_linear(r), GL::to_linear(g), GL::to_linear(b), a); } }; } // namespace GL