Module: Skrift::Color::CPAL
- Defined in:
- lib/skrift/color/cpal.rb
Overview
Parses a CPAL table’s first palette into an array of [r, g, b, a] (0..255). CPAL stores colours as BGRA; we normalise to RGBA. Returns nil if the font has no CPAL table.
Class Method Summary collapse
Class Method Details
.parse(font) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/skrift/color/cpal.rb', line 11 def parse(font) off = font.tables["CPAL"] return nil unless off num_entries = font.getu16(off + 2) records_off = off + font.getu32(off + 8) first_index = font.getu16(off + 12) # colorRecordIndices[0] num_entries.times.map do |i| rec = records_off + (first_index + i) * 4 b = font.getu8(rec) g = font.getu8(rec + 1) r = font.getu8(rec + 2) a = font.getu8(rec + 3) [r, g, b, a] end end |