Skip to content

Commit

Permalink
[PixImage] Simplify preferred extension dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jun 19, 2024
1 parent f651a0e commit bb6bfd8
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ public PixImage(Col.Format format)

#region Static Tables and Methods

protected static Dictionary<string, PixFileFormat> s_formatOfExtension =
new Dictionary<string, PixFileFormat>()
private static readonly Dictionary<string, PixFileFormat> s_formatOfExtension = new()
{
{ ".tga", PixFileFormat.Targa },
{ ".png", PixFileFormat.Png },
Expand All @@ -335,19 +334,12 @@ public PixImage(Col.Format format)
{ ".exr", PixFileFormat.Exr },
};

protected static Lazy<Dictionary<PixFileFormat, string>> s_preferredExtensionOfFormat =
new Lazy<Dictionary<PixFileFormat, string>>(() =>
private static readonly Lazy<Dictionary<PixFileFormat, string>> s_preferredExtensionOfFormat = new(() =>
{
var result = new Dictionary<PixFileFormat, string>();
foreach (var pext in from kvp in s_formatOfExtension
group kvp by kvp.Value into g
select new
{
g.Key,
Value = g.OrderBy(x => x.Key.Length).Select(x => x.Key).First()
})
foreach (var kvp in s_formatOfExtension)
{
result[pext.Key] = pext.Value;
result[kvp.Value] = kvp.Key;
}
return result;
},
Expand Down

0 comments on commit bb6bfd8

Please sign in to comment.