From b150970f838b2d404e755a0549fbb6892beb1da7 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 5 Jul 2026 08:39:43 +0900 Subject: [PATCH] =?UTF-8?q?getpixelregion=E3=81=AE=E5=80=A4=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=82=92=E5=85=B1=E6=9C=89DynValue=E3=82=AD=E3=83=A3?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5=E3=81=B8=E7=BD=AE=E6=8F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript.Runtime/Engine/LuaScriptEngine.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LuaScript.Runtime/Engine/LuaScriptEngine.cs b/LuaScript.Runtime/Engine/LuaScriptEngine.cs index 86bad93..508c7f2 100644 --- a/LuaScript.Runtime/Engine/LuaScriptEngine.cs +++ b/LuaScript.Runtime/Engine/LuaScriptEngine.cs @@ -990,6 +990,22 @@ namespace LuaScript private double[] _regionScratch = []; private double[] _kernelScratch = []; + private static readonly DynValue[] s_byteNumbers = CreateByteNumbers(); + + private static DynValue[] CreateByteNumbers() + { + var values = new DynValue[256]; + for (int i = 0; i < values.Length; i++) + values[i] = DynValue.NewNumber(i).AsReadOnly(); + return values; + } + + private static DynValue ChannelValue(double value) + { + int b = (int)value; + return b == value && (uint)b < 256u ? s_byteNumbers[b] : DynValue.NewNumber(value); + } + [LuaFunction("fill")] private DynValue Fill(CallbackArguments args) { @@ -1031,7 +1047,7 @@ namespace LuaScript _regionScratch = new double[count]; _activeContext.ReadRegion(x, y, w, h, _regionScratch); for (int i = 0; i < count; i++) - table.Set(i + 1, DynValue.NewNumber(_regionScratch[i])); + table.Set(i + 1, ChannelValue(_regionScratch[i])); return DynValue.NewTable(table); }