00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_COLOR_HPP_)
00012 #define _XRB_COLOR_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <stdio.h>
00017
00018 #include "xrb_ntuple.hpp"
00019
00020 namespace Xrb
00021 {
00022
00023 typedef Float ColorCoord;
00024 class Color : public NTuple<ColorCoord, 4>
00025 {
00026 public:
00027
00028 static Color const ms_opaque_white;
00029 static Color const ms_opaque_black;
00030 static Color const ms_transparent_black;
00031
00032 static Color const &ms_identity_color_mask;
00033 static Color const &ms_identity_color_bias;
00034
00035
00036 Color () { }
00037
00038 Color (ColorCoord r, ColorCoord g, ColorCoord b)
00039 :
00040 NTuple<ColorCoord, 4>(r, g, b, 1.0f)
00041 { }
00042
00043 Color (ColorCoord r, ColorCoord g, ColorCoord b, ColorCoord a)
00044 :
00045 NTuple<ColorCoord, 4>(r, g, b, a)
00046 { }
00047
00048 Color (NTuple<ColorCoord, 4> const &c)
00049 :
00050 NTuple<ColorCoord, 4>(c)
00051 { }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 void Blend (Color const &y)
00068 {
00069
00070 Color &x = *this;
00071 ColorCoord old_a = x[Dim::A];
00072 x[Dim::A] += y[Dim::A] - x[Dim::A]*y[Dim::A];
00073 if (x[Dim::A] == 0.0f)
00074 x[Dim::R] = x[Dim::G] = x[Dim::B] = 0.0f;
00075 else
00076 {
00077 x[Dim::R] = (x[Dim::R]*old_a + y[Dim::R]*y[Dim::A] - y[Dim::R]*old_a*y[Dim::A]) / x[Dim::A];
00078 x[Dim::G] = (x[Dim::G]*old_a + y[Dim::G]*y[Dim::A] - y[Dim::G]*old_a*y[Dim::A]) / x[Dim::A];
00079 x[Dim::B] = (x[Dim::B]*old_a + y[Dim::B]*y[Dim::A] - y[Dim::B]*old_a*y[Dim::A]) / x[Dim::A];
00080 }
00081 }
00082 static Color Blend (Color x, Color const &y)
00083 {
00084 x.Blend(y);
00085 return x;
00086 }
00087 };
00088
00089
00090 }
00091
00092 #endif // !defined(_XRB_COLOR_HPP_)
00093