Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ColorRGB.h"
- /*
- template <class T>
- void ColorRGB::setColor(const T Red, const T Green, const T Blue)
- {
- T* RGBBuf = new T[3] {Red, Green, Blue};
- int* typeValue = new int;
- *typeValue = typeDef(RGBBuf);
- bool* valueLessZero = new bool;
- bool* valueLargerByte = new bool;
- bool* valueFloat = new bool;
- for (int i = 0; i < 3; i++)
- {
- valueLessZero = RGBBuf[i] < 0;
- valueLargerByte = RGBBuf[i] > 255;
- if (!valueLessZero && !valueLargerByte) {
- RGBByte[i] = RGBBuf[i];
- } else if (valueLargerByte) {
- RGBByte[i] = 255;
- } else if (valueLessZero) {
- RGBByte[i] = 0;
- }
- }
- this->convertRGBtoRGBF();
- this->convertRGBtoINT();
- }
- */
- void tst(int a)
- {
- a = 1;
- }
- void debugRGBByte(ColorRGB &object)
- {
- std::cout << "RGB Byte value." <<
- " R: " << (int)object.RGBByteR <<
- " G: " << (int)object.RGBByteG <<
- " B: " << (int)object.RGBByteB <<
- std::endl;
- }
- void debugRGBInt(ColorRGB &object)
- {
- std::cout << "RGB Int value: " << object.RGBInt << std::endl;
- }
- void debugRGBFloat(ColorRGB &object)
- {
- std::cout << "RGB Float value." <<
- " R: " << object.RGBFloatR <<
- " G: " << object.RGBFloatG <<
- " B: " << object.RGBFloatB <<
- std::endl;
- }
- ColorRGB::ColorRGB(const int Red, const int Green, int Blue)
- {
- RGBByteR = Red;
- RGBByteG = Green;
- RGBByteB = Blue;
- this->convertRGBtoRGBF();
- this->convertRGBtoINT();
- }
- ColorRGB::ColorRGB(const unsigned long RGBInt_)
- {
- RGBInt = RGBInt_;
- }
- void ColorRGB::convertRGBtoRGBF()
- {
- RGBFloatR = RGBByteR / 255.0;
- RGBFloatG = RGBByteG / 255.0;
- RGBFloatB = RGBByteB / 255.0;
- }
- void ColorRGB::convertRGBFtoRGB()
- {
- RGBByteR = RGBFloatR * 255.0;
- RGBByteG = RGBFloatG * 255.0;
- RGBByteB = RGBFloatB * 255.0;
- }
- void ColorRGB::convertRGBtoINT()
- {
- RGBInt = 65536 * RGBByteR + 256 * RGBByteG + RGBByteB;
- }
- void ColorRGB::convertRGBIntToRGB()
- {
- RGBByteB = RGBInt % 256;
- RGBByteG = (RGBInt - RGBByteB) / 256;
- RGBByteR = ((RGBInt - RGBByteB) / (256 * 256)) - RGBByteG / 256;
- }
- template <class T>
- int ColorRGB::typeDef(T *RGBBuffer)
- {
- if (typeid(RGBBuffer) == typeid(RGBByte))
- {
- return 255;
- } else if (typeid(RGBBuffer) == typeid(RGBFloat)) {
- return 1;
- } else {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement