# Re: [Gimp-developer] =?utf-8?q?Overlay_Mode_-_fix=2E?=

• To: gimp-developer-list gnome org
• Subject: Re: [Gimp-developer] Overlay Mode - fix.
• Date: Wed, 14 Nov 2012 00:14:55 +0400

I had some experience in converting sRGB to linear RGB. When I coded in GLSL. I have taken this code from blender GLSL shader.
The main idea is: convert all inputs to linear RGB, then make formula calculation, then convert output to sRGB.

The methods from blender GLSL shader (it works per channel):

float srgb_to_linearrgb(float c)
{
if(c < 0.04045)
return (c < 0.0)? 0.0: c * (1.0/12.92);
else
return pow((c + 0.055)*(1.0/1.055), 2.4);
}

float linearrgb_to_srgb(float c)
{
if(c < 0.0031308)
return (c < 0.0)? 0.0: c * 12.92;
else
return 1.055 * pow(c, 1.0/2.4) - 0.055;
}

So, now we have these 2 methods which can convert from sRGB to linearRGB and from linear RGB to sRGB.
----------

For example we have 2 layers:
layer1 and layer2.

layer1.r = srgb_to_linearrgb(layer1.r);  // convert srgb input to liner rgb
layer1.g = srgb_to_linearrgb(layer1.g);
layer1.b = srgb_to_linearrgb(layer1.b);
layer2.r = srgb_to_linearrgb(layer2.r);
layer2.g = srgb_to_linearrgb(layer2.g);
layer2.b = srgb_to_linearrgb(layer2.b);

output = layer1*layer2; //this is a formula example to multyply
output.r =linearrgb_to_srgb(output.r ); // convert linear output to srgb
output.g= linearrgb_to_srgb(output.g);
output.b =linearrgb_to_srgb(output.b );

------

What do you say about it?
But i think Photoshop does not convert anything to linear...

Втр 13 Ноя 2012 18:37:19 от Michael Natterer <mitch gimp org>:
On Tue, 2012-11-13 at 16:27 +0100, Simon Budig wrote:
> Alexandre Prokoudine (alexandre prokoudine gmail com) wrote:
> > I would suggest to detect XCF version and for files with legacy
> > blending modes rename the mode to "Legacy Overlay" and suggest
> > resaving, while using just "Overlay" for all new files.
>
> There is no need to fiddle around with the XCF version. The layer mode
> basically is an enum. We simply keep the old enum value (and the "buggy"
> legacy overlay implementation) around and assign a new one to the fixed
> "Overlay". Then we hide the "Legacy Overlay" in the menu (unless it is
> used).

The problem is much bigger. Almost *all* of our layer modes
will be "Legacy", and the new modes will operate in linear
light. Just adding a hack for overlay is not going to
fix the root problem.

--mitch

> This however needs to be done. Just exchanging the math in the overlay
> operation won't cut it.
>
> Bye,
> Simon

_______________________________________________
gimp-developer-list mailing list
gimp-developer-list gnome org
https://mail.gnome.org/mailman/listinfo/gimp-developer-list