123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "olcPGE_Pixel.h"
-
- namespace olc {
- Pixel::Pixel()
- {
- r = 0; g = 0; b = 0; a = 255;
- }
-
- Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
- {
- r = red; g = green; b = blue; a = alpha;
- }
-
- Pixel::Pixel(uint32_t p)
- {
- n = p;
- }
-
- Pixel Pixel::CreateFromHSV(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
- Pixel rgb;
- rgb.a = alpha;
- uint8_t region, remainder, p, q, t;
-
- if (s == 0)
- {
- rgb.r = v;
- rgb.g = v;
- rgb.b = v;
- return rgb;
- }
-
- region = h / 43;
- remainder = (h - (region * 43)) * 6;
-
- p = (v * (255 - s)) >> 8;
- q = (v * (255 - ((s * remainder) >> 8))) >> 8;
- t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
-
- switch (region)
- {
- case 0:
- rgb.r = v; rgb.g = t; rgb.b = p;
- break;
- case 1:
- rgb.r = q; rgb.g = v; rgb.b = p;
- break;
- case 2:
- rgb.r = p; rgb.g = v; rgb.b = t;
- break;
- case 3:
- rgb.r = p; rgb.g = q; rgb.b = v;
- break;
- case 4:
- rgb.r = t; rgb.g = p; rgb.b = v;
- break;
- default:
- rgb.r = v; rgb.g = p; rgb.b = q;
- break;
- }
-
- return rgb;
- }
- }
|