Swirth to ImageMagick which supports PSD and RAW images

This commit is contained in:
Paddy Xu
2017-06-02 19:01:45 +03:00
parent 903c90472b
commit 96a46e3a23
6 changed files with 90 additions and 77 deletions

View File

@@ -1,10 +1,22 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
namespace QuickLook.Plugin.ImageViewer
{
public class Plugin : IViewer
{
private static readonly string[] _formats =
{
// camera raw
".3fr", ".ari", ".arw", ".bay", ".crw", ".cr2", ".cap", ".data", ".dcs", ".dcr", ".dng", ".drf", ".eip",
".erf", ".fff", ".gpr", ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm",
".orf", ".pef", ".ptx", ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw",
".tif", ".x3f",
// normal
".bmp", ".gif", ".ico", ".jpg", ".jpeg", ".png", ".psd", ".svg", ".wdp", ".tiff", ".tga"
};
private Size _imageSize;
private ImagePanel _ip;
@@ -13,47 +25,39 @@ namespace QuickLook.Plugin.ImageViewer
public bool CanHandle(string path)
{
// TODO: determine file type by content
if (Directory.Exists(path))
return false;
switch (Path.GetExtension(path).ToLower())
{
case ".bmp":
case ".gif":
case ".ico":
case ".jpg":
case ".jpeg":
case ".png":
case ".wdp":
case ".tiff":
return true;
default:
return false;
}
return _formats.Contains(Path.GetExtension(path).ToLower());
}
public void Prepare(string path, ContextObject context)
{
_imageSize = ImageFileHelper.GetImageSize(path);
// ImageMagick want to have dcraw.exe
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
context.SetPreferredSizeFit(_imageSize, 0.8);
_imageSize = ImageFileHelper.GetImageSize(path) ?? Size.Empty;
if (!_imageSize.IsEmpty)
context.SetPreferredSizeFit(_imageSize, 0.8);
else
context.PreferredSize = new Size(1024, 768);
}
public void View(string path, ContextObject context)
{
_ip = new ImagePanel(path);
context.ViewerContent = _ip;
context.Title = $"{Path.GetFileName(path)} ({_imageSize.Width}×{_imageSize.Height})";
context.Title = _imageSize.IsEmpty
? $"{Path.GetFileName(path)}"
: $"{Path.GetFileName(path)} ({_imageSize.Width}×{_imageSize.Height})";
context.IsBusy = false;
}
public void Cleanup()
{
Directory.SetCurrentDirectory(App.AppPath);
_ip = null;
}
}