diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index e458c3f6b8..61568676d8 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -4368,119 +4368,18 @@ namespace OpenSim.Framework bw.Close(); fs.Close(); } - } - /* don't like this code - public class DoubleQueue where T:class + //https://www.color.org/sRGB.pdf + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float LinearTosRGB(float linear) { - private Queue m_lowQueue = new Queue(); - private Queue m_highQueue = new Queue(); - - private object m_syncRoot = new object(); - private Semaphore m_s = new Semaphore(0, 1); - - public DoubleQueue() - { - } - - public virtual int Count - { - get - { - lock (m_syncRoot) - return m_highQueue.Count + m_lowQueue.Count; - } - } - - public virtual void Enqueue(T data) - { - Enqueue(m_lowQueue, data); - } - - public virtual void EnqueueLow(T data) - { - Enqueue(m_lowQueue, data); - } - - public virtual void EnqueueHigh(T data) - { - Enqueue(m_highQueue, data); - } - - private void Enqueue(Queue q, T data) - { - lock (m_syncRoot) - { - q.Enqueue(data); - m_s.WaitOne(0); - m_s.Release(); - } - } - - public virtual T Dequeue() - { - return Dequeue(Timeout.Infinite); - } - - public virtual T Dequeue(int tmo) - { - return Dequeue(TimeSpan.FromMilliseconds(tmo)); - } - - public virtual T Dequeue(TimeSpan wait) - { - T res = null; - - if (!Dequeue(wait, ref res)) - return null; - - return res; - } - - public bool Dequeue(int timeout, ref T res) - { - return Dequeue(TimeSpan.FromMilliseconds(timeout), ref res); - } - - public bool Dequeue(TimeSpan wait, ref T res) - { - if (!m_s.WaitOne(wait)) - return false; - - lock (m_syncRoot) - { - if (m_highQueue.Count > 0) - res = m_highQueue.Dequeue(); - else if (m_lowQueue.Count > 0) - res = m_lowQueue.Dequeue(); - - if (m_highQueue.Count == 0 && m_lowQueue.Count == 0) - return true; - - try - { - m_s.Release(); - } - catch - { - } - - return true; - } - } - - public virtual void Clear() - { - - lock (m_syncRoot) - { - // Make sure sem count is 0 - m_s.WaitOne(0); - - m_lowQueue.Clear(); - m_highQueue.Clear(); - } - } + return linear <= 0.0031308f ? (linear * 12.92f) : (1.055f * MathF.Pow(linear, 0.4166667f) - 0.055f); } - */ + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float sRGBtoLinear(float rgb) + { + return (rgb < 0.04045f) ? rgb * 0.07739938f : MathF.Pow((rgb + 0.055f) / 1.055f, 2.4f); + } + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index a3fb5d637a..c90a30d5f5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -18281,6 +18281,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return src; } } + + public LSL_Vector llLinear2sRGB(LSL_Vector src) + { + return new LSL_Vector(Util.LinearTosRGB((float)src.x), Util.LinearTosRGB((float)src.y), Util.LinearTosRGB((float)src.z)); + } + + public LSL_Vector llsRGB2Linear(LSL_Vector src) + { + return new LSL_Vector(Util.sRGBtoLinear((float)src.x), Util.sRGBtoLinear((float)src.y), Util.sRGBtoLinear((float)src.z)); + } + } public class NotecardCache diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index c0c85ce4f3..f5488ec489 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -495,5 +495,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void llLinkPlaySound(LSL_Integer linknumber, string sound, double volume); void llLinkSetSoundQueueing(int linknumber, int queue); void llLinkSetSoundRadius(int linknumber, double radius); + + LSL_Vector llLinear2sRGB(LSL_Vector src); + LSL_Vector llsRGB2Linear(LSL_Vector src); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 5d0ff81459..332b13c145 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -2682,5 +2682,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { m_LSL_Functions.llLinkSetSoundRadius(linknumber, radius); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public LSL_Vector llLinear2sRGB(LSL_Vector src) + { + return m_LSL_Functions.llLinear2sRGB(src); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public LSL_Vector llsRGB2Linear(LSL_Vector src) + { + return m_LSL_Functions.llsRGB2Linear(src); + } } }