Notifications
Clear all
[Closed] Swap green for blue wisely
Page 4 / 4
Prev
Dec 08, 2020 2:39 am
Super interesting guys, I never realized that a simple color change wouldn’t be enough with regards to intensity and the above reads are enlightening (pun intended)
Dec 08, 2020 2:39 am
that’s the difference between “desaturate” and “grayscale”
Dec 08, 2020 2:39 am
That looks pretty good to me.
It may not be numerically correct but visually it looks as good as it can be.
Here my last code, now optimized.
fn SwapBlueGreenChannels colour =
(
l1 = (colour.g^2 * 5.0 + colour.b^2)+1.0
l2 = (colour.b^2 * 5.0 + colour.g^2)+1.0
delta = sqrt (l1 / l2)
b = colour.g * delta
if b > 255 then
(
g = sqrt ((l1 - 65025)/5.0)
b = 255
)else(
g = colour.b * delta
)
return (color colour.r g b)
)
Dec 08, 2020 2:39 am
Yes. I mean no, it’s there because it has secret powers.
Well, I didn’t want to use int() or “if”. Do we have other options?
I know, it looks horrible!
Dec 08, 2020 2:39 am
it makes sense anyway:
if (c.g == 0 and c.b == 0) or (c.g == c.b) return c
here is c++
AColor SwapGreenBlue(const AColor colour, double R = 0.299, double G = 0.587, double B = 0.114)
{
double r(colour.r);
double g(colour.g);
double b(colour.b);
double a(colour.a);
if ((!g && !b) || g == b) return colour;
double lum_org = (g*g * G + b*b * B);
double lum_swp = (b*b * G + g*g * B);
double delta = sqrt(lum_org/lum_swp);
double _b = g * delta;
if (_b > 1)
{
g = sqrt((lum_org - B)/G);
_b = 1;
}
else
{
g = b * delta;
}
return AColor(r, g, _b, a);
}
Dec 08, 2020 2:39 am
I didn’t want to use “if” since it is a little more expensive in MXS.
But in other lenguages I would have used it.
You can also simplify it to:
if (colour.g != colour.b) then ... else colour
fn SwapBlueGreenChannels colour =
(
if (colour.g != colour.b) then
(
l1 = colour.g^2 * 5.0 + colour.b^2
l2 = colour.b^2 * 5.0 + colour.g^2
delta = sqrt (l1 / l2)
b = colour.g * delta
if b > 255 then
(
g = sqrt ((l1 - 65025)/5.0)
b = 255
)else(
g = colour.b * delta
)
return (color colour.r g b)
)else(
return colour
)
)
Page 4 / 4
Prev