color.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright 2017 Jason Williams
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef COLOR_H
  17. #define COLOR_H
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #if defined(__GNUC__)
  21. # define PACKED __attribute__((__packed__))
  22. #else
  23. # define PACKED
  24. #endif
  25. #if defined(_MSC_VER)
  26. # pragma pack(push, 1)
  27. #endif
  28. #ifdef RGBW
  29. # define LED_TYPE cRGBW
  30. #else
  31. # define LED_TYPE RGB
  32. #endif
  33. #define WS2812_BYTE_ORDER_RGB 0
  34. #define WS2812_BYTE_ORDER_GRB 1
  35. #ifndef WS2812_BYTE_ORDER
  36. # define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB
  37. #endif
  38. typedef struct PACKED {
  39. #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
  40. uint8_t g;
  41. uint8_t r;
  42. uint8_t b;
  43. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
  44. uint8_t r;
  45. uint8_t g;
  46. uint8_t b;
  47. #endif
  48. } cRGB;
  49. typedef cRGB RGB;
  50. // WS2812 specific layout
  51. typedef struct PACKED {
  52. #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
  53. uint8_t g;
  54. uint8_t r;
  55. uint8_t b;
  56. #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
  57. uint8_t r;
  58. uint8_t g;
  59. uint8_t b;
  60. #endif
  61. uint8_t w;
  62. } cRGBW;
  63. typedef struct PACKED {
  64. uint8_t h;
  65. uint8_t s;
  66. uint8_t v;
  67. } HSV;
  68. #if defined(_MSC_VER)
  69. # pragma pack(pop)
  70. #endif
  71. RGB hsv_to_rgb(HSV hsv);
  72. RGB hsv_to_rgb_nocie(HSV hsv);
  73. #ifdef RGBW
  74. void convert_rgb_to_rgbw(LED_TYPE *led);
  75. #endif
  76. #endif // COLOR_H