Flame::Palette - Perl extension to parse, unparse, create, process Flam3 palettes


  use Flame::Palette;

  my $pal = Flame::Palette->new;
  $pal->set(index => 0, red => 255, green => 0, blue => 0);
  $pal->set(index => 127, red => 0, green => 255, blue => 0);
  $pal->set(index => 255, red => 0, green => 0, blue => 255);


This module provides a palette class, which knows these methods:

  • $pal = Flame::Palette->new

    Constructor. Creates an empty palette, consisting of nothing

  • $pal->set(index => n, red => x, green => y, blue => z)

    Set the entry whose number is n to the RGB values red=x, green=y, blue=z. All of those values have to be in the range 0...255

  • (red, green, blue) = $pal->get(index => n)

    Retrieve the entry whose number is n. Returns an array in array context and an array reference otherwise. Returns black if the requested entry was not previously set.

  • $pal->parse_xml(stream)

    Clear the existing palette and parse the XML file which is retrieved when reading the supplied stream. The XML file has to look like:

       <color index="0" rgb="255 0 0" />
       <!-- some entries are omitted -->
       <color index="255" rgb="0 0 255" />

    Trick: you can read from plain strings so you do not need to provide an actual file. Try this:

     my $string;
     open(my $stream, '<', \$string);
  • $pal->parse_flame(stream)

    Do the same as the parse_xml() method, with the exception that the XML file must be a .flame one.

  • $pal->unparse_xml(stream)

    Dump the palette to an XML file. The stream doesn't have to be an open file, the trick shown above also works in the opposite direction:

     my $string;
     open(my $stream, '>', \$string);
  • $pal->interpolate

    If the palette is sparse, e.g there are at least two entries with no other entires but space in between (similar to the sparse file concept of modern operating systems), the missing entries are interpolated from the entries around. Try the example shown at the top.

  • $pal->clear

    Remove all the existing entries.




Flam3 itself:


SVN: $Id: 125 2010-12-28 23:34:37Z daniel $


David Kroeber <>


Copyright (C) 2010 by David Kroeber

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.2 or, at your option, any later version of Perl 5 you may have available.