Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

olcPGE_Pixel.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "olcPGE_Pixel.h"
  2. namespace olc {
  3. Pixel::Pixel()
  4. {
  5. r = 0; g = 0; b = 0; a = 255;
  6. }
  7. Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
  8. {
  9. r = red; g = green; b = blue; a = alpha;
  10. }
  11. Pixel::Pixel(uint32_t p)
  12. {
  13. n = p;
  14. }
  15. Pixel Pixel::CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
  16. Pixel rgb;
  17. rgb.a = alpha;
  18. uint8_t region, remainder, p, q, t;
  19. if (s == 0)
  20. {
  21. rgb.r = v;
  22. rgb.g = v;
  23. rgb.b = v;
  24. return rgb;
  25. }
  26. region = h / 43;
  27. remainder = (h - (region * 43)) * 6;
  28. p = (v * (255 - s)) >> 8;
  29. q = (v * (255 - ((s * remainder) >> 8))) >> 8;
  30. t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
  31. switch (region)
  32. {
  33. case 0:
  34. rgb.r = v; rgb.g = t; rgb.b = p;
  35. break;
  36. case 1:
  37. rgb.r = q; rgb.g = v; rgb.b = p;
  38. break;
  39. case 2:
  40. rgb.r = p; rgb.g = v; rgb.b = t;
  41. break;
  42. case 3:
  43. rgb.r = p; rgb.g = q; rgb.b = v;
  44. break;
  45. case 4:
  46. rgb.r = t; rgb.g = p; rgb.b = v;
  47. break;
  48. default:
  49. rgb.r = v; rgb.g = p; rgb.b = q;
  50. break;
  51. }
  52. return rgb;
  53. }
  54. }