Skip to content

Commit

Permalink
Fixed typo and compilation error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Mahoudeau committed Sep 7, 2024
1 parent 256515a commit cef7cac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
10 changes: 0 additions & 10 deletions lib/graphics/src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,3 @@ void graphics::unpackRGB565(const color_t rgb, uint8_t* r, uint8_t* g, uint8_t*
*g = ((((rgb >> 5) & 0x3F) * 259) + 33) >> 6;
*b = (((rgb & 0x1F) * 527) + 23) >> 6;
}

constexpr color_t graphics::constPackRGB565(const uint8_t r, const uint8_t g, const uint8_t b) {
uint16_t rgb = 0;

rgb |= (r >> 3) << 11;
rgb |= (g >> 2) << 5;
rgb |= (b >> 3);

return rgb;
}
46 changes: 29 additions & 17 deletions lib/graphics/src/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#define COLOR_HPP

#include <cstdint>

/**
* Color type, RGB565.
*/
typedef uint16_t color_t;

namespace graphics {
Expand Down Expand Up @@ -37,7 +41,15 @@ namespace graphics {
* @param b The blue component.
* @return A RGB565 color.
*/
constexpr color_t constPackRGB565(uint8_t r, uint8_t g, uint8_t b);
constexpr color_t constPackRGB565(const uint8_t r, const uint8_t g, const uint8_t b) {
uint16_t rgb = 0;

rgb |= (r >> 3) << 11;
rgb |= (g >> 2) << 5;
rgb |= (b >> 3);

return rgb;
}
}

#define COLOR_DARK 0x0000
Expand All @@ -51,23 +63,23 @@ namespace graphics {
// #define COLOR_BLACK 0x0000
// #define COLOR_GREY 0x8410

#define COLOR_WHITE graphics::constPackRGBG565(255, 255, 255)
#define COLOR_BLACK graphics::constPackRGBG565(0, 0, 0)
#define COLOR_RED graphics::constPackRGBG565(255, 0, 0)
#define COLOR_GREEN graphics::constPackRGBG565(0, 128, 0)
#define COLOR_BLUE graphics::constPackRGBG565(0, 0, 255)
#define COLOR_WHITE graphics::constPackRGB565(255, 255, 255)
#define COLOR_BLACK graphics::constPackRGB565(0, 0, 0)
#define COLOR_RED graphics::constPackRGB565(255, 0, 0)
#define COLOR_GREEN graphics::constPackRGB565(0, 128, 0)
#define COLOR_BLUE graphics::constPackRGB565(0, 0, 255)

#define COLOR_YELLOW graphics::constPackRGBG565(255, 255, 0)
#define COLOR_GREY graphics::constPackRGBG565(128, 128, 128)
#define COLOR_MAGENTA graphics::constPackRGBG565(255, 0, 255)
#define COLOR_CYAN graphics::constPackRGBG565(0, 255, 255)
#define COLOR_VIOLET graphics::constPackRGBG565(128, 0, 128)
#define COLOR_ORANGE graphics::constPackRGBG565(255, 165, 0)
#define COLOR_PINK graphics::constPackRGBG565(255,192,203)
#define COLOR_YELLOW graphics::constPackRGB565(255, 255, 0)
#define COLOR_GREY graphics::constPackRGB565(128, 128, 128)
#define COLOR_MAGENTA graphics::constPackRGB565(255, 0, 255)
#define COLOR_CYAN graphics::constPackRGB565(0, 255, 255)
#define COLOR_VIOLET graphics::constPackRGB565(128, 0, 128)
#define COLOR_ORANGE graphics::constPackRGB565(255, 165, 0)
#define COLOR_PINK graphics::constPackRGB565(255,192,203)

#define COLOR_LIGHT_GREEN graphics::constPackRGBG565(0, 255, 0)
#define COLOR_LIGHT_ORANGE graphics::constPackRGBG565(255, 213, 128)
#define COLOR_LIGHT_BLUE graphics::constPackRGBG565(173,216,230)
#define COLOR_LIGHT_GREY graphics::constPackRGBG565(211,211,211)
#define COLOR_LIGHT_GREEN graphics::constPackRGB565(0, 255, 0)
#define COLOR_LIGHT_ORANGE graphics::constPackRGB565(255, 213, 128)
#define COLOR_LIGHT_BLUE graphics::constPackRGB565(173,216,230)
#define COLOR_LIGHT_GREY graphics::constPackRGB565(211,211,211)

#endif //COLOR_HPP

0 comments on commit cef7cac

Please sign in to comment.