Sunday, June 16 2013

Adobe Swatch Exchange file format

The only things I can really add to this excellent description of the format are:

  • the code for grayscale is actually “Gray”, not “GRAY”, although it’s possible some software will accept either.
  • all values are stored big-endian.
  • numbers are single-precision floating point (in Perl pack() terms, “f>”), strings are UTF-16 with a trailing NUL word.
  • LAB colors are in the range 0-1, -128-127, -128-127; no adjustment is necessary.
  • Apparently none of the generated files he examined included the end-palette chunk, which has type 0xC0020000 and does not include a name field.
  • In actual parsing, Illustrator ignores the end-palette chunk anyway, though; all colors have to be part of some group when imported, so they’re added to the most recently named group.

With those additions, my little Perl script is capable of reading everything that comes with Illustrator or is generated by the current version of the Kuler service. Piping the output of my ase2txt script into txt2ase produces identical files, so I’m pretty sure I’ve got everything right.

For fun, I even added the ability to sort swatches by lightness in the L*ab space, and merge in color names using the closest match in Aubrey Jaffer’s collection of color dictionaries (using the conversion and distance formulas from EasyRGB).

Combining the NBS/ISCC dictionary with the results of the XKCD color survey produces a quite reasonable set of names (except for the NBS-ISCC definition of “black”, which might be useful for surface colors, but is useless for monitors). The Resene paint colors offer excellent coverage, but the names are just too eccentric for general description (ex: jon, shark, zeus, cello, haiti, nero, merlin, etc).