From e8a6f5b8039cce3f7ec568fd90fe73690e49a037 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Fri, 19 Oct 2018 18:23:42 +0330 Subject: [PATCH] Add three macros for separating color channels --- src/dump-emoji.cc | 8 ++++---- src/hb-ot-color.cc | 1 - src/hb-ot-color.h | 15 ++++++++++----- test/api/test-ot-color.c | 10 +++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index fe4dd4ca6..4be14be9f 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -151,10 +151,10 @@ static void colr_cpal_rendering (hb_face_t *face, cairo_font_face_t *cairo_face) uint32_t color = 0xFF; if (color_indices[layer] != 0xFFFF) color = colors[color_indices[layer]]; - int alpha = color & 0xFF; - int r = (color >> 8) & 0xFF; - int g = (color >> 16) & 0xFF; - int b = (color >> 24) & 0xFF; + int alpha = hb_ot_color_get_alpha (color); + int r = hb_ot_color_get_red (color); + int g = hb_ot_color_get_green (color); + int b = hb_ot_color_get_blue (color); cairo_set_source_rgba (cr, r / 255., g / 255., b / 255., alpha); cairo_glyph_t glyph; diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index e2d502ca8..8a463d29e 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -201,7 +201,6 @@ hb_ot_color_get_color_layers (hb_face_t *face, if (count) { unsigned int layer_count = MIN(*count, num_layers - start_offset); - printf ("%d ", *count); for (unsigned int i = 0; i < layer_count; i++) { if (colr.get_layer_record (start_layer_index + start_offset + i, diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h index 5b9e5aabf..4ec1a89d3 100644 --- a/src/hb-ot-color.h +++ b/src/hb-ot-color.h @@ -49,6 +49,11 @@ HB_BEGIN_DECLS */ 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_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_ot_color_get_color_layers (hb_face_t *face, - hb_codepoint_t gid, - unsigned int offset, - unsigned int *count, /* IN/OUT */ - hb_codepoint_t *gids, /* OUT */ - unsigned int *color_indices /* OUT */); + hb_codepoint_t gid, + unsigned int offset, + unsigned int *count, /* IN/OUT */ + hb_codepoint_t *gids, /* OUT */ + unsigned int *color_indices /* OUT */); HB_END_DECLS diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index ed6d3e5e4..06b249cf5 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -102,19 +102,19 @@ static hb_face_t *cpal_v1 = NULL; const hb_ot_color_t *_colors = (colors); \ const size_t _i = (i); \ 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, \ "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, \ "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, \ "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, \ "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 */ /* 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 (num_colors, ==, 0); assert_color_rgba (colors, 0, 0x77, 0x77, 0x77, 0x77); /* untouched */