diff options
author | Jason Ekstrand <[email protected]> | 2018-01-25 22:52:37 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-05-09 11:16:33 -0700 |
commit | 98156b0019ba8c9ea32a17d1c6ae81997b518856 (patch) | |
tree | ff99b76eced16a01f1a48d0d43cdb10b914a1cc3 /src/compiler | |
parent | 2fdd966e3dd1d984229a62272b42f6b3bc46486c (diff) |
nir/format_convert: Add linear <-> sRGB helpers
Reviewed-by: Topi Pohjolainen <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir_format_convert.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_format_convert.h b/src/compiler/nir/nir_format_convert.h index e09c955f8c8..e8c84944c21 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_fge(b, nir_imm_float(b, 0.04045f), c), + linear, curved)); +} |