RSS/Atom feed Twitter
Site is read-only, email is disabled

Layer modes ported to GEGL, explanation of new compositing model

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.

7 of 8 messages available
Toggle history

Please log in to manage your subscriptions.

Layer modes ported to GEGL, explanation of new compositing model Martin Nordholts 08 Nov 19:06
23f4e3390811082245x7cec14a9... 07 Oct 20:26
  Layer modes ported to GEGL, explanation of new compositing model David Gowers 09 Nov 07:50
  Layer modes ported to GEGL, explanation of new compositing model Martin Nordholts 09 Nov 22:48
   Layer modes ported to GEGL, explanation of new compositing model David Gowers 09 Nov 23:48
    Layer modes ported to GEGL, explanation of new compositing model Martin Nordholts 10 Nov 00:07
    Layer modes ported to GEGL, explanation of new compositing model David Gowers 10 Nov 03:20
     Layer modes ported to GEGL, explanation of new compositing model David Gowers 10 Nov 03:37
Martin Nordholts
2008-11-08 19:06:35 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hi

The layer modes have now been ported to GEGL.

As layer mode compositing with GEGL uses a different model than legacy layer mode compositing it deserves some elaboration. If you want to try out the new layer mode compositing you can do View -> Use GEGL in GIMP trunk.

The new model is based on the one in the SVG 1.2 draft: http://www.w3.org/TR/2004/WD-SVG12-20041027/rendering.html

The model used is

Dca' = f(Sc, Dc) * Sa * Da + Sca * (1 - Da) + Dca * (1 - Sa) Da' = Sa * Da + Sa * (1 - Da) + Da * (1 - Sa)

where

Sc is the layer color (channels) Dc is the composite of the layers below Dc' is the result composite
Xa means alpha channel
Xca means pre-multiplied data
f(Sc, Dc) is a blending formula

Things to note about this model:

The contribution to the end pixel that comes from the layer mode specific blending is proportial to Sa * Da, i.e. the subpixel area that contains both the layer and below composite in the Porter-Duff alpha compositing model. The rest of the contribution to the end pixel comes from the unblended (since there is nothing sensible to blend with) layer and below composite pixels: Sca * (1 - Da) + Dca * (1 - Sa). All layers independent of layer mode are treated as having an opacity and thus affect the alpha of the final composite.

This new model creates a more consistent and predictable layer mode blending experience.

Examples of differences compared to legacy layer mode compositing:

1. With a 50% opaque Addition mode layer put on top a 50% opaque Normal mode layer, the resulting composite has an opacity of 0.5 + 0.5 - 0.5 * 0.5 = 75% with GEGL layer mode compositing, but 50% with legacy layer mode compositing.

2. With a 100% opaque Addition mode layer put on top a completely transparent layer, the resulting composite becomes 100% opaque containing the unblended Addition mode layer pixels when using GEGL, but completely transparent when using legacy compositing.

The current plan is to have add kind of compatibility rendering mode so that old .xcfs will render the same as in old versions of GIMP also when using GEGL.

BR,
Martin

David Gowers
2008-11-09 07:50:38 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hello Martin,

On Sun, Nov 9, 2008 at 4:36 AM, Martin Nordholts wrote:

2. With a 100% opaque Addition mode layer put on top a completely transparent layer, the resulting composite becomes 100% opaque containing the unblended Addition mode layer pixels when using GEGL, but completely transparent when using legacy compositing.

Ah, so if I want to make the result preserve the alpha of the underlying layer, I'll need to do that via layer mask?

FWIW, since you changed the meaning of the layer modes, is this a good time to make compositing gamma-correct? Currently, GIMP blends pixels as if they had gamma == 1.0, whereas the typical is sRGB (approximation of gamma 2.2). I thought GIMP would do this as it was switched over to GEGL; it doesn't currently. Evidence:
1. Create a new square image (with sRGB profile or no color profile) 2. Fill with black
3. Add another layer
4. Draw a radial gradient white->transparent 5. Set layer mode to Addition
6. Toggle 'View->Use gegl' on and off. The result is identical; rather than showing a linear blend white -> black, an exponential blend (ie sRGB) white->black is shown.

Small example images attached, 'wrongblend.png' and 'rightblend.png'. IMO it is correct for GIMP to produce results similar to 'rightblend.png' when GEGL use is enabled.

The current plan is to have add kind of compatibility rendering mode so that old .xcfs will render the same as in old versions of GIMP also when using GEGL.

In this case, we should definitely aim to have gamma-correct blending. Legacy compatibility for gamma can be done by binding our current behaviour (pretend the data is gamma 1.0 while it really isn't) to the 'legacy rendering' option (presumably auto-triggered on detection of legacy XCFs)

David

Martin Nordholts
2008-11-09 22:48:19 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hi David

David Gowers wrote:

Ah, so if I want to make the result preserve the alpha of the underlying layer, I'll need to do that via layer mask?

Exactly, masking should generally be performed *after* blending with the new layer mode compositing model.

FWIW, since you changed the meaning of the layer modes, is this a good time to make compositing gamma-correct?

Yes definitely. In fact, layer mode compositing with GEGL _does_ work on data with gamma = 1.0. That is, the layer mode blending occurs on color data in the babl format "RaGaBaA float", i.e pre-multiplied, linear light 32 bit per channel RGBA.

The reason you don't see a difference when toggling Use GEGL is that now during development the source data, namely the data from the tiles of the TileManagers of the GimpDrawables, are treated as if containing color data in the babl format "RGBA u8", i.e. linear light 8 bit per channel RGBA. A more correct assumption would be "R'G'B'A u8", i.e. gamma corrected RGBA.

The long term goal is of course to make sure color space conversions are correct throughout the whole image processing pipeline, taking into account the current color profile of the image etc.

BR, Martin

David Gowers
2008-11-09 23:48:40 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hello Martin,

On Mon, Nov 10, 2008 at 8:18 AM, Martin Nordholts wrote:

Hi David

David Gowers wrote:

Ah, so if I want to make the result preserve the alpha of the underlying layer, I'll need to do that via layer mask?

Exactly, masking should generally be performed *after* blending with the new layer mode compositing model.

Cool, I like this, it certainly is more consistent :)

FWIW, since you changed the meaning of the layer modes, is this a good time to make compositing gamma-correct?

Yes definitely. In fact, layer mode compositing with GEGL _does_ work on data with gamma = 1.0. That is, the layer mode blending occurs on color data in the babl format "RaGaBaA float", i.e pre-multiplied, linear light 32 bit per channel RGBA.

The reason you don't see a difference when toggling Use GEGL is that now during development the source data, namely the data from the tiles of the TileManagers of the GimpDrawables, are treated as if containing color data in the babl format "RGBA u8", i.e. linear light 8 bit per channel RGBA. A more correct assumption would be "R'G'B'A u8", i.e.

Thank you for explaining that, it was just what I suspected :)

I'll see what happens when I make that change :) (apparently just one line, app/core/gimpprojection.c:391, is needed to be changed to implement this now :D)

gamma corrected RGBA.

The long term goal is of course to make sure color space conversions are correct throughout the whole image processing pipeline, taking into account the current color profile of the image etc.

So eventually we need to be able to construct on-demand babl_formats which utilize arbitrary profiles, and have babl depend on lcms to get a acceptably quick transform between those and the standard spaces? And recognize the use of standard colorspace profiles (eg sRGB, linear-light RGB) so we can get faster processing for them?

David

Martin Nordholts
2008-11-10 00:07:46 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

David Gowers wrote:

So eventually we need to be able to construct on-demand babl_formats which utilize arbitrary profiles, and have babl depend on lcms to get a acceptably quick transform between those and the standard spaces? And recognize the use of standard colorspace profiles (eg sRGB, linear-light RGB) so we can get faster processing for them?

David

Exactly where in the pipeline to insert color profile conversions is an open question. Some kind of integration with babl sounds sane to me as well. We probably want to make use of caching in GEGL somehow too, to avoid doing color space conversions all the time.

- Martin

David Gowers
2008-11-10 03:20:21 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hi,

On Mon, Nov 10, 2008 at 9:18 AM, David Gowers wrote:

I'll see what happens when I make that change :) (apparently just one line, app/core/gimpprojection.c:391, is needed to be changed to implement this now :D)

This was slightly more complex than I said. Somewhat hackish diff attached.

It effects color tools as well as compositing. (that may be controversial, since it changes the meaning of existing Levels, etc.. tool settings. It does mean you can do a proper linear inversion, and recoloring with the Curves tool is a good deal more intuitive than before. (recoloring with 'colorize' is VASTLY better than before -- the output actually is good quality :))

Easiest way to see the color-tool difference is to make a greyscale gradient and use the Levels tool (set output minimum to 255 and output maximum to 0, then toggle 'Colors->Use Gegl')

It exposes a bug in either the 'threshold' op, or babl. Try it with default settings, on a greyscale B->W gradient, and notice #ffffff becomes black rather than white

Of course, this does not fix the various places where we refer to values in range 0...255 (eg Threshold dialog) where really, we should use 0..1 or 0...100. IMO adjustment step-size needs to be carefully thought out -- 1/255.
(0.0039215686274509803)
is actually wrong (because the adjustment is done in linear space; the correct minimum step size is
0.00030352698354883752)

Lastly! I don't know whether this merges shadow-tiles in linear-light RGB or not. It appears that it does, but I haven't run proper tests yet :)

I am amazed and excited how easy this was :D

David

David Gowers
2008-11-10 03:37:41 UTC (about 16 years ago)

Layer modes ported to GEGL, explanation of new compositing model

Hello,

On Mon, Nov 10, 2008 at 12:50 PM, David Gowers wrote:

Lastly! I don't know whether this merges shadow-tiles in linear-light RGB or not. It appears that it does, but I haven't run proper tests yet :)

No, it doesn't.

David