From c8a0a21823f7c5209d238784c22ccad0970fc5e7 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 23 Apr 2020 00:36:08 +0200 Subject: [PATCH] Add llLinear2sRGB / llsRGB2Linear implementations --- lslopt/lslbasefuncs.py | 16 ++++++++++++++++ unit_tests/expr.suite/math-funcs.lsl | 4 ++++ unit_tests/expr.suite/math-funcs.out | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 9922b9d..1fc8300 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -1236,6 +1236,14 @@ def llIntegerToBase64(x): return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255) + chr(x&255)).decode('utf8') +def llLinear2sRGB(v): + v = v2f(v) + return F32(Vector( + 12.920000076293945 * x if x <= 0.0031308000907301903 else + F32(1.0549999475479126 * F32(x ** 0.4166666567325592)) + - 0.054999999701976776 + for x in v)) + def llList2CSV(lst): lst = fl(lst) ret = [] @@ -1771,6 +1779,14 @@ def llSqrt(f): # LSL and Python both produce -0.0 when the input is -0.0. return F32(math.sqrt(f)) +def llsRGB2Linear(v): + v = v2f(v) + return F32(Vector( + x / 12.920000076293945 if x <= 0.040449999272823334 else + F32(F32(x + 0.054999999701976776) / 1.0549999475479126) + ** 2.4000000953674316 + for x in v)) + def llStringLength(s): s = fs(s) return len(s) diff --git a/unit_tests/expr.suite/math-funcs.lsl b/unit_tests/expr.suite/math-funcs.lsl index 189b990..b2b3093 100644 --- a/unit_tests/expr.suite/math-funcs.lsl +++ b/unit_tests/expr.suite/math-funcs.lsl @@ -64,4 +64,8 @@ , llVecDist(<0,0,0>, <0,0,0>) , llVecDist(<0,0,0>, <48,-60,-64>) , llVecDist(<-30,30,30>, <18,-30,-34>) +, llLinear2sRGB(<0.002, 0.14875476, 0.047648344>)*16777216 +, llLinear2sRGB(<0.98946905, 0.6663575, 0.018204538>)*16777216 +, llsRGB2Linear(<0.002, 0.16214077, 0.28536963>)*16777216 +, llsRGB2Linear(<0.80262023, 0.6663575, 0.018204538>)*16777216 ] diff --git a/unit_tests/expr.suite/math-funcs.out b/unit_tests/expr.suite/math-funcs.out index 967bdbc..65f6e85 100644 --- a/unit_tests/expr.suite/math-funcs.out +++ b/unit_tests/expr.suite/math-funcs.out @@ -64,4 +64,8 @@ , 0. , 100. , 100. +, <433523.28, 7078700., 4056445.5> +, <16699309., 14022980., 2411880.> +, <2597.0922, 377653.25, 1110698.> +, <10205213., 6737136.5, 23639.431> ] \ No newline at end of file