mirror of
https://github.com/stuff-by-3-random-dudes/UWUVCI-AIO-WPF
synced 2025-02-18 03:28:23 +00:00
Grabbed the images first, and edited them before passing them BitMapImage
In a try/catch, downloaded the images and put them into an Images type. Then I push that over to graphics, and redraw everything.
This commit is contained in:
parent
ef12988957
commit
f7330e1e2f
4 changed files with 173 additions and 42 deletions
|
@ -2758,29 +2758,16 @@ namespace UWUVCI_AIO_WPF
|
||||||
}
|
}
|
||||||
public void getBootIMGSNES(string rom)
|
public void getBootIMGSNES(string rom)
|
||||||
{
|
{
|
||||||
string linkbase = "https://raw.githubusercontent.com/Flumpster/UWUVCI-Images/master/";
|
|
||||||
string repoid = "";
|
|
||||||
string SystemType = "snes/";
|
string SystemType = "snes/";
|
||||||
IMG_Message img = null;
|
var repoid = GetFakeSNESProdcode(rom);
|
||||||
repoid = GetFakeSNESProdcode(rom);
|
List<string> repoids = new List<string>
|
||||||
string[] ext = { "png", "tga", "jpg", "jpeg" };
|
{
|
||||||
List<string> repoids = new List<string>();
|
SystemType + repoid
|
||||||
|
};
|
||||||
|
|
||||||
if (CheckForInternetConnectionWOWarning())
|
if (CheckForInternetConnectionWOWarning())
|
||||||
{
|
{
|
||||||
repoids.Add(SystemType + repoid);
|
GetRepoImages(SystemType, repoids, repoid);
|
||||||
foreach (var e in ext)
|
|
||||||
{
|
|
||||||
if (RemoteFileExists(linkbase + SystemType + repoid + $"/iconTex.{e}") == true)
|
|
||||||
{
|
|
||||||
img = new IMG_Message(linkbase + SystemType + repoid + $"/iconTex.{e}", linkbase + SystemType + repoid + $"/bootTvTex.{e}", SystemType + repoid);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
img.Owner = mw;
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
img.ShowDialog(); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkForAdditionalFiles(GameConsoles.SNES, repoids);
|
checkForAdditionalFiles(GameConsoles.SNES, repoids);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3212,7 +3199,7 @@ namespace UWUVCI_AIO_WPF
|
||||||
fs.Close();
|
fs.Close();
|
||||||
Console.WriteLine("prodcode after scramble: "+repoid);
|
Console.WriteLine("prodcode after scramble: "+repoid);
|
||||||
}
|
}
|
||||||
string[] ext = { "png", "tga", "jpg", "jpeg" };
|
string[] ext = {"png", "tga", "jpg", "jpeg" };
|
||||||
if (CheckForInternetConnectionWOWarning())
|
if (CheckForInternetConnectionWOWarning())
|
||||||
{
|
{
|
||||||
repoids.Add(SystemType + repoid);
|
repoids.Add(SystemType + repoid);
|
||||||
|
@ -3833,5 +3820,32 @@ namespace UWUVCI_AIO_WPF
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Was supposed to replace all of the code that reaches out to UWUVCI-Images, but I don't wanna have to test everything since this is already as Italian as code comes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="SystemType"></param>
|
||||||
|
/// <param name="repoids"></param>
|
||||||
|
/// <param name="repoid"></param>
|
||||||
|
private void GetRepoImages(string SystemType, List<string> repoids, string repoid)
|
||||||
|
{
|
||||||
|
string linkbase = "https://raw.githubusercontent.com/Flumpster/UWUVCI-Images/master/";
|
||||||
|
IMG_Message img = null;
|
||||||
|
string[] ext = { "png", "tga", "jpg", "jpeg" };
|
||||||
|
|
||||||
|
foreach (var e in ext)
|
||||||
|
{
|
||||||
|
if (RemoteFileExists(linkbase + SystemType + repoid + $"/iconTex.{e}") == true)
|
||||||
|
{
|
||||||
|
img = new IMG_Message(linkbase + SystemType + repoid + $"/iconTex.{e}", linkbase + SystemType + repoid + $"/bootTvTex.{e}", SystemType + repoid);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
img.Owner = mw;
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
img.ShowDialog(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
using GameBaseClassLibrary;
|
using GameBaseClassLibrary;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
|
||||||
using UWUVCI_AIO_WPF.Classes;
|
|
||||||
using UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations;
|
using UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations;
|
||||||
using Path = System.IO.Path;
|
using Path = System.IO.Path;
|
||||||
|
using Rectangle = System.Drawing.Rectangle;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using PixelFormat = System.Windows.Media.PixelFormat;
|
||||||
|
using Pfim;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using Image = System.Windows.Controls.Image;
|
||||||
|
|
||||||
namespace UWUVCI_AIO_WPF.UI.Windows
|
namespace UWUVCI_AIO_WPF.UI.Windows
|
||||||
{
|
{
|
||||||
|
@ -30,6 +27,7 @@ namespace UWUVCI_AIO_WPF.UI.Windows
|
||||||
string repoid = "";
|
string repoid = "";
|
||||||
string icback = "";
|
string icback = "";
|
||||||
string tvback = "";
|
string tvback = "";
|
||||||
|
private static List<GCHandle> handles = new List<GCHandle>();
|
||||||
public IMG_Message(string icon, string tv, string repoid)
|
public IMG_Message(string icon, string tv, string repoid)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -65,20 +63,135 @@ namespace UWUVCI_AIO_WPF.UI.Windows
|
||||||
tvl.Visibility = Visibility.Hidden;
|
tvl.Visibility = Visibility.Hidden;
|
||||||
tgtv.Visibility = Visibility.Visible;
|
tgtv.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
BitmapImage bitmap = new BitmapImage();
|
|
||||||
bitmap.BeginInit();
|
|
||||||
bitmap.UriSource = new Uri(icon, UriKind.Absolute);
|
|
||||||
bitmap.EndInit();
|
|
||||||
|
|
||||||
this.icon.Source = bitmap;
|
|
||||||
|
|
||||||
BitmapImage bmp2 = new BitmapImage();
|
this.icon.Source = GetRepoImages(icon);
|
||||||
bmp2.BeginInit();
|
this.tv.Source = GetRepoImages(tv);
|
||||||
bmp2.UriSource = new Uri(tv, UriKind.Absolute);
|
|
||||||
bmp2.EndInit();
|
|
||||||
this.tv.Source = bmp2;
|
|
||||||
this.repoid = repoid;
|
this.repoid = repoid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BitmapImage GetRepoImages(string imageURL)
|
||||||
|
{
|
||||||
|
BitmapImage bitmap = new BitmapImage();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(imageURL, UriKind.Absolute));
|
||||||
|
webRequest.AllowWriteStreamBuffering = true;
|
||||||
|
webRequest.Timeout = 30000;
|
||||||
|
|
||||||
|
var webReponse = webRequest.GetResponse();
|
||||||
|
var stream = webReponse.GetResponseStream();
|
||||||
|
|
||||||
|
if (!imageURL.EndsWith(".tga"))
|
||||||
|
{
|
||||||
|
var image = System.Drawing.Image.FromStream(stream);
|
||||||
|
|
||||||
|
using (var graphics = Graphics.FromImage(image))
|
||||||
|
{
|
||||||
|
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||||
|
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||||
|
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||||
|
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
|
||||||
|
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var memory = new MemoryStream())
|
||||||
|
{
|
||||||
|
image.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
|
memory.Position = 0;
|
||||||
|
|
||||||
|
bitmap.BeginInit();
|
||||||
|
bitmap.StreamSource = memory;
|
||||||
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmap.EndInit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var image = Pfim.Pfim.FromStream(stream);
|
||||||
|
foreach (var im in WpfImage(image))
|
||||||
|
{
|
||||||
|
var encoder = new PngBitmapEncoder();
|
||||||
|
using (var memory = new MemoryStream())
|
||||||
|
{
|
||||||
|
BitmapSource bitmapSource = (BitmapSource)im.Source;
|
||||||
|
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
|
||||||
|
encoder.Save(memory);
|
||||||
|
memory.Position = 0;
|
||||||
|
|
||||||
|
bitmap.BeginInit();
|
||||||
|
bitmap.StreamSource = memory;
|
||||||
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmap.EndInit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//something broke, so yolo we go with the old method!
|
||||||
|
bitmap.BeginInit();
|
||||||
|
bitmap.UriSource = new Uri(imageURL, UriKind.Absolute);
|
||||||
|
bitmap.EndInit();
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PixelFormat PixelFormat(IImage image)
|
||||||
|
{
|
||||||
|
switch (image.Format)
|
||||||
|
{
|
||||||
|
case ImageFormat.Rgb24:
|
||||||
|
return PixelFormats.Bgr24;
|
||||||
|
case ImageFormat.Rgba32:
|
||||||
|
return PixelFormats.Bgra32;
|
||||||
|
case ImageFormat.Rgb8:
|
||||||
|
return PixelFormats.Gray8;
|
||||||
|
case ImageFormat.R5g5b5a1:
|
||||||
|
case ImageFormat.R5g5b5:
|
||||||
|
return PixelFormats.Bgr555;
|
||||||
|
case ImageFormat.R5g6b5:
|
||||||
|
return PixelFormats.Bgr565;
|
||||||
|
default:
|
||||||
|
throw new Exception($"Unable to convert {image.Format} to WPF PixelFormat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<Image> WpfImage(IImage image)
|
||||||
|
{
|
||||||
|
var pinnedArray = GCHandle.Alloc(image.Data, GCHandleType.Pinned);
|
||||||
|
var addr = pinnedArray.AddrOfPinnedObject();
|
||||||
|
var bsource = BitmapSource.Create(image.Width, image.Height, 96.0, 96.0,
|
||||||
|
PixelFormat(image), null, addr, image.DataLen, image.Stride);
|
||||||
|
|
||||||
|
handles.Add(pinnedArray);
|
||||||
|
yield return new Image
|
||||||
|
{
|
||||||
|
Source = bsource,
|
||||||
|
Width = image.Width,
|
||||||
|
Height = image.Height,
|
||||||
|
MaxHeight = image.Height,
|
||||||
|
MaxWidth = image.Width,
|
||||||
|
Margin = new Thickness(4),
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var mip in image.MipMaps)
|
||||||
|
{
|
||||||
|
var mipAddr = addr + mip.DataOffset;
|
||||||
|
var mipSource = BitmapSource.Create(mip.Width, mip.Height, 96.0, 96.0,
|
||||||
|
PixelFormat(image), null, mipAddr, mip.DataLen, mip.Stride);
|
||||||
|
yield return new Image
|
||||||
|
{
|
||||||
|
Source = mipSource,
|
||||||
|
Width = mip.Width,
|
||||||
|
Height = mip.Height,
|
||||||
|
MaxHeight = mip.Height,
|
||||||
|
MaxWidth = mip.Width,
|
||||||
|
Margin = new Thickness(4)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
|
|
|
@ -106,6 +106,9 @@
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Pfim, Version=0.10.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Pfim.0.10.3\lib\netstandard2.0\Pfim.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
|
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<package id="McMaster.Extensions.CommandLineUtils" version="2.4.2" targetFramework="net48" />
|
<package id="McMaster.Extensions.CommandLineUtils" version="2.4.2" targetFramework="net48" />
|
||||||
<package id="NAudio" version="1.10.0" targetFramework="net46" />
|
<package id="NAudio" version="1.10.0" targetFramework="net46" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
|
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
|
||||||
|
<package id="Pfim" version="0.10.3" targetFramework="net472" />
|
||||||
<package id="SharpZipLib" version="1.2.0" targetFramework="net48" />
|
<package id="SharpZipLib" version="1.2.0" targetFramework="net48" />
|
||||||
<package id="System.Buffers" version="4.5.0" targetFramework="net48" />
|
<package id="System.Buffers" version="4.5.0" targetFramework="net48" />
|
||||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net48" />
|
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net48" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue