Skip to content


A QT Project – Fractal Generator – Loading Palette

So far I didn’t spend too much time with the colors themselves in the palette. I used a palette which I generated by changing the rgb values linearly. I still do not want to spend time for figuring out new palette generation algorithms or implementing existing ones. Rather I added palette loading functionality to Arthur to load ready made palettes. This way palettes can be generated by other programs like GIMP. So I checked what palette file format gimp is using. It is very simple. The rgb values are stored in a text file. Each value is in its own line. Values are separated by white spaces. I wrote a loader that opens a text file and reads lines from it until the end of the file or until we filled all the 256 colors in the color table.

For each line I do the followings:

  1. Simplify the line (white spaces converted to spaces)
  2. Split the line to items at each space
  3. Remove empty items
  4. If we had at least three items remained, try to convert the first three items to integer numbers.
  5. If all the three conversion went fine, add the color to the color table

If the file ends before we fill all the 256 colors, the loader fills the rest of the colors with black values.

If the file contains more than 256 color entries than the loader does not read further after the 256th color is loaded.

This way I can handle e.g. GIMP palette files (*.gpl) or anything that fulfills the rule of the algorithm above.

I added a palette folder to the sources and copied two palettes from GIMP as examples.

Here is a Julia fractal rendered with the Firecode.gpl palette:

You can get the sources from here: fractal014

Posted in Arthur Fractal Generator, QT Programming.

Tagged with , , , .