DATAKIT API  V2025.1
dtk_rgb.hpp
Go to the documentation of this file.
1 #ifndef __DTK_RGB_HPP__
2 #define __DTK_RGB_HPP__
3 #include <fstream>
4 #include "def/define.h"
5 
6 class Dtk_RGB
7 {
8 private:
9  int _RGBA[5];
10  void init();
11  void reset();
12  Dtk_bool compare(Dtk_RGB) const;
13  void copy(const Dtk_RGB& s);
14 public:
16  Dtk_RGB(const Dtk_RGB& s);
17  Dtk_RGB(int r, int g, int b, int a = -1, int inIndexReader = -1 );
18  Dtk_RGB(int (&rgba)[5]);
19  Dtk_RGB(int (&rgba)[4]);
20  Dtk_RGB(int (&rgb)[3]);
21  void Clear() { reset(); }
23 
25  int& operator [](int pos);
26  const int& operator [](int pos) const;
27 
28  inline bool HasColor() const { return _RGBA[0] >= 0;}
29 
30  inline bool HasAlpha() const { return _RGBA[3] >= 0;}
31 
32  inline bool IsFilled() const { return (_RGBA[0] >= 0 || _RGBA[3] >= 0);}
33 
34  inline int & R() {return _RGBA[0];}
35  inline const int & R() const {return _RGBA[0];}
36 
37  inline int & G() {return _RGBA[1];}
38  inline const int & G() const {return _RGBA[1];}
39 
40  inline int & B() {return _RGBA[2];}
41  inline const int & B() const {return _RGBA[2];}
42 
43  inline int & A() {return _RGBA[3];}
44  inline const int & A() const {return _RGBA[3];}
45 
46  inline int & IndexReader() {return _RGBA[4];}
47  inline const int & IndexReader() const {return _RGBA[4];}
48 
49  inline void SetRGBA(const int& inRed, const int& inGreen, const int& inBlue, const int& inAlpha = -1)
50  {
51  _RGBA[0] = inRed;
52  _RGBA[1] = inGreen;
53  _RGBA[2] = inBlue;
54  _RGBA[3] = inAlpha;
55  }
56 
57  inline void GetRGB(int& outRed, int& outGreen, int& outBlue)
58  {
59  outRed = _RGBA[0];
60  outGreen = _RGBA[1];
61  outBlue = _RGBA[2];
62  }
63  inline void GetRGBA(int& outRed, int& outGreen, int& outBlue, int& outAlpha)
64  {
65  GetRGB(outRed, outGreen, outBlue);
66  outAlpha = _RGBA[3];
67  }
68 
69  friend bool operator==(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
70 
71  friend bool operator<(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
72 
73  friend bool operator!=(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
74 
75  friend bool operator>(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
76 
77  friend bool operator<=(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
78 
79  friend bool operator>=(const Dtk_RGB & lhs, const Dtk_RGB & rhs);
80 };
81 
82 
83 #endif
Dtk_RGB::G
int & G()
Definition: dtk_rgb.hpp:37
Dtk_RGB::operator>=
friend bool operator>=(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_RGB::Dtk_RGB
Dtk_RGB(int(&rgba)[5])
Dtk_RGB::G
const int & G() const
Definition: dtk_rgb.hpp:38
Dtk_RGB::Dtk_RGB
Dtk_RGB(int(&rgb)[3])
Dtk_RGB::R
int & R()
Definition: dtk_rgb.hpp:34
Dtk_RGB::SetRGBA
void SetRGBA(const int &inRed, const int &inGreen, const int &inBlue, const int &inAlpha=-1)
Definition: dtk_rgb.hpp:49
Dtk_RGB::operator>
friend bool operator>(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_RGB::GetRGB
void GetRGB(int &outRed, int &outGreen, int &outBlue)
Definition: dtk_rgb.hpp:57
Dtk_RGB::IndexReader
int & IndexReader()
Definition: dtk_rgb.hpp:46
Dtk_RGB::operator=
Dtk_RGB & operator=(const Dtk_RGB &s)
Dtk_RGB::operator<
friend bool operator<(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_bool
char Dtk_bool
Definition: define.h:725
Dtk_RGB::B
const int & B() const
Definition: dtk_rgb.hpp:41
Dtk_RGB::operator<=
friend bool operator<=(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_RGB::A
int & A()
Definition: dtk_rgb.hpp:43
Dtk_RGB::operator==
friend bool operator==(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_RGB::Dtk_RGB
Dtk_RGB(int r, int g, int b, int a=-1, int inIndexReader=-1)
Dtk_RGB::HasAlpha
bool HasAlpha() const
Definition: dtk_rgb.hpp:30
Dtk_RGB::operator!=
friend bool operator!=(const Dtk_RGB &lhs, const Dtk_RGB &rhs)
Dtk_RGB::IsFilled
bool IsFilled() const
Definition: dtk_rgb.hpp:32
Dtk_RGB::B
int & B()
Definition: dtk_rgb.hpp:40
define.h
Dtk_RGB::Dtk_RGB
Dtk_RGB(const Dtk_RGB &s)
Dtk_RGB::Dtk_RGB
Dtk_RGB()
Dtk_RGB::~Dtk_RGB
~Dtk_RGB()
Dtk_RGB::IndexReader
const int & IndexReader() const
Definition: dtk_rgb.hpp:47
Dtk_RGB::operator[]
int & operator[](int pos)
Dtk_RGB::Clear
void Clear()
Definition: dtk_rgb.hpp:21
Dtk_RGB::Dtk_RGB
Dtk_RGB(int(&rgba)[4])
Dtk_RGB::GetRGBA
void GetRGBA(int &outRed, int &outGreen, int &outBlue, int &outAlpha)
Definition: dtk_rgb.hpp:63
Dtk_RGB::HasColor
bool HasColor() const
Definition: dtk_rgb.hpp:28
Dtk_RGB
Definition: dtk_rgb.hpp:7
Dtk_RGB::A
const int & A() const
Definition: dtk_rgb.hpp:44
Dtk_RGB::R
const int & R() const
Definition: dtk_rgb.hpp:35