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

github.com/ClusterM/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-27 16:59:30 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-10-27 16:59:30 +0300
commitdfd7e9a652514fe6abf5d84e2f1736036afdcc1c (patch)
tree4aba9a8d474c717d3f6ee5da63f5f8741f1e4eaa
parent63709d7d298968d62c754c5f6a114316de3bec61 (diff)
Some fixes and optimization.
-rw-r--r--NesTiler/FastBitmap.cs23
-rw-r--r--NesTiler/Program.cs2
2 files changed, 17 insertions, 8 deletions
diff --git a/NesTiler/FastBitmap.cs b/NesTiler/FastBitmap.cs
index 5910f43..07b33e5 100644
--- a/NesTiler/FastBitmap.cs
+++ b/NesTiler/FastBitmap.cs
@@ -14,21 +14,30 @@ namespace com.clusterrr.Famicom.NesTiler
private readonly Color[] colors;
private static Dictionary<string, SKBitmap> imagesCache = new Dictionary<string, SKBitmap>();
- private FastBitmap(SKBitmap skBitmap, int verticalOffset = 0, int height = 0)
+ private FastBitmap(SKBitmap skBitmap, int verticalOffset = 0, int height = -1)
{
Width = skBitmap.Width;
Height = height <= 0 ? skBitmap.Height - verticalOffset : height;
- if (skBitmap.Height - verticalOffset - Height <= 0) throw new InvalidOperationException("Invalid image height.");
+ if (skBitmap.Height - verticalOffset - Height < 0 || Height <= 0) throw new InvalidOperationException("Invalid image height.");
var pixels = skBitmap.Pixels;
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 = -1)
{
- using var image = SKBitmap.Decode(filename);
- if (image == null) return null;
- imagesCache[filename] = image;
- return new FastBitmap(image, verticalOffset, height);
+ try
+ {
+ using (var image = SKBitmap.Decode(filename))
+ {
+ if (image == null) return null;
+ imagesCache[filename] = image;
+ return new FastBitmap(image, verticalOffset, height);
+ }
+ }
+ finally
+ {
+ GC.Collect();
+ }
}
public Color GetPixelColor(int x, int y)
diff --git a/NesTiler/Program.cs b/NesTiler/Program.cs
index 852cbc1..92c6d12 100644
--- a/NesTiler/Program.cs
+++ b/NesTiler/Program.cs
@@ -113,7 +113,7 @@ namespace com.clusterrr.Famicom.NesTiler
var heightS = match.Groups["height"].Value;
// Crop it if need
int offset = 0;
- int height = 0;
+ int height = -1;
if (!string.IsNullOrEmpty(offsetS))
{
offset = int.Parse(offsetS);