Sign up now! · Forgot password?
RSS/Atom feed Twitter

Format of GIMP gradient files

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

8 of 8 messages available
Toggle history

Please log in to manage your subscriptions.

Format of GIMP gradient files Gordon Royle 30 May 11:44
  Format of GIMP gradient files Branko Collin 30 May 12:14
  Format of GIMP gradient files Sven Neumann 30 May 13:52
   Format of GIMP gradient files David Neary 30 May 14:25
    Format of GIMP gradient files Steinar H. Gunderson 30 May 14:44
    Format of GIMP gradient files Sven Neumann 30 May 14:55
  Format of GIMP gradient files David Neary 30 May 14:06
Format of GIMP gradient files Michael Natterer 30 May 16:02
Gordon Royle
2002-05-30 11:44:43 UTC (over 17 years ago)

Format of GIMP gradient files

Hi,

What is the format of the GIMP gradient files?

For example, the gradient "default" which goes from black->white with a grey midpoint has the following text format:

GIMP Gradient 1
0.000000 0.500000 1.000000 0.000000 0.000000 0.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0

and the gradient French flag has the format:

GIMP Gradient 3
0.000000 0.166667 0.333333 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0 0 0.333333 0.500000 0.666667 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0 0.666667 0.833333 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 0 0

So the first number is obviously the number of segments in the gradient, and therefore each line must describe one segment.

The first three values are the left/middle/right end points of the segments respectively.

this leaves me with 8 floating point numbers and 2 integers to describe the three colours - the first 3 numbers seem to be the RGB values of the left end point. But what the heck are the remaining numbers? They don't seem to correspond to anything !

Any help appreciated...

Branko Collin
2002-05-30 12:14:29 UTC (over 17 years ago)

Format of GIMP gradient files

On 30 May 2002, at 17:44, Gordon Royle wrote:

What is the format of the GIMP gradient files?

For example, the gradient "default" which goes from black->white with a grey midpoint has the following text format:

GIMP Gradient 1
0.000000 0.500000 1.000000 0.000000 0.000000 0.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0

and the gradient French flag has the format:

GIMP Gradient 3
0.000000 0.166667 0.333333 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0 0 0.333333 0.500000 0.666667 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0 0.666667 0.833333 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 0 0

So the first number is obviously the number of segments in the gradient, and therefore each line must describe one segment.

The first three values are the left/middle/right end points of the segments respectively.

this leaves me with 8 floating point numbers and 2 integers to describe the three colours - the first 3 numbers seem to be the RGB values of the left end point. But what the heck are the remaining numbers? They don't seem to correspond to anything !

What helps for me usually is look at the code for loading and saving GIMPy things, in this case gradients. It depends a bit on who coded and how well-chosen variable names are, but most of the time numbers are loaded in the order they are written and you should be able to make some sense of them by looking at the variable names.

If you don't want to download the GIMP's source, you can study it through .

Another way of finding out may be to look at the PDB (/Xtns/Database Browser..., if I am not mistaken) and see if there are any public functions for manipulating

I am sorry if this is not very helpful, but I am busy. Perhaps someone else could give a more exact answer.

Sven Neumann
2002-05-30 13:52:08 UTC (over 17 years ago)

Format of GIMP gradient files

Hi,

Gordon Royle writes:

What is the format of the GIMP gradient files?

this routine saves the gradient. You should be able to determine the format from this info:

for (seg = gradient->segments; seg; seg = seg->next) {
gchar buf[11][G_ASCII_DTOSTR_BUF_SIZE];

g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left); g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->middle); g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right); g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.r); g_ascii_formatd (buf[4], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.g); g_ascii_formatd (buf[5], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.b); g_ascii_formatd (buf[6], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.a); g_ascii_formatd (buf[7], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.r); g_ascii_formatd (buf[8], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.g); g_ascii_formatd (buf[9], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.b); g_ascii_formatd (buf[10], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.a);

fprintf (file, "%s %s %s %s %s %s %s %s %s %s %s %d %d\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], (gint) seg->type,
(gint) seg->color);
}

Salut, Sven

David Neary
2002-05-30 14:06:23 UTC (over 17 years ago)

Format of GIMP gradient files

Gordon Royle wrote:

Hi,

What is the format of the GIMP gradient files?

For example, the gradient "default" which goes from black->white with a grey midpoint has the following text format:

GIMP Gradient 1
0.000000 0.500000 1.000000 0.000000 0.000000 0.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0

and the gradient French flag has the format:

GIMP Gradient 3
0.000000 0.166667 0.333333 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0 0 0.333333 0.500000 0.666667 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0 0.666667 0.833333 1.000000 1.000000 0.000000 0.000000 1.000000 1.000000 0.000000 0.000000 1.000000 0 0

So the first number is obviously the number of segments in the gradient, and therefore each line must describe one segment.

The first three values are the left/middle/right end points of the segments respectively.

this leaves me with 8 floating point numbers and 2 integers to describe the three colours - the first 3 numbers seem to be the RGB values of the left end point. But what the heck are the remaining numbers? They don't seem to correspond to anything !

The format seems to be
start middle end [range 0...1]
R G B A left endpoint
R G B A right endpoint
type where type is one of linear (0), curved, sine, sphere_increasing and shere_decreasing coloring, one of rgb, hsv_ccw, hsv_cw

The type & colouring are accessible to the gradient editor (the user, I mean) in the "blending function for segment" and "Colouring type for segment" menus of the gradient editor menu.

This information is available in app/gradient.c and app/gradient_header.h.

Dave.

David Neary
2002-05-30 14:25:04 UTC (over 17 years ago)

Format of GIMP gradient files

Sven Neumann wrote:

Hi,

Gordon Royle writes:

What is the format of the GIMP gradient files?

this routine saves the gradient. You should be able to determine the format from this info:

Really? In 1.2, it appears to be this...

fprintf (file, "%d\n", num_segments);

for (seg = grad->segments; seg; seg = seg->next) fprintf (file, "%f %f %f %f %f %f %f %f %f %f %f %d %d\n", seg->left, seg->middle, seg->right, seg->r0, seg->g0, seg->b0, seg->a0, seg->r1, seg->g1, seg->b1, seg->a1, (int) seg->type, (int) seg->color);

Why the huge change?

Dave.

Steinar H. Gunderson
2002-05-30 14:44:01 UTC (over 17 years ago)

Format of GIMP gradient files

On Thu, May 30, 2002 at 02:25:04PM +0200, David Neary wrote:

Really? In 1.2, it appears to be this...

fprintf (file, "%d\n", num_segments);

for (seg = grad->segments; seg; seg = seg->next) fprintf (file, "%f %f %f %f %f %f %f %f %f %f %f %d %d\n", seg->left, seg->middle, seg->right, seg->r0, seg->g0, seg->b0, seg->a0, seg->r1, seg->g1, seg->b1, seg->a1, (int) seg->type, (int) seg->color);

Why the huge change?

That's hardly a "huge change" from the original, is it?

/* Steinar */

Sven Neumann
2002-05-30 14:55:10 UTC (over 17 years ago)

Format of GIMP gradient files

Hi,

David Neary writes:

Really? In 1.2, it appears to be this...

fprintf (file, "%d\n", num_segments);

for (seg = grad->segments; seg; seg = seg->next) fprintf (file, "%f %f %f %f %f %f %f %f %f %f %f %d %d\n", seg->left, seg->middle, seg->right, seg->r0, seg->g0, seg->b0, seg->a0, seg->r1, seg->g1, seg->b1, seg->a1, (int) seg->type, (int) seg->color);

Why the huge change?

because the string representaion of doubles and floats is locale-dependent. In GIMP-1.2 we had to explicitely set LC_NUMERIC to C to make it work. Since this is a bad idea we changed to the locale-indenpendent g_ascii_formatd() / g_ascii_dtostr() in GIMP-1.3.

You might have noticed that numbers are displayed with the digits-seperator specified by your locale in GIMP-1.3 while in GIMP-1.2 it's always '.' as defined the C locale.

Salut, Sven

Michael Natterer
2002-05-30 16:02:50 UTC (over 17 years ago)

Format of GIMP gradient files

David Neary writes:

Sven Neumann wrote:

Hi,

Gordon Royle writes:

What is the format of the GIMP gradient files?

this routine saves the gradient. You should be able to determine the format from this info:

Really? In 1.2, it appears to be this...

fprintf (file, "%d\n", num_segments);

for (seg = grad->segments; seg; seg = seg->next) fprintf (file, "%f %f %f %f %f %f %f %f %f %f %f %d %d\n", seg->left, seg->middle, seg->right, seg->r0, seg->g0, seg->b0, seg->a0, seg->r1, seg->g1, seg->b1, seg->a1, (int) seg->type, (int) seg->color);

Why the huge change?

I don't see any change in the file format except the following:

In GIMP 1.3, gradients have an extension ".ggr" and don't encode thair name in the filename anymore but inside the .ggr file:

GIMP Gradient Name: Abstract 1
6
0.000000 0.286311 0.572621 0.269543 0.259267 1.000000 1.000000 0.215635 0.407414 0.984953 1.000000 0 0 0.572621 0.657763 0.716194 0.215635 0.407414 0.984953 1.000000 0.040368 0.833333 0.619375 1.000000 0 0 0.716194 0.734558 0.749583 0.040368 0.833333 0.619375 1.000000 0.680490 0.355264 0.977430 1.000000 0 0 0.749583 0.784641 0.824708 0.680490 0.355264 0.977430 1.000000 0.553909 0.351853 0.977430 1.000000 0 0 0.824708 0.853088 0.876461 0.553909 0.351853 0.977430 1.000000 1.000000 0.000000 1.000000 1.000000 0 0 0.876461 0.943172 1.000000 1.000000 0.000000 1.000000 1.000000 1.000000 1.000000 0.000000 1.000000 0 0

Which is still so ugly that i think we should never allow the new format to become used, but port it to a GimpConfig style format:

# GIMP Gradient file

(GimpGradient "Abstract 1" (segment 0.000000 0.286311 0.572621 (left-color (gimp-rgba 0.269543 0.259267 1.000000 1.000000)) (right-color (gimp-rgba 0.215635 0.407414 0.984953 1.000000)) (blending-function linear) (coloring-type rgb)) (segment ...)
...
(segment ...))

Of course, GIMP would continue to read the old files.

ciao, --mitch