Skip to content

Commit

Permalink
Merge 922972f into a3e29fd
Browse files Browse the repository at this point in the history
  • Loading branch information
ebraminio committed Mar 4, 2018
2 parents a3e29fd + 922972f commit 7e5cff9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
60 changes: 20 additions & 40 deletions src/hb-ot-color-cpal-table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@
namespace OT {


struct ColorRecord
{
friend struct CPAL;

inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (true);
}

protected:
HBUINT8 blue;
HBUINT8 green;
HBUINT8 red;
HBUINT8 alpha;
public:
DEFINE_SIZE_STATIC (4);
};

struct CPALV1Tail
{
friend struct CPAL;
Expand Down Expand Up @@ -96,6 +77,8 @@ struct CPALV1Tail
DEFINE_SIZE_STATIC (12);
};

typedef HBUINT32 BGRAColor;

struct CPAL
{
static const hb_tag_t tableTag = HB_OT_TAG_CPAL;
Expand All @@ -104,28 +87,20 @@ struct CPAL
{
TRACE_SANITIZE (this);
if (!(c->check_struct (this) &&
colorRecords.sanitize (c)))
return_trace (false);

unsigned int palettes = numPalettes;
if (!c->check_array (colorRecordIndices, sizeof (HBUINT16), palettes))
c->check_array ((const void*) &colorRecords, sizeof (BGRAColor), numColorRecords) &&
c->check_array ((const void*) &colorRecordIndices, sizeof (HBUINT16), numPalettes)))
return_trace (false);

for (unsigned int i = 0; i < palettes; ++i)
if (colorRecordIndices[i] + numPaletteEntries > colorRecords.get_size ())
for (unsigned int i = 0; i < numPalettes; ++i)
if (colorRecordIndices[i] + numPaletteEntries > 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);

const CPALV1Tail &v1 = StructAfter<CPALV1Tail> (*this);
return_trace (v1.sanitize (c, palettes));
}

inline unsigned int get_size (void) const
{
return min_size + numPalettes * 2;
return_trace (v1.sanitize (c, numPalettes));
}

inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette) const
Expand All @@ -151,22 +126,27 @@ struct CPAL
return numPalettes;
}

inline void get_color_record (int palette_index, uint8_t &r, uint8_t &g,
uint8_t &b, uint8_t &a) const
inline unsigned int get_size (void) const
{
return min_size + numPalettes * sizeof (HBUINT16);
}

inline uint32_t get_color_record_argb (unsigned int color_index, unsigned int palette) const
{
// We should check if palette_index is in range as it is not done on COLR sanitization
r = colorRecords[palette_index].red;
g = colorRecords[palette_index].green;
b = colorRecords[palette_index].blue;
a = colorRecords[palette_index].alpha;
if (color_index > numPaletteEntries || palette > numPalettes)
return 0;

const BGRAColor* records = &colorRecords(this);
return records[colorRecordIndices[palette] + color_index];
}

protected:
HBUINT16 version;
/* Version 0 */
HBUINT16 numPaletteEntries;
HBUINT16 numPalettes;
ArrayOf<ColorRecord> colorRecords;
HBUINT16 numColorRecords;
LOffsetTo<HBUINT32> colorRecords;
HBUINT16 colorRecordIndices[VAR]; // VAR=numPalettes
/*CPALV1Tail v1[VAR];*/
public:
Expand Down
5 changes: 1 addition & 4 deletions src/hb-ot-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ HB_BEGIN_DECLS
*
* Since: REPLACEME
*/
typedef struct
{
uint8_t red, green, blue, alpha;
} hb_ot_color_t;
typedef uint32_t hb_ot_color_t;


/**
Expand Down

0 comments on commit 7e5cff9

Please sign in to comment.