Merge pull request #1694 from wabbajack-tools/optimize-gallery

Further optimize the gallery
This commit is contained in:
Timothy Baldridge 2021-10-27 17:23:34 -06:00 committed by GitHub
commit 2f583ff40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -10,11 +10,7 @@
<Grid Width="540" Height="480" RowDefinitions="Auto, *, 40" ColumnDefinitions="*, Auto"> <Grid Width="540" Height="480" RowDefinitions="Auto, *, 40" ColumnDefinitions="*, Auto">
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0, 0, 0, 1"> <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0, 0, 0, 1">
<Grid ClipToBounds="True"> <Grid ClipToBounds="True">
<Viewbox Height="340" HorizontalAlignment="Center" VerticalAlignment="Center"
Stretch="UniformToFill">
<Image x:Name="ModListImage" /> <Image x:Name="ModListImage" />
</Viewbox>
<Label Margin="10, 242, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Top" <Label Margin="10, 242, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Top"
x:Name="VersionText" /> x:Name="VersionText" />
</Grid> </Grid>

View File

@ -167,7 +167,7 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel
public async Task LoadListImage() public async Task LoadListImage()
{ {
Image = await _imageCache.From(ImageUri); Image = await _imageCache.From(ImageUri, 540, 300);
} }
public async Task<ModListState> GetState() public async Task<ModListState> GetState()

View File

@ -28,16 +28,18 @@ public class ImageCache
_limiter = limiter; _limiter = limiter;
} }
public async Task<IBitmap> From(Uri uri) public async Task<IBitmap> From(Uri uri, int width, int height)
{ {
var hash = (await Encoding.UTF8.GetBytes(uri.ToString()).Hash()).ToHex(); var hash = (await Encoding.UTF8.GetBytes(uri.ToString()).Hash()).ToHex();
var file = _configuration.ImageCacheLocation.Combine(hash); var file = _configuration.ImageCacheLocation.Combine(hash + $"_{width}_{height}");
if (!file.FileExists()) if (!file.FileExists())
{ {
using var job = await _limiter.Begin("Loading Image", 0, CancellationToken.None); using var job = await _limiter.Begin("Loading Image", 0, CancellationToken.None);
var wdata = await _client.GetByteArrayAsync(uri); var wdata = await _client.GetByteArrayAsync(uri);
await file.WriteAllBytesAsync(wdata); var resized = SKBitmap.Decode(wdata).Resize(new SKSizeI(width, height), SKFilterQuality.High);
return new Bitmap(new MemoryStream(wdata)); await file.WriteAllBytesAsync(resized.Encode(SKEncodedImageFormat.Webp, 90).ToArray());
} }
var data = await file.ReadAllBytesAsync(); var data = await file.ReadAllBytesAsync();

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">  <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework> <TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework>
@ -50,7 +50,7 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)libcef.dll')"> <Target Name="AferBuild" AfterTargets="Build" Condition="!Exists('$(ProjectDir)$(OutDir)swiftshader')">
<Message Text="Downloading Cef" /> <Message Text="Downloading Cef" />
<Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" /> <Exec Command="dotnet run --project $(ProjectDir)../Wabbajack.CLI/Wabbajack.CLI.csproj -- download-cef -f $(ProjectDir)$(OutDir)" />
</Target> </Target>