Skip to content

Commit

Permalink
Revert "Work around for mono/SkiaSharp#2645"
Browse files Browse the repository at this point in the history
This reverts commit d5956ad.
  • Loading branch information
davidxuang committed Jul 13, 2024
1 parent 752e509 commit 8131b62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
11 changes: 0 additions & 11 deletions MusicDecrypto.Avalonia/Helpers/MathHelper.cs

This file was deleted.

26 changes: 3 additions & 23 deletions MusicDecrypto.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using ByteSizeLib;
using MusicDecrypto.Avalonia.Helpers;
using MusicDecrypto.Library;

namespace MusicDecrypto.Avalonia.ViewModels;
Expand All @@ -21,8 +20,7 @@ public partial class MainViewModel : ViewModelBase
private static partial Regex NameRegex();
private static readonly Regex _regex = NameRegex();

private const int _imageWidth = 72;
private readonly int _imageSize;
private readonly double _scaling = 0;

public ObservableCollection<Item> Items { get; private set; } = [];

Expand All @@ -32,7 +30,7 @@ public MainViewModel() : this(1) { }

public MainViewModel(double scaling)
{
_imageSize = (int)MathHelper.RoundToEven(_imageWidth * 2 * scaling);
_scaling = scaling;
Items.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(IsEmpty));
}

Expand All @@ -44,10 +42,6 @@ public void AddFile(IStorageFile file)
Items.Add(item);
Task.Run(async () => await DecryptFileAsync(item));
}
else
{
file.Dispose();
}
}

public async ValueTask DecryptFileAsync(Item item)
Expand Down Expand Up @@ -87,21 +81,7 @@ public async ValueTask DecryptFileAsync(Item item)
if (info.Cover != null)
{
using var stream = new MemoryStream(info.Cover);
// https://github.com/mono/SkiaSharp/issues/2645
// item.Cover = Bitmap.DecodeToWidth(stream, (int)(72 * 2 * _scaling));
var bm = new Bitmap(stream);
var size = Math.Max(bm.Size.Width, bm.Size.Height);
if (size > _imageSize)
{
item.Cover = bm.Size.Width > bm.Size.Height
? bm.CreateScaledBitmap(new(_imageSize, (int)Math.Round(_imageSize * bm.Size.Height / bm.Size.Width)))
: bm.CreateScaledBitmap(new((int)Math.Round(_imageSize * bm.Size.Width / bm.Size.Height), _imageSize));
bm.Dispose();
}
else
{
item.Cover = bm;
}
item.Cover = Bitmap.DecodeToWidth(stream, (int)(72 * 2 * _scaling));
}

await using (var file = await newFile!.OpenWriteAsync())
Expand Down

0 comments on commit 8131b62

Please sign in to comment.