Add llLinear2sRGB / llsRGB2Linear implementations

This commit is contained in:
Sei Lisa 2020-04-23 00:36:08 +02:00
parent 5755bb1c30
commit c8a0a21823
3 changed files with 24 additions and 0 deletions

View file

@ -1236,6 +1236,14 @@ def llIntegerToBase64(x):
return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255) return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255)
+ chr(x&255)).decode('utf8') + 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): def llList2CSV(lst):
lst = fl(lst) lst = fl(lst)
ret = [] ret = []
@ -1771,6 +1779,14 @@ def llSqrt(f):
# LSL and Python both produce -0.0 when the input is -0.0. # LSL and Python both produce -0.0 when the input is -0.0.
return F32(math.sqrt(f)) 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): def llStringLength(s):
s = fs(s) s = fs(s)
return len(s) return len(s)

View file

@ -64,4 +64,8 @@
, llVecDist(<0,0,0>, <0,0,0>) , llVecDist(<0,0,0>, <0,0,0>)
, llVecDist(<0,0,0>, <48,-60,-64>) , llVecDist(<0,0,0>, <48,-60,-64>)
, llVecDist(<-30,30,30>, <18,-30,-34>) , 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
] ]

View file

@ -64,4 +64,8 @@
, 0. , 0.
, 100. , 100.
, 100. , 100.
, <433523.28, 7078700., 4056445.5>
, <16699309., 14022980., 2411880.>
, <2597.0922, 377653.25, 1110698.>
, <10205213., 6737136.5, 23639.431>
] ]