Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include "ColorRGB.h"
  2. /*
  3. template <class T>
  4. void ColorRGB::setColor(const T Red, const T Green, const T Blue)
  5. {
  6. T* RGBBuf = new T[3] {Red, Green, Blue};
  7.  
  8. int* typeValue = new int;
  9.  
  10. *typeValue = typeDef(RGBBuf);
  11.  
  12. bool* valueLessZero = new bool;
  13. bool* valueLargerByte = new bool;
  14. bool* valueFloat = new bool;
  15.  
  16. for (int i = 0; i < 3; i++)
  17. {
  18. valueLessZero = RGBBuf[i] < 0;
  19. valueLargerByte = RGBBuf[i] > 255;
  20.  
  21. if (!valueLessZero && !valueLargerByte) {
  22. RGBByte[i] = RGBBuf[i];
  23. } else if (valueLargerByte) {
  24. RGBByte[i] = 255;
  25. } else if (valueLessZero) {
  26. RGBByte[i] = 0;
  27. }
  28. }
  29.  
  30. this->convertRGBtoRGBF();
  31. this->convertRGBtoINT();
  32. }
  33. */
  34. void tst(int a)
  35. {
  36. a = 1;
  37. }
  38.  
  39. void debugRGBByte(ColorRGB &object)
  40. {
  41. std::cout << "RGB Byte value." <<
  42. " R: " << (int)object.RGBByteR <<
  43. " G: " << (int)object.RGBByteG <<
  44. " B: " << (int)object.RGBByteB <<
  45. std::endl;
  46. }
  47.  
  48. void debugRGBInt(ColorRGB &object)
  49. {
  50. std::cout << "RGB Int value: " << object.RGBInt << std::endl;
  51. }
  52.  
  53. void debugRGBFloat(ColorRGB &object)
  54. {
  55. std::cout << "RGB Float value." <<
  56. " R: " << object.RGBFloatR <<
  57. " G: " << object.RGBFloatG <<
  58. " B: " << object.RGBFloatB <<
  59. std::endl;
  60. }
  61.  
  62. ColorRGB::ColorRGB(const int Red, const int Green, int Blue)
  63. {
  64. RGBByteR = Red;
  65. RGBByteG = Green;
  66. RGBByteB = Blue;
  67.  
  68. this->convertRGBtoRGBF();
  69. this->convertRGBtoINT();
  70. }
  71.  
  72. ColorRGB::ColorRGB(const unsigned long RGBInt_)
  73. {
  74. RGBInt = RGBInt_;
  75. }
  76.  
  77. void ColorRGB::convertRGBtoRGBF()
  78. {
  79. RGBFloatR = RGBByteR / 255.0;
  80. RGBFloatG = RGBByteG / 255.0;
  81. RGBFloatB = RGBByteB / 255.0;
  82. }
  83. void ColorRGB::convertRGBFtoRGB()
  84. {
  85. RGBByteR = RGBFloatR * 255.0;
  86. RGBByteG = RGBFloatG * 255.0;
  87. RGBByteB = RGBFloatB * 255.0;
  88. }
  89. void ColorRGB::convertRGBtoINT()
  90. {
  91. RGBInt = 65536 * RGBByteR + 256 * RGBByteG + RGBByteB;
  92. }
  93. void ColorRGB::convertRGBIntToRGB()
  94. {
  95. RGBByteB = RGBInt % 256;
  96. RGBByteG = (RGBInt - RGBByteB) / 256;
  97. RGBByteR = ((RGBInt - RGBByteB) / (256 * 256)) - RGBByteG / 256;
  98. }
  99.  
  100. template <class T>
  101. int ColorRGB::typeDef(T *RGBBuffer)
  102. {
  103. if (typeid(RGBBuffer) == typeid(RGBByte))
  104. {
  105. return 255;
  106. } else if (typeid(RGBBuffer) == typeid(RGBFloat)) {
  107. return 1;
  108. } else {
  109. return -1;
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement