Add three macros for separating color channels

This commit is contained in:
Ebrahim Byagowi 2018-10-19 18:23:42 +03:30 committed by Khaled Hosny
parent 0e33467e52
commit e8a6f5b803
4 changed files with 19 additions and 15 deletions

View File

@ -151,10 +151,10 @@ static void colr_cpal_rendering (hb_face_t *face, cairo_font_face_t *cairo_face)
uint32_t color = 0xFF; uint32_t color = 0xFF;
if (color_indices[layer] != 0xFFFF) if (color_indices[layer] != 0xFFFF)
color = colors[color_indices[layer]]; color = colors[color_indices[layer]];
int alpha = color & 0xFF; int alpha = hb_ot_color_get_alpha (color);
int r = (color >> 8) & 0xFF; int r = hb_ot_color_get_red (color);
int g = (color >> 16) & 0xFF; int g = hb_ot_color_get_green (color);
int b = (color >> 24) & 0xFF; int b = hb_ot_color_get_blue (color);
cairo_set_source_rgba (cr, r / 255., g / 255., b / 255., alpha); cairo_set_source_rgba (cr, r / 255., g / 255., b / 255., alpha);
cairo_glyph_t glyph; cairo_glyph_t glyph;

View File

@ -201,7 +201,6 @@ hb_ot_color_get_color_layers (hb_face_t *face,
if (count) if (count)
{ {
unsigned int layer_count = MIN<unsigned int>(*count, num_layers - start_offset); unsigned int layer_count = MIN<unsigned int>(*count, num_layers - start_offset);
printf ("%d ", *count);
for (unsigned int i = 0; i < layer_count; i++) for (unsigned int i = 0; i < layer_count; i++)
{ {
if (colr.get_layer_record (start_layer_index + start_offset + i, if (colr.get_layer_record (start_layer_index + start_offset + i,

View File

@ -49,6 +49,11 @@ HB_BEGIN_DECLS
*/ */
typedef uint32_t hb_ot_color_t; typedef uint32_t hb_ot_color_t;
#define hb_ot_color_get_alpha(color) (color & 0xFF)
#define hb_ot_color_get_red(color) ((color >> 8) & 0xFF)
#define hb_ot_color_get_green(color) ((color >> 16) & 0xFF)
#define hb_ot_color_get_blue(color) ((color >> 24) & 0xFF)
HB_EXTERN hb_bool_t HB_EXTERN hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face); hb_ot_color_has_cpal_data (hb_face_t *face);
@ -74,11 +79,11 @@ hb_ot_color_get_palette_colors (hb_face_t *face,
HB_EXTERN unsigned int HB_EXTERN unsigned int
hb_ot_color_get_color_layers (hb_face_t *face, hb_ot_color_get_color_layers (hb_face_t *face,
hb_codepoint_t gid, hb_codepoint_t gid,
unsigned int offset, unsigned int offset,
unsigned int *count, /* IN/OUT */ unsigned int *count, /* IN/OUT */
hb_codepoint_t *gids, /* OUT */ hb_codepoint_t *gids, /* OUT */
unsigned int *color_indices /* OUT */); unsigned int *color_indices /* OUT */);
HB_END_DECLS HB_END_DECLS

View File

@ -102,19 +102,19 @@ static hb_face_t *cpal_v1 = NULL;
const hb_ot_color_t *_colors = (colors); \ const hb_ot_color_t *_colors = (colors); \
const size_t _i = (i); \ const size_t _i = (i); \
const uint8_t red = (r), green = (g), blue = (b), alpha = (a); \ const uint8_t red = (r), green = (g), blue = (b), alpha = (a); \
if ((_colors[_i] >> 16 & 0xff) != red) { \ if (hb_ot_color_get_red (_colors[_i]) != red) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", red, 'x'); \ "colors[" #i "]", _colors[_i], "==", red, 'x'); \
} \ } \
if ((_colors[_i] >> 8 & 0xff) != green) { \ if (hb_ot_color_get_green (_colors[_i]) != green) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", green, 'x'); \ "colors[" #i "]", _colors[_i], "==", green, 'x'); \
} \ } \
if ((_colors[_i] & 0xff) != blue) { \ if (hb_ot_color_get_blue (_colors[_i]) != blue) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", colors[_i], "==", blue, 'x'); \ "colors[" #i "]", colors[_i], "==", blue, 'x'); \
} \ } \
if ((_colors[_i] >> 24 & 0xff) != alpha) { \ if (hb_ot_color_get_alpha (_colors[_i]) != alpha) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", alpha, 'x'); \ "colors[" #i "]", _colors[_i], "==", alpha, 'x'); \
} \ } \
@ -285,7 +285,7 @@ test_hb_ot_color_get_palette_colors_v1 (void)
// assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */ // assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
/* Palette #3 (out of bounds), start_index=0 */ /* Palette #3 (out of bounds), start_index=0 */
memset(colors, 0x77, colors_size); memset (colors, 0x77, colors_size);
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 3, 0, &num_colors, colors), ==, 0); g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 3, 0, &num_colors, colors), ==, 0);
g_assert_cmpint (num_colors, ==, 0); g_assert_cmpint (num_colors, ==, 0);
assert_color_rgba (colors, 0, 0x77, 0x77, 0x77, 0x77); /* untouched */ assert_color_rgba (colors, 0, 0x77, 0x77, 0x77, 0x77); /* untouched */