forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys/color: added RGB inversion and complementary color
- Loading branch information
Simon Brummer
committed
Mar 16, 2016
1 parent
1d6d54e
commit 1af9612
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* | ||
* @author Hauke Petersen <[email protected]> | ||
* @author Cenk Gündoğan <[email protected]> | ||
* @author Simon Brummer <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
@@ -175,3 +176,20 @@ void color_rgb2str(const color_rgb_t *rgb, char* str) | |
tmp = rgb->b & 0x0F; | ||
str[5] = (tmp > 9) ? ('A' - 10 + tmp) : ('0' + tmp); | ||
} | ||
|
||
void color_rgb_complementary(const color_rgb_t *rgb, color_rgb_t *comp_rgb) | ||
{ | ||
uint8_t max = 0; | ||
uint8_t min = 0; | ||
uint16_t val = 0; | ||
|
||
max = (rgb->r > rgb->g) ? rgb->r : rgb->g; | ||
max = (rgb->b > max) ? rgb->b : max; | ||
min = (rgb->r < rgb->g) ? rgb->r : rgb->g; | ||
min = (rgb->b < min) ? rgb->b : min; | ||
val = max + min; | ||
|
||
comp_rgb->r = val - rgb->r; | ||
comp_rgb->g = val - rgb->g; | ||
comp_rgb->b = val - rgb->b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
* | ||
* @author Hauke Petersen <[email protected]> | ||
* @author Cenk Gündoğan <[email protected]> | ||
* @author Simon Brummer <[email protected]> | ||
*/ | ||
|
||
#ifndef __COLOR_H | ||
|
@@ -104,6 +105,34 @@ void color_str2rgb(const char *str, color_rgb_t *color); | |
*/ | ||
void color_rgb2str(const color_rgb_t *rgb, char *str); | ||
|
||
/** | ||
* @brief Invert a given rgb color | ||
* | ||
* @pre ((rgb != NULL) && (inv_rgb != NULL)) | ||
* | ||
* @param[in] rgb Input rgb color, that should be converted. Must be NOT NULL | ||
* @param[out] inv_rgb Output rgb color, result of the conversion. Must be NOT NULL | ||
*/ | ||
static inline void color_rgb_invert(const color_rgb_t *rgb, color_rgb_t *inv_rgb) | ||
{ | ||
inv_rgb->r = rgb->r ^ 0xFF; | ||
inv_rgb->g = rgb->g ^ 0xFF; | ||
inv_rgb->b = rgb->b ^ 0xFF; | ||
} | ||
|
||
/** | ||
* @brief Calculate the complementary color of a given rgb color. | ||
* | ||
* @note Complementary color calculation according to adobe illustator calculations. | ||
* See https://helpx.adobe.com/illustrator/using/adjusting-colors.html | ||
* | ||
* @pre ((rgb != NULL) && (comp_rgb != NULL)) | ||
* | ||
* @param[in] rgb Input rgb color. Must be NOT NULL | ||
* @param[out] comp_rgb Output rgb color, result of the complementary color calculation. Must be NOT NULL | ||
*/ | ||
void color_rgb_complementary(const color_rgb_t *rgb, color_rgb_t *comp_rgb); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters