[color] Finish reviewing / revamping CPAL
Now to hb_color_t.
This commit is contained in:
parent
683fad0627
commit
228f96c9d0
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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. */);
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user