From e657a3b476b096250a473b3b684abf328b7f0cbe Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Fri, 28 Oct 2022 20:01:12 +0400 Subject: Better error messages. --- NesTiler/Palette.cs | 7 +++---- NesTiler/Program.cs | 10 ++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NesTiler/Palette.cs b/NesTiler/Palette.cs index 921f9af..d6d1747 100644 --- a/NesTiler/Palette.cs +++ b/NesTiler/Palette.cs @@ -14,11 +14,11 @@ namespace com.clusterrr.Famicom.NesTiler public struct LossyInfo { public int ImageNum { get; init; } - public int ColorCount { get; init; } public int TileX { get; init; } public int TileY { get; init; } public int TileWidth { get; init; } public int TileHeight { get; init; } + public SKColor[] Colors { get; init; } } private SKColor[] colors; @@ -51,16 +51,15 @@ namespace com.clusterrr.Famicom.NesTiler } } - // TODO: one more lossy level? var colorsCandidates = colorCounter.OrderByDescending(kv => kv.Value); if (colorsCandidates.Count() > 3) ColorLossy = new() { ImageNum = imageNum, - ColorCount = colorsCandidates.Count(), TileX = tileX, TileY = tileY, TileWidth = tileWidth, - TileHeight = tileHeight + TileHeight = tileHeight, + Colors = Enumerable.Concat(new SKColor[] { bgColor }, colorsCandidates.Select(kv => kv.Key)).ToArray() }; colors = colorsCandidates.Take(3).OrderBy(kv => kv.Key.ToArgb()).Select(kv => kv.Key).ToArray(); } diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs index 990f0dd..c23d5ab 100644 --- a/NesTiler/Program.cs +++ b/NesTiler/Program.cs @@ -174,7 +174,10 @@ namespace com.clusterrr.Famicom.NesTiler c.TilePalHeight, c.BgColor.Value); if ((c.LossyLevel <= 1) && (lossyInfo != null)) - throw new InvalidDataException($"Image #{lossyInfo?.ImageNum}, tile at X={lossyInfo?.TileX} Y={lossyInfo?.TileY} has {lossyInfo?.ColorCount + 1} colors while only 4 is possible."); + throw new InvalidDataException($"Image #{lossyInfo?.ImageNum}, " + + $"tile at ({lossyInfo?.TileX},{lossyInfo?.TileY})-" + + $"({lossyInfo?.TileX + lossyInfo?.TileWidth},{lossyInfo?.TileY + lossyInfo?.TileHeight}) has {lossyInfo?.Colors?.Length} " + + $"colors ({string.Join(", ", lossyInfo?.Colors?.Select(c => c.ToHtml())!)}) while only 4 possible."); } else { @@ -237,7 +240,10 @@ namespace com.clusterrr.Famicom.NesTiler var kvLossy = calcResults.OrderBy(kv => kv.Value.Palettes.Length).First(); lossyInfo = kvLossy.Value.LossyInfo; if (c.LossyLevel <= 1) - throw new InvalidDataException($"Image #{lossyInfo?.ImageNum}, tile at X={lossyInfo?.TileX} Y={lossyInfo?.TileY} has {lossyInfo?.ColorCount + 1} colors while only 4 is possible."); + throw new InvalidDataException($"Image #{lossyInfo?.ImageNum}, " + + $"tile at ({lossyInfo?.TileX},{lossyInfo?.TileY})-" + + $"({lossyInfo?.TileX + lossyInfo?.TileWidth},{lossyInfo?.TileY + lossyInfo?.TileHeight}) has {lossyInfo?.Colors?.Length} " + + $"colors ({string.Join(", ", lossyInfo?.Colors?.Select(c => c.ToHtml())!)}) while only 4 possible."); (bgColor, calculatedPalettes) = (kvLossy.Key, kvLossy.Value.Palettes); } Trace.WriteLine(bgColor.ToHtml()); -- cgit v1.2.3