📄 color.h
字号:
//
// color.h
//
// $Id: color.h,v 1.1.1.1 2001/02/28 00:28:35 cstolte Exp $
//
#ifndef SGL_COLOR_H
#define SGL_COLOR_H
#if 0
#include <assert.h>
#include <iostream>
#include <sgl/defs.h>
#include <sgl/mathfunc.h>
#ifdef __GNUG__
#include <sgl/matrix.h>
#endif // __GNUG__
class XYZ;
class Primary;
class RGB;
class RGBA;
class ShortRGB;
class ShortRGBA;
class RGBPrimary;
extern const Primary SMPTE_Primary;
///
/// Chroma
///
class Chroma {
public:
Chroma() : X(0), Y(0) { }
Chroma(double a, double b) : X(a), Y(b) { }
Chroma(const XYZ &);
Chroma operator+(const Chroma &) const;
Chroma &operator+=(const Chroma &);
int operator==(const Chroma &) const;
double x() const {return X;}
double y() const {return Y;}
double z() const {return 1 - X - Y;}
private:
double X, Y;
};
///
/// Primary
///
class Primary {
public:
Primary(const Chroma &r, const Chroma &g,
const Chroma &b, const Chroma &w);
Primary(const Chroma c[4]);
XYZ toXYZ(const RGBPrimary &) const;
RGBPrimary RGB(const XYZ &) const;
private:
void init();
Chroma p[3];
Chroma white;
#ifdef __GNUG__
Mat<3, double> RGB2XYZ, XYZ2RGB;
#else
double RGB2XYZ[3][3], XYZ2RGB[3][3];
#endif // __GNUG__
};
///
/// XYZ
///
class XYZ {
public:
XYZ() : x(0), y(0), z(0) { }
XYZ(double a, double b, double c)
: x(a), y(b), z(c) { }
XYZ(double XYZ[3])
: x(XYZ[0]), y(XYZ[1]), z(XYZ[2]) { }
XYZ(const RGBPrimary &p);
int operator==(const XYZ &) const;
XYZ operator+(const XYZ &) const;
XYZ operator*(double) const;
XYZ &operator*=(double);
XYZ &operator+=(const XYZ &);
friend XYZ operator*(double, const XYZ &);
double X() const { return x; }
double Y() const { return y; }
double Z() const { return z; }
private:
double x, y, z;
};
///
/// Lab
///
class Lab {
public:
Lab(const XYZ &c, const XYZ &white);
Lab(double l, double a, double b, const XYZ &w); /* ref. color */
Lab(double Lab[3], const XYZ &);
Lab(const Lab &, const XYZ &); /* change of ref. */
Lab operator+(const Lab &) const;
Lab &operator+=(const Lab &);
Lab operator*(double) const;
Lab &operator*=(double);
Lab operator/(double) const;
Lab &operator/=(double);
int operator==(const Lab &) const;
double l() const { return L; }
double a() const { return A; }
double b() const { return B; }
private:
double L, A, B;
XYZ white;
};
///
/// Luv
///
class Luv {
public:
Luv(const XYZ &c, const XYZ &white);
Luv(double l, double a, double b, const XYZ &w);
Luv(double Luv[3], const XYZ &w);
Luv(const Luv &c, const XYZ &white); /* change of ref. */
int operator==(const Luv &) const;
Luv operator+(const Luv &) const;
Luv &operator+=(const Luv &);
Luv operator*(double) const;
Luv &operator*=(double);
double l() const { return L; }
double u() const { return U; }
double v() const { return V; }
private:
double L, U, V;
XYZ white;
};
#endif
#endif /* SGL_COLOR_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -