📄 rgb.h
字号:
//
// rgb.h
//
// $Id: rgb.h,v 1.1.1.1 2001/02/28 00:28:38 cstolte Exp $
//
#ifndef SGL_RGB_H
#define SGL_RGB_H
#if 0
#include <sgl/defs.h>
#include <sgl/color.h>
class RGB;
class RGBA;
class ShortRGB;
class ShortRGBA;
class RGBPrimary;
///
/// RGB
///
class RGB {
public:
RGB() { }
RGB(double r1, double g1, double b1) : r(r1), g(g1), b(b1) { }
RGB(const ShortRGB &);
int operator==(const RGB &) const;
int operator!=(const RGB &) const;
RGB operator-() const;
RGB operator+(const RGB &) const;
RGB &operator+=(const RGB &);
RGB operator-(const RGB &) const;
RGB &operator-=(const RGB &);
RGB operator*(const RGB &) const;
RGB &operator*=(const RGB &);
RGB operator*(double) const;
RGB operator/(double) const;
RGB &operator*=(double);
RGB &operator/=(double);
friend RGB operator*(double, const RGB &);
RGB clamp(double min = 0, double max = 1) const;
int out_of_gammut() const;
RGB scale_to_gammut(double max = 1) const;
RGB const_intensity_clip() const;
double intensity() const { return (r + g + b) / 3; }
double R() const { return r; }
double G() const { return g; }
double B() const { return b; }
public:
double r, g, b;
};
///
/// RGBA
///
// actually storing a*r, a*g, a*b, a
class RGBA : public RGB {
public:
RGBA() { }
RGBA(double r1, double g1, double b1, double a1) :
RGB(r1, g1, b1), a(a1) { }
RGBA(const RGB &rgb) : RGB(rgb), a(1) { }
RGBA(const ShortRGBA &);
int operator==(const RGBA &) const;
int operator!=(const RGBA &) const;
RGBA operator-() const;
RGBA operator+(const RGBA &) const;
RGBA &operator+=(const RGBA &);
RGBA operator-(const RGBA &) const;
RGBA &operator-=(const RGBA &);
RGBA operator*(double) const;
RGBA operator/(double) const;
RGBA &operator*=(double);
RGBA &operator/=(double);
friend RGBA operator*(double, const RGBA &);
RGBA &clear();
RGBA &over(const RGBA &);
RGBA &in(const RGBA &);
RGBA &out(const RGBA &);
RGBA &atop(const RGBA &);
RGBA &xor(const RGBA &);
RGBA &darken(double d);
RGBA &dissolve(double d);
double intensity() const { return a * (r + g + b) / 3; }
double A() const { return a; }
public:
double a;
};
///
/// ShortRGB
///
class ShortRGB {
public:
ShortRGB() { }
ShortRGB(u_char r1, u_char g1, u_char b1) : r(r1), g(g1), b(b1) { }
ShortRGB(const RGB &);
int operator==(const ShortRGB &) const;
int operator!=(const ShortRGB &) const;
ShortRGB operator+(const ShortRGB &) const;
ShortRGB &operator+=(const ShortRGB &);
ShortRGB operator-(const ShortRGB &) const;
ShortRGB &operator-=(const ShortRGB &);
ShortRGB operator*(const ShortRGB &) const;
ShortRGB &operator*=(const ShortRGB &);
ShortRGB operator*(double) const;
ShortRGB operator/(double) const;
ShortRGB &operator*=(double);
ShortRGB &operator/=(double);
friend ShortRGB operator*(double, const ShortRGB &);
double R() const { return (double)r / 255.; }
double G() const { return (double)g / 255.; }
double B() const { return (double)b / 255.; }
public:
u_char r, g, b;
};
///
/// ShortRGBA
///
class ShortRGBA : public ShortRGB {
public:
ShortRGBA() { }
ShortRGBA(u_char r1, u_char g1, u_char b1, u_char a1)
: ShortRGB(r1, g1, b1), a(a1) { }
ShortRGBA(const ShortRGB &rgb)
: ShortRGB(rgb), a(1) { }
ShortRGBA(const RGBA &);
int operator==(const ShortRGBA &) const;
int operator!=(const ShortRGBA &) const;
ShortRGBA operator+(const ShortRGBA &) const;
ShortRGBA &operator+=(const ShortRGBA &);
ShortRGBA operator-(const ShortRGBA &) const;
ShortRGBA &operator-=(const ShortRGBA &);
ShortRGBA operator*(double) const;
ShortRGBA operator/(double) const;
ShortRGBA &operator*=(double);
ShortRGBA &operator/=(double);
friend ShortRGBA operator*(double, const ShortRGBA &);
ShortRGBA &clear();
ShortRGBA &over(const ShortRGBA &);
ShortRGBA &in(const ShortRGBA &);
ShortRGBA &out(const ShortRGBA &);
ShortRGBA &atop(const ShortRGBA &);
ShortRGBA &xor(const ShortRGBA &);
ShortRGBA &darken(double d);
ShortRGBA &dissolve(double d);
double A() const { return (double)a / 255.; }
public:
u_char a;
};
///
/// RGBPrimary
///
class RGBPrimary : public RGB {
public:
RGBPrimary() : primary(0) { }
RGBPrimary(double r1, double g1, double b1,
const Primary *p = &SMPTE_Primary)
: RGB(r1, g1, b1), primary(p) { }
RGBPrimary(const RGB &, const Primary *p = &SMPTE_Primary);
RGBPrimary(double RGBPrimary[3], const Primary *p = &SMPTE_Primary);
RGBPrimary(const XYZ &c, const Primary *p = &SMPTE_Primary);
/* XYZ -> RGBPrimary */
RGBPrimary(const RGBPrimary &c, const Primary *p); /* change of Primary */
XYZ toXYZ() const { return primary->toXYZ(*this); }
int operator==(const RGBPrimary &) const;
int operator!=(const RGBPrimary &) const;
RGBPrimary operator+(const RGBPrimary &) const;
RGBPrimary &operator+=(const RGBPrimary &);
RGBPrimary operator-(const RGBPrimary &) const;
RGBPrimary &operator-=(const RGBPrimary &);
RGBPrimary operator*(const RGBPrimary &) const;
RGBPrimary &operator*=(const RGBPrimary &);
private:
const Primary *primary;
};
#endif
#endif // SGL_RGB_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -