Allow text drawing to use the alpha channel.
We pass alpha channel information to the current text drawing code and use it if it is available. The previous behavior of using full opacity for RGB format colors is preserved.
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
@ -25,14 +26,23 @@
|
||||
*
|
||||
*/
|
||||
uint32_t get_colorpixel(const char *hex) {
|
||||
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
|
||||
{hex[3], hex[4], '\0'},
|
||||
{hex[5], hex[6], '\0'}};
|
||||
char alpha[2];
|
||||
if (strlen(hex) == strlen("#rrggbbaa")) {
|
||||
alpha[0] = hex[7];
|
||||
alpha[1] = hex[8];
|
||||
} else {
|
||||
alpha[0] = alpha[1] = 'F';
|
||||
}
|
||||
|
||||
char strgroups[4][3] = {
|
||||
{hex[1], hex[2], '\0'},
|
||||
{hex[3], hex[4], '\0'},
|
||||
{hex[5], hex[6], '\0'},
|
||||
{alpha[0], alpha[1], '\0'}};
|
||||
uint8_t r = strtol(strgroups[0], NULL, 16);
|
||||
uint8_t g = strtol(strgroups[1], NULL, 16);
|
||||
uint8_t b = strtol(strgroups[2], NULL, 16);
|
||||
uint8_t a = strtol(strgroups[3], NULL, 16);
|
||||
|
||||
/* We set the first 8 bits high to have 100% opacity in case of a 32 bit
|
||||
* color depth visual. */
|
||||
return (0xFF << 24) | (r << 16 | g << 8 | b);
|
||||
return (a << 24) | (r << 16 | g << 8 | b);
|
||||
}
|
||||
|
Reference in New Issue
Block a user