Skip to content

Commit 47012e2

Browse files
committed
fix: file extensions are case-insensitive
Signed-off-by: leo <[email protected]>
1 parent 8db033b commit 47012e2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/ViewModels/ImageSource.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.IO;
34
using System.Runtime.InteropServices;
45

@@ -23,7 +24,7 @@ public ImageSource(Bitmap bitmap, long size)
2324

2425
public static Models.ImageDecoder GetDecoder(string file)
2526
{
26-
var ext = Path.GetExtension(file) ?? ".invalid_img";
27+
var ext = (Path.GetExtension(file) ?? ".invalid_img").ToLower(CultureInfo.CurrentCulture);
2728

2829
switch (ext)
2930
{
@@ -92,9 +93,9 @@ private static ImageSource DecodeWithAvalonia(Stream stream, long size)
9293

9394
private static ImageSource DecodeWithPfim(Stream stream, long size)
9495
{
95-
using (var pfiImage = Pfimage.FromStream(stream))
96+
try
9697
{
97-
try
98+
using (var pfiImage = Pfimage.FromStream(stream))
9899
{
99100
var data = pfiImage.Data;
100101
var stride = pfiImage.Stride;
@@ -136,7 +137,7 @@ private static ImageSource DecodeWithPfim(Stream stream, long size)
136137
data[i * 4 + 0] = (byte)Math.Round(((v & 0b1111100000000000) >> 11) / 31.0 * 255);
137138
data[i * 4 + 1] = (byte)Math.Round(((v & 0b11111000000) >> 6) / 31.0 * 255);
138139
data[i * 4 + 2] = (byte)Math.Round(((v & 0b111110) >> 1) / 31.0 * 255);
139-
data[i * 4 + 3] = (byte)((v & 1) == 1 ? 255 : 0);
140+
data[i * 4 + 3] = (byte)((v & 1) == 1 ? 255 : 0);
140141
}
141142
alphaFormat = AlphaFormat.Premul;
142143
break;
@@ -157,10 +158,10 @@ private static ImageSource DecodeWithPfim(Stream stream, long size)
157158
var bitmap = new Bitmap(pixelFormat, alphaFormat, ptr, pixelSize, dpi, stride);
158159
return new ImageSource(bitmap, size);
159160
}
160-
catch
161-
{
162-
return new ImageSource(null, 0);
163-
}
161+
}
162+
catch (Exception e)
163+
{
164+
return new ImageSource(null, 0);
164165
}
165166
}
166167
}

0 commit comments

Comments
 (0)