Compat を1ファイル1クラス化しフォルダへ整理
このコミットが含まれているのは:
14ファイル変更
+16
-12
検索条件に一致するファイルはありません
@@ -0,0 +1,137 @@
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal static class AviUtlGlobalFunctions
|
||||
{
|
||||
public static int BitOr(double a, double b) => ToBitOperand(a) | ToBitOperand(b);
|
||||
|
||||
public static int BitAnd(double a, double b) => ToBitOperand(a) & ToBitOperand(b);
|
||||
|
||||
public static int BitXor(double a, double b) => ToBitOperand(a) ^ ToBitOperand(b);
|
||||
|
||||
public static int BitShift(double value, double shift)
|
||||
{
|
||||
int v = ToBitOperand(value);
|
||||
int n = ToBitOperand(shift);
|
||||
return n >= 0 ? v << n : v >> -n;
|
||||
}
|
||||
|
||||
public static int ToBitOperand(double value)
|
||||
{
|
||||
if (double.IsNaN(value))
|
||||
return 0;
|
||||
if (value <= int.MinValue)
|
||||
return int.MinValue;
|
||||
if (value >= int.MaxValue)
|
||||
return int.MaxValue;
|
||||
return (int)Math.Ceiling(value - 0.5);
|
||||
}
|
||||
|
||||
public static int RgbCompose(double r, double g, double b) =>
|
||||
(ToColorChannel(r) << 16) | (ToColorChannel(g) << 8) | ToColorChannel(b);
|
||||
|
||||
public static void RgbComponents(double color, out int r, out int g, out int b)
|
||||
{
|
||||
int c = ToColor(color);
|
||||
r = (c >> 16) & 0xFF;
|
||||
g = (c >> 8) & 0xFF;
|
||||
b = c & 0xFF;
|
||||
}
|
||||
|
||||
public static int RgbInterpolate(double r1, double g1, double b1, double r2, double g2, double b2, double t) =>
|
||||
RgbCompose(r1 + (r2 - r1) * t, g1 + (g2 - g1) * t, b1 + (b2 - b1) * t);
|
||||
|
||||
public static int HsvCompose(double h, double s, double v)
|
||||
{
|
||||
h = WrapHue(h);
|
||||
s = ClampRatio(s);
|
||||
v = ClampRatio(v);
|
||||
|
||||
double c = v * s;
|
||||
double x = c * (1d - Math.Abs(h / 60d % 2d - 1d));
|
||||
double m = v - c;
|
||||
int sector = (int)Math.Floor(h / 60d);
|
||||
|
||||
double r, g, b;
|
||||
if (sector == 0) { r = c; g = x; b = 0d; }
|
||||
else if (sector == 1) { r = x; g = c; b = 0d; }
|
||||
else if (sector == 2) { r = 0d; g = c; b = x; }
|
||||
else if (sector == 3) { r = 0d; g = x; b = c; }
|
||||
else if (sector == 4) { r = x; g = 0d; b = c; }
|
||||
else { r = c; g = 0d; b = x; }
|
||||
|
||||
return (ToColorChannel(RoundHalfUp((r + m) * 255d)) << 16) |
|
||||
(ToColorChannel(RoundHalfUp((g + m) * 255d)) << 8) |
|
||||
ToColorChannel(RoundHalfUp((b + m) * 255d));
|
||||
}
|
||||
|
||||
public static void HsvComponents(double color, out int h, out int s, out int v)
|
||||
{
|
||||
RgbComponents(color, out int r, out int g, out int b);
|
||||
double rf = r / 255d;
|
||||
double gf = g / 255d;
|
||||
double bf = b / 255d;
|
||||
|
||||
double max = Math.Max(rf, Math.Max(gf, bf));
|
||||
double min = Math.Min(rf, Math.Min(gf, bf));
|
||||
double delta = max - min;
|
||||
|
||||
double hue = 0d;
|
||||
if (delta > 0d)
|
||||
{
|
||||
if (max == rf)
|
||||
hue = 60d * (((gf - bf) / delta % 6d + 6d) % 6d);
|
||||
else if (max == gf)
|
||||
hue = 60d * ((bf - rf) / delta + 2d);
|
||||
else
|
||||
hue = 60d * ((rf - gf) / delta + 4d);
|
||||
}
|
||||
|
||||
h = (int)RoundHalfUp(hue);
|
||||
s = (int)RoundHalfUp(max > 0d ? delta / max * 100d : 0d);
|
||||
v = (int)RoundHalfUp(max * 100d);
|
||||
}
|
||||
|
||||
public static int HsvInterpolate(double h1, double s1, double v1, double h2, double s2, double v2, double t) =>
|
||||
HsvCompose(h1 + (h2 - h1) * t, s1 + (s2 - s1) * t, v1 + (v2 - v1) * t);
|
||||
|
||||
private static int ToColorChannel(double value)
|
||||
{
|
||||
if (double.IsNaN(value) || value <= 0d)
|
||||
return 0;
|
||||
if (value >= 255d)
|
||||
return 255;
|
||||
return (int)Math.Floor(value);
|
||||
}
|
||||
|
||||
private static int ToColor(double value)
|
||||
{
|
||||
if (double.IsNaN(value))
|
||||
return 0;
|
||||
if (value <= int.MinValue)
|
||||
value = int.MinValue;
|
||||
else if (value >= int.MaxValue)
|
||||
value = int.MaxValue;
|
||||
long floored = (long)Math.Floor(value);
|
||||
return (int)(floored & 0xFFFFFF);
|
||||
}
|
||||
|
||||
private static double WrapHue(double h)
|
||||
{
|
||||
if (double.IsNaN(h) || double.IsInfinity(h))
|
||||
return 0d;
|
||||
double wrapped = h - Math.Floor(h / 360d) * 360d;
|
||||
return wrapped >= 360d ? 0d : wrapped;
|
||||
}
|
||||
|
||||
private static double ClampRatio(double value)
|
||||
{
|
||||
if (double.IsNaN(value) || value <= 0d)
|
||||
return 0d;
|
||||
if (value >= 100d)
|
||||
return 1d;
|
||||
return value / 100d;
|
||||
}
|
||||
|
||||
private static double RoundHalfUp(double value) => Math.Floor(value + 0.5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal static class AviUtlRandom
|
||||
{
|
||||
public static double Next(double a, double b, double seed, double frame)
|
||||
{
|
||||
long seedBits = BitConverter.DoubleToInt64Bits(seed);
|
||||
long frameBits = BitConverter.DoubleToInt64Bits(frame);
|
||||
uint s = (uint)(seedBits ^ (seedBits >> 32));
|
||||
uint f = (uint)(frameBits ^ (frameBits >> 32));
|
||||
|
||||
uint h = s * 374761393u + f * 668265263u;
|
||||
h = (h ^ (h >> 13)) * 1274126177u;
|
||||
h ^= h >> 16;
|
||||
|
||||
double r = h / 4294967295.0;
|
||||
|
||||
long lo = (long)Math.Floor(Math.Min(a, b));
|
||||
long hi = (long)Math.Floor(Math.Max(a, b));
|
||||
long span = hi - lo + 1L;
|
||||
if (span <= 1L)
|
||||
return lo;
|
||||
|
||||
long value = lo + (long)(r * span);
|
||||
return value > hi ? hi : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal static class Bit32
|
||||
{
|
||||
public static uint ToUInt32(double value) => unchecked((uint)(long)value);
|
||||
|
||||
public static uint Band(params double[] values)
|
||||
{
|
||||
uint accum = 0xFFFFFFFFu;
|
||||
foreach (var value in values)
|
||||
accum &= ToUInt32(value);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static uint Bor(params double[] values)
|
||||
{
|
||||
uint accum = 0u;
|
||||
foreach (var value in values)
|
||||
accum |= ToUInt32(value);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static uint Bxor(params double[] values)
|
||||
{
|
||||
uint accum = 0u;
|
||||
foreach (var value in values)
|
||||
accum ^= ToUInt32(value);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static bool Btest(params double[] values) => Band(values) != 0u;
|
||||
|
||||
public static uint Bnot(double value) => ~ToUInt32(value);
|
||||
|
||||
public static uint Lshift(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = (int)shift;
|
||||
if (a <= -32 || a >= 32)
|
||||
return 0u;
|
||||
return a >= 0 ? v << a : v >> -a;
|
||||
}
|
||||
|
||||
public static uint Rshift(double value, double shift) => Lshift(value, -shift);
|
||||
|
||||
public static uint Arshift(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = (int)shift;
|
||||
if (a < 0)
|
||||
return Lshift(value, -shift);
|
||||
bool negative = (v & 0x80000000u) != 0u;
|
||||
if (a >= 32)
|
||||
return negative ? 0xFFFFFFFFu : 0u;
|
||||
if (a == 0)
|
||||
return v;
|
||||
uint result = v >> a;
|
||||
if (negative)
|
||||
result |= ~0u << (32 - a);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static uint Lrotate(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = ((int)shift % 32 + 32) % 32;
|
||||
return a == 0 ? v : (v << a) | (v >> (32 - a));
|
||||
}
|
||||
|
||||
public static uint Rrotate(double value, double shift) => Lrotate(value, -shift);
|
||||
|
||||
public static uint Extract(double value, double pos, double? width)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int p = (int)pos;
|
||||
int w = width is null ? 1 : (int)width.Value;
|
||||
ValidatePosWidth(p, w);
|
||||
return (v >> p) & NBitMask(w);
|
||||
}
|
||||
|
||||
public static uint Replace(double value, double replacement, double pos, double? width)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
uint u = ToUInt32(replacement);
|
||||
int p = (int)pos;
|
||||
int w = width is null ? 1 : (int)width.Value;
|
||||
ValidatePosWidth(p, w);
|
||||
uint mask = NBitMask(w) << p;
|
||||
return (v & ~mask) | ((u & NBitMask(w)) << p);
|
||||
}
|
||||
|
||||
private static void ValidatePosWidth(int pos, int width)
|
||||
{
|
||||
if (pos < 0 || width < 1 || pos + width > 32)
|
||||
throw new ArgumentException("trying to access non-existent bits");
|
||||
}
|
||||
|
||||
private static uint NBitMask(int bits)
|
||||
{
|
||||
if (bits <= 0)
|
||||
return 0u;
|
||||
if (bits >= 32)
|
||||
return 0xFFFFFFFFu;
|
||||
return (1u << bits) - 1u;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal static class MoonSharpBit32
|
||||
{
|
||||
private const double Modulo = 4294967296.0;
|
||||
|
||||
public static uint ToUInt32(double value) => unchecked((uint)Math.IEEERemainder(value, Modulo));
|
||||
|
||||
public static int ToInt32(double value) => unchecked((int)Math.IEEERemainder(value, Modulo));
|
||||
|
||||
public static uint Band(params double[] values)
|
||||
{
|
||||
uint accum = ToUInt32(values[0]);
|
||||
for (int i = 1; i < values.Length; i++)
|
||||
accum &= ToUInt32(values[i]);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static uint Bor(params double[] values)
|
||||
{
|
||||
uint accum = ToUInt32(values[0]);
|
||||
for (int i = 1; i < values.Length; i++)
|
||||
accum |= ToUInt32(values[i]);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static uint Bxor(params double[] values)
|
||||
{
|
||||
uint accum = ToUInt32(values[0]);
|
||||
for (int i = 1; i < values.Length; i++)
|
||||
accum ^= ToUInt32(values[i]);
|
||||
return accum;
|
||||
}
|
||||
|
||||
public static bool Btest(params double[] values) => Band(values) != 0u;
|
||||
|
||||
public static uint Bnot(double value) => ~ToUInt32(value);
|
||||
|
||||
public static uint Lshift(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = (int)shift;
|
||||
return a < 0 ? v >> -a : v << a;
|
||||
}
|
||||
|
||||
public static uint Rshift(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = (int)shift;
|
||||
return a < 0 ? v << -a : v >> a;
|
||||
}
|
||||
|
||||
public static int Arshift(double value, double shift)
|
||||
{
|
||||
int v = ToInt32(value);
|
||||
int a = (int)shift;
|
||||
return a < 0 ? v << -a : v >> a;
|
||||
}
|
||||
|
||||
public static uint Lrotate(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = ((int)shift) % 32;
|
||||
return a < 0 ? (v >> -a) | (v << (32 + a)) : (v << a) | (v >> (32 - a));
|
||||
}
|
||||
|
||||
public static uint Rrotate(double value, double shift)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int a = ((int)shift) % 32;
|
||||
return a < 0 ? (v << -a) | (v >> (32 + a)) : (v >> a) | (v << (32 - a));
|
||||
}
|
||||
|
||||
public static uint Extract(double value, double pos, double? width)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
int p = (int)pos;
|
||||
int w = width is null ? 1 : (int)width.Value;
|
||||
ValidatePosWidth(p, w);
|
||||
return (v >> p) & NBitMask(w);
|
||||
}
|
||||
|
||||
public static uint Replace(double value, double replacement, double pos, double? width)
|
||||
{
|
||||
uint v = ToUInt32(value);
|
||||
uint u = ToUInt32(replacement);
|
||||
int p = (int)pos;
|
||||
int w = width is null ? 1 : (int)width.Value;
|
||||
ValidatePosWidth(p, w);
|
||||
uint mask = NBitMask(w) << p;
|
||||
return (v & ~mask) | (u & mask);
|
||||
}
|
||||
|
||||
private static void ValidatePosWidth(int pos, int width)
|
||||
{
|
||||
if (pos > 31 || pos + width > 31)
|
||||
throw new ArgumentException("trying to access non-existent bits");
|
||||
}
|
||||
|
||||
private static uint NBitMask(int bits)
|
||||
{
|
||||
if (bits <= 0)
|
||||
return 0u;
|
||||
if (bits >= 32)
|
||||
return 0xFFFFFFFFu;
|
||||
return (1u << bits) - 1u;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする