POV-Ray : Newsgroups : povray.general : Assumed_gamma and .gray : Re: Assumed_gamma and .gray Server Time
24 Apr 2024 19:33:13 EDT (-0400)
  Re: Assumed_gamma and .gray  
From: clipka
Date: 18 Jan 2017 19:50:04
Message: <58800d3c$1@news.povray.org>
Am 18.01.2017 um 20:42 schrieb Cousin Ricky:
> Does the .gray operator even work properly if assumed_gamma is not 1.0?

Strictly speaking, it does not work properly in _any_ gamma mode. And
less strictly speaking, I am sorry to say that it actually works "/more/
properly" in legacy gamma mode.

The operator is currently implemented as:

    0.297 * .red + 0.589 * .green + 0.114 * .blue

With `assumed_gamma 1.0` this should actually be:

    0.2126 * .red + 0.7152 * .green + 0.0722 * .blue

For any other `assumed_gamma` setting it is difficult to provide a
"correct" formula, as this is an addition, which is always wrong in
non-linear colour space (unless all terms but one are non-zero). One
could redefine ".grey" to mean ".luma", which is a technical term
specifically denoting a weighted sum of the colour channels in a
non-linear RGB colour space, but I'm not aware of any "official" formula
for Luma in sRGB; for the ITU-R BT.709 colour space (`assumed_gamma
bt709`), which uses the same primary colours as sRGB but a slightly
different gamma function, two conflicting formulae have been codified:

CCIR recommendation 601-1 (which does not officially reference BT.709,
but effectively defines the same colour space) suggests a formula that
comes close to the current implementation:

    0.299 * R' + 0.587 * G' + 0.114 * B'

(where R', G' and B' represent the gamma-encoded, i.e. non-linear,
colour values)

On the other hand, ITU-R BT.709 suggests to use the same formula as for
luminance (i.e. linear greyscale):

    0.2126 * R' + 0.7152 * G' + 0.0722 * B'

Since this formula is embedded deep in the bowels of POV-Ray's colour
math, I hadn't found the guts to update it along with the other gamma
stuff back when 3.7.0 came up, as it would have been difficult to
maintain backward compatibility.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.