Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NesTiler.git/NesTiler.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-10-26 14:55:35 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-10-26 14:58:03 +0300
commit1d54c302c81616846ad21ecc958d526ca05f3c1d (patch)
tree77c49fcf5cffa751e7340b6c35354d9b436eb0a5 /NesTiler
parent6fe1271fa4570f380c0eda7e647774ec3a78a30b (diff)
Nullable reference types.
Diffstat (limited to 'NesTiler')
-rw-r--r--NesTiler/FastBitmap.cs2
-rw-r--r--NesTiler/NesTiler.csproj2
-rw-r--r--NesTiler/Palette.cs20
-rw-r--r--NesTiler/Program.cs36
-rw-r--r--NesTiler/Tile.cs4
5 files changed, 32 insertions, 32 deletions
diff --git a/NesTiler/FastBitmap.cs b/NesTiler/FastBitmap.cs
index 70a3382..8ed84e9 100644
--- a/NesTiler/FastBitmap.cs
+++ b/NesTiler/FastBitmap.cs
@@ -25,7 +25,7 @@ namespace com.clusterrr.Famicom.NesTiler
colors = skBitmap.Pixels.Skip(verticalOffset * Width).Take(Width * Height).Select(p => Color.FromArgb(p.Alpha, p.Red, p.Green, p.Blue)).ToArray();
}
- public static FastBitmap Decode(string filename, int verticalOffset = 0, int height = 0)
+ public static FastBitmap? Decode(string filename, int verticalOffset = 0, int height = 0)
{
using var image = SKBitmap.Decode(filename);
if (image == null) return null;
diff --git a/NesTiler/NesTiler.csproj b/NesTiler/NesTiler.csproj
index 3836d09..8f7138e 100644
--- a/NesTiler/NesTiler.csproj
+++ b/NesTiler/NesTiler.csproj
@@ -65,7 +65,7 @@
<Authors>Alexey "Cluster" Avdyukhin</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Product>NesTiler</Product>
- <Nullable>disable</Nullable>
+ <Nullable>enable</Nullable>
</PropertyGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="make commit buildtime&#xD;&#xA;" />
diff --git a/NesTiler/Palette.cs b/NesTiler/Palette.cs
index 2e11241..ff4c3c5 100644
--- a/NesTiler/Palette.cs
+++ b/NesTiler/Palette.cs
@@ -92,32 +92,32 @@ namespace com.clusterrr.Famicom.NesTiler
Color2 = bgColor
};
if (deltaCache.ContainsKey(pair)) return deltaCache[pair];
- var ac = Enumerable.Concat(colors.Where(c => c.HasValue).Select(c => c.Value), new Color[] { bgColor });
+ var ac = Enumerable.Concat(colors.Where(c => c.HasValue).Select(c => c!.Value), new Color[] { bgColor });
var result = ac.OrderBy(c => c.GetDelta(color)).First();
var r = (result, result.GetDelta(color));
deltaCache[pair] = r;
return r;
}
- public bool Equals(Palette other)
+ public bool Equals(Palette? other)
{
if (other == null) return false;
var colors1 = colors.Where(c => c.HasValue)
- .OrderBy(c => c.Value.ToArgb())
- .Select(c => c.Value)
+ .OrderBy(c => c!.Value.ToArgb())
+ .Select(c => c!.Value)
.ToArray();
var colors2 = new Color?[] { other[1], other[2], other[3] }
.Where(c => c.HasValue)
- .OrderBy(c => c.Value.ToArgb())
- .Select(c => c.Value)
+ .OrderBy(c => c!.Value.ToArgb())
+ .Select(c => c!.Value)
.ToArray();
- return Enumerable.SequenceEqual<Color>(colors1, colors2);
+ return Enumerable.SequenceEqual(colors1, colors2);
}
public bool Contains(Palette other)
{
var thisColors = colors.Where(c => c.HasValue);
- var otherColors = new Color?[] { other[1], other[2], other[3] }.Where(c => c.HasValue).Select(c => c.Value);
+ var otherColors = new Color?[] { other[1], other[2], other[3] }.Where(c => c.HasValue).Select(c => c!.Value);
foreach (var color in otherColors)
{
@@ -129,7 +129,7 @@ namespace com.clusterrr.Famicom.NesTiler
public IEnumerator<Color> GetEnumerator()
{
- return colors.Where(c => c.HasValue).Select(c => c.Value).GetEnumerator();
+ return colors.Where(c => c.HasValue).Select(c => c!.Value).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
@@ -137,7 +137,7 @@ namespace com.clusterrr.Famicom.NesTiler
return GetEnumerator();
}
- public override string ToString() => string.Join(", ", colors.Where(c => c.HasValue).Select(c => ColorTranslator.ToHtml(c.Value)).OrderBy(c => c));
+ public override string ToString() => string.Join(", ", colors.Where(c => c.HasValue).Select(c => ColorTranslator.ToHtml(c!.Value)).OrderBy(c => c));
public override int GetHashCode()
{
diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs
index 62ac1fa..65034b8 100644
--- a/NesTiler/Program.cs
+++ b/NesTiler/Program.cs
@@ -82,8 +82,8 @@ namespace com.clusterrr.Famicom.NesTiler
colorsFile = Path.Combine("/etc", DEFAULT_COLORS_FILE);
var imageFiles = new Dictionary<int, string>();
Color? bgColor = null;
- var paletteEnabled = new bool[4] { true, true, true, true };
- var fixedPalettes = new Palette[4] { null, null, null, null };
+ bool[] paletteEnabled = new bool[4] { true, true, true, true };
+ Palette?[] fixedPalettes = new Palette?[4] { null, null, null, null };
var mode = TilesMode.Backgrounds;
int tileWidth = 8;
int tileHeight = 8;
@@ -101,12 +101,12 @@ namespace com.clusterrr.Famicom.NesTiler
var outPreview = new Dictionary<int, string>();
var outPalette = new Dictionary<int, string>();
var outPatternTable = new Dictionary<int, string>();
- string outPatternTableShared = null;
+ string? outPatternTableShared = null;
var outNameTable = new Dictionary<int, string>();
var outAttributeTable = new Dictionary<int, string>();
- string outTilesCsv = null;
- string outPalettesCsv = null;
- string outColorsTable = null;
+ string? outTilesCsv = null;
+ string? outPalettesCsv = null;
+ string? outColorsTable = null;
var console = (string text) => { if (!quiet) Console.WriteLine(text); };
// Data
@@ -337,7 +337,7 @@ namespace com.clusterrr.Famicom.NesTiler
for (int i = 0; i < fixedPalettes.Length; i++)
{
if (fixedPalettes[i] == null) continue;
- var colorsInPalette = fixedPalettes[i].ToArray();
+ var colorsInPalette = fixedPalettes[i]!.ToArray();
for (int j = 0; j < colorsInPalette.Length; j++)
colorsInPalette[j] = nesColors[FindSimilarColor(nesColors, colorsInPalette[j], nesColorsCache)];
fixedPalettes[i] = new Palette(colorsInPalette);
@@ -456,7 +456,7 @@ namespace com.clusterrr.Famicom.NesTiler
}
// Select palettes
- var palettes = new Palette[4] { null, null, null, null };
+ var palettes = new Palette?[4] { null, null, null, null };
outPalettesCsvLines?.Add("palette_id,color0,color1,color2,color3");
for (var i = 0; i < palettes.Length; i++)
{
@@ -481,9 +481,9 @@ namespace com.clusterrr.Famicom.NesTiler
if (palettes[i] != null)
{
- console($"Palette #{i}: {ColorTranslator.ToHtml(bgColor.Value)}(BG) {string.Join(" ", palettes[i].Select(p => ColorTranslator.ToHtml(p)))}");
+ console($"Palette #{i}: {ColorTranslator.ToHtml(bgColor.Value)}(BG) {string.Join(" ", palettes[i]!.Select(p => ColorTranslator.ToHtml(p)))}");
// Write CSV if required
- outPalettesCsvLines?.Add($"{i},{ColorTranslator.ToHtml(bgColor.Value)},{string.Join(",", Enumerable.Range(1, 3).Select(c => (palettes[i][c] != null ? ColorTranslator.ToHtml(palettes[i][c].Value) : "")))}");
+ outPalettesCsvLines?.Add($"{i},{ColorTranslator.ToHtml(bgColor.Value)},{string.Join(",", Enumerable.Range(1, 3).Select(c => (palettes[i]![c] != null ? ColorTranslator.ToHtml(palettes[i]![c]!.Value) : "")))}");
}
}
}
@@ -500,8 +500,8 @@ namespace com.clusterrr.Famicom.NesTiler
{
if (palettes[p] == null)
paletteRaw[c] = 0;
- else if (palettes[p][c].HasValue)
- paletteRaw[c] = FindSimilarColor(nesColors, palettes[p][c].Value, nesColorsCache);
+ else if (palettes[p]![c].HasValue)
+ paletteRaw[c] = FindSimilarColor(nesColors, palettes[p]![c]!.Value, nesColorsCache);
}
File.WriteAllBytes(outPalette[p], paletteRaw);
console($"Palette #{p} saved to {outPalette[p]}");
@@ -527,7 +527,7 @@ namespace com.clusterrr.Famicom.NesTiler
for (byte paletteIndex = 0; paletteIndex < palettes.Length; paletteIndex++)
{
if (palettes[paletteIndex] == null) continue;
- double delta = palettes[paletteIndex].GetTileDelta(
+ double delta = palettes[paletteIndex]!.GetTileDelta(
image, tilePalX * tilePalWidth, (tilePalY * tilePalHeight) - attributeTableOffset,
tilePalWidth, tilePalHeight, bgColor.Value);
// Find palette with most similar colors
@@ -537,7 +537,7 @@ namespace com.clusterrr.Famicom.NesTiler
bestPaletteIndex = paletteIndex;
}
}
- Palette bestPalette = palettes[bestPaletteIndex];
+ Palette bestPalette = palettes[bestPaletteIndex]!; // at least one palette enabled, so can't be null here
// Remember palette index
paletteIndexes[imageNum][tilePalX, tilePalY] = bestPaletteIndex;
@@ -660,7 +660,7 @@ namespace com.clusterrr.Famicom.NesTiler
if (color != bgColor)
{
colorIndex = 1;
- while (palette[colorIndex] != color) colorIndex++;
+ while (palette![colorIndex] != color) colorIndex++;
}
tileData[(y * tileWidth) + x] = colorIndex;
}
@@ -718,7 +718,7 @@ namespace com.clusterrr.Famicom.NesTiler
}
// Save shared pattern table to file
- if (sharePatternTable)
+ if (sharePatternTable && outPatternTableShared != null)
{
var patternTableReversed = patternTables[0].ToDictionary(kv => kv.Value, kv => kv.Key);
var patternTableRaw = new List<byte>();
@@ -848,7 +848,7 @@ namespace com.clusterrr.Famicom.NesTiler
File.WriteAllBytes(filename, image.Encode(SKEncodedImageFormat.Png, 0).ToArray());
}
- static Palette[] CalculatePalettes(Dictionary<int, FastBitmap> images, bool[] paletteEnabled, Palette[] fixedPalettes, Dictionary<int, int> attributeTableOffsets, int tilePalWidth, int tilePalHeight, Color bgColor)
+ static Palette[] CalculatePalettes(Dictionary<int, FastBitmap> images, bool[] paletteEnabled, Palette?[] fixedPalettes, Dictionary<int, int> attributeTableOffsets, int tilePalWidth, int tilePalHeight, Color bgColor)
{
var required = Enumerable.Range(0, 4).Select(i => paletteEnabled[i] && fixedPalettes[i] == null);
// Creating and counting the palettes
@@ -946,7 +946,7 @@ namespace com.clusterrr.Famicom.NesTiler
return result;
}
- static byte FindSimilarColor(Dictionary<byte, Color> colors, Color color, Dictionary<Color, byte> cache = null)
+ static byte FindSimilarColor(Dictionary<byte, Color> colors, Color color, Dictionary<Color, byte>? cache = null)
{
if (cache != null)
{
diff --git a/NesTiler/Tile.cs b/NesTiler/Tile.cs
index b1b52fd..a33f00f 100644
--- a/NesTiler/Tile.cs
+++ b/NesTiler/Tile.cs
@@ -10,7 +10,7 @@ namespace com.clusterrr.Famicom.NesTiler
public const int Width = 8;
public readonly int Height;
private int? hash;
- private byte[] data = null;
+ private byte[]? data = null;
public Tile(byte[] data, int height)
{
@@ -42,7 +42,7 @@ namespace com.clusterrr.Famicom.NesTiler
return data;
}
- public bool Equals(Tile other)
+ public bool Equals(Tile? other)
{
if (other == null) return false;
var data1 = GetAsPatternData();