MCPcopy Create free account
hub / github.com/GreycLab/CImg / st_RGB

Class st_RGB

examples/use_RGBclass.cpp:83–119  ·  view source on GitHub ↗

Define a simple structure of *references* to R,G,B values. ----------------------------------------------------------- (Feel free to add your own operators in there !)

Source from the content-addressed store, hash-verified

81//-----------------------------------------------------------
82// (Feel free to add your own operators in there !)
83struct st_RGB {
84 T _R,_G,_B,&R,&G,&B;
85
86 // Construct from R,G,B references of values.
87 st_RGB(const T& nR, const T& nG, const T& nB):_R(nR),_G(nG),_B(nB),R(_R),G(_G),B(_B) {}
88 st_RGB(T& nR, T& nG, T& nB):R(nR),G(nG),B(nB) {}
89
90 // Copy constructors.
91 st_RGB(const st_RGB& rgb):_R(rgb.R),_G(rgb.G),_B(rgb.B),R(_R),G(_G),B(_B) {}
92 template<typename t>
93 st_RGB(const t& rgb):_R(rgb[0]),_G(rgb[1]),_B(rgb[2]) {}
94
95 // Assignement operator.
96 st_RGB& operator=(const st_RGB& rgb) {
97 R = (T)(rgb[0]); G = (T)(rgb[1]); B = (T)(rgb[2]);
98 return *this;
99 }
100 template<typename t>
101 st_RGB& operator=(const t& rgb) {
102 R = (T)(rgb[0]); G = (T)(rgb[1]); B = (T)(rgb[2]);
103 return *this;
104 }
105
106 // Data (R,G or B) access operator.
107 const T& operator[](const unsigned int i) const {
108 return i==2?B:(i==1?G:R);
109 }
110 T& operator[](const unsigned int i) {
111 return i==2?B:(i==1?G:R);
112 }
113
114 // Print instance on the standard error.
115 const st_RGB& print() const {
116 std::fprintf(stderr,"{ %d %d %d }\n",(int)R,(int)G,(int)B);
117 return *this;
118 }
119};
120
121// Define CImg<T> member functions which return pixel values as st_RGB instances.
122//--------------------------------------------------------------------------------

Callers 1

RGB_atFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected