It is currently Wed Apr 24, 2024 6:20 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 9:09 am  (#1) 
Offline
GimpChat Member

Joined: Aug 27, 2013
Posts: 7
GIMP Version: 2.8.4
Operating System: Windows
GIMP Experience: Beginner Level



How could I know the algorithms for the blending modes in GIMP per pixel?

For example, if we discuss the "normal" blending mode. Here is what the help says:

"
Normal mode is the default layer mode. The layer on top covers the layers below it. If you want to see anything below the top layer when you use this mode, the layer must have some transparent areas.

The equation is:

Equation 8.2. Equation for layer mode “Normal”

E = M
"

I have made a test image with 1x1 size. I am testing with two layers. The end result per channel seems to be some sort of interpolation that depends on the alpha values of the layers, and it is not quite as simple as the above equation says. I usually want to understand what is happening when I am doing something, so it would be nice to know what is the real magic behind the scenes.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 9:35 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
See this article for more information.
http://gimp-savvy.com/BOOK/index.html?node55.html

The entire HTML book tarball download link -
http://gimp-savvy.com/BOOK/TarDist/Grok ... 1.0.tar.gz

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 9:55 am  (#3) 
Offline
GimpChat Member

Joined: Aug 27, 2013
Posts: 7
Thanks. Unfortunately, however, the article does not cover the information I am after, if I understood correctly.

For example, let's say that I have these layers:

Foreground: (Normal blending) R: 0 / G: 1 / B: 0 / A: 0.49
Background: (Normal blending) R: 0 / G: 0 / B: 1 / A: 0.84
Result: R: 0 / G: 0.54 / B: 0.46 / A: 0.92

The result is a mystery for me.


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 10:15 am  (#4) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
usually the background layer remain in normal mode at 100% opacity, are the layer(s) above that may have different mode and opacity.

I suppose is not a rule but vary mode and opacity of the BG layer doesn't seems give good result and for sure made the result less easy to predict ... if you modify BG transparency there is nothing behind that may transpare

About the formula were a couple of discussions in the gmic group on flickr on merging mode , with links to the sources of algorithms used.

Gmic may be more interesting because has more modes supported, instead gimp has still a couple of serius bugs in the color modes (mainly "Soft Light" and "Overlay" give always the identical result but where also discussion on the color mode, compared with the PS color mode )

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 10:17 am  (#5) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The equations that are given in the GIMP Users Manual presume an opacity of 100% for the pixels of both layers. The resulting pixel's value, taking into account opacity(or alpha), is the linear interpolation between the lower layer (I) and the result of the given formula.

So for Normal mode, the actual equation is E= α*M + (1-α)*I . Where α is the opacity of the pixel (normalized to fall within the range 0..1).

For Hard Light, where the given equation is E=(2*M*I)/256 for when M's value is < 128, the actual equation is E=(α*2*M*I)/256 + (1-α)*I . When M's value is >128, the formula is E=α*(255 - ((255-I)*(255-(2*(M-128))))/256) + (1-α)*I .

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Wed Aug 28, 2013 10:37 am, edited 1 time in total.

Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 10:36 am  (#6) 
Offline
GimpChat Member

Joined: Aug 27, 2013
Posts: 7
Thanks saulgoode, this seems to be what I am looking for.

Does this equation concern the calculation of a color channel? If so, is 'a' the alpha channel value of the upper or lower layer, or of the end result?

According to my calculations, the result pixel's alpha channel value seems to be: resultA = upperA + (1 - upperA) * lowerA. (values being 0-1, not 0-255)


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 10:59 am  (#7) 
Offline
GimpChat Member

Joined: Aug 27, 2013
Posts: 7
My test calculations with what results gimp gives me are not matching the equation. Could you possibly give me an example with values, using for example the green channel in the example of post #3, please? I would like to understand this.


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 11:55 am  (#8) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
5.6 The Blending Modes at Grokking the Gimp is not exactly what your looking for but does contain useful information on the topic.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 12:11 pm  (#9) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
Quote:
The equations that are given in the GIMP Users Manual presume an opacity of 100% for the pixels of both layers.


Yes and in practice is needed to be able to modify the opacity of the layer above and that make the calculation more complex .

But from your example on merging the channels i believe you want modify also the opacity and mode of the BG layer and that in most of cases doesn't make much sense and anyway add even more complexities to the calculation :

I believe without much good reasons because i can't see reasons to modify mode and transparency of the BG layer , merging mode is almost meaningless for the BG layer because , as example Lighten Only, Darken Only, Multiply, all are supposed to be used with a layer below and have no any sense with nothing below, that is always the case for the BG layer that for definition has no layer below it

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 3:18 pm  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
Gimp uses the standard algorithm: http://en.wikipedia.org/wiki/Alpha_compositing

However, if I understand correctly a couple of exchanges I have seen on the developer's list, it all depends whether you are working in direct light on in gamma-corrected light. As I understand it, 8-bit Gimp always work in gamma-corrected light(*), so what really happens is that the RGB value are gamma-uncorrected to go back to direct light, then the compositing is computed, and then the gamma-correction is applied on the result, so you don't get exactly what the straightforward computation gives you. If you need more info there is a full source tarball awaiting you :)

(*) IIRC the discussion was about the possibility to drop the gamma-correction when working in high-precision in the future versions.

_________________
Image


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 5:51 pm  (#11) 
Offline
GimpChat Member

Joined: Aug 27, 2013
Posts: 7
Thanks. This should help me understand the issue. :)

PhotoComix: Yeah, I think the lower layer's blend mode does not affect it, unless there are layers underneath that.


Top
 Post subject: Re: Exact algorithms for blend modes
PostPosted: Wed Aug 28, 2013 6:43 pm  (#12) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
In practice affect a lot (you may try and see ) but creates only problems

It happened to me, by changing layers position to move as BG layer one with low opacity and different mode and never that had interesting effect ,
merge suppose something BELOW to be merged with , if there is nothing as always in case of the BG layer is even possible presume for usability (and/or to no crash the programs with impossible calculation when moving layers ) a imaginary layer filled with transparency , white or the BG color below the BG layer

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Is there anyway to add blend modes inbetween operations in Bimp?

2

No new posts Attachment(s) How to reproduce Gimp's levels using blend modes of color fills

0

No new posts Attachment(s) GEGL Custom Bevel - Change internal blend modes, blur types & more

39

No new posts Attachment(s) GEGL Color Light Fusion (12 blend modes for color overlay)

9

No new posts Attachment(s) My plan to deal with many bevel algorithms (put them all in one place)

13



* Login  



Powered by phpBB3 © phpBB Group