[Mesa-dev] [PATCH 08/29] nir/format_convert: Add linear <-> sRGB helpers

Jason Ekstrand jason at jlekstrand.net
Sun Mar 4 13:36:05 UTC 2018


On March 4, 2018 01:57:33 "Pohjolainen, Topi" <topi.pohjolainen at gmail.com> 
wrote:

> On Fri, Jan 26, 2018 at 05:59:37PM -0800, Jason Ekstrand wrote:
>> ---
>>  src/compiler/nir/nir_format_convert.h | 26 ++++++++++++++++++++++++++
>>  1 file changed, 26 insertions(+)
>
> I don't what is the official reference for the formulas and I just took what
> google gave me first. There was discussion about the cutoff point between
> linear and curved. I got the impression that what you chose below
> (open-ended: 0 <= linear < 0.0031308f and 0 <= linear < 0.04045f instead of
> close-ended) was more "correct". Just thought I check that anyway (that you
> chose that on purpose).

I have no recollection whatsoever why I chose that one.

> Reviewed-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
>
>>
>> diff --git a/src/compiler/nir/nir_format_convert.h 
>> b/src/compiler/nir/nir_format_convert.h
>> index e09c955..07618dc 100644
>> --- a/src/compiler/nir/nir_format_convert.h
>> +++ b/src/compiler/nir/nir_format_convert.h
>> @@ -104,3 +104,29 @@ nir_format_pack_uint(nir_builder *b, nir_ssa_def *color,
>>     return nir_format_pack_uint_unmasked(b, nir_iand(b, color, mask_imm),
>>                                          bits, num_components);
>>  }
>> +
>> +static inline nir_ssa_def *
>> +nir_format_linear_to_srgb(nir_builder *b, nir_ssa_def *c)
>> +{
>> +   nir_ssa_def *linear = nir_fmul(b, c, nir_imm_float(b, 12.92f));
>> +   nir_ssa_def *curved =
>> +      nir_fsub(b, nir_fmul(b, nir_imm_float(b, 1.055f),
>> +                              nir_fpow(b, c, nir_imm_float(b, 1.0 / 2.4))),
>> +                  nir_imm_float(b, 0.055f));
>> +
>> +   return nir_fsat(b, nir_bcsel(b, nir_flt(b, c, nir_imm_float(b, 
>> 0.0031308f)),
>> +                                   linear, curved));
>> +}
>> +
>> +static inline nir_ssa_def *
>> +nir_format_srgb_to_linear(nir_builder *b, nir_ssa_def *c)
>> +{
>> +   nir_ssa_def *linear = nir_fdiv(b, c, nir_imm_float(b, 12.92f));
>> +   nir_ssa_def *curved =
>> +      nir_fpow(b, nir_fdiv(b, nir_fadd(b, c, nir_imm_float(b, 0.055f)),
>> +                              nir_imm_float(b, 1.055f)),
>> +                  nir_imm_float(b, 2.4f));
>> +
>> +   return nir_fsat(b, nir_bcsel(b, nir_flt(b, c, nir_imm_float(b, 0.04045f)),
>> +                                   linear, curved));
>> +}
>> --
>> 2.5.0.400.gff86faf
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev




More information about the mesa-dev mailing list