mirror of
https://github.com/4sval/FModel.git
synced 2026-04-25 07:21:54 -05:00
upscale linear images
This commit is contained in:
parent
bfe648f06c
commit
8349d2bb93
|
|
@ -19,6 +19,7 @@ using CUE4Parse.UE4.Assets.Exports.Sound;
|
||||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||||
using CUE4Parse.UE4.Assets.Exports.Wwise;
|
using CUE4Parse.UE4.Assets.Exports.Wwise;
|
||||||
using CUE4Parse.UE4.Localization;
|
using CUE4Parse.UE4.Localization;
|
||||||
|
using CUE4Parse.UE4.Objects.UObject;
|
||||||
using CUE4Parse.UE4.Oodle.Objects;
|
using CUE4Parse.UE4.Oodle.Objects;
|
||||||
using CUE4Parse.UE4.Wwise;
|
using CUE4Parse.UE4.Wwise;
|
||||||
using CUE4Parse_Conversion.Materials;
|
using CUE4Parse_Conversion.Materials;
|
||||||
|
|
@ -538,7 +539,8 @@ namespace FModel.ViewModels
|
||||||
{
|
{
|
||||||
case UTexture2D texture:
|
case UTexture2D texture:
|
||||||
{
|
{
|
||||||
SetImage(texture.Decode());
|
var filter = texture.GetOrDefault<FName>("Filter");
|
||||||
|
SetImage(texture.Decode(), filter.IsNone ? null : filter.Text);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case UAkMediaAssetData:
|
case UAkMediaAssetData:
|
||||||
|
|
@ -587,17 +589,43 @@ namespace FModel.ViewModels
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetImage(SKImage img)
|
private void SetImage(SKImage img, string filter = null)
|
||||||
{
|
{
|
||||||
using var stream = img.Encode().AsStream();
|
const int UPSCALE_SIZE = 512;
|
||||||
var image = new BitmapImage();
|
SKData data;
|
||||||
image.BeginInit();
|
|
||||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
if (filter != null && img.Width < UPSCALE_SIZE && img.Height < UPSCALE_SIZE && filter.EndsWith("TF_Nearest", StringComparison.Ordinal))
|
||||||
image.StreamSource = stream;
|
{
|
||||||
image.EndInit();
|
var width = img.Width;
|
||||||
image.Freeze();
|
var heigth = img.Height;
|
||||||
|
|
||||||
|
while (width < UPSCALE_SIZE || heigth < UPSCALE_SIZE)
|
||||||
|
{
|
||||||
|
width *= 2;
|
||||||
|
heigth *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var bitmap = SKBitmap.FromImage(img);
|
||||||
|
using var resized = bitmap.Resize(new SKImageInfo(width, heigth), SKFilterQuality.None);
|
||||||
|
data = resized.Encode(SKEncodedImageFormat.Png, 100); // maybe dispose 'img' at this point?
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = img.Encode(SKEncodedImageFormat.Png, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (data)
|
||||||
|
{
|
||||||
|
using var stream = data.AsStream(false);
|
||||||
|
var image = new BitmapImage();
|
||||||
|
image.BeginInit();
|
||||||
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
image.StreamSource = stream;
|
||||||
|
image.EndInit();
|
||||||
|
image.Freeze();
|
||||||
|
TabControl.SelectedTab.Image = image;
|
||||||
|
}
|
||||||
|
|
||||||
TabControl.SelectedTab.Image = image;
|
|
||||||
if (UserSettings.Default.IsAutoSaveTextures)
|
if (UserSettings.Default.IsAutoSaveTextures)
|
||||||
TabControl.SelectedTab.SaveImage(true);
|
TabControl.SelectedTab.SaveImage(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user