src/hb-common.h | 14 ++++--- src/hb-ot-color-cpal-table.hh | 81 ++++++++++++++++++------------------------ src/hb-ot-color.cc | 39 ++++---------------- src/hb-ot-color.h | 10 ++--- 4 files changed, 58 insertions(+), 86 deletions(-)
New commits: commit b18acab7bce062fef397d3d8b0efc7826f473b50 Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 22 18:20:57 2018 -0700 [color] Add HB_COLOR Normally I would have added to_string / from_string like other types have. But since we don't use hb_color_t much, I'm not going to do that. Although, if we did, we could use it in hb-view to parse colors... diff --git a/src/hb-common.h b/src/hb-common.h index f9171b41..0858c0e2 100644 --- a/src/hb-common.h +++ b/src/hb-common.h @@ -446,16 +446,20 @@ hb_variation_to_string (hb_variation_t *variation, /** * hb_color_t: - * ARGB data type for holding color values. + * + * Data type for holding color values. * * Since: REPLACEME */ typedef uint32_t hb_color_t; -#define hb_color_get_alpha(color) (color & 0xFF) -#define hb_color_get_red(color) ((color >> 8) & 0xFF) -#define hb_color_get_green(color) ((color >> 16) & 0xFF) -#define hb_color_get_blue(color) ((color >> 24) & 0xFF) +#define HB_COLOR(b,g,r,a) ((hb_color_t) HB_TAG ((b),(g),(r),(a))) + +#define hb_color_get_alpha(color) ((color) & 0xFF) +#define hb_color_get_red(color) (((color) >> 8) & 0xFF) +#define hb_color_get_green(color) (((color) >> 16) & 0xFF) +#define hb_color_get_blue(color) (((color) >> 24) & 0xFF) + HB_END_DECLS commit 228f96c9d09272c8f677935a640e75e173b817a3 Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 22 16:55:12 2018 -0700 [color] Finish reviewing / revamping CPAL Now to hb_color_t. diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 37e0db36..3f2165c4 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -133,17 +133,30 @@ struct CPAL inline unsigned int get_color_name_id (unsigned int color_index) const { return v1 ().get_color_name_id (this, color_index, numColors); } - bool - get_color_record_argb (unsigned int color_index, unsigned int palette_index, hb_color_t* color) const + inline unsigned int get_palette_colors (unsigned int palette_index, + unsigned int start_offset, + unsigned int *color_count, /* IN/OUT. May be NULL. */ + hb_color_t *colors /* OUT. May be NULL. */) const { - if (unlikely (color_index >= numColors || palette_index >= numPalettes)) - return false; - - /* No need for more range check as it is already done on #sanitize */ - const UnsizedArrayOf<BGRAColor>& color_records = this+colorRecordsZ; - if (color) - *color = color_records[colorRecordIndicesZ[palette_index] + color_index]; - return true; + if (unlikely (palette_index >= numPalettes)) + { + if (color_count) *color_count = 0; + return 0; + } + unsigned int start_index = colorRecordIndicesZ[palette_index]; + hb_array_t<const BGRAColor> all_colors ((this+colorRecordsZ).arrayZ, numColorRecords); + hb_array_t<const BGRAColor> palette_colors = all_colors.sub_array (start_index, + numColors); + if (color_count) + { + hb_array_t<const BGRAColor> segment_colors = palette_colors.sub_array (start_offset, *color_count); + /* Always return numColors colors per palette even if it has out-of-bounds start index. */ + unsigned int count = MIN<unsigned int> (MAX<int> (numColors - start_offset, 0), *color_count); + *color_count = count; + for (unsigned int i = 0; i < count; i++) + colors[i] = segment_colors[i]; /* Bound-checked read. */ + } + return numColors; } private: @@ -157,21 +170,10 @@ struct CPAL inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!(c->check_struct (this) && - (this+colorRecordsZ).sanitize (c, numColorRecords)))) - return_trace (false); - - /* TODO */ - /* Check for indices sanity so no need for doing it runtime */ - for (unsigned int i = 0; i < numPalettes; ++i) - if (unlikely (colorRecordIndicesZ[i] + numColors > numColorRecords)) - return_trace (false); - - /* If version is zero, we are done here; otherwise we need to check tail also */ - if (version == 0) - return_trace (true); - - return_trace (likely (v1 ().sanitize (c, this, numPalettes, numColors))); + return_trace (c->check_struct (this) && + (this+colorRecordsZ).sanitize (c, numColorRecords) && + colorRecordIndicesZ.sanitize (c, numPalettes) && + (version == 0 || v1 ().sanitize (c, this, numPalettes, numColors))); } protected: diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index 59f7da72..229b6e66 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -189,34 +189,13 @@ hb_ot_color_palette_get_flags (hb_face_t *face, * Since: REPLACEME */ unsigned int -hb_ot_color_palette_get_colors (hb_face_t *face, - unsigned int palette_index, /* default=0 */ - unsigned int start_offset, - unsigned int *colors_count /* IN/OUT. May be NULL. */, - hb_color_t *colors /* OUT. May be NULL. */) +hb_ot_color_palette_get_colors (hb_face_t *face, + unsigned int palette_index, + unsigned int start_offset, + unsigned int *colors_count /* IN/OUT. May be NULL. */, + hb_color_t *colors /* OUT. May be NULL. */) { - const OT::CPAL& cpal = _get_cpal(face); - if (unlikely (palette_index >= cpal.get_palette_count ())) - { - if (colors_count) *colors_count = 0; - return 0; - } - - unsigned int num_results = 0; - if (colors_count) - { - unsigned int platte_count; - platte_count = MIN<unsigned int>(*colors_count, - cpal.get_color_count () - start_offset); - for (unsigned int i = 0; i < platte_count; i++) - { - if (cpal.get_color_record_argb(start_offset + i, palette_index, &colors[num_results])) - ++num_results; - } - } - - if (likely (colors_count)) *colors_count = num_results; - return cpal.get_color_count (); + return _get_cpal (face).get_palette_colors (palette_index, start_offset, colors_count, colors); } diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h index 4d08eb06..02b76bff 100644 --- a/src/hb-ot-color.h +++ b/src/hb-ot-color.h @@ -79,11 +79,11 @@ hb_ot_color_palette_get_flags (hb_face_t *face, unsigned int palette_index); HB_EXTERN unsigned int -hb_ot_color_palette_get_colors (hb_face_t *face, - unsigned int palette_index, - unsigned int start_offset, - unsigned int *color_count, /* IN/OUT. May be NULL. */ - hb_color_t *colors /* OUT. May be NULL. */); +hb_ot_color_palette_get_colors (hb_face_t *face, + unsigned int palette_index, + unsigned int start_offset, + unsigned int *color_count, /* IN/OUT. May be NULL. */ + hb_color_t *colors /* OUT. May be NULL. */); /* commit 683fad062792a199e2fe86fe161f41b9389d08c3 Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 22 16:35:03 2018 -0700 [color] Minor diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index 3ca8751a..59f7da72 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -161,8 +161,7 @@ hb_ot_color_palette_flags_t hb_ot_color_palette_get_flags (hb_face_t *face, unsigned int palette_index) { - const OT::CPAL& cpal = _get_cpal(face); - return cpal.get_palette_flags (palette_index); + return _get_cpal(face).get_palette_flags (palette_index); } /** @@ -258,6 +257,5 @@ hb_ot_color_glyph_get_layers (hb_face_t *face, unsigned int *count, /* IN/OUT. May be NULL. */ hb_ot_color_layer_t *layers /* OUT. May be NULL. */) { - const OT::COLR& colr = _get_colr (face); - return colr.get_glyph_layers (glyph, start_offset, count, layers); + return _get_colr (face).get_glyph_layers (glyph, start_offset, count, layers); } commit 14474d21040bf9b025b53bb9b0df599eaf260119 Author: Behdad Esfahbod <[email protected]> Date: Mon Oct 22 16:30:30 2018 -0700 [color] Rely on CPALV1Tail Null object diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 205613e4..37e0db36 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -125,31 +125,13 @@ struct CPAL inline unsigned int get_color_count () const { return numColors; } inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette_index) const - { - if (unlikely (version == 0)) - return HB_OT_COLOR_PALETTE_FLAG_DEFAULT; - - const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this); - return cpal1.get_palette_flags (this, palette_index, numPalettes); - } + { return v1 ().get_palette_flags (this, palette_index, numPalettes); } inline unsigned int get_palette_name_id (unsigned int palette_index) const - { - if (unlikely (version == 0)) - return HB_NAME_ID_INVALID; - - const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this); - return cpal1.get_palette_name_id (this, palette_index, numPalettes); - } + { return v1 ().get_palette_name_id (this, palette_index, numPalettes); } inline unsigned int get_color_name_id (unsigned int color_index) const - { - if (unlikely (version == 0)) - return HB_NAME_ID_INVALID; - - const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this); - return cpal1.get_color_name_id (this, color_index, numColors); - } + { return v1 ().get_color_name_id (this, color_index, numColors); } bool get_color_record_argb (unsigned int color_index, unsigned int palette_index, hb_color_t* color) const @@ -164,14 +146,22 @@ struct CPAL return true; } + private: + inline const CPALV1Tail& v1 (void) const + { + if (version == 0) return Null(CPALV1Tail); + return StructAfter<CPALV1Tail> (*this); + } + + public: inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!(c->check_struct (this) && /* it checks colorRecordIndices also - * See #get_size */ + if (unlikely (!(c->check_struct (this) && (this+colorRecordsZ).sanitize (c, numColorRecords)))) return_trace (false); + /* TODO */ /* Check for indices sanity so no need for doing it runtime */ for (unsigned int i = 0; i < numPalettes; ++i) if (unlikely (colorRecordIndicesZ[i] + numColors > numColorRecords)) @@ -181,8 +171,7 @@ struct CPAL if (version == 0) return_trace (true); - const CPALV1Tail &v1 = StructAfter<CPALV1Tail> (*this); - return_trace (likely (v1.sanitize (c, this, numPalettes, numColors))); + return_trace (likely (v1 ().sanitize (c, this, numPalettes, numColors))); } protected: _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
