Based on libcompface code by James Ashton <James.Ashton@anu.edu.au>, and relicensed to LGPL with the author's consent.