Some mods target the Mono version of the game, which is available by opting into the Steam beta branch "alternate"
Decompiled source of Inkubator v1.0.0
Inkubator.dll
Decompiled 7 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using DooDesch.UI; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppScheduleOne.AvatarFramework; using Il2CppScheduleOne.UI.MainMenu; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Inkubator; using Inkubator.Editor; using MelonLoader; using MelonLoader.Utils; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using S1API.Rendering; using S1API.UI; using SideHustle; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(Core), "Inkubator", "1.0.0", "DooDesch", "https://github.com/DooDesch-Mods/ScheduleOne-Inkubator")] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: MelonOptionalDependencies(new string[] { "SideHustle" })] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("Inkubator")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+8cf46bbbb5ad7b2e99f6bc9ffbb274d41c24de52")] [assembly: AssemblyProduct("Inkubator")] [assembly: AssemblyTitle("Inkubator")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace DooDesch.UI { public enum Severity { Info, Success, Warning, Danger } public static class Components { public static void SeverityColors(Severity s, out Color bar, out Color text, out Color bg) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) switch (s) { case Severity.Success: bar = Theme.Success; text = Theme.SuccessText; bg = Theme.SuccessSubtle; break; case Severity.Warning: bar = Theme.Warning; text = Theme.WarningText; bg = Theme.WarningSubtle; break; case Severity.Danger: bar = Theme.Danger; text = Theme.DangerText; bg = Theme.DangerSubtle; break; default: bar = Theme.Info; text = Theme.InfoText; bg = Theme.InfoSubtle; break; } } public static GameObject Divider(Transform parent) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) GameObject obj = UIFactory.Panel("Divider", parent, Theme.Hairline, (Vector2?)null, (Vector2?)null, false); Image component = obj.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } return obj; } public static float Banner(Transform parent, Severity sev, string text, float y, float height = 30f, float gap = 6f, float inset = 16f) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) SeverityColors(sev, out var bar, out var text2, out var bg); GameObject val = UIFactory.Panel("banner", parent, bg, (Vector2?)null, (Vector2?)null, false); Image component = val.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { component.sprite = Theme.RoundedSprite(); component.type = (Type)1; ((Graphic)component).raycastTarget = false; } RectTransform component2 = val.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0f, 1f); component2.anchorMax = new Vector2(1f, 1f); component2.pivot = new Vector2(0.5f, 1f); component2.offsetMin = new Vector2(inset, y - height); component2.offsetMax = new Vector2(0f - inset, y); GameObject obj = UIFactory.Panel("bar", val.transform, bar, (Vector2?)null, (Vector2?)null, false); Image component3 = obj.GetComponent<Image>(); if ((Object)(object)component3 != (Object)null) { ((Graphic)component3).raycastTarget = false; } RectTransform component4 = obj.GetComponent<RectTransform>(); component4.anchorMin = new Vector2(0f, 0f); component4.anchorMax = new Vector2(0f, 1f); component4.pivot = new Vector2(0f, 0.5f); component4.offsetMin = new Vector2(0f, 4f); component4.offsetMax = new Vector2(3f, -4f); Text obj2 = UIFactory.Text("t", text, val.transform, 13, (TextAnchor)3, (FontStyle)0); ((Graphic)obj2).color = text2; ((Graphic)obj2).raycastTarget = false; obj2.horizontalOverflow = (HorizontalWrapMode)0; obj2.verticalOverflow = (VerticalWrapMode)0; RectTransform rectTransform = ((Graphic)obj2).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.offsetMin = new Vector2(12f, 0f); rectTransform.offsetMax = new Vector2(-8f, 0f); return y - (height + gap); } public static GameObject Segmented(Transform parent, string[] labels, int active, Action<int> onSelect, out Button[] buttons, bool vertical = false, float spacing = 6f, Texture2D[] icons = null) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("segmented"); val.transform.SetParent(parent, false); val.AddComponent<RectTransform>(); if (vertical) { VerticalLayoutGroup obj = val.AddComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true; } else { HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj2).spacing = spacing; ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true; } buttons = (Button[])(object)new Button[labels.Length]; for (int i = 0; i < labels.Length; i++) { int idx = i; Texture2D val2 = ((icons != null && i < icons.Length) ? icons[i] : null); ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("seg_" + i, ((Object)(object)val2 != (Object)null) ? "" : labels[i], val.transform, (i == active) ? Theme.Accent : Theme.Button, 0f, 0f); GameObject item = valueTuple.Item1; Button item2 = valueTuple.Item2; Text item3 = valueTuple.Item3; LayoutElement obj3 = item.AddComponent<LayoutElement>(); obj3.flexibleWidth = 1f; obj3.flexibleHeight = 1f; obj3.minHeight = 28f; if ((Object)(object)item3 != (Object)null) { item3.fontSize = 14; } if ((Object)(object)val2 != (Object)null) { AddCenterIcon(item.transform, val2, 20f); } if (onSelect != null) { ((UnityEvent)item2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { onSelect(idx); })); } buttons[i] = item2; } return val; } public static void AddCenterIcon(Transform parent, Texture2D tex, float size) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)tex == (Object)null)) { GameObject val = new GameObject("icon"); val.transform.SetParent(parent, false); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0.5f, 0.5f); obj.anchorMax = new Vector2(0.5f, 0.5f); obj.pivot = new Vector2(0.5f, 0.5f); obj.sizeDelta = new Vector2(size, size); obj.anchoredPosition = Vector2.zero; Image obj2 = val.AddComponent<Image>(); obj2.sprite = Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f), 100f); obj2.preserveAspect = true; ((Graphic)obj2).raycastTarget = false; } } public static void ConfirmDialog(Transform canvasRoot, string title, string message, string confirmLabel, Action onConfirm) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_040d: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) GameObject scrim; if (!((Object)(object)canvasRoot == (Object)null)) { scrim = UIFactory.Panel("DD_ConfirmScrim", canvasRoot, new Color(0f, 0f, 0f, 0.6f), (Vector2?)null, (Vector2?)null, true); scrim.transform.SetAsLastSibling(); GameObject val = UIFactory.Panel("catcher", scrim.transform, new Color(0f, 0f, 0f, 0.01f), (Vector2?)null, (Vector2?)null, true); Button obj = val.AddComponent<Button>(); ((Selectable)obj).targetGraphic = (Graphic)(object)val.GetComponent<Image>(); ((UnityEvent)obj.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { Close(); })); GameObject val2 = UIFactory.Panel("card", scrim.transform, Theme.BgElevated, (Vector2?)null, (Vector2?)null, false); Image component = val2.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { component.sprite = Theme.RoundedSprite(); component.type = (Type)1; } RectTransform component2 = val2.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0.5f, 0.5f); component2.anchorMax = new Vector2(0.5f, 0.5f); component2.pivot = new Vector2(0.5f, 0.5f); component2.sizeDelta = new Vector2(440f, 190f); Outline obj2 = val2.AddComponent<Outline>(); ((Shadow)obj2).effectColor = Theme.HairlineStrong; ((Shadow)obj2).effectDistance = new Vector2(1f, -1f); Text obj3 = UIFactory.Text("title", title, val2.transform, 16, (TextAnchor)0, (FontStyle)1); ((Graphic)obj3).color = Theme.TextPrimary; ((Graphic)obj3).raycastTarget = false; RectTransform rectTransform = ((Graphic)obj3).rectTransform; rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.pivot = new Vector2(0.5f, 1f); rectTransform.offsetMin = new Vector2(20f, -52f); rectTransform.offsetMax = new Vector2(-20f, -18f); Text obj4 = UIFactory.Text("msg", message, val2.transform, 13, (TextAnchor)0, (FontStyle)0); ((Graphic)obj4).color = Theme.TextMuted; ((Graphic)obj4).raycastTarget = false; RectTransform rectTransform2 = ((Graphic)obj4).rectTransform; rectTransform2.anchorMin = new Vector2(0f, 1f); rectTransform2.anchorMax = new Vector2(1f, 1f); rectTransform2.pivot = new Vector2(0.5f, 1f); rectTransform2.offsetMin = new Vector2(20f, -120f); rectTransform2.offsetMax = new Vector2(-20f, -58f); ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("Cancel", "Cancel", val2.transform, Theme.Button, 140f, 40f); GameObject item = valueTuple.Item1; Button item2 = valueTuple.Item2; RectTransform component3 = item.GetComponent<RectTransform>(); component3.anchorMin = new Vector2(0f, 0f); component3.anchorMax = new Vector2(0f, 0f); component3.pivot = new Vector2(0f, 0f); component3.anchoredPosition = new Vector2(20f, 18f); component3.sizeDelta = new Vector2(140f, 40f); ((UnityEvent)item2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { Close(); })); ValueTuple<GameObject, Button, Text> valueTuple2 = UIFactory.ButtonWithLabel("Confirm", confirmLabel, val2.transform, Theme.Danger, 180f, 40f); GameObject item3 = valueTuple2.Item1; Button item4 = valueTuple2.Item2; RectTransform component4 = item3.GetComponent<RectTransform>(); component4.anchorMin = new Vector2(1f, 0f); component4.anchorMax = new Vector2(1f, 0f); component4.pivot = new Vector2(1f, 0f); component4.anchoredPosition = new Vector2(-20f, 18f); component4.sizeDelta = new Vector2(180f, 40f); ((UnityEvent)item4.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { Close(); onConfirm?.Invoke(); })); Interactions.PolishButtons(val2.transform); } void Close() { Object.Destroy((Object)(object)scrim); } } public static void SetSegmentedActive(Button[] buttons, int active) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (buttons == null) { return; } for (int i = 0; i < buttons.Length; i++) { if (!((Object)(object)buttons[i] == (Object)null)) { Graphic targetGraphic = ((Selectable)buttons[i]).targetGraphic; Image val = (Image)(((object)((targetGraphic is Image) ? targetGraphic : null)) ?? ((object)((Component)buttons[i]).GetComponent<Image>())); if (!((Object)(object)val == (Object)null)) { ((Graphic)val).color = ((i == active) ? Theme.Accent : Theme.Button); Interactions.ApplyStates(buttons[i]); } } } } public static Slider Slider(Transform parent, float min, float max, float value, Action<float> onChange) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Expected O, but got Unknown //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("slider"); val.transform.SetParent(parent, false); val.AddComponent<RectTransform>(); Slider val2 = val.AddComponent<Slider>(); GameObject val3 = new GameObject("Background"); val3.transform.SetParent(val.transform, false); RectTransform obj = val3.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0f, 0.5f); obj.anchorMax = new Vector2(1f, 0.5f); obj.sizeDelta = new Vector2(0f, 6f); obj.anchoredPosition = Vector2.zero; Image obj2 = val3.AddComponent<Image>(); ((Graphic)obj2).color = Theme.SurfaceInput; obj2.sprite = Theme.RoundedSprite(); obj2.type = (Type)1; GameObject val4 = new GameObject("Fill Area"); val4.transform.SetParent(val.transform, false); RectTransform obj3 = val4.AddComponent<RectTransform>(); obj3.anchorMin = new Vector2(0f, 0.5f); obj3.anchorMax = new Vector2(1f, 0.5f); obj3.sizeDelta = new Vector2(-16f, 6f); obj3.anchoredPosition = Vector2.zero; GameObject val5 = new GameObject("Fill"); val5.transform.SetParent(val4.transform, false); RectTransform val6 = val5.AddComponent<RectTransform>(); val6.anchorMin = new Vector2(0f, 0f); val6.anchorMax = new Vector2(1f, 1f); val6.sizeDelta = Vector2.zero; Image obj4 = val5.AddComponent<Image>(); ((Graphic)obj4).color = Theme.Accent; obj4.sprite = Theme.RoundedSprite(); obj4.type = (Type)1; GameObject val7 = new GameObject("Handle Slide Area"); val7.transform.SetParent(val.transform, false); RectTransform obj5 = val7.AddComponent<RectTransform>(); obj5.anchorMin = new Vector2(0f, 0f); obj5.anchorMax = new Vector2(1f, 1f); obj5.sizeDelta = new Vector2(-16f, 0f); obj5.anchoredPosition = Vector2.zero; GameObject val8 = new GameObject("Handle"); val8.transform.SetParent(val7.transform, false); RectTransform val9 = val8.AddComponent<RectTransform>(); val9.sizeDelta = new Vector2(16f, 16f); Image val10 = val8.AddComponent<Image>(); ((Graphic)val10).color = Theme.AccentBorder; val10.sprite = Theme.RoundedSprite(); val10.type = (Type)1; val2.fillRect = val6; val2.handleRect = val9; ((Selectable)val2).targetGraphic = (Graphic)(object)val10; val2.direction = (Direction)0; val2.minValue = min; val2.maxValue = max; val2.wholeNumbers = false; val2.value = value; if (onChange != null) { ((UnityEvent<float>)(object)val2.onValueChanged).AddListener(UnityAction<float>.op_Implicit((Action<float>)delegate(float v) { onChange(v); })); } return val2; } } public static class Toast { private class Entry { public GameObject go; public CanvasGroup cg; public float expire; } private const float Ttl = 3.4f; private const float FadeFor = 0.45f; private const float Width = 480f; private const float RowH = 40f; private const float Gap = 8f; private const float BaseY = 96f; private static Transform _host; private static readonly List<Entry> _entries = new List<Entry>(); public static void Init(Transform canvasRoot) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)canvasRoot == (Object)null) && !((Object)(object)_host != (Object)null)) { GameObject obj = UIFactory.Panel("DD_ToastHost", canvasRoot, Theme.Clear, (Vector2?)null, (Vector2?)null, true); Image component = obj.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } obj.transform.SetAsLastSibling(); _host = obj.transform; } } public static void Clear() { _entries.Clear(); if ((Object)(object)_host != (Object)null) { Object.Destroy((Object)(object)((Component)_host).gameObject); _host = null; } } public static void Show(string message, Severity sev = Severity.Info) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_host == (Object)null) && !string.IsNullOrEmpty(message)) { Components.SeverityColors(sev, out var bar, out var _, out var _); GameObject val = UIFactory.Panel("toast", _host, Theme.BgElevated, (Vector2?)null, (Vector2?)null, false); Image component = val.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { component.sprite = Theme.RoundedSprite(); component.type = (Type)1; ((Graphic)component).raycastTarget = false; } RectTransform component2 = val.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0.5f, 0f); component2.anchorMax = new Vector2(0.5f, 0f); component2.pivot = new Vector2(0.5f, 0f); component2.sizeDelta = new Vector2(480f, 40f); Outline obj = val.AddComponent<Outline>(); ((Shadow)obj).effectColor = Theme.HairlineStrong; ((Shadow)obj).effectDistance = new Vector2(1f, -1f); GameObject obj2 = UIFactory.Panel("bar", val.transform, bar, (Vector2?)null, (Vector2?)null, false); Image component3 = obj2.GetComponent<Image>(); if ((Object)(object)component3 != (Object)null) { ((Graphic)component3).raycastTarget = false; } RectTransform component4 = obj2.GetComponent<RectTransform>(); component4.anchorMin = new Vector2(0f, 0f); component4.anchorMax = new Vector2(0f, 1f); component4.pivot = new Vector2(0f, 0.5f); component4.offsetMin = new Vector2(0f, 6f); component4.offsetMax = new Vector2(4f, -6f); Text obj3 = UIFactory.Text("t", message, val.transform, 13, (TextAnchor)3, (FontStyle)0); ((Graphic)obj3).color = Theme.TextPrimary; ((Graphic)obj3).raycastTarget = false; obj3.horizontalOverflow = (HorizontalWrapMode)0; obj3.verticalOverflow = (VerticalWrapMode)0; RectTransform rectTransform = ((Graphic)obj3).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.offsetMin = new Vector2(16f, 2f); rectTransform.offsetMax = new Vector2(-12f, -2f); CanvasGroup cg = val.AddComponent<CanvasGroup>(); _entries.Add(new Entry { go = val, cg = cg, expire = Time.time + 3.4f }); Reflow(); } } public static void Tick() { if (_entries.Count == 0) { return; } float time = Time.time; for (int num = _entries.Count - 1; num >= 0; num--) { Entry entry = _entries[num]; if ((Object)(object)entry.go == (Object)null) { _entries.RemoveAt(num); } else if (time >= entry.expire) { Object.Destroy((Object)(object)entry.go); _entries.RemoveAt(num); } else { float num2 = entry.expire - time; if ((Object)(object)entry.cg != (Object)null) { entry.cg.alpha = ((num2 < 0.45f) ? Mathf.Clamp01(num2 / 0.45f) : 1f); } } } Reflow(); } private static void Reflow() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) float num = 96f; for (int i = 0; i < _entries.Count; i++) { RectTransform val = (((Object)(object)_entries[i].go != (Object)null) ? _entries[i].go.GetComponent<RectTransform>() : null); if (!((Object)(object)val == (Object)null)) { val.anchoredPosition = new Vector2(0f, num); num += 48f; } } } } public static class Interactions { public static void PolishButtons(Transform root, bool round = true) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)root == (Object)null) { return; } Il2CppArrayBase<Button> componentsInChildren = ((Component)root).GetComponentsInChildren<Button>(true); if (componentsInChildren == null) { return; } for (int i = 0; i < componentsInChildren.Length; i++) { Button val = componentsInChildren[i]; if ((Object)(object)val == (Object)null) { continue; } Graphic targetGraphic = ((Selectable)val).targetGraphic; Image val2 = (Image)(((object)((targetGraphic is Image) ? targetGraphic : null)) ?? ((object)((Component)val).GetComponent<Image>())); if (!((Object)(object)val2 == (Object)null) && !(((Graphic)val2).color.a < 0.02f)) { if (round) { val2.sprite = Theme.RoundedSprite(); val2.type = (Type)1; } ApplyStates(val); } } } public static void ApplyStates(Button btn) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) Graphic targetGraphic = ((Selectable)btn).targetGraphic; Image val = (Image)(((object)((targetGraphic is Image) ? targetGraphic : null)) ?? ((object)((Component)btn).GetComponent<Image>())); if (!((Object)(object)val == (Object)null)) { Color color = ((Graphic)val).color; if (!(color.a < 0.02f)) { Color val2 = Theme.Lighten(color, 0.06f); Color target = Theme.Darken(color, 0.06f); Color target2 = Color.Lerp(color, Theme.BgPanel, 0.55f); target2.a = color.a * 0.6f; ((Graphic)val).color = val2; ColorBlock colors = ((Selectable)btn).colors; ((ColorBlock)(ref colors)).normalColor = Ratio(color, val2); ((ColorBlock)(ref colors)).highlightedColor = Color.white; ((ColorBlock)(ref colors)).pressedColor = Ratio(target, val2); ((ColorBlock)(ref colors)).selectedColor = Ratio(color, val2); ((ColorBlock)(ref colors)).disabledColor = Ratio(target2, val2); ((ColorBlock)(ref colors)).colorMultiplier = 1f; ((ColorBlock)(ref colors)).fadeDuration = 0.12f; ((Selectable)btn).colors = colors; ((Selectable)btn).transition = (Transition)1; } } } private static Color Ratio(Color target, Color baseC) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) return new Color((baseC.r <= 0.0001f) ? 0f : Mathf.Clamp01(target.r / baseC.r), (baseC.g <= 0.0001f) ? 0f : Mathf.Clamp01(target.g / baseC.g), (baseC.b <= 0.0001f) ? 0f : Mathf.Clamp01(target.b / baseC.b), (baseC.a <= 0.0001f) ? 0f : Mathf.Clamp01(target.a / baseC.a)); } } public static class Theme { public static readonly Color BgDeep = new Color(0.043f, 0.047f, 0.063f, 1f); public static readonly Color BgBase = new Color(0.063f, 0.071f, 0.094f, 1f); public static readonly Color BgPanel = new Color(0.086f, 0.098f, 0.133f, 1f); public static readonly Color BgElevated = new Color(0.114f, 0.129f, 0.173f, 1f); public static readonly Color SurfaceInput = new Color(0.051f, 0.059f, 0.082f, 1f); public static readonly Color Clear = new Color(0f, 0f, 0f, 0f); public static readonly Color Hairline = new Color(1f, 1f, 1f, 0.08f); public static readonly Color HairlineStrong = new Color(1f, 1f, 1f, 0.14f); public static readonly Color TextPrimary = new Color(0.925f, 0.929f, 0.945f, 1f); public static readonly Color TextMuted = new Color(0.541f, 0.561f, 0.62f, 1f); public static readonly Color TextDisabled = new Color(0.337f, 0.357f, 0.408f, 1f); public static readonly Color Accent = new Color(0.369f, 0.416f, 0.824f, 1f); public static readonly Color AccentHover = new Color(0.431f, 0.475f, 0.859f, 1f); public static readonly Color AccentPressed = new Color(0.298f, 0.341f, 0.737f, 1f); public static readonly Color AccentSubtle = new Color(0.125f, 0.133f, 0.227f, 1f); public static readonly Color AccentBorder = new Color(0.486f, 0.525f, 0.91f, 1f); public static readonly Color Button = new Color(0.2f, 0.212f, 0.263f, 1f); public static readonly Color Danger = new Color(0.784f, 0.29f, 0.329f, 1f); public static readonly Color DangerText = new Color(0.945f, 0.439f, 0.478f, 1f); public static readonly Color DangerSubtle = new Color(0.165f, 0.082f, 0.094f, 1f); public static readonly Color Warning = new Color(0.788f, 0.569f, 0.18f, 1f); public static readonly Color WarningText = new Color(0.902f, 0.706f, 0.314f, 1f); public static readonly Color WarningSubtle = new Color(0.165f, 0.133f, 0.071f, 1f); public static readonly Color Success = new Color(0.184f, 0.659f, 0.467f, 1f); public static readonly Color SuccessText = new Color(0.373f, 0.816f, 0.604f, 1f); public static readonly Color SuccessSubtle = new Color(0.071f, 0.165f, 0.125f, 1f); public static readonly Color Info = new Color(0.239f, 0.498f, 0.753f, 1f); public static readonly Color InfoText = new Color(0.435f, 0.659f, 0.902f, 1f); public static readonly Color InfoSubtle = new Color(0.071f, 0.125f, 0.192f, 1f); public const int RadiusMd = 6; public const float Fade = 0.12f; public const int Caption = 11; public const int Body = 13; public const int Label = 14; public const int H3 = 16; public const int H2 = 20; public const int H1 = 28; private static Sprite _rounded; private static Sprite _frame; public static Color Lighten(Color c, float amount) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) return new Color(Mathf.Clamp01(c.r + amount), Mathf.Clamp01(c.g + amount), Mathf.Clamp01(c.b + amount), c.a); } public static Color Darken(Color c, float amount) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return Lighten(c, 0f - amount); } public static Color WithAlpha(Color c, float a) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) return new Color(c.r, c.g, c.b, a); } public static Sprite RoundedSprite() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_rounded != (Object)null) { return _rounded; } Texture2D val = new Texture2D(32, 32, (TextureFormat)5, false); ((Object)val).hideFlags = (HideFlags)32; Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)0, (byte)0, (byte)0, (byte)0); Color32 val3 = default(Color32); ((Color32)(ref val3))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { bool flag = ((float)j < 6f && (float)i < 6f && Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(6f, 6f)) > 6f) || ((float)j > 25f && (float)i < 6f && Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(25f, 6f)) > 6f) || ((float)j < 6f && (float)i > 25f && Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(6f, 25f)) > 6f) || ((float)j > 25f && (float)i > 25f && Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(25f, 25f)) > 6f); val.SetPixel(j, i, Color32.op_Implicit(flag ? val2 : val3)); } } val.Apply(); _rounded = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(8f, 8f, 8f, 8f)); return _rounded; } public static Sprite FrameSprite() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_frame != (Object)null) { return _frame; } Texture2D val = new Texture2D(32, 32, (TextureFormat)5, false); ((Object)val).hideFlags = (HideFlags)32; Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)0, (byte)0, (byte)0, (byte)0); Color32 val3 = default(Color32); ((Color32)(ref val3))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { bool flag = j < 3 || j >= 29 || i < 3 || i >= 29; val.SetPixel(j, i, Color32.op_Implicit(flag ? val3 : val2)); } } val.Apply(); _frame = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(4f, 4f, 4f, 4f)); return _frame; } } } namespace Inkubator { public sealed class Core : MelonMod { public static Core Instance { get; private set; } public static Instance Log { get; private set; } public override void OnInitializeMelon() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown Instance = this; Log = ((MelonBase)this).LoggerInstance; try { API.Register(new GamemodeDescriptor { Id = "doodesch.inkubator", DisplayName = "Inkubator", Description = "Design and export custom tattoo mods.", Author = "DooDesch", Support = (GamemodeSupport)0, Surface = (GamemodeSurface)0, OnLaunchSingleplayer = OnLaunch, OnExitToHub = OnExit }); Log.Msg("Inkubator 1.0.0 registered with Side Hustle."); } catch (Exception ex) { Log.Warning("Side Hustle not available, Inkubator cannot register: " + ex.Message); } } private static void OnLaunch(LaunchContext ctx) { EditorUI.Open(ctx); } private static void OnExit(LaunchContext ctx) { EditorUI.Close(); } public override void OnSceneWasUnloaded(int buildIndex, string sceneName) { if (sceneName == "Menu") { EditorUI.Close(); Preview.Forget(); } } public override void OnUpdate() { if (EditorUI.IsOpen) { EditorUI.Tick(); } } } } namespace Inkubator.Editor { public static class Baker { public const int CanvasSize = 1024; public static Texture2D Bake(Project project, TattooEntry entry, int size = 1024) { return Bake(project, entry?.Decals, size); } public static Texture2D Bake(Project project, IList<Decal> decalList, int size = 1024) { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown Color32[] array = (Color32[])(object)new Color32[size * size]; List<Decal> list = new List<Decal>(decalList ?? new List<Decal>()); list.Sort((Decal a, Decal b) => a.Order.CompareTo(b.Order)); foreach (Decal item in list) { string text = ProjectStore.ResolveSource(project, item); Color32[] pixels; int w; int h; if (string.IsNullOrEmpty(text) || !File.Exists(text)) { Instance log = Core.Log; if (log != null) { log.Warning("[bake] missing source: " + item.Source); } } else if (!TryReadPixels(text, out pixels, out w, out h)) { Instance log2 = Core.Log; if (log2 != null) { log2.Warning("[bake] unreadable: " + item.Source); } } else { Composite(array, size, size, pixels, w, h, item); } } Texture2D val = new Texture2D(size, size, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1 }; val.SetPixels32(new Il2CppStructArray<Color32>(array)); val.Apply(false); ((Object)val).hideFlags = (HideFlags)32; return val; } public static bool BakeToFile(Project project, TattooEntry entry, string pngPath, int size = 1024) { Texture2D val = null; try { val = Bake(project, entry, size); byte[] array = Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)ImageConversion.EncodeToPNG(val)); if (array == null || array.Length == 0) { return false; } Directory.CreateDirectory(Path.GetDirectoryName(pngPath)); File.WriteAllBytes(pngPath, array); return true; } catch (Exception ex) { Instance log = Core.Log; if (log != null) { log.Warning("[bake] write failed: " + ex.Message); } return false; } finally { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } } private static void Composite(Color32[] canvas, int w, int h, Color32[] dpx, int dw, int dh, Decal d) { //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(1f, d.Scale * (float)w); float num2 = num * ((float)dh / (float)dw); float num3 = d.U * (float)w; float num4 = d.V * (float)h; float num5 = d.RotationDeg * ((float)Math.PI / 180f); float num6 = Mathf.Cos(num5); float num7 = Mathf.Sin(num5); float num8 = num * 0.5f; float num9 = num2 * 0.5f; float num10 = Mathf.Abs(num8 * num6) + Mathf.Abs(num9 * num7); float num11 = Mathf.Abs(num8 * num7) + Mathf.Abs(num9 * num6); int num12 = Mathf.Max(0, Mathf.FloorToInt(num3 - num10)); int num13 = Mathf.Min(w - 1, Mathf.CeilToInt(num3 + num10)); int num14 = Mathf.Max(0, Mathf.FloorToInt(num4 - num11)); int num15 = Mathf.Min(h - 1, Mathf.CeilToInt(num4 + num11)); Color32 val = ParseHex(d.Tint); float num16 = Mathf.Clamp01(d.Opacity); for (int i = num14; i <= num15; i++) { for (int j = num12; j <= num13; j++) { float num17 = (float)j - num3; float num18 = (float)i - num4; float num19 = num17 * num6 + num18 * num7; float num20 = (0f - num17) * num7 + num18 * num6; float num21 = num19 / num + 0.5f; float num22 = num20 / num2 + 0.5f; if (num21 < 0f || num21 > 1f || num22 < 0f || num22 > 1f) { continue; } if (d.FlipX) { num21 = 1f - num21; } if (d.FlipY) { num22 = 1f - num22; } int num23 = Mathf.Clamp((int)(num21 * (float)dw), 0, dw - 1); int num24 = Mathf.Clamp((int)(num22 * (float)dh), 0, dh - 1); Color32 val2 = dpx[num24 * dw + num23]; float num25 = (float)(int)val2.a / 255f * num16; if (!(num25 <= 0f)) { int num26 = i * w + j; Color32 val3 = canvas[num26]; float num27 = (float)(int)val3.a / 255f; float num28 = num25 + num27 * (1f - num25); if (num28 <= 0f) { canvas[num26] = new Color32((byte)0, (byte)0, (byte)0, (byte)0); continue; } float num29 = (float)(int)val2.r * ((float)(int)val.r / 255f); float num30 = (float)(int)val2.g * ((float)(int)val.g / 255f); float num31 = (float)(int)val2.b * ((float)(int)val.b / 255f); byte b = (byte)Mathf.Clamp((num29 * num25 + (float)(int)val3.r * num27 * (1f - num25)) / num28, 0f, 255f); byte b2 = (byte)Mathf.Clamp((num30 * num25 + (float)(int)val3.g * num27 * (1f - num25)) / num28, 0f, 255f); byte b3 = (byte)Mathf.Clamp((num31 * num25 + (float)(int)val3.b * num27 * (1f - num25)) / num28, 0f, 255f); canvas[num26] = new Color32(b, b2, b3, (byte)Mathf.Clamp(num28 * 255f, 0f, 255f)); } } } } private static bool TryReadPixels(string absPath, out Color32[] pixels, out int w, out int h) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) pixels = null; w = 0; h = 0; Texture2D val = null; Texture2D val2 = null; RenderTexture val3 = null; RenderTexture active = RenderTexture.active; try { val = ImageLoader.LoadTexture(absPath); if ((Object)(object)val == (Object)null) { return false; } w = ((Texture)val).width; h = ((Texture)val).height; val3 = RenderTexture.GetTemporary(w, h, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); Graphics.Blit((Texture)(object)val, val3); RenderTexture.active = val3; val2 = new Texture2D(w, h, (TextureFormat)4, false); val2.ReadPixels(new Rect(0f, 0f, (float)w, (float)h), 0, 0); val2.Apply(false); Il2CppStructArray<Color32> pixels2 = val2.GetPixels32(); int length = ((Il2CppArrayBase<Color32>)(object)pixels2).Length; pixels = (Color32[])(object)new Color32[length]; for (int i = 0; i < length; i++) { pixels[i] = ((Il2CppArrayBase<Color32>)(object)pixels2)[i]; } return true; } catch (Exception ex) { Instance log = Core.Log; if (log != null) { log.Warning("[bake] read '" + absPath + "': " + ex.Message); } return false; } finally { RenderTexture.active = active; if ((Object)(object)val3 != (Object)null) { RenderTexture.ReleaseTemporary(val3); } if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)val2); } if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } } private static Color32 ParseHex(string hex) { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) try { if (string.IsNullOrEmpty(hex)) { return new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } hex = hex.TrimStart('#'); byte num = Convert.ToByte(hex.Substring(0, 2), 16); byte b = Convert.ToByte(hex.Substring(2, 2), 16); byte b2 = Convert.ToByte(hex.Substring(4, 2), 16); byte b3 = ((hex.Length >= 8) ? Convert.ToByte(hex.Substring(6, 2), 16) : byte.MaxValue); return new Color32(num, b, b2, b3); } catch { return new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } } } public static class EditorUI { private enum Tool { Move, Rotate, Scale } private enum RightTab { Inspector, Import } private sealed class SmoothScroller { public ScrollRect sr; public float target; public bool animating; } private static LaunchContext _ctx; private static GameObject _canvasGO; private static GameObject _screen; private static Project _project; private static Placement _tab = Placement.Chest; private static string _status = ""; private static Text _statusText; private static RectTransform _uvArea; private static float _uvSize; private static readonly Dictionary<Decal, GameObject> _decalSprites = new Dictionary<Decal, GameObject>(); private static Decal _selected; private static TattooEntry _selectedTattoo; private static GameObject _selRing; private static readonly Stack<string> _undo = new Stack<string>(); private static readonly Stack<string> _redo = new Stack<string>(); private static ExportResult _lastExport; private static Tool _tool = Tool.Move; private static Button[] _toolSegButtons; private static RightTab _rightTab = RightTab.Import; private static GameObject _rightPanel; private static GameObject _rightContent; private static Text _zoomLabel; private static bool _dragging; private static int _dragMode; private static Vector2 _dragOffset; private static Vector2 _dragStartMouse; private static Vector2 _lastMouse; private static float _startRot; private static float _startScale; private static bool _dragSnapped; private static bool _previewDirty; private static float _lastEdit; private static bool _layersLogged; private static Text _sizeVal; private static Text _rotVal; private static Text _opVal; private static Slider _scaleSlider; private static Slider _rotSlider; private static Slider _opSlider; private static bool _suppressSlider; private static float _lastSliderSnap; private const float Gutter = 18f; private static readonly Color Clear = Theme.Clear; private static readonly Color Panel = Theme.BgPanel; private static readonly Color CanvasBg = Theme.WithAlpha(Theme.BgDeep, 0.95f); private static readonly Color Accent = Theme.Accent; private static readonly Color Btn = Theme.Button; private static readonly Color BtnSel = new Color(0.24f, 0.255f, 0.42f, 1f); private static float _lastWheelSnap; private static readonly Color ReviewBg = Theme.BgBase; private static readonly Color Hint = Theme.TextMuted; private static readonly List<(TattooEntry t, Text cell)> _reviewIdCells = new List<(TattooEntry, Text)>(); private static GameObject _dropdownPopup; private static GameObject _iconModal; private static readonly List<SmoothScroller> _scrollers = new List<SmoothScroller>(); private const float ScrollStepPx = 72f; private const float ScrollEase = 16f; private const float DefaultTattooPrice = 250f; public static bool IsOpen => (Object)(object)_canvasGO != (Object)null; public static void Open(LaunchContext ctx) { _ctx = ctx; if ((Object)(object)_canvasGO == (Object)null) { BuildCanvas(); } Preview.EnsureAvatar(); ShowProjectSelect(); } public static void Close() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) try { Preview.ExitEditor(); } catch { } try { Cursor.SetCursor((Texture2D)null, Vector2.zero, (CursorMode)0); } catch { } try { Toast.Clear(); } catch { } ClearScrollers(); _decalSprites.Clear(); _selected = null; _selRing = null; _dragging = false; _previewDirty = false; if ((Object)(object)_canvasGO != (Object)null) { Object.Destroy((Object)(object)_canvasGO); _canvasGO = null; } _screen = null; _project = null; _uvArea = null; _statusText = null; _sizeVal = (_rotVal = (_opVal = null)); } private static void BuildCanvas() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown _canvasGO = new GameObject("Inkubator_EditorCanvas"); Object.DontDestroyOnLoad((Object)(object)_canvasGO); Canvas obj = _canvasGO.AddComponent<Canvas>(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 30000; _canvasGO.AddComponent<GraphicRaycaster>(); Toast.Init(_canvasGO.transform); } private static void ShowProjectSelect() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_04a4: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Expected O, but got Unknown //IL_04d0: Unknown result type (might be due to invalid IL or missing references) //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_0531: Unknown result type (might be due to invalid IL or missing references) //IL_0538: Expected O, but got Unknown //IL_0557: Unknown result type (might be due to invalid IL or missing references) //IL_0563: Unknown result type (might be due to invalid IL or missing references) //IL_056f: Unknown result type (might be due to invalid IL or missing references) //IL_057b: Unknown result type (might be due to invalid IL or missing references) //IL_05a0: Unknown result type (might be due to invalid IL or missing references) //IL_05c4: Unknown result type (might be due to invalid IL or missing references) //IL_05cb: Expected O, but got Unknown //IL_05f4: Unknown result type (might be due to invalid IL or missing references) //IL_060a: Unknown result type (might be due to invalid IL or missing references) //IL_0620: Unknown result type (might be due to invalid IL or missing references) //IL_062c: Unknown result type (might be due to invalid IL or missing references) //IL_0638: Unknown result type (might be due to invalid IL or missing references) //IL_07da: Unknown result type (might be due to invalid IL or missing references) //IL_0661: Unknown result type (might be due to invalid IL or missing references) //IL_0677: Unknown result type (might be due to invalid IL or missing references) //IL_06d9: Unknown result type (might be due to invalid IL or missing references) //IL_06ee: Unknown result type (might be due to invalid IL or missing references) //IL_0703: Unknown result type (might be due to invalid IL or missing references) //IL_0718: Unknown result type (might be due to invalid IL or missing references) //IL_072c: Unknown result type (might be due to invalid IL or missing references) //IL_0751: Unknown result type (might be due to invalid IL or missing references) //IL_0768: Unknown result type (might be due to invalid IL or missing references) //IL_0773: Unknown result type (might be due to invalid IL or missing references) //IL_0788: Unknown result type (might be due to invalid IL or missing references) //IL_079c: Unknown result type (might be due to invalid IL or missing references) //IL_0830: Unknown result type (might be due to invalid IL or missing references) //IL_0863: Unknown result type (might be due to invalid IL or missing references) //IL_0878: Unknown result type (might be due to invalid IL or missing references) //IL_088d: Unknown result type (might be due to invalid IL or missing references) //IL_08a2: Unknown result type (might be due to invalid IL or missing references) //IL_08b6: Unknown result type (might be due to invalid IL or missing references) ClearScreen(); _screen = UIFactory.Panel("ProjectSelect", _canvasGO.transform, Theme.BgBase, (Vector2?)null, (Vector2?)null, true); float num = Mathf.Min(760f, (float)Screen.height * 0.84f); GameObject val = UIFactory.Panel("Card", _screen.transform, Theme.BgPanel, (Vector2?)null, (Vector2?)null, false); Image component = val.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { component.sprite = Theme.RoundedSprite(); component.type = (Type)1; } RectTransform component2 = val.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0.5f, 0.5f); component2.anchorMax = new Vector2(0.5f, 0.5f); component2.pivot = new Vector2(0.5f, 0.5f); component2.sizeDelta = new Vector2(640f, num); component2.anchoredPosition = Vector2.zero; Outline obj = val.AddComponent<Outline>(); ((Shadow)obj).effectColor = Theme.HairlineStrong; ((Shadow)obj).effectDistance = new Vector2(1f, -1f); Text obj2 = UIFactory.Text("Title", "Inkubator", val.transform, 28, (TextAnchor)1, (FontStyle)1); ((Graphic)obj2).color = Theme.TextPrimary; ((Graphic)obj2).raycastTarget = false; RectTransform rectTransform = ((Graphic)obj2).rectTransform; rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.pivot = new Vector2(0.5f, 1f); rectTransform.offsetMin = new Vector2(18f, -70f); rectTransform.offsetMax = new Vector2(-18f, -26f); Text obj3 = UIFactory.Text("Sub", "Design and export complete tattoo modpacks.", val.transform, 14, (TextAnchor)1, (FontStyle)0); ((Graphic)obj3).color = Theme.TextMuted; ((Graphic)obj3).raycastTarget = false; RectTransform rectTransform2 = ((Graphic)obj3).rectTransform; rectTransform2.anchorMin = new Vector2(0f, 1f); rectTransform2.anchorMax = new Vector2(1f, 1f); rectTransform2.pivot = new Vector2(0.5f, 1f); rectTransform2.offsetMin = new Vector2(18f, -98f); rectTransform2.offsetMax = new Vector2(-18f, -74f); ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("New", "New pack", val.transform, Accent, 210f, 50f); GameObject item = valueTuple.Item1; Button item2 = valueTuple.Item2; RectTransform component3 = item.GetComponent<RectTransform>(); component3.anchorMin = new Vector2(0.5f, 1f); component3.anchorMax = new Vector2(0.5f, 1f); component3.pivot = new Vector2(0.5f, 1f); component3.anchoredPosition = new Vector2(0f, -118f); component3.sizeDelta = new Vector2(210f, 50f); SetLeadingIcon(item, "add"); ((UnityEvent)item2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { CreateProjectFlow(); })); RectTransform component4 = Components.Divider(val.transform).GetComponent<RectTransform>(); component4.anchorMin = new Vector2(0f, 1f); component4.anchorMax = new Vector2(1f, 1f); component4.pivot = new Vector2(0.5f, 1f); component4.offsetMin = new Vector2(18f, -181f); component4.offsetMax = new Vector2(-18f, -180f); List<string> list = ProjectStore.List(); TopLabel(val.transform, "YP", "Your packs (" + list.Count + ")", -192f, 22f, 15, (FontStyle)1); Button obj4 = IconButton(val.transform, ToolIcons.Get("folder"), Theme.Button); RectTransform component5 = ((Component)obj4).GetComponent<RectTransform>(); component5.anchorMin = new Vector2(1f, 1f); component5.anchorMax = new Vector2(1f, 1f); component5.pivot = new Vector2(1f, 1f); component5.sizeDelta = new Vector2(28f, 28f); component5.anchoredPosition = new Vector2(-18f, -188f); ((UnityEvent)obj4.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { OpenFolder(Paths.Projects); })); GameObject val2 = new GameObject("PackScroll"); val2.transform.SetParent(val.transform, false); RectTransform obj5 = val2.AddComponent<RectTransform>(); obj5.anchorMin = new Vector2(0f, 0f); obj5.anchorMax = new Vector2(1f, 1f); obj5.offsetMin = new Vector2(18f, 76f); obj5.offsetMax = new Vector2(-18f, -218f); ScrollRect obj6 = val2.AddComponent<ScrollRect>(); obj6.horizontal = false; TuneScroll(obj6); GameObject val3 = new GameObject("Viewport"); val3.transform.SetParent(val2.transform, false); RectTransform val4 = val3.AddComponent<RectTransform>(); val4.anchorMin = Vector2.zero; val4.anchorMax = Vector2.one; val4.offsetMin = Vector2.zero; val4.offsetMax = Vector2.zero; ((Graphic)val3.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.04f); val3.AddComponent<Mask>().showMaskGraphic = false; obj6.viewport = val4; GameObject val5 = new GameObject("Content"); val5.transform.SetParent(val3.transform, false); RectTransform val6 = val5.AddComponent<RectTransform>(); val6.anchorMin = new Vector2(0f, 1f); val6.anchorMax = new Vector2(1f, 1f); val6.pivot = new Vector2(0.5f, 1f); val6.offsetMin = Vector2.zero; val6.offsetMax = Vector2.zero; obj6.content = val6; if (list.Count == 0) { val6.sizeDelta = new Vector2(0f, 84f); GameObject val7 = UIFactory.Panel("Empty", val5.transform, Theme.BgElevated, (Vector2?)null, (Vector2?)null, false); Image component6 = val7.GetComponent<Image>(); if ((Object)(object)component6 != (Object)null) { component6.sprite = Theme.RoundedSprite(); component6.type = (Type)1; ((Graphic)component6).raycastTarget = false; } RectTransform component7 = val7.GetComponent<RectTransform>(); component7.anchorMin = new Vector2(0f, 1f); component7.anchorMax = new Vector2(1f, 1f); component7.pivot = new Vector2(0.5f, 1f); component7.offsetMin = new Vector2(0f, -80f); component7.offsetMax = new Vector2(0f, -4f); Text obj7 = UIFactory.Text("EmptyT", "No packs yet.\nCreate your first one above.", val7.transform, 13, (TextAnchor)4, (FontStyle)0); ((Graphic)obj7).color = Theme.TextMuted; ((Graphic)obj7).raycastTarget = false; RectTransform rectTransform3 = ((Graphic)obj7).rectTransform; rectTransform3.anchorMin = Vector2.zero; rectTransform3.anchorMax = Vector2.one; rectTransform3.offsetMin = new Vector2(12f, 6f); rectTransform3.offsetMax = new Vector2(-12f, -6f); } else { val6.sizeDelta = new Vector2(0f, 4f + (float)list.Count * 50f + (float)Mathf.Max(0, list.Count - 1) * 8f); for (int num2 = 0; num2 < list.Count; num2++) { BuildPackRow(val5.transform, list[num2], num2, 50f, 8f, 2f); } } ValueTuple<GameObject, Button, Text> valueTuple2 = UIFactory.ButtonWithLabel("Back", "Back to hub", val.transform, Btn, 220f, 44f); GameObject item3 = valueTuple2.Item1; Button item4 = valueTuple2.Item2; RectTransform component8 = item3.GetComponent<RectTransform>(); component8.anchorMin = new Vector2(0.5f, 0f); component8.anchorMax = new Vector2(0.5f, 0f); component8.pivot = new Vector2(0.5f, 0f); component8.anchoredPosition = new Vector2(0f, 18f); component8.sizeDelta = new Vector2(220f, 44f); SetLeadingIcon(item3, "back"); ((UnityEvent)item4.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { Close(); LaunchContext ctx = _ctx; if (ctx != null) { ctx.ReturnToHub(); } })); Interactions.PolishButtons(_screen.transform); } private static void BuildPackRow(Transform content, string folder, int index, float rowH, float gap, float pad) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) int tcount = ProjectStore.TattooCount(folder); string display = ProjectStore.DisplayName(folder); GameObject val = new GameObject("pack_" + folder); val.transform.SetParent(content, false); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0f, 1f); obj.anchorMax = new Vector2(1f, 1f); obj.pivot = new Vector2(0.5f, 1f); obj.sizeDelta = new Vector2(0f, rowH); obj.anchoredPosition = new Vector2(0f, 0f - (pad + (float)index * (rowH + gap))); Image val2 = val.AddComponent<Image>(); ((Graphic)val2).color = Theme.BgElevated; Button obj2 = val.AddComponent<Button>(); ((Selectable)obj2).targetGraphic = (Graphic)(object)val2; ((UnityEvent)obj2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { OpenProject(folder); })); Text obj3 = UIFactory.Text("nm", display, val.transform, 15, (TextAnchor)3, (FontStyle)1); ((Graphic)obj3).color = Theme.TextPrimary; ((Graphic)obj3).raycastTarget = false; obj3.horizontalOverflow = (HorizontalWrapMode)1; RectTransform rectTransform = ((Graphic)obj3).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.offsetMin = new Vector2(16f, 0f); rectTransform.offsetMax = new Vector2(-160f, 0f); Text obj4 = UIFactory.Text("ct", tcount + ((tcount == 1) ? " tattoo" : " tattoos"), val.transform, 13, (TextAnchor)5, (FontStyle)0); ((Graphic)obj4).color = Theme.TextMuted; ((Graphic)obj4).raycastTarget = false; RectTransform rectTransform2 = ((Graphic)obj4).rectTransform; rectTransform2.anchorMin = new Vector2(1f, 0.5f); rectTransform2.anchorMax = new Vector2(1f, 0.5f); rectTransform2.pivot = new Vector2(1f, 0.5f); rectTransform2.sizeDelta = new Vector2(100f, rowH); rectTransform2.anchoredPosition = new Vector2(-52f, 0f); Button obj5 = IconButton(val.transform, ToolIcons.Get("trash"), Color.Lerp(Theme.Button, Theme.Danger, 0.55f)); RectTransform component = ((Component)obj5).GetComponent<RectTransform>(); component.anchorMin = new Vector2(1f, 0.5f); component.anchorMax = new Vector2(1f, 0.5f); component.pivot = new Vector2(1f, 0.5f); component.sizeDelta = new Vector2(30f, 30f); component.anchoredPosition = new Vector2(-12f, 0f); ((UnityEvent)obj5.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { Components.ConfirmDialog(_canvasGO.transform, "Delete pack?", "Delete '" + display + "' and its " + tcount + " tattoo(s)? This permanently removes the pack folder and cannot be undone.", "Delete pack", delegate { ProjectStore.Delete(folder); ShowProjectSelect(); }); })); } private static void CreateProjectFlow() { string text = "New Tattoo Pack"; string name = text; int num = 2; while (ProjectStore.Exists(name)) { name = text + " " + num; num++; } _project = ProjectStore.Create(name); _selectedTattoo = null; _selected = null; _undo.Clear(); _redo.Clear(); ShowEditor(); } private static void OpenProject(string folder) { _project = ProjectStore.Load(folder); if (_project == null) { SetStatus("Failed to open '" + folder + "'"); return; } _selectedTattoo = null; _selected = null; _undo.Clear(); _redo.Clear(); ShowEditor(); } private static void ShowEditor() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) try { ClearScreen(); Preview.SetFocusPlacement(_tab); _screen = UIFactory.Panel("Editor", _canvasGO.transform, Clear, (Vector2?)null, (Vector2?)null, true); Image component = _screen.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } _uvSize = Mathf.Min((float)Screen.width * 0.3f, (float)Screen.height * 0.8f); GameObject val = UIFactory.Panel("Top", _screen.transform, Panel, (Vector2?)null, (Vector2?)null, false); Place(val, 0f, 0.92f, 1f, 1f); HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>(); ((LayoutGroup)obj).padding = new RectOffset(20, 20, 8, 8); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f; ((LayoutGroup)obj).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true; Text obj2 = UIFactory.Text("Ink", "Inkubator", val.transform, 18, (TextAnchor)3, (FontStyle)1); ((Graphic)obj2).color = Theme.TextPrimary; AddLE(((Component)obj2).gameObject, 0f, 92f); AddLE(((Component)MakeInput(val.transform, _project.Name, UnityAction<string>.op_Implicit((Action<string>)delegate(string s) { _project.Name = (string.IsNullOrWhiteSpace(s) ? _project.Name : s.Trim()); ProjectStore.Save(_project); }))).gameObject, 34f, 200f); MakeBarButton(val.transform, "Switch pack", Btn, delegate { ProjectStore.Save(_project); ShowProjectSelect(); }, 132f, "switchpack"); BarDivider(val.transform); MakeBarButton(val.transform, "Save", Btn, delegate { ProjectStore.Save(_project); SetStatus("Saved.", Severity.Success); }, 92f, "save"); Button val2 = MakeBarButton(val.transform, "Undo", Btn, Undo, 46f, "undo", iconOnly: true); Button obj3 = MakeBarButton(val.transform, "Redo", Btn, Redo, 46f, "redo", iconOnly: true); ((Selectable)val2).interactable = _undo.Count > 0; ((Selectable)obj3).interactable = _redo.Count > 0; BarSpacer(val.transform); MakeBarButton(val.transform, "Export", Accent, delegate { ProjectStore.Save(_project); _lastExport = null; ShowReviewExport(); }, 124f, "export"); MakeBarButton(val.transform, "Back to hub", Btn, delegate { ProjectStore.Save(_project); Close(); LaunchContext ctx = _ctx; if (ctx != null) { ctx.ReturnToHub(); } }, 132f, "back"); GameObject obj4 = UIFactory.Panel("Left", _screen.transform, Panel, (Vector2?)null, (Vector2?)null, false); Place(obj4, 0f, 0f, 0.2f, 0.92f); BuildTabs(SubRegionPx(obj4, "TabsR", 212f, top: true).transform); BuildTattooList(SubRegionPx(obj4, "ListR", 212f, top: false).transform); BuildStageControls(); BuildUvCanvas(); BuildRightPanel(); _statusText = null; RebuildDecalSprites(); PreviewAll(); if (!_layersLogged) { _layersLogged = true; Preview.LogLayers(); } Interactions.PolishButtons(_screen.transform); } catch (Exception ex) { Instance log = Core.Log; if (log != null) { log.Error("[editor] ShowEditor failed: " + ex); } } } private static void BarDivider(Transform parent) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) GameObject obj = UIFactory.Panel("bardiv", parent, Theme.Hairline, (Vector2?)null, (Vector2?)null, false); Image component = obj.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } LayoutElement obj2 = obj.AddComponent<LayoutElement>(); obj2.minWidth = 1f; obj2.preferredWidth = 1f; obj2.flexibleWidth = 0f; obj2.minHeight = 22f; } private static void BarSpacer(Transform parent) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) GameObject obj = UIFactory.Panel("barspace", parent, Clear, (Vector2?)null, (Vector2?)null, false); Image component = obj.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } LayoutElement obj2 = obj.AddComponent<LayoutElement>(); obj2.flexibleWidth = 1f; obj2.minWidth = 10f; } private static void BuildStageControls() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Expected O, but got Unknown GameObject val = UIFactory.Panel("StageA", _screen.transform, Clear, (Vector2?)null, (Vector2?)null, false); Place(val, 0.2f, 0.085f, 0.46f, 0.135f); Image component = val.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).raycastTarget = false; } HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f; ((LayoutGroup)obj).childAlignment = (TextAnchor)4; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((LayoutGroup)obj).padding = new RectOffset(8, 8, 4, 4); StageBtn(val.transform, "turn left", delegate { Preview.RotateAvatar(-25f); }, 46f, "turn_l"); StageBtn(val.transform, "turn right", delegate { Preview.RotateAvatar(25f); }, 46f, "turn_r"); StageBtn(val.transform, "zoom out", delegate { Preview.ZoomCamera(-1f); UpdateZoomLabel(); }, 46f, "zoom_out"); StageBtn(val.transform, "zoom in", delegate { Preview.ZoomCamera(1f); UpdateZoomLabel(); }, 46f, "zoom_in"); _zoomLabel = UIFactory.Text("zoom", Preview.ZoomPercent + "%", val.transform, 13, (TextAnchor)4, (FontStyle)1); ((Graphic)_zoomLabel).color = Theme.TextMuted; AddLE(((Component)_zoomLabel).gameObject, 30f, 54f); GameObject obj2 = UIFactory.Panel("StageB", _screen.transform, Clear, (Vector2?)null, (Vector2?)null, false); Place(obj2, 0.2f, 0.028f, 0.46f, 0.078f); Image component2 = obj2.GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { ((Graphic)component2).raycastTarget = false; } HorizontalLayoutGroup obj3 = obj2.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj3).spacing = 8f; ((LayoutGroup)obj3).childAlignment = (TextAnchor)4; ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false; ((LayoutGroup)obj3).padding = new RectOffset(8, 8, 4, 4); ClothesChip(obj2.transform); UnderwearChip(obj2.transform); } private static void StageBtn(Transform parent, string label, Action onClick, float w, string icon = null) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) var (val, val2, _) = UIFactory.ButtonWithLabel("st_" + label, label, parent, Btn, w, 34f); AddLE(val, 34f, w); ((UnityEvent)val2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { onClick(); })); if (icon != null) { SetLeadingIcon(val, icon, iconOnly: true); } } private static void ClothesChip(Transform parent) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) bool isClothingStripped = Preview.IsClothingStripped; var (go, btn, txt) = UIFactory.ButtonWithLabel("clchip", isClothingStripped ? "Show clothes" : "Hide clothes", parent, isClothingStripped ? Accent : Btn, 130f, 34f); AddLE(go, 34f, 130f); ((UnityEvent)btn.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) bool flag = Preview.SetStripClothing(!Preview.IsClothingStripped); txt.text = (flag ? "Show clothes" : "Hide clothes"); Graphic targetGraphic = ((Selectable)btn).targetGraphic; Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null); if ((Object)(object)val != (Object)null) { ((Graphic)val).color = (flag ? Accent : Btn); Interactions.ApplyStates(btn); } PreviewAll(); SetStatus(flag ? "Clothes hidden - body tattoos now visible." : "Clothes shown."); })); } private static void UnderwearChip(Transform parent) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) bool isUnderwearStripped = Preview.IsUnderwearStripped; var (go, btn, txt) = UIFactory.ButtonWithLabel("uwchip", isUnderwearStripped ? "Show underwear" : "Hide underwear", parent, isUnderwearStripped ? Accent : Btn, 140f, 34f); AddLE(go, 34f, 140f); ((UnityEvent)btn.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) bool flag = Preview.SetStripUnderwear(!Preview.IsUnderwearStripped); txt.text = (flag ? "Show underwear" : "Hide underwear"); Graphic targetGraphic = ((Selectable)btn).targetGraphic; Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null); if ((Object)(object)val != (Object)null) { ((Graphic)val).color = (flag ? Accent : Btn); Interactions.ApplyStates(btn); } PreviewAll(); SetStatus(flag ? "Underwear hidden." : "Underwear shown."); })); } private static void UpdateZoomLabel() { if ((Object)(object)_zoomLabel != (Object)null) { _zoomLabel.text = Preview.ZoomPercent + "%"; } } private static void UpdateToolSeg() { if (_toolSegButtons != null) { Components.SetSegmentedActive(_toolSegButtons, (int)_tool); } } private static void BuildRightPanel() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) _rightPanel = UIFactory.Panel("Right", _screen.transform, Panel, (Vector2?)null, (Vector2?)null, false); Place(_rightPanel, 0.78f, 0f, 1f, 0.92f); RefreshRightPanel(polish: false); } private static void RefreshRightPanel(bool polish = true) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_rightPanel == (Object)null)) { UIFactory.ClearChildren(_rightPanel.transform); _sizeVal = (_rotVal = (_opVal = null)); _scaleSlider = (_rotSlider = (_opSlider = null)); int active = ((_rightTab != RightTab.Inspector) ? 1 : 0); Button[] buttons; RectTransform component = Components.Segmented(_rightPanel.transform, new string[2] { "Inspector", "Import" }, active, delegate(int i) { _rightTab = ((i != 0) ? RightTab.Import : RightTab.Inspector); RefreshRightPanel(); }, out buttons).GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(1f, 1f); component.pivot = new Vector2(0.5f, 1f); component.sizeDelta = new Vector2(-36f, 32f); component.anchoredPosition = new Vector2(0f, -14f); _rightContent = UIFactory.Panel("RightContent", _rightPanel.transform, Clear, (Vector2?)null, (Vector2?)null, false); Image component2 = _rightContent.GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { ((Graphic)component2).raycastTarget = false; } RectTransform component3 = _rightContent.GetComponent<RectTransform>(); component3.anchorMin = new Vector2(0f, 0f); component3.anchorMax = new Vector2(1f, 1f); component3.offsetMin = new Vector2(0f, 0f); component3.offsetMax = new Vector2(0f, -60f); if (_rightTab == RightTab.Inspector) { BuildInspector(_rightContent.transform); } else { BuildImportList(_rightContent.transform); } if (polish) { Interactions.PolishButtons(_rightPanel.transform); } } } private static void BuildTabs(Transform parent) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) TopLabel(parent, "TabsH", "Body part", -14f, 22f, 16, (FontStyle)1); float num = -44f; Placement[] all = Placements.All; for (int i = 0; i < all.Length; i++) { Placement placement = all[i]; Placement pp = placement; bool flag = placement == _tab; int count = TattoosFor(placement).Count; ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("tab_" + placement, Label(placement) + ((count > 0) ? (" (" + count + ")") : ""), parent, flag ? BtnSel : Btn, 0f, 36f); GameObject item = valueTuple.Item1; Button item2 = valueTuple.Item2; RectTransform component = item.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(1f, 1f); component.pivot = new Vector2(0.5f, 1f); component.offsetMin = new Vector2(18f, num - 36f); component.offsetMax = new Vector2(-18f, num); ((UnityEvent)item2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { _tab = pp; _selected = null; _selectedTattoo = null; ShowEditor(); })); num -= 40f; } } private static void BuildTattooList(Transform parent) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Expected O, but got Unknown //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due
UserLibs/SixLabors.ImageSharp.dll
Decompiled 7 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Buffers; using System.Buffers.Binary; using System.Buffers.Text; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.CodeAnalysis; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Companding; using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Diagnostics; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; using SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder; using SixLabors.ImageSharp.Formats.Pbm; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png.Chunks; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Tga; using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff.Compression; using SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors; using SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors; using SixLabors.ImageSharp.Formats.Tiff.Constants; using SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation; using SixLabors.ImageSharp.Formats.Tiff.Utils; using SixLabors.ImageSharp.Formats.Tiff.Writers; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.BitReader; using SixLabors.ImageSharp.Formats.Webp.BitWriter; using SixLabors.ImageSharp.Formats.Webp.Lossless; using SixLabors.ImageSharp.Formats.Webp.Lossy; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory.Internals; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Iptc; using SixLabors.ImageSharp.Metadata.Profiles.Xmp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats.PixelBlenders; using SixLabors.ImageSharp.PixelFormats.Utils; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors.Binarization; using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Effects; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors.Normalization; using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tuples; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v3.1", FrameworkDisplayName = ".NET Core 3.1")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] [assembly: InternalsVisibleTo("ImageSharp.Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("ImageSharp.Tests.ProfilingSandbox, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: AssemblyCompany("Six Labors")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © Six Labors")] [assembly: AssemblyDescription("A new, fully featured, fully managed, cross-platform, 2D graphics API for .NET")] [assembly: AssemblyFileVersion("2.1.9.0")] [assembly: AssemblyInformationalVersion("2.1.9+9816ca45016c5d3859986f3c600e8934bc450a56")] [assembly: AssemblyProduct("SixLabors.ImageSharp")] [assembly: AssemblyTitle("SixLabors.ImageSharp")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/SixLabors/ImageSharp")] [assembly: NeutralResourcesLanguage("en")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.0.0.0")] [assembly: TypeForwardedTo(typeof(ExcludeFromCodeCoverageAttribute))] [assembly: TypeForwardedTo(typeof(HashCode))] [assembly: TypeForwardedTo(typeof(MathF))] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsUnmanagedAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NativeIntegerAttribute : Attribute { public readonly bool[] TransformFlags; public NativeIntegerAttribute() { TransformFlags = new bool[1] { true }; } public NativeIntegerAttribute(bool[] P_0) { TransformFlags = P_0; } } } namespace SixLabors { [DebuggerStepThrough] internal static class DebugGuard { [Conditional("DEBUG")] public static void IsTrue(bool target, string message) { if (!target) { throw new InvalidOperationException(message); } } [Conditional("DEBUG")] public static void NotDisposed(bool isDisposed, string objectName) { if (isDisposed) { throw new ObjectDisposedException(objectName); } } [Conditional("DEBUG")] public static void MustBeSameSized<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> other, string parameterName) where T : struct { if (target.Length != other.Length) { throw new ArgumentException("Span-s must be the same size!", parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> minSpan, string parameterName) where T : struct { if (target.Length < minSpan.Length) { throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}!", parameterName); } } [Conditional("DEBUG")] public static void NotNull<TValue>(TValue value, string parameterName) where TValue : class { if (value == null) { ThrowArgumentNullException(parameterName); } } [Conditional("DEBUG")] public static void NotNullOrWhiteSpace(string value, string parameterName) { if (value == null) { ThrowArgumentNullException(parameterName); } if (string.IsNullOrWhiteSpace(value)) { ThrowArgumentException("Must not be empty or whitespace.", parameterName); } } [Conditional("DEBUG")] public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) >= 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than {max}."); } } [Conditional("DEBUG")] public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) > 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than or equal to {max}."); } } [Conditional("DEBUG")] public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) <= 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than {min}."); } } [Conditional("DEBUG")] public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min}."); } } [Conditional("DEBUG")] public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}."); } } [Conditional("DEBUG")] public static void IsTrue(bool target, string parameterName, string message) { if (!target) { ThrowArgumentException(message, parameterName); } } [Conditional("DEBUG")] public static void IsFalse(bool target, string parameterName, string message) { if (target) { ThrowArgumentException(message, parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowArgumentException($"The size must be at least {minLength}.", parameterName); } } [Conditional("DEBUG")] public static void DestinationShouldNotBeTooShort<TSource, TDest>(ReadOnlySpan<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowArgumentException("Destination span is too short!", destinationParamName); } } [Conditional("DEBUG")] public static void DestinationShouldNotBeTooShort<TSource, TDest>(Span<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentException(string message, string parameterName) { throw new ArgumentException(message, parameterName); } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentOutOfRangeException(string parameterName, string message) { throw new ArgumentOutOfRangeException(parameterName, message); } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentNullException(string parameterName) { throw new ArgumentNullException(parameterName); } } [DebuggerStepThrough] internal static class Guard { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeValueType<TValue>(TValue value, string parameterName) { if (!value.GetType().IsValueType) { ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void NotNull<TValue>(TValue value, string parameterName) where TValue : class { if (value == null) { ThrowHelper.ThrowArgumentNullExceptionForNotNull(parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void NotNullOrWhiteSpace(string value, string parameterName) { if (string.IsNullOrWhiteSpace(value)) { ThrowHelper.ThrowArgumentExceptionForNotNullOrWhitespace(value, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) >= 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) > 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) <= 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsTrue(bool target, string parameterName, string message) { if (!target) { ThrowHelper.ThrowArgumentException(message, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsFalse(bool target, string parameterName, string message) { if (target) { ThrowHelper.ThrowArgumentException(message, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(minLength, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(minLength, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DestinationShouldNotBeTooShort<TSource, TDest>(ReadOnlySpan<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowHelper.ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DestinationShouldNotBeTooShort<TSource, TDest>(Span<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowHelper.ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(byte value, byte max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(byte value, byte max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(byte value, byte min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(byte value, byte min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(byte value, byte min, byte max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(sbyte value, sbyte max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(sbyte value, sbyte max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(sbyte value, sbyte min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(sbyte value, sbyte min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(sbyte value, sbyte min, sbyte max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(short value, short max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(short value, short max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(short value, short min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(short value, short min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(short value, short min, short max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(ushort value, ushort max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(ushort value, ushort max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(ushort value, ushort min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(ushort value, ushort min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(ushort value, ushort min, ushort max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(char value, char max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(char value, char max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(char value, char min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(char value, char min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(char value, char min, char max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(int value, int max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(int value, int max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(int value, int min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(int value, int min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(int value, int min, int max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(uint value, uint max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(uint value, uint max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(uint value, uint min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(uint value, uint min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(uint value, uint min, uint max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(float value, float max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(float value, float max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(float value, float min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(float value, float min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(float value, float min, float max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(long value, long max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(long value, long max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(long value, long min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(long value, long min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(long value, long min, long max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(ulong value, ulong max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(ulong value, ulong max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(ulong value, ulong min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(ulong value, ulong min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(ulong value, ulong min, ulong max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(double value, double max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(double value, double max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(double value, double min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(double value, double min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(double value, double min, double max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(decimal value, decimal max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(decimal value, decimal max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(decimal value, decimal min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(decimal value, decimal min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(decimal value, decimal min, decimal max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } } internal static class ThrowHelper { [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentNullExceptionForNotNull(string name) { ThrowArgumentNullException(name, "Parameter \"" + name + "\" must be not null."); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForNotNullOrWhitespace(string value, string name) { if (value == null) { ThrowArgumentNullException(name, "Parameter \"" + name + "\" must be not null."); } else { ThrowArgumentException(name, "Parameter \"" + name + "\" must not be empty or whitespace."); } } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeLessThan<T>(T value, T max, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be less than {max}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo<T>(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be less than or equal to {maximum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan<T>(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be greater than {minimum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo<T>(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be greater than or equal to {minimum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be between or equal to {minimum} and {maximum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(int minLength, string parameterName) { ThrowArgumentException($"Spans must be at least of length {minLength}!", parameterName); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentException(string message, string name) { throw new ArgumentException(message, name); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeException(string name, string message) { throw new ArgumentOutOfRangeException(name, message); } } } namespace SixLabors.ImageSharp { public readonly struct Color : IEquatable<Color> { private readonly Rgba64 data; private readonly IPixel boxedHighPrecisionPixel; private static readonly Lazy<Dictionary<string, Color>> NamedColorsLookupLazy = new Lazy<Dictionary<string, Color>>(CreateNamedColorsLookup, isThreadSafe: true); public static readonly Color AliceBlue = FromRgba(240, 248, byte.MaxValue, byte.MaxValue); public static readonly Color AntiqueWhite = FromRgba(250, 235, 215, byte.MaxValue); public static readonly Color Aqua = FromRgba(0, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color Aquamarine = FromRgba(127, byte.MaxValue, 212, byte.MaxValue); public static readonly Color Azure = FromRgba(240, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color Beige = FromRgba(245, 245, 220, byte.MaxValue); public static readonly Color Bisque = FromRgba(byte.MaxValue, 228, 196, byte.MaxValue); public static readonly Color Black = FromRgba(0, 0, 0, byte.MaxValue); public static readonly Color BlanchedAlmond = FromRgba(byte.MaxValue, 235, 205, byte.MaxValue); public static readonly Color Blue = FromRgba(0, 0, byte.MaxValue, byte.MaxValue); public static readonly Color BlueViolet = FromRgba(138, 43, 226, byte.MaxValue); public static readonly Color Brown = FromRgba(165, 42, 42, byte.MaxValue); public static readonly Color BurlyWood = FromRgba(222, 184, 135, byte.MaxValue); public static readonly Color CadetBlue = FromRgba(95, 158, 160, byte.MaxValue); public static readonly Color Chartreuse = FromRgba(127, byte.MaxValue, 0, byte.MaxValue); public static readonly Color Chocolate = FromRgba(210, 105, 30, byte.MaxValue); public static readonly Color Coral = FromRgba(byte.MaxValue, 127, 80, byte.MaxValue); public static readonly Color CornflowerBlue = FromRgba(100, 149, 237, byte.MaxValue); public static readonly Color Cornsilk = FromRgba(byte.MaxValue, 248, 220, byte.MaxValue); public static readonly Color Crimson = FromRgba(220, 20, 60, byte.MaxValue); public static readonly Color Cyan = Aqua; public static readonly Color DarkBlue = FromRgba(0, 0, 139, byte.MaxValue); public static readonly Color DarkCyan = FromRgba(0, 139, 139, byte.MaxValue); public static readonly Color DarkGoldenrod = FromRgba(184, 134, 11, byte.MaxValue); public static readonly Color DarkGray = FromRgba(169, 169, 169, byte.MaxValue); public static readonly Color DarkGreen = FromRgba(0, 100, 0, byte.MaxValue); public static readonly Color DarkGrey = DarkGray; public static readonly Color DarkKhaki = FromRgba(189, 183, 107, byte.MaxValue); public static readonly Color DarkMagenta = FromRgba(139, 0, 139, byte.MaxValue); public static readonly Color DarkOliveGreen = FromRgba(85, 107, 47, byte.MaxValue); public static readonly Color DarkOrange = FromRgba(byte.MaxValue, 140, 0, byte.MaxValue); public static readonly Color DarkOrchid = FromRgba(153, 50, 204, byte.MaxValue); public static readonly Color DarkRed = FromRgba(139, 0, 0, byte.MaxValue); public static readonly Color DarkSalmon = FromRgba(233, 150, 122, byte.MaxValue); public static readonly Color DarkSeaGreen = FromRgba(143, 188, 143, byte.MaxValue); public static readonly Color DarkSlateBlue = FromRgba(72, 61, 139, byte.MaxValue); public static readonly Color DarkSlateGray = FromRgba(47, 79, 79, byte.MaxValue); public static readonly Color DarkSlateGrey = DarkSlateGray; public static readonly Color DarkTurquoise = FromRgba(0, 206, 209, byte.MaxValue); public static readonly Color DarkViolet = FromRgba(148, 0, 211, byte.MaxValue); public static readonly Color DeepPink = FromRgba(byte.MaxValue, 20, 147, byte.MaxValue); public static readonly Color DeepSkyBlue = FromRgba(0, 191, byte.MaxValue, byte.MaxValue); public static readonly Color DimGray = FromRgba(105, 105, 105, byte.MaxValue); public static readonly Color DimGrey = DimGray; public static readonly Color DodgerBlue = FromRgba(30, 144, byte.MaxValue, byte.MaxValue); public static readonly Color Firebrick = FromRgba(178, 34, 34, byte.MaxValue); public static readonly Color FloralWhite = FromRgba(byte.MaxValue, 250, 240, byte.MaxValue); public static readonly Color ForestGreen = FromRgba(34, 139, 34, byte.MaxValue); public static readonly Color Fuchsia = FromRgba(byte.MaxValue, 0, byte.MaxValue, byte.MaxValue); public static readonly Color Gainsboro = FromRgba(220, 220, 220, byte.MaxValue); public static readonly Color GhostWhite = FromRgba(248, 248, byte.MaxValue, byte.MaxValue); public static readonly Color Gold = FromRgba(byte.MaxValue, 215, 0, byte.MaxValue); public static readonly Color Goldenrod = FromRgba(218, 165, 32, byte.MaxValue); public static readonly Color Gray = FromRgba(128, 128, 128, byte.MaxValue); public static readonly Color Green = FromRgba(0, 128, 0, byte.MaxValue); public static readonly Color GreenYellow = FromRgba(173, byte.MaxValue, 47, byte.MaxValue); public static readonly Color Grey = Gray; public static readonly Color Honeydew = FromRgba(240, byte.MaxValue, 240, byte.MaxValue); public static readonly Color HotPink = FromRgba(byte.MaxValue, 105, 180, byte.MaxValue); public static readonly Color IndianRed = FromRgba(205, 92, 92, byte.MaxValue); public static readonly Color Indigo = FromRgba(75, 0, 130, byte.MaxValue); public static readonly Color Ivory = FromRgba(byte.MaxValue, byte.MaxValue, 240, byte.MaxValue); public static readonly Color Khaki = FromRgba(240, 230, 140, byte.MaxValue); public static readonly Color Lavender = FromRgba(230, 230, 250, byte.MaxValue); public static readonly Color LavenderBlush = FromRgba(byte.MaxValue, 240, 245, byte.MaxValue); public static readonly Color LawnGreen = FromRgba(124, 252, 0, byte.MaxValue); public static readonly Color LemonChiffon = FromRgba(byte.MaxValue, 250, 205, byte.MaxValue); public static readonly Color LightBlue = FromRgba(173, 216, 230, byte.MaxValue); public static readonly Color LightCoral = FromRgba(240, 128, 128, byte.MaxValue); public static readonly Color LightCyan = FromRgba(224, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color LightGoldenrodYellow = FromRgba(250, 250, 210, byte.MaxValue); public static readonly Color LightGray = FromRgba(211, 211, 211, byte.MaxValue); public static readonly Color LightGreen = FromRgba(144, 238, 144, byte.MaxValue); public static readonly Color LightGrey = LightGray; public static readonly Color LightPink = FromRgba(byte.MaxValue, 182, 193, byte.MaxValue); public static readonly Color LightSalmon = FromRgba(byte.MaxValue, 160, 122, byte.MaxValue); public static readonly Color LightSeaGreen = FromRgba(32, 178, 170, byte.MaxValue); public static readonly Color LightSkyBlue = FromRgba(135, 206, 250, byte.MaxValue); public static readonly Color LightSlateGray = FromRgba(119, 136, 153, byte.MaxValue); public static readonly Color LightSlateGrey = LightSlateGray; public static readonly Color LightSteelBlue = FromRgba(176, 196, 222, byte.MaxValue); public static readonly Color LightYellow = FromRgba(byte.MaxValue, byte.MaxValue, 224, byte.MaxValue); public static readonly Color Lime = FromRgba(0, byte.MaxValue, 0, byte.MaxValue); public static readonly Color LimeGreen = FromRgba(50, 205, 50, byte.MaxValue); public static readonly Color Linen = FromRgba(250, 240, 230, byte.MaxValue); public static readonly Color Magenta = Fuchsia; public static readonly Color Maroon = FromRgba(128, 0, 0, byte.MaxValue); public static readonly Color MediumAquamarine = FromRgba(102, 205, 170, byte.MaxValue); public static readonly Color MediumBlue = FromRgba(0, 0, 205, byte.MaxValue); public static readonly Color MediumOrchid = FromRgba(186, 85, 211, byte.MaxValue); public static readonly Color MediumPurple = FromRgba(147, 112, 219, byte.MaxValue); public static readonly Color MediumSeaGreen = FromRgba(60, 179, 113, byte.MaxValue); public static readonly Color MediumSlateBlue = FromRgba(123, 104, 238, byte.MaxValue); public static readonly Color MediumSpringGreen = FromRgba(0, 250, 154, byte.MaxValue); public static readonly Color MediumTurquoise = FromRgba(72, 209, 204, byte.MaxValue); public static readonly Color MediumVioletRed = FromRgba(199, 21, 133, byte.MaxValue); public static readonly Color MidnightBlue = FromRgba(25, 25, 112, byte.MaxValue); public static readonly Color MintCream = FromRgba(245, byte.MaxValue, 250, byte.MaxValue); public static readonly Color MistyRose = FromRgba(byte.MaxValue, 228, 225, byte.MaxValue); public static readonly Color Moccasin = FromRgba(byte.MaxValue, 228, 181, byte.MaxValue); public static readonly Color NavajoWhite = FromRgba(byte.MaxValue, 222, 173, byte.MaxValue); public static readonly Color Navy = FromRgba(0, 0, 128, byte.MaxValue); public static readonly Color OldLace = FromRgba(253, 245, 230, byte.MaxValue); public static readonly Color Olive = FromRgba(128, 128, 0, byte.MaxValue); public static readonly Color OliveDrab = FromRgba(107, 142, 35, byte.MaxValue); public static readonly Color Orange = FromRgba(byte.MaxValue, 165, 0, byte.MaxValue); public static readonly Color OrangeRed = FromRgba(byte.MaxValue, 69, 0, byte.MaxValue); public static readonly Color Orchid = FromRgba(218, 112, 214, byte.MaxValue); public static readonly Color PaleGoldenrod = FromRgba(238, 232, 170, byte.MaxValue); public static readonly Color PaleGreen = FromRgba(152, 251, 152, byte.MaxValue); public static readonly Color PaleTurquoise = FromRgba(175, 238, 238, byte.MaxValue); public static readonly Color PaleVioletRed = FromRgba(219, 112, 147, byte.MaxValue); public static readonly Color PapayaWhip = FromRgba(byte.MaxValue, 239, 213, byte.MaxValue); public static readonly Color PeachPuff = FromRgba(byte.MaxValue, 218, 185, byte.MaxValue); public static readonly Color Peru = FromRgba(205, 133, 63, byte.MaxValue); public static readonly Color Pink = FromRgba(byte.MaxValue, 192, 203, byte.MaxValue); public static readonly Color Plum = FromRgba(221, 160, 221, byte.MaxValue); public static readonly Color PowderBlue = FromRgba(176, 224, 230, byte.MaxValue); public static readonly Color Purple = FromRgba(128, 0, 128, byte.MaxValue); public static readonly Color RebeccaPurple = FromRgba(102, 51, 153, byte.MaxValue); public static readonly Color Red = FromRgba(byte.MaxValue, 0, 0, byte.MaxValue); public static readonly Color RosyBrown = FromRgba(188, 143, 143, byte.MaxValue); public static readonly Color RoyalBlue = FromRgba(65, 105, 225, byte.MaxValue); public static readonly Color SaddleBrown = FromRgba(139, 69, 19, byte.MaxValue); public static readonly Color Salmon = FromRgba(250, 128, 114, byte.MaxValue); public static readonly Color SandyBrown = FromRgba(244, 164, 96, byte.MaxValue); public static readonly Color SeaGreen = FromRgba(46, 139, 87, byte.MaxValue); public static readonly Color SeaShell = FromRgba(byte.MaxValue, 245, 238, byte.MaxValue); public static readonly Color Sienna = FromRgba(160, 82, 45, byte.MaxValue); public static readonly Color Silver = FromRgba(192, 192, 192, byte.MaxValue); public static readonly Color SkyBlue = FromRgba(135, 206, 235, byte.MaxValue); public static readonly Color SlateBlue = FromRgba(106, 90, 205, byte.MaxValue); public static readonly Color SlateGray = FromRgba(112, 128, 144, byte.MaxValue); public static readonly Color SlateGrey = SlateGray; public static readonly Color Snow = FromRgba(byte.MaxValue, 250, 250, byte.MaxValue); public static readonly Color SpringGreen = FromRgba(0, byte.MaxValue, 127, byte.MaxValue); public static readonly Color SteelBlue = FromRgba(70, 130, 180, byte.MaxValue); public static readonly Color Tan = FromRgba(210, 180, 140, byte.MaxValue); public static readonly Color Teal = FromRgba(0, 128, 128, byte.MaxValue); public static readonly Color Thistle = FromRgba(216, 191, 216, byte.MaxValue); public static readonly Color Tomato = FromRgba(byte.MaxValue, 99, 71, byte.MaxValue); public static readonly Color Transparent = FromRgba(0, 0, 0, 0); public static readonly Color Turquoise = FromRgba(64, 224, 208, byte.MaxValue); public static readonly Color Violet = FromRgba(238, 130, 238, byte.MaxValue); public static readonly Color Wheat = FromRgba(245, 222, 179, byte.MaxValue); public static readonly Color White = FromRgba(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color WhiteSmoke = FromRgba(245, 245, 245, byte.MaxValue); public static readonly Color Yellow = FromRgba(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue); public static readonly Color YellowGreen = FromRgba(154, 205, 50, byte.MaxValue); private static readonly Lazy<Color[]> WebSafePaletteLazy = new Lazy<Color[]>(CreateWebSafePalette, isThreadSafe: true); private static readonly Lazy<Color[]> WernerPaletteLazy = new Lazy<Color[]>(CreateWernerPalette, isThreadSafe: true); public static ReadOnlyMemory<Color> WebSafePalette => WebSafePaletteLazy.Value; public static ReadOnlyMemory<Color> WernerPalette => WernerPaletteLazy.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgba64 pixel) { data = pixel; boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgb48 pixel) { data = new Rgba64(pixel.R, pixel.G, pixel.B, ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(La32 pixel) { data = new Rgba64(pixel.L, pixel.L, pixel.L, pixel.A); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(L16 pixel) { data = new Rgba64(pixel.PackedValue, pixel.PackedValue, pixel.PackedValue, ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgba32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Argb32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Bgra32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Abgr32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgb24 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Bgr24 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector4 vector) { vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One); boxedHighPrecisionPixel = new RgbaVector(vector.X, vector.Y, vector.Z, vector.W); data = default(Rgba64); } public static explicit operator Vector4(Color color) { return color.ToVector4(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Color(Vector4 source) { return new Color(source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Rgba32 ToRgba32() { if (boxedHighPrecisionPixel == null) { return data.ToRgba32(); } Rgba32 dest = default(Rgba32); boxedHighPrecisionPixel.ToRgba32(ref dest); return dest; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Bgra32 ToBgra32() { if (boxedHighPrecisionPixel == null) { return data.ToBgra32(); } Bgra32 result = default(Bgra32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Argb32 ToArgb32() { if (boxedHighPrecisionPixel == null) { return data.ToArgb32(); } Argb32 result = default(Argb32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Abgr32 ToAbgr32() { if (boxedHighPrecisionPixel == null) { return data.ToAbgr32(); } Abgr32 result = default(Abgr32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Rgb24 ToRgb24() { if (boxedHighPrecisionPixel == null) { return data.ToRgb24(); } Rgb24 result = default(Rgb24); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Bgr24 ToBgr24() { if (boxedHighPrecisionPixel == null) { return data.ToBgr24(); } Bgr24 result = default(Bgr24); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Vector4 ToVector4() { if (boxedHighPrecisionPixel == null) { return data.ToScaledVector4(); } return boxedHighPrecisionPixel.ToScaledVector4(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(byte r, byte g, byte b, byte a) { data = new Rgba64(ColorNumerics.UpscaleFrom8BitTo16Bit(r), ColorNumerics.UpscaleFrom8BitTo16Bit(g), ColorNumerics.UpscaleFrom8BitTo16Bit(b), ColorNumerics.UpscaleFrom8BitTo16Bit(a)); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(byte r, byte g, byte b) { data = new Rgba64(ColorNumerics.UpscaleFrom8BitTo16Bit(r), ColorNumerics.UpscaleFrom8BitTo16Bit(g), ColorNumerics.UpscaleFrom8BitTo16Bit(b), ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(IPixel pixel) { boxedHighPrecisionPixel = pixel; data = default(Rgba64); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Color left, Color right) { return left.Equals(right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Color left, Color right) { return !left.Equals(right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromRgba(byte r, byte g, byte b, byte a) { return new Color(r, g, b, a); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromRgb(byte r, byte g, byte b) { return new Color(r, g, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromPixel<TPixel>(TPixel pixel) where TPixel : unmanaged, IPixel<TPixel> { if (typeof(TPixel) == typeof(Rgba64)) { return new Color((Rgba64)(object)pixel); } if (typeof(TPixel) == typeof(Rgb48)) { return new Color((Rgb48)(object)pixel); } if (typeof(TPixel) == typeof(La32)) { return new Color((La32)(object)pixel); } if (typeof(TPixel) == typeof(L16)) { return new Color((L16)(object)pixel); } if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>()) { Rgba32 dest = default(Rgba32); pixel.ToRgba32(ref dest); return new Color(dest); } return new Color(pixel); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color ParseHex(string hex) { return new Color(Rgba32.ParseHex(hex)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseHex(string hex, out Color result) { result = default(Color); if (Rgba32.TryParseHex(hex, out var result2)) { result = new Color(result2); return true; } return false; } public static Color Parse(string input) { Guard.NotNull(input, "input"); if (!TryParse(input, out var result)) { throw new ArgumentException("Input string is not in the correct format.", "input"); } return result; } public static bool TryParse(string input, out Color result) { result = default(Color); if (string.IsNullOrWhiteSpace(input)) { return false; } if (NamedColorsLookupLazy.Value.TryGetValue(input, out result)) { return true; } return TryParseHex(input, out result); } public Color WithAlpha(float alpha) { Vector4 vector = (Vector4)this; vector.W = alpha; return new Color(vector); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public string ToHex() { return data.ToRgba32().ToHex(); } public override string ToString() { return ToHex(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TPixel ToPixel<TPixel>() where TPixel : unmanaged, IPixel<TPixel> { IPixel pixel = boxedHighPrecisionPixel; if (pixel is TPixel) { return (TPixel)pixel; } TPixel result; if (boxedHighPrecisionPixel == null) { result = default(TPixel); result.FromRgba64(data); return result; } result = default(TPixel); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ToPixel<TPixel>(Configuration configuration, ReadOnlySpan<Color> source, Span<TPixel> destination) where TPixel : unmanaged, IPixel<TPixel> { Guard.DestinationShouldNotBeTooShort(source, destination, "destination"); for (int i = 0; i < source.Length; i++) { destination[i] = source[i].ToPixel<TPixel>(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Color other) { if (boxedHighPrecisionPixel == null && other.boxedHighPrecisionPixel == null) { return data.PackedValue == other.data.PackedValue; } return boxedHighPrecisionPixel?.Equals(other.boxedHighPrecisionPixel) ?? false; } public override bool Equals(object obj) { if (obj is Color other) { return Equals(other); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { if (boxedHighPrecisionPixel == null) { return data.PackedValue.GetHashCode(); } return boxedHighPrecisionPixel.GetHashCode(); } private static Dictionary<string, Color> CreateNamedColorsLookup() { return new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase) { { "AliceBlue", AliceBlue }, { "AntiqueWhite", AntiqueWhite }, { "Aqua", Aqua }, { "Aquamarine", Aquamarine }, { "Azure", Azure }, { "Beige", Beige }, { "Bisque", Bisque }, { "Black", Black }, { "BlanchedAlmond", BlanchedAlmond }, { "Blue", Blue }, { "BlueViolet", BlueViolet }, { "Brown", Brown }, { "BurlyWood", BurlyWood }, { "CadetBlue", CadetBlue }, { "Chartreuse", Chartreuse }, { "Chocolate", Chocolate }, { "Coral", Coral }, { "CornflowerBlue", CornflowerBlue }, { "Cornsilk", Cornsilk }, { "Crimson", Crimson }, { "Cyan", Cyan }, { "DarkBlue", DarkBlue }, { "DarkCyan", DarkCyan }, { "DarkGoldenrod", DarkGoldenrod }, { "DarkGray", DarkGray }, { "DarkGreen", DarkGreen }, { "DarkGrey", DarkGrey }, { "DarkKhaki", DarkKhaki }, { "DarkMagenta", DarkMagenta }, { "DarkOliveGreen", DarkOliveGreen }, { "DarkOrange", DarkOrange }, { "DarkOrchid", DarkOrchid }, { "DarkRed", DarkRed }, { "DarkSalmon", DarkSalmon }, { "DarkSeaGreen", DarkSeaGreen }, { "DarkSlateBlue", DarkSlateBlue }, { "DarkSlateGray", DarkSlateGray }, { "DarkSlateGrey", DarkSlateGrey }, { "DarkTurquoise", DarkTurquoise }, { "DarkViolet", DarkViolet }, { "DeepPink", DeepPink }, { "DeepSkyBlue", DeepSkyBlue }, { "DimGray", DimGray }, { "DimGrey", DimGrey }, { "DodgerBlue", DodgerBlue }, { "Firebrick", Firebrick }, { "FloralWhite", FloralWhite }, { "ForestGreen", ForestGreen }, { "Fuchsia", Fuchsia }, { "Gainsboro", Gainsboro }, { "GhostWhite", GhostWhite }, { "Gold", Gold }, { "Goldenrod", Goldenrod }, { "Gray", Gray }, { "Green", Green }, { "GreenYellow", GreenYellow }, { "Grey", Grey }, { "Honeydew", Honeydew }, { "HotPink", HotPink }, { "IndianRed", IndianRed }, { "Indigo", Indigo }, { "Ivory", Ivory }, { "Khaki", Khaki }, { "Lavender", Lavender }, { "LavenderBlush", LavenderBlush }, { "LawnGreen", LawnGreen }, { "LemonChiffon", LemonChiffon }, { "LightBlue", LightBlue }, { "LightCoral", LightCoral }, { "LightCyan", LightCyan }, { "LightGoldenrodYellow", LightGoldenrodYellow }, { "LightGray", LightGray }, { "LightGreen", LightGreen }, { "LightGrey", LightGrey }, { "LightPink", LightPink }, { "LightSalmon", LightSalmon }, { "LightSeaGreen", LightSeaGreen }, { "LightSkyBlue", LightSkyBlue }, { "LightSlateGray", LightSlateGray }, { "LightSlateGrey", LightSlateGrey }, { "LightSteelBlue", LightSteelBlue }, { "LightYellow", LightYellow }, { "Lime", Lime }, { "LimeGreen", LimeGreen }, { "Linen", Linen }, { "Magenta", Magenta }, { "Maroon", Maroon }, { "MediumAquamarine", MediumAquamarine }, { "MediumBlue", MediumBlue }, { "MediumOrchid", MediumOrchid }, { "MediumPurple", MediumPurple }, { "MediumSeaGreen", MediumSeaGreen }, { "MediumSlateBlue", MediumSlateBlue }, { "MediumSpringGreen", MediumSpringGreen }, { "MediumTurquoise", MediumTurquoise }, { "MediumVioletRed", MediumVioletRed }, { "MidnightBlue", MidnightBlue }, { "MintCream", MintCream }, { "MistyRose", MistyRose }, { "Moccasin", Moccasin }, { "NavajoWhite", NavajoWhite }, { "Navy", Navy }, { "OldLace", OldLace }, { "Olive", Olive }, { "OliveDrab", OliveDrab }, { "Orange", Orange }, { "OrangeRed", OrangeRed }, { "Orchid", Orchid }, { "PaleGoldenrod", PaleGoldenrod }, { "PaleGreen", PaleGreen }, { "PaleTurquoise", PaleTurquoise }, { "PaleVioletRed", PaleVioletRed }, { "PapayaWhip", PapayaWhip }, { "PeachPuff", PeachPuff }, { "Peru", Peru }, { "Pink", Pink }, { "Plum", Plum }, { "PowderBlue", PowderBlue }, { "Purple", Purple }, { "RebeccaPurple", RebeccaPurple }, { "Red", Red }, { "RosyBrown", RosyBrown }, { "RoyalBlue", RoyalBlue }, { "SaddleBrown", SaddleBrown }, { "Salmon", Salmon }, { "SandyBrown", SandyBrown }, { "SeaGreen", SeaGreen }, { "SeaShell", SeaShell }, { "Sienna", Sienna }, { "Silver", Silver }, { "SkyBlue", SkyBlue }, { "SlateBlue", SlateBlue }, { "SlateGray", SlateGray }, { "SlateGrey", SlateGrey }, { "Snow", Snow }, { "SpringGreen", SpringGreen }, { "SteelBlue", SteelBlue }, { "Tan", Tan }, { "Teal", Teal }, { "Thistle", Thistle }, { "Tomato", Tomato }, { "Transparent", Transparent }, { "Turquoise", Turquoise }, { "Violet", Violet }, { "Wheat", Wheat }, { "White", White }, { "WhiteSmoke", WhiteSmoke }, { "Yellow", Yellow }, { "YellowGreen", YellowGreen } }; } private static Color[] CreateWebSafePalette() { return new Color[142] { AliceBlue, AntiqueWhite, Aqua, Aquamarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, Firebrick, FloralWhite, ForestGreen, Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrodYellow, LightGray, LightGreen, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, RebeccaPurple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Transparent, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen }; } private static Color[] CreateWernerPalette() { return new Color[110] { ParseHex("#f1e9cd"), ParseHex("#f2e7cf"), ParseHex("#ece6d0"), ParseHex("#f2eacc"), ParseHex("#f3e9ca"), ParseHex("#f2ebcd"), ParseHex("#e6e1c9"), ParseHex("#e2ddc6"), ParseHex("#cbc8b7"), ParseHex("#bfbbb0"), ParseHex("#bebeb3"), ParseHex("#b7b5ac"), ParseHex("#bab191"), ParseHex("#9c9d9a"), ParseHex("#8a8d84"), ParseHex("#5b5c61"), ParseHex("#555152"), ParseHex("#413f44"), ParseHex("#454445"), ParseHex("#423937"), ParseHex("#433635"), ParseHex("#252024"), ParseHex("#241f20"), ParseHex("#281f3f"), ParseHex("#1c1949"), ParseHex("#4f638d"), ParseHex("#383867"), ParseHex("#5c6b8f"), ParseHex("#657abb"), ParseHex("#6f88af"), ParseHex("#7994b5"), ParseHex("#6fb5a8"), ParseHex("#719ba2"), ParseHex("#8aa1a6"), ParseHex("#d0d5d3"), ParseHex("#8590ae"), ParseHex("#3a2f52"), ParseHex("#39334a"), ParseHex("#6c6d94"), ParseHex("#584c77"), ParseHex("#533552"), ParseHex("#463759"), ParseHex("#bfbac0"), ParseHex("#77747f"), ParseHex("#4a475c"), ParseHex("#b8bfaf"), ParseHex("#b2b599"), ParseHex("#979c84"), ParseHex("#5d6161"), ParseHex("#61ac86"), ParseHex("#a4b6a7"), ParseHex("#adba98"), ParseHex("#93b778"), ParseHex("#7d8c55"), ParseHex("#33431e"), ParseHex("#7c8635"), ParseHex("#8e9849"), ParseHex("#c2c190"), ParseHex("#67765b"), ParseHex("#ab924b"), ParseHex("#c8c76f"), ParseHex("#ccc050"), ParseHex("#ebdd99"), ParseHex("#ab9649"), ParseHex("#dbc364"), ParseHex("#e6d058"), ParseHex("#ead665"), ParseHex("#d09b2c"), ParseHex("#a36629"), ParseHex("#a77d35"), ParseHex("#f0d696"), ParseHex("#d7c485"), ParseHex("#f1d28c"), ParseHex("#efcc83"), ParseHex("#f3daa7"), ParseHex("#dfa837"), ParseHex("#ebbc71"), ParseHex("#d17c3f"), ParseHex("#92462f"), ParseHex("#be7249"), ParseHex("#bb603c"), ParseHex("#c76b4a"), ParseHex("#a75536"), ParseHex("#b63e36"), ParseHex("#b5493a"), ParseHex("#cd6d57"), ParseHex("#711518"), ParseHex("#e9c49d"), ParseHex("#eedac3"), ParseHex("#eecfbf"), ParseHex("#ce536b"), ParseHex("#b74a70"), ParseHex("#b7757c"), ParseHex("#612741"), ParseHex("#7a4848"), ParseHex("#3f3033"), ParseHex("#8d746f"), ParseHex("#4d3635"), ParseHex("#6e3b31"), ParseHex("#864735"), ParseHex("#553d3a"), ParseHex("#613936"), ParseHex("#7a4b3a"), ParseHex("#946943"), ParseHex("#c39e6d"), ParseHex("#513e32"), ParseHex("#8b7859"), ParseHex("#9b856b"), ParseHex("#766051"), ParseHex("#453b32") }; } } public enum ByteOrder { BigEndian, LittleEndian } internal static class Constants { public static readonly float Epsilon = 0.001f; public static readonly float EpsilonSquared = Epsilon * Epsilon; } public class ImageFormatException : Exception { internal ImageFormatException(string errorMessage) : base(errorMessage) { } internal ImageFormatException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } } public sealed class ImageProcessingException : Exception { public ImageProcessingException() { } public ImageProcessingException(string errorMessage) : base(errorMessage) { } public ImageProcessingException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } } public sealed class InvalidImageContentException : ImageFormatException { public InvalidImageContentException(string errorMessage) : base(errorMessage) { } public InvalidImageContentException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } internal InvalidImageContentException(Size size, InvalidMemoryOperationException memoryException) : this($"Cannot decode image. Failed to allocate buffers for possibly degenerate dimensions: {size.Width}x{size.Height}.", memoryException) { } } public sealed class UnknownImageFormatException : ImageFormatException { public UnknownImageFormatException(string errorMessage) : base(errorMessage) { } } internal static class ConfigurationExtensions { public static ParallelOptions GetParallelOptions(this Configuration configuration) { return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; } } internal static class EnumerableExtensions { public static IEnumerable<int> SteppedRange(int fromInclusive, Func<int, bool> toDelegate, int step) { return RangeIterator(fromInclusive, toDelegate, step); } private static IEnumerable<int> RangeIterator(int fromInclusive, Func<int, bool> toDelegate, int step) { for (int i = fromInclusive; toDelegate(i); i += step) { yield return i; } } } internal static class StreamExtensions { public static void Write(this Stream stream, Span<byte> buffer, int offset, int count) { stream.Write(buffer.Slice(offset, count)); } public static int Read(this Stream stream, Span<byte> buffer, int offset, int count) { return stream.Read(buffer.Slice(offset, count)); } public static void Skip(this Stream stream, int count) { if (count < 1) { return; } if (stream.CanSeek) { stream.Seek(count, SeekOrigin.Current); return; } byte[] array = ArrayPool<byte>.Shared.Rent(count); try { while (count > 0) { int num = stream.Read(array, 0, count); if (num == 0) { break; } count -= num; } } finally { ArrayPool<byte>.Shared.Return(array); } } } internal static class ColorNumerics { private static readonly Vector4 Bt709 = new Vector4(0.2126f, 0.7152f, 0.0722f, 0f); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels) { return (int)MathF.Round(Vector4.Dot(vector, Bt709) * (float)(luminanceLevels - 1)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte Get8BitBT709Luminance(byte r, byte g, byte b) { return (byte)((float)(int)r * 0.2126f + (float)(int)g * 0.7152f + (float)(int)b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) { return (ushort)((float)(int)r * 0.2126f + (float)(int)g * 0.7152f + (float)(int)b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Get16BitBT709Luminance(float r, float g, float b) { return (ushort)(r * 0.2126f + g * 0.7152f + b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte DownScaleFrom16BitTo8Bit(ushort component) { return (byte)(component * 255 + 32895 >> 16); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort UpscaleFrom8BitTo16Bit(byte component) { return (ushort)(component * 257); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetBitsNeededForColorDepth(int colors) { return Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2.0))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetColorCountForBitDepth(int bitDepth) { return 1 << bitDepth; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Transform(ref Vector4 vector, ref ColorMatrix matrix) { float x = vector.X; float y = vector.Y; float z = vector.Z; float w = vector.W; vector.X = x * matrix.M11 + y * matrix.M21 + z * matrix.M31 + w * matrix.M41 + matrix.M51; vector.Y = x * matrix.M12 + y * matrix.M22 + z * matrix.M32 + w * matrix.M42 + matrix.M52; vector.Z = x * matrix.M13 + y * matrix.M23 + z * matrix.M33 + w * matrix.M43 + matrix.M53; vector.W = x * matrix.M14 + y * matrix.M24 + z * matrix.M34 + w * matrix.M44 + matrix.M54; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Transform(Span<Vector4> vectors, ref ColorMatrix matrix) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); for (int i = 0; i < vectors.Length; i++) { Transform(ref Unsafe.Add(ref reference, i), ref matrix); } } } internal static class EnumUtils { public static TEnum Parse<TEnum>(int value, TEnum defaultValue) where TEnum : Enum { foreach (TEnum value2 in Enum.GetValues(typeof(TEnum))) { TEnum source = value2; if (value == Unsafe.As<TEnum, int>(ref source)) { return value2; } } return defaultValue; } public static bool HasFlag<TEnum>(TEnum value, TEnum flag) where TEnum : Enum { uint num = Unsafe.As<TEnum, uint>(ref flag); return (Unsafe.As<TEnum, uint>(ref value) & num) == num; } } internal static class InliningOptions { public const MethodImplOptions AlwaysInline = MethodImplOptions.AggressiveInlining; public const MethodImplOptions HotPath = MethodImplOptions.AggressiveOptimization; public const MethodImplOptions ShortMethod = MethodImplOptions.AggressiveInlining; public const MethodImplOptions ColdPath = MethodImplOptions.NoInlining; } internal static class Numerics { public const int BlendAlphaControl = 136; private const int ShuffleAlphaControl = 255; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GreatestCommonDivisor(int a, int b) { while (b != 0) { int num = b; b = a % b; a = num; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LeastCommonMultiple(int a, int b) { return a / GreatestCommonDivisor(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo2(int x) { return x & 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo4(int x) { return x & 3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo8(int x) { return x & 7; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ModuloP2(int x, int m) { return x & (m - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Abs(int x) { int num = x >> 31; return (x ^ num) - num; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Pow2(float x) { return x * x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Pow3(float x) { return x * x * x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Gaussian(float x, float sigma) { float num = MathF.Sqrt((float)Math.PI * 2f) * sigma; float num2 = (0f - x) * x; float num3 = 2f * Pow2(sigma); float num4 = 1f / num; float num5 = MathF.Exp(num2 / num3); return num4 * num5; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float SinC(float f) { if (MathF.Abs(f) > Constants.Epsilon) { f *= (float)Math.PI; float num = MathF.Sin(f) / f; if (!(MathF.Abs(num) < Constants.Epsilon)) { return num; } return 0f; } return 1f; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte Clamp(byte value, byte min, byte max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Clamp(uint value, uint min, uint max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Clamp(int value, int min, int max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Clamp(float value, float min, float max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Clamp(double value, double min, double max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max) { return Vector4.Min(Vector4.Max(value, min), max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<byte> span, byte min, byte max) { Span<byte> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref byte reference = ref MemoryMarshal.GetReference(span2); ref byte right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<uint> span, uint min, uint max) { Span<uint> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref uint reference = ref MemoryMarshal.GetReference(span2); ref uint right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<int> span, int min, int max) { Span<int> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref int reference = ref MemoryMarshal.GetReference(span2); ref int right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<float> span, float min, float max) { Span<float> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref float reference = ref MemoryMarshal.GetReference(span2); ref float right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<double> span, double min, double max) { Span<double> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref double reference = ref MemoryMarshal.GetReference(span2); ref double right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int ClampReduce<T>(Span<T> span, T min, T max) where T : unmanaged { if (Vector.IsHardwareAccelerated && span.Length >= Vector<T>.Count) { int num = ModuloP2(span.Length, Vector<T>.Count); int num2 = span.Length - num; if (num2 > 0) { ClampImpl(span.Slice(0, num2), min, max); } return num2; } return 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ClampImpl<T>(Span<T> span, T min, T max) where T : unmanaged { MemoryMarshal.GetReference(span); Vector<T> left = new Vector<T>(min); Vector<T> right = new Vector<T>(max); int num = span.Length / Vector<T>.Count; int num2 = Modulo4(num); int elementOffset = num - num2; ref Vector<T> reference = ref Unsafe.As<T, Vector<T>>(ref MemoryMarshal.GetReference(span)); ref Vector<T> reference2 = ref Unsafe.Add(ref reference, 1); ref Vector<T> reference3 = ref Unsafe.Add(ref reference, 2); ref Vector<T> reference4 = ref Unsafe.Add(ref reference, 3); ref Vector<T> reference5 = ref Unsafe.Add(ref reference, elementOffset); while (Unsafe.IsAddressLessThan(in reference, in reference5)) { reference = Vector.Min(Vector.Max(left, reference), right); reference2 = Vector.Min(Vector.Max(left, reference2), right); reference3 = Vector.Min(Vector.Max(left, reference3), right); reference4 = Vector.Min(Vector.Max(left, reference4), right); reference = ref Unsafe.Add(ref reference, 4); reference2 = ref Unsafe.Add(ref reference2, 4); reference3 = ref Unsafe.Add(ref reference3, 4); reference4 = ref Unsafe.Add(ref reference4, 4); } if (num2 > 0) { reference = ref reference5; reference5 = ref Unsafe.Add(ref reference5, num2); while (Unsafe.IsAddressLessThan(in reference, in reference5)) { reference = Vector.Min(Vector.Max(left, reference), right); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Premultiply(ref Vector4 source) { float w = source.W; source *= w; source.W = w; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UnPremultiply(ref Vector4 source) { float w = source.W; source /= w; source.W = w; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Premultiply(Span<Vector4> vectors) { if (Avx2.IsSupported && vectors.Length >= 2) { ref Vector256<float> reference = ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors)); ref Vector256<float> right = ref Unsafe.Add(ref reference, (IntPtr)((uint)vectors.Length / 2u)); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector256<float> vector = reference; Vector256<float> right2 = Avx.Shuffle(vector, vector, byte.MaxValue); reference = Avx.Blend(Avx.Multiply(vector, right2), vector, 136); reference = ref Unsafe.Add(ref reference, 1); } if (Modulo2(vectors.Length) != 0) { Premultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); } } else { ref Vector4 reference2 = ref MemoryMarshal.GetReference(vectors); ref Vector4 right3 = ref Unsafe.Add(ref reference2, vectors.Length); while (Unsafe.IsAddressLessThan(in reference2, in right3)) { Premultiply(ref reference2); reference2 = ref Unsafe.Add(ref reference2, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UnPremultiply(Span<Vector4> vectors) { if (Avx2.IsSupported && vectors.Length >= 2) { ref Vector256<float> reference = ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors)); ref Vector256<float> right = ref Unsafe.Add(ref reference, (IntPtr)((uint)vectors.Length / 2u)); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector256<float> vector = reference; Vector256<float> right2 = Avx.Shuffle(vector, vector, byte.MaxValue); reference = Avx.Blend(Avx.Divide(vector, right2), vector, 136); reference = ref Unsafe.Add(ref reference, 1); } if (Modulo2(vectors.Length) != 0) { UnPremultiply(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1))); } } else { ref Vector4 reference2 = ref MemoryMarshal.GetReference(vectors); ref Vector4 right3 = ref Unsafe.Add(ref reference2, vectors.Length); while (Unsafe.IsAddressLessThan(in reference2, in right3)) { UnPremultiply(ref reference2); reference2 = ref Unsafe.Add(ref reference2, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CubePowOnXYZ(Span<Vector4> vectors) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); ref Vector4 right = ref Unsafe.Add(ref reference, vectors.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector4 vector = reference; float w = vector.W; vector = vector * vector * vector; vector.W = w; reference = vector; reference = ref Unsafe.Add(ref reference, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void CubeRootOnXYZ(Span<Vector4> vectors) { if (Sse41.IsSupported) { ref Vector128<float> reference = ref Unsafe.As<Vector4, Vector128<float>>(ref MemoryMarshal.GetReference(vectors)); ref Vector128<float> right = ref Unsafe.Add(ref reference, vectors.Length); Vector128<int> right2 = Vector128.Create(341); Vector128<int> vector = Vector128.Create(-0f).AsInt32(); Vector128<int> right3 = Vector128.Create(1f).AsInt32(); Vector128<float> left = Vector128.Create(1f / 3f); Vector128<float> vector2 = Vector128.Create(2f / 3f); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector128<float> vector3 = reference; Vector128<int> right4 = vector3.AsInt32(); right4 = Sse2.AndNot(vector, right4); right4 = Sse2.Subtract(right4, right3); right4 = Sse2.ShiftRightArithmetic(right4, 10); right4 = Sse41.MultiplyLow(right4, right2); right4 = Sse2.Add(right4, right3); right4 = Sse2.AndNot(vector, right4); right4 = Sse2.Or(right4, Sse2.And(vector3.AsInt32(), vector)); Vector128<float> vector4 = right4.AsSingle(); if (Fma.IsSupported) { vector4 = Fma.MultiplyAdd(vector2, vector4, Sse.Multiply(left, Sse.Divide(vector3, Sse.Multiply(vector4, vector4)))); vector4 = Fma.MultiplyAdd(vector2, vector4, Sse.Multiply(left, Sse.Divide(vector3, Sse.Multiply(vector4, vector4)))); } else { vector4 = Sse.Add(Sse.Multiply(vector2, vector4), Sse.Multiply(left, Sse.Divide(vector3, Sse.Multiply(vector4, vector4)))); vector4 = Sse.Add(Sse.Multiply(vector2, vector4), Sse.Multiply(left, Sse.Divide(vector3, Sse.Multiply(vector4, vector4)))); } vector4 = Sse41.Insert(vector4, vector3, 240); reference = vector4; reference = ref Unsafe.Add(ref reference, 1); } } else { ref Vector4 reference2 = ref MemoryMarshal.GetReference(vectors); ref Vector4 right5 = ref Unsafe.Add(ref reference2, vectors.Length); Vector4 vector6 = default(Vector4); while (Unsafe.IsAddressLessThan(in reference2, in right5)) { Vector4 vector5 = reference2; double num = vector5.X; double num2 = vector5.Y; double num3 = vector5.Z; float w = vector5.W; ulong num4 = *(ulong*)(&num); ulong num5 = *(ulong*)(&num2); ulong num6 = *(ulong*)(&num3); num4 = 3071325735593686528L + num4 / 3; num5 = 3071325735593686528L + num5 / 3; num6 = 3071325735593686528L + num6 / 3; vector6.X = (float)(*(double*)(&num4)); vector6.Y = (float)(*(double*)(&num5)); vector6.Z = (float)(*(double*)(&num6)); vector6.W = 0f; vector6 = 2f / 3f * vector6 + 1f / 3f * (vector5 / (vector6 * vector6)); vector6 = 2f / 3f * vector6 + 1f / 3f * (vector5 / (vector6 * vector6)); vector6.W = w; reference2 = vector6; reference2 = ref Unsafe.Add(ref reference2, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector256<float> Lerp(in Vector256<float> value1, in Vector256<float> value2, in Vector256<float> amount) { Vector256<float> vector = Avx.Subtract(value2, value1); if (Fma.IsSupported) { return Fma.MultiplyAdd(vector, amount, value1); } return Avx.Add(Avx.Multiply(vector, amount), value1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Lerp(float value1, float value2, float amount) { return (value2 - value1) * amount + value1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Accumulate(ref Vector<uint> accumulator, Vector<byte> values) { Vector.Widen(values, out var low, out var high); Vector.Widen(low, out var low2, out var high2); accumulator += low2; accumulator += high2; Vector.Widen(high, out low2, out high2); accumulator += low2; accumulator += high2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ReduceSum(Vector128<int> accumulator) { if (Ssse3.IsSupported) { Vector128<int> vector = Ssse3.HorizontalAdd(accumulator, accumulator); Vector128<int> right = Sse2.Shuffle(vector, 1); return Sse2.ConvertToInt32(Sse2.Add(vector, right)); } int num = 0; for (int i = 0; i < Vector128<int>.Count; i++) { num += accumulator.GetElement(i); } return num; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ReduceSum(Vector256<int> accumulator) { Vector128<int> vector = Sse2.Add(accumulator.GetLower(), accumulator.GetUpper()); Vector128<int> vector2 = Sse2.Add(vector, Sse2.Shuffle(vector, 245)); return Sse2.ConvertToInt32(Sse2.Add(vector2, Sse2.Shuffle(vector2, 238))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int EvenReduceSum(Vector256<int> accumulator) { Vector128<int> vector = Sse2.Add(accumulator.GetLower(), accumulator.GetUpper()); return Sse2.ConvertToInt32(Sse2.Add(vector, Sse2.Shuffle(vector, 238))); } public static int Log2(uint value) { return BitOperations.Log2(value); } public static uint DivideCeil(uint value, uint divisor) { return (value + divisor - 1) / divisor; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateLeft(uint value, int offset) { return BitOperations.RotateLeft(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateRight(uint value, int offset) { return BitOperations.RotateRight(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOutOfRange(int value, int min, int max) { return (uint)(value - min) > (uint)(max - min); } } internal static class RuntimeEnvironment { private static readonly Lazy<bool> IsNetCoreLazy = new Lazy<bool>(() => FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase)); public static bool IsNetCore => IsNetCoreLazy.Value; public static string FrameworkDescription => RuntimeInformation.FrameworkDescription; public static bool IsOSPlatform(OSPlatform osPlatform) { return RuntimeInformation.IsOSPlatform(osPlatform); } } internal interface IComponentShuffle { byte Control { get; } void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest); } internal interface IShuffle4 : IComponentShuffle { } internal readonly struct DefaultShuffle4 : IShuffle4, IComponentShuffle { private readonly byte p3; private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultShuffle4(byte p3, byte p2, byte p1, byte p0) { this.p3 = p3; this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(p3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int num = p3; int num2 = p2; int num3 = p1; int num4 = p0; for (int i = 0; i < source.Length; i += 4) { Unsafe.Add(ref reference2, i) = Unsafe.Add(ref reference, num4 + i); Unsafe.Add(ref reference2, i + 1) = Unsafe.Add(ref reference, num3 + i); Unsafe.Add(ref reference2, i + 2) = Unsafe.Add(ref reference, num2 + i); Unsafe.Add(ref reference2, i + 3) = Unsafe.Add(ref reference, num + i); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct WXYZShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(2, 1, 0, 3); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = (num2 << 8) | (num2 >> 24); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct WZYXShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(0, 1, 2, 3); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint value = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = BinaryPrimitives.ReverseEndianness(value); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct YZWXShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(0, 3, 2, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint value = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = Numerics.RotateRight(value, 8); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct ZYXWShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(3, 0, 1, 2); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); uint num3 = num2 & 0xFF00FF00u; uint num4 = Numerics.RotateLeft(num2 & 0xFF00FF, 16); Unsafe.Add(ref source3, i) = num3 + num4; } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct XWZYShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(1, 2, 3, 0); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); uint num3 = num2 & 0xFF00FF; uint num4 = Numerics.RotateLeft(num2 & 0xFF00FF00u, 16); Unsafe.Add(ref source3, i) = num3 + num4; } } } internal interface IPad3Shuffle4 : IComponentShuffle { } internal readonly struct DefaultPad3Shuffle4 : IPad3Shuffle4, IComponentShuffle { private readonly byte p3; private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultPad3Shuffle4(byte p3, byte p2, byte p1, byte p0) { this.p3 = p3; this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(p3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int elementOffset = p3; int elementOffset2 = p2; int elementOffset3 = p1; int elementOffset4 = p0; ref byte reference3 = ref MemoryMarshal.GetReference(stackalloc byte[4]); ref uint reference4 = ref Unsafe.As<byte, uint>(ref reference3); int num = 0; int num2 = 0; while (num < source.Length) { reference4 = Unsafe.As<byte, uint>(ref Unsafe.Add(ref reference, num)) | 0xFF000000u; Unsafe.Add(ref reference2, num2) = Unsafe.Add(ref reference3, elementOffset4); Unsafe.Add(ref reference2, num2 + 1) = Unsafe.Add(ref reference3, elementOffset3); Unsafe.Add(ref reference2, num2 + 2) = Unsafe.Add(ref reference3, elementOffset2); Unsafe.Add(ref reference2, num2 + 3) = Unsafe.Add(ref reference3, elementOffset); num += 3; num2 += 4; } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct XYZWPad3Shuffle4 : IPad3Shuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(3, 2, 1, 0); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte source2 = ref MemoryMarshal.GetReference(dest); ref byte reference2 = ref Unsafe.Add(ref reference, source.Length); ref byte right = ref Unsafe.Subtract(ref reference2, 4); while (Unsafe.IsAddressLessThan(in reference, in right)) { Unsafe.As<byte, uint>(ref source2) = Unsafe.As<byte, uint>(ref reference) |