diff --git a/Common.ruleset b/Common.ruleset index b28bc6ec93..32f7bb17ae 100644 --- a/Common.ruleset +++ b/Common.ruleset @@ -237,7 +237,7 @@ - + @@ -622,7 +622,7 @@ - + diff --git a/src/BizHawk.BizInvoke/MemoryViewStream.cs b/src/BizHawk.BizInvoke/MemoryViewStream.cs index 3a5e9a535e..175482e2cd 100644 --- a/src/BizHawk.BizInvoke/MemoryViewStream.cs +++ b/src/BizHawk.BizInvoke/MemoryViewStream.cs @@ -38,7 +38,7 @@ namespace BizHawk.BizInvoke set { if (value < 0 || value > _length) - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(paramName: nameof(value), value, message: "index out of range"); _pos = value; } } diff --git a/src/BizHawk.Bizware.OpenTK3/IGL_TK.cs b/src/BizHawk.Bizware.OpenTK3/IGL_TK.cs index ad7844d962..a5b68bcf16 100644 --- a/src/BizHawk.Bizware.OpenTK3/IGL_TK.cs +++ b/src/BizHawk.Bizware.OpenTK3/IGL_TK.cs @@ -664,9 +664,7 @@ namespace BizHawk.Bizware.OpenTK3 private GLControl CastControl(swf.Control swfControl) { - GLControl glc = swfControl as GLControl; - if (glc == null) - throw new ArgumentException("Argument isn't a control created by the IGL interface", "glControl"); + if (swfControl is not GLControl glc) throw new ArgumentException(message: "Argument isn't a control created by the IGL interface", paramName: nameof(swfControl)); return glc; } diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index 7292e11736..afb9aa2ff6 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -32,9 +32,9 @@ namespace BizHawk.Client.Common _dialogParent = dialogParent; _quickBmpFile = quickBmpFile; _pauseCallback = pauseCallback - ?? throw new ArgumentNullException($"{nameof(pauseCallback)} cannot be null."); + ?? throw new ArgumentNullException(paramName: nameof(pauseCallback)); _modeChangedCallback = modeChangedCallback - ?? throw new ArgumentNullException($"{nameof(modeChangedCallback)} CannotUnloadAppDomainException be null."); + ?? throw new ArgumentNullException(paramName: nameof(modeChangedCallback)); } public IMovieConfig Settings { get; } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index f924def8d0..abfab5e054 100755 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -14,7 +14,9 @@ namespace BizHawk.Client.Common { if (string.IsNullOrWhiteSpace(filename)) { - throw new ArgumentNullException($"{nameof(filename)} can not be null."); + throw filename is null + ? new ArgumentNullException(paramName: nameof(filename)) + : new ArgumentException(message: "path cannot be blank", paramName: nameof(filename)); } Session = session; diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs b/src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs index fdead917ab..45f101a2de 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs @@ -105,10 +105,7 @@ namespace BizHawk.Client.Common public new void Add(TasBranch item) { - if (item == null) - { - throw new ArgumentNullException($"{nameof(item)} cannot be null"); - } + if (item is null) throw new ArgumentNullException(paramName: nameof(item)); if (item.Uuid == Guid.Empty) { diff --git a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs index 0d0695456f..85d273339a 100644 --- a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs +++ b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs @@ -24,10 +24,7 @@ namespace BizHawk.Client.Common throw new ArgumentException("ZwinderBuffer's settings cannot be null."); long targetSize = settings.BufferSize * 1024 * 1024; - if (settings.TargetFrameLength < 1) - { - throw new ArgumentOutOfRangeException(nameof(settings.TargetFrameLength)); - } + if (settings.TargetFrameLength < 1) throw new ArgumentException(message: nameof(IRewindSettings.TargetFrameLength) + " of provided settings is invalid", paramName: nameof(settings)); Size = 1L << (int)Math.Floor(Math.Log(targetSize, 2)); _sizeMask = Size - 1; diff --git a/src/BizHawk.Client.Common/tools/CheatList.cs b/src/BizHawk.Client.Common/tools/CheatList.cs index 2b33b0cff8..7fa9a2300d 100644 --- a/src/BizHawk.Client.Common/tools/CheatList.cs +++ b/src/BizHawk.Client.Common/tools/CheatList.cs @@ -112,10 +112,7 @@ namespace BizHawk.Client.Common /// is null public void Add(Cheat cheat) { - if (cheat is null) - { - throw new ArgumentNullException($"{nameof(cheat)} can not be null"); - } + if (cheat is null) throw new ArgumentNullException(paramName: nameof(cheat)); if (cheat.IsSeparator) { diff --git a/src/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs b/src/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs index e8d18e4449..555552b1e0 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs @@ -73,11 +73,7 @@ namespace BizHawk.Client.EmuHawk /// is not in use public void ReleaseBuffer(T[] buffer) { - if (!_inUse.Remove(buffer)) - { - throw new ArgumentException(); - } - + if (!_inUse.Remove(buffer)) throw new ArgumentException(message: "already released?", paramName: nameof(buffer)); _available.Add(buffer); } } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs index c9445e59e1..7145d7483c 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -11,10 +11,7 @@ namespace BizHawk.Client.EmuHawk { public bool StartNewMovie(IMovie movie, bool record) { - if (movie == null) - { - throw new ArgumentNullException($"{nameof(movie)} cannot be null."); - } + if (movie is null) throw new ArgumentNullException(paramName: nameof(movie)); var oldPreferredCores = new Dictionary(Config.PreferredCores); try diff --git a/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs b/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs index 363b9ca5da..5f9fb5b85b 100755 --- a/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs +++ b/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs @@ -104,7 +104,7 @@ namespace BizHawk.Client.EmuHawk NLuaRadio.Checked = true; break; default: - throw new ArgumentOutOfRangeException(); + throw new InvalidOperationException(); } } diff --git a/src/BizHawk.Common/Util.cs b/src/BizHawk.Common/Util.cs index f3f7c0f185..86ffca0134 100644 --- a/src/BizHawk.Common/Util.cs +++ b/src/BizHawk.Common/Util.cs @@ -104,13 +104,13 @@ namespace BizHawk.Common /// has an odd number of chars or contains a char not in [0-9A-Fa-f] public static byte[] HexStringToBytes(this string str) { - if (str.Length % 2 != 0) throw new ArgumentException(); + if (str.Length % 2 is not 0) throw new ArgumentException(message: "string length must be even (add 0 padding if necessary)", paramName: nameof(str)); static int CharToNybble(char c) { if ('0' <= c && c <= '9') return c - 0x30; if ('A' <= c && c <= 'F') return c - 0x37; if ('a' <= c && c <= 'f') return c - 0x57; - throw new ArgumentException(); + throw new ArgumentException(message: "not a hex digit", paramName: nameof(c)); } using var ms = new MemoryStream(); for (int i = 0, l = str.Length / 2; i != l; i++) ms.WriteByte((byte) ((CharToNybble(str[2 * i]) << 4) + CharToNybble(str[2 * i + 1]))); diff --git a/src/BizHawk.Common/checksums/CRC32.cs b/src/BizHawk.Common/checksums/CRC32.cs index df0f111674..3924c2e481 100644 --- a/src/BizHawk.Common/checksums/CRC32.cs +++ b/src/BizHawk.Common/checksums/CRC32.cs @@ -51,7 +51,7 @@ namespace BizHawk.Common private static void gf2_matrix_square(Span square, ReadOnlySpan mat) { - if (mat.Length != square.Length) throw new ArgumentException(); + if (mat.Length != square.Length) throw new ArgumentException(message: "must be same length as " + nameof(square), paramName: nameof(mat)); for (var n = 0; n < square.Length; n++) square[n] = gf2_matrix_times(mat, mat[n]); } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomain.cs b/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomain.cs index c1b4f66303..2f89aed99f 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomain.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomain.cs @@ -105,10 +105,8 @@ namespace BizHawk.Emulation.Common public virtual void BulkPeekByte(Range addresses, byte[] values) { - if (addresses == null || values == null) - { - throw new ArgumentException(); - } + if (addresses is null) throw new ArgumentNullException(paramName: nameof(addresses)); + if (values is null) throw new ArgumentNullException(paramName: nameof(values)); if ((long) addresses.Count() != values.Length) { @@ -126,10 +124,9 @@ namespace BizHawk.Emulation.Common public virtual void BulkPeekUshort(Range addresses, bool bigEndian, ushort[] values) { - if (addresses == null || values == null) - { - throw new ArgumentException(); - } + if (addresses is null) throw new ArgumentNullException(paramName: nameof(addresses)); + if (values is null) throw new ArgumentNullException(paramName: nameof(values)); + var start = addresses.Start; var end = addresses.EndInclusive + 1; @@ -151,10 +148,9 @@ namespace BizHawk.Emulation.Common public virtual void BulkPeekUint(Range addresses, bool bigEndian, uint[] values) { - if (addresses == null || values == null) - { - throw new ArgumentException(); - } + if (addresses is null) throw new ArgumentNullException(paramName: nameof(addresses)); + if (values is null) throw new ArgumentNullException(paramName: nameof(values)); + var start = addresses.Start; var end = addresses.EndInclusive + 1; diff --git a/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomainStream.cs b/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomainStream.cs index 58175cb989..795d4ddb13 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomainStream.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/MemoryDomainStream.cs @@ -90,7 +90,7 @@ namespace BizHawk.Emulation.Common Position = Length + offset; break; default: - throw new ArgumentOutOfRangeException("origin"); + throw new ArgumentOutOfRangeException(paramName: nameof(origin)); } return Position; } diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs index cc5cd83938..8fed0a4555 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs @@ -46,11 +46,7 @@ namespace BizHawk.Emulation.Common get => _cpu ??= AvailableCpus.First(); set { - if (!AvailableCpus.Contains(value)) - { - throw new ArgumentException(); - } - + if (!AvailableCpus.Contains(value)) throw new ArgumentException(message: $"must be the name of a CPU with disassembly available (see {nameof(AvailableCpus)})", paramName: nameof(value)); _cpu = value; } } diff --git a/src/BizHawk.Emulation.Common/Sound/BlipBuffer.cs b/src/BizHawk.Emulation.Common/Sound/BlipBuffer.cs index d42f9bc1ff..432fafcf88 100644 --- a/src/BizHawk.Emulation.Common/Sound/BlipBuffer.cs +++ b/src/BizHawk.Emulation.Common/Sound/BlipBuffer.cs @@ -143,36 +143,24 @@ namespace BizHawk.Emulation.Common return BlipBufDll.blip_samples_avail(_context); } - /// can't hold samples (or twice that if is ) + /// can't hold samples (or twice that if is ) public int ReadSamples(short[] output, int count, bool stereo) { - if (output.Length < count * (stereo ? 2 : 1)) - { - throw new ArgumentOutOfRangeException(); - } - + if (output.Length < count * (stereo ? 2 : 1)) throw new ArgumentException(message: "buffer too small", paramName: nameof(output)); return BlipBufDll.blip_read_samples(_context, output, count, stereo ? 1 : 0); } - /// can't hold 2 * samples + /// can't hold 2 * samples public int ReadSamplesLeft(short[] output, int count) { - if (output.Length < count * 2) - { - throw new ArgumentOutOfRangeException(); - } - + if (output.Length < count * 2) throw new ArgumentException(message: "buffer too small", paramName: nameof(output)); return BlipBufDll.blip_read_samples(_context, output, count, 1); } - /// can't hold 2 * samples + /// can't hold 2 * samples public int ReadSamplesRight(short[] output, int count) { - if (output.Length < count * 2) - { - throw new ArgumentOutOfRangeException(); - } - + if (output.Length < count * 2) throw new ArgumentException(message: "buffer too small", paramName: nameof(output)); unsafe { fixed (short* s = &output[1]) diff --git a/src/BizHawk.Emulation.Common/Sound/DCFilter.cs b/src/BizHawk.Emulation.Common/Sound/DCFilter.cs index 76debfbcaf..6e6f737dae 100644 --- a/src/BizHawk.Emulation.Common/Sound/DCFilter.cs +++ b/src/BizHawk.Emulation.Common/Sound/DCFilter.cs @@ -33,15 +33,8 @@ namespace BizHawk.Emulation.Common /// is not in 8..65536 public DCFilter(ISoundProvider input, int filterWidth) { - if (input == null) - { - throw new ArgumentNullException(); - } - - if (filterWidth < 8 || filterWidth > 65536) - { - throw new ArgumentOutOfRangeException(); - } + if (input is null) throw new ArgumentNullException(paramName: nameof(input)); + if (filterWidth is < 8 or > 65536) throw new ArgumentOutOfRangeException(paramName: nameof(filterWidth), filterWidth, message: "invalid width"); _depth = DepthFromFilterWidth(filterWidth); diff --git a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs index 515b3c9854..ae1ade26fc 100644 --- a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs @@ -11,10 +11,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME private byte _peek(long addr, int firstOffset, long size) { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); if (!_memAccess) { @@ -33,10 +30,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME private void _poke(long addr, byte val, int firstOffset, long size) { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); if (!_memAccess) { diff --git a/src/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs b/src/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs index e6c6cbfad8..ae42bb7f13 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/Z80A/Interrupts.cs @@ -31,7 +31,11 @@ namespace BizHawk.Emulation.Cores.Components.Z80A public int InterruptMode { get => interruptMode; - set { if (value < 0 || value > 2) throw new ArgumentOutOfRangeException(); interruptMode = value; } + set + { + if (value is < 0 or > 2) throw new ArgumentOutOfRangeException(paramName: nameof(value), value, message: "invalid interrupt mode"); + interruptMode = value; + } } public Action IRQCallback = () => {}; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.ISaveRam.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.ISaveRam.cs index 1d0c573615..3cbb9d7975 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.ISaveRam.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.ISaveRam.cs @@ -26,10 +26,7 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx throw new InvalidOperationException(); } - if (size != srcData.Length) - { - throw new ArgumentOutOfRangeException(); - } + if (srcData.Length != size) throw new ArgumentException(message: "buffer too small", paramName: nameof(srcData)); Marshal.Copy(srcData, 0, data, size); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IMemoryDomains.cs index 3510f10a34..08c6fe098d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IMemoryDomains.cs @@ -41,21 +41,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA addr => { var a = (uint)addr; - if (a >= 0x10000000) - { - throw new ArgumentOutOfRangeException(); - } - + if (a >= 0x10000000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); return LibmGBA.BizReadBus(Core, a); }, (addr, val) => { var a = (uint)addr; - if (a >= 0x10000000) - { - throw new ArgumentOutOfRangeException(); - } - + if (a >= 0x10000000) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range"); LibmGBA.BizWriteBus(Core, a, val); }, 4)); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs index abb4e09f7d..0bbfd0aaa8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs @@ -32,20 +32,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { peekByte = addr => { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return Marshal.ReadByte(memPtr, (int)(addr ^ 3)); }; pokeByte = (addr, val) => { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Marshal.WriteByte(memPtr, (int)(addr ^ 3), val); }; } @@ -53,20 +45,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { peekByte = addr => { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); return Marshal.ReadByte(memPtr, (int)(addr)); }; pokeByte = (addr, val) => { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - + if (addr < 0 || addr >= size) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range"); Marshal.WriteByte(memPtr, (int)(addr), val); }; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs index 8d44fcd0a9..f535e0471f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs @@ -153,8 +153,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public void InsertSide(int side) { - if (side >= NumSides) - throw new ArgumentOutOfRangeException(); + if (side >= NumSides) throw new ArgumentOutOfRangeException(paramName: nameof(side), side, message: "index out of range"); byte[] buf = new byte[65500]; Buffer.BlockCopy(diskimage, 16 + side * 65500, buf, 0, 65500); diskdrive.InsertBrokenImage(buf, false /*true*/); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.ISettable.cs index 62d126ff6d..e171164df2 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.ISettable.cs @@ -80,19 +80,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES get => _Palette; set { - if (value == null) - { - throw new ArgumentNullException(); - } - - if (value.Length == 64 * 8 * 3) - { - _Palette = value; - } - else - { - throw new ArgumentOutOfRangeException(); - } + if (value is null) throw new ArgumentNullException(paramName: nameof(value)); + const int PALETTE_LENGTH = 64 * 8 * 3; + if (value.Length is not PALETTE_LENGTH) throw new ArgumentException(message: "incorrect length", paramName: nameof(value)); + _Palette = value; } } @@ -117,10 +108,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES //TODO - support 512 color palettes int nColors = pal.GetLength(0); int nElems = pal.GetLength(1); - if (!(nColors == 64 || nColors == 512) || nElems != 3) - { - throw new ArgumentOutOfRangeException(); - } + if (nColors is not (64 or 512) || nElems is not 3) throw new ArgumentException(message: "incorrect array dimensions", paramName: nameof(pal)); if (nColors == 512) {