mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
Fix #825 properly
This commit is contained in:
@@ -50,10 +50,10 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
|
||||
private static AnimationProvider InitAnimationProvider(Uri path, MetaProvider meta)
|
||||
{
|
||||
var ext = Path.GetExtension(path.OriginalString).ToLower();
|
||||
var ext = Path.GetExtension(path.LocalPath).ToLower();
|
||||
var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value;
|
||||
|
||||
var provider = type.CreateInstance<AnimationProvider>(path.OriginalString, meta);
|
||||
var provider = type.CreateInstance<AnimationProvider>(path, meta);
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
@@ -25,13 +25,13 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
||||
{
|
||||
internal abstract class AnimationProvider : IDisposable
|
||||
{
|
||||
protected AnimationProvider(string path, MetaProvider meta)
|
||||
protected AnimationProvider(Uri path, MetaProvider meta)
|
||||
{
|
||||
Path = path;
|
||||
Meta = meta;
|
||||
}
|
||||
|
||||
public string Path { get; }
|
||||
public Uri Path { get; }
|
||||
|
||||
public MetaProvider Meta { get; }
|
||||
|
||||
|
@@ -37,16 +37,16 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
private int _lastEffectivePreviousPreviousFrameIndex;
|
||||
private NativeProvider _nativeImageProvider;
|
||||
|
||||
public APngProvider(string path, MetaProvider meta) : base(path, meta)
|
||||
public APngProvider(Uri path, MetaProvider meta) : base(path, meta)
|
||||
{
|
||||
if (!IsAnimatedPng(path))
|
||||
if (!IsAnimatedPng(path.LocalPath))
|
||||
{
|
||||
_nativeImageProvider = new NativeProvider(path, meta);
|
||||
Animator = _nativeImageProvider.Animator;
|
||||
return;
|
||||
}
|
||||
|
||||
var decoder = new APNGBitmap(path);
|
||||
var decoder = new APNGBitmap(path.LocalPath);
|
||||
|
||||
_baseFrame = decoder.DefaultImage;
|
||||
_frames = new List<FrameInfo>(decoder.Frames.Length);
|
||||
|
@@ -21,7 +21,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
{
|
||||
internal class DcrawProvider : NativeProvider
|
||||
{
|
||||
public DcrawProvider(string path, MetaProvider meta) : base(path, meta)
|
||||
public DcrawProvider(Uri path, MetaProvider meta) : base(path, meta)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@@ -33,15 +33,15 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
private bool _isPlaying;
|
||||
private NativeProvider _nativeProvider;
|
||||
|
||||
public GifProvider(string path, MetaProvider meta) : base(path, meta)
|
||||
public GifProvider(Uri path, MetaProvider meta) : base(path, meta)
|
||||
{
|
||||
if (!ImageAnimator.CanAnimate(Image.FromFile(path)))
|
||||
if (!ImageAnimator.CanAnimate(Image.FromFile(path.LocalPath)))
|
||||
{
|
||||
_nativeProvider = new NativeProvider(path, meta);
|
||||
return;
|
||||
}
|
||||
|
||||
_fileHandle = (Bitmap) Image.FromFile(path);
|
||||
_fileHandle = (Bitmap) Image.FromFile(path.LocalPath);
|
||||
|
||||
_fileHandle.SetResolution(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
|
||||
DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);
|
||||
|
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
{
|
||||
internal class ImageMagickProvider : AnimationProvider
|
||||
{
|
||||
public ImageMagickProvider(string path, MetaProvider meta) : base(path, meta)
|
||||
public ImageMagickProvider(Uri path, MetaProvider meta) : base(path, meta)
|
||||
{
|
||||
Animator = new Int32AnimationUsingKeyFrames();
|
||||
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
|
||||
@@ -90,7 +90,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
|
||||
try
|
||||
{
|
||||
using (var mi = new MagickImage(Path, settings))
|
||||
using (var mi = new MagickImage(Path.LocalPath, settings))
|
||||
{
|
||||
var profile = mi.GetColorProfile();
|
||||
if (mi.ColorSpace == ColorSpace.RGB || mi.ColorSpace == ColorSpace.sRGB ||
|
||||
|
@@ -27,7 +27,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
{
|
||||
internal class NativeProvider : AnimationProvider
|
||||
{
|
||||
public NativeProvider(string path, MetaProvider meta) : base(path, meta)
|
||||
public NativeProvider(Uri path, MetaProvider meta) : base(path, meta)
|
||||
{
|
||||
Animator = new Int32AnimationUsingKeyFrames();
|
||||
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
|
||||
@@ -55,7 +55,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
{
|
||||
var img = new BitmapImage();
|
||||
img.BeginInit();
|
||||
img.UriSource = new Uri(Path);
|
||||
img.UriSource = Path;
|
||||
img.CacheOption = BitmapCacheOption.OnLoad;
|
||||
// specific renderSize to avoid .net's double to int conversion
|
||||
img.DecodePixelWidth = rotate ? decodeHeight : decodeWidth;
|
||||
@@ -94,7 +94,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
|
||||
{
|
||||
var img = new BitmapImage();
|
||||
img.BeginInit();
|
||||
img.UriSource = new Uri(Path);
|
||||
img.UriSource = Path;
|
||||
img.CacheOption = BitmapCacheOption.OnLoad;
|
||||
img.DecodePixelWidth = (int) (rotate ? fullSize.Height : fullSize.Width);
|
||||
img.DecodePixelHeight = (int) (rotate ? fullSize.Width : fullSize.Height);
|
||||
|
@@ -15,7 +15,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Windows.Media.Imaging;
|
||||
using QuickLook.Common.Helpers;
|
||||
|
||||
@@ -37,5 +40,32 @@ namespace QuickLook.Plugin.ImageViewer
|
||||
dpiX?.SetValue(img, newDpiX);
|
||||
dpiY?.SetValue(img, newDpiY);
|
||||
}
|
||||
|
||||
public static Uri FilePathToFileUrl(string filePath)
|
||||
{
|
||||
var uri = new StringBuilder();
|
||||
foreach (var v in filePath)
|
||||
if (v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' || v >= '0' && v <= '9' ||
|
||||
v == '+' || v == '/' || v == ':' || v == '.' || v == '-' || v == '_' || v == '~' ||
|
||||
v > '\x80')
|
||||
uri.Append(v);
|
||||
else if (v == Path.DirectorySeparatorChar || v == Path.AltDirectorySeparatorChar)
|
||||
uri.Append('/');
|
||||
else
|
||||
uri.Append($"%{(int) v:X2}");
|
||||
if (uri.Length >= 2 && uri[0] == '/' && uri[1] == '/') // UNC path
|
||||
uri.Insert(0, "file:");
|
||||
else
|
||||
uri.Insert(0, "file:///");
|
||||
|
||||
try
|
||||
{
|
||||
return new Uri(uri.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -86,7 +86,7 @@ namespace QuickLook.Plugin.ImageViewer
|
||||
? $"{Path.GetFileName(path)}"
|
||||
: $"{size.Width}×{size.Height}: {Path.GetFileName(path)}";
|
||||
|
||||
_ip.ImageUriSource = new Uri(path);
|
||||
_ip.ImageUriSource = Helper.FilePathToFileUrl(path);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
|
Reference in New Issue
Block a user