done new image viewer

This commit is contained in:
Paddy Xu
2018-08-28 22:48:10 +03:00
parent 3bcb48a43c
commit 9832b0f99e
12 changed files with 323 additions and 176 deletions

View File

@@ -17,35 +17,38 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using LibAPNG;
using QuickLook.Common.ExtensionMethods;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal class APNGAnimationProvider : AnimationProvider
internal class APngAnimationProvider : AnimationProvider
{
private readonly Frame _baseFrame;
private readonly List<FrameInfo> _frames;
private readonly List<BitmapSource> _renderedFrames;
private NETImageProvider _imageMagickProvider;
private int _lastEffecitvePreviousPreviousFrameIndex;
private int _lastEffectivePreviousPreviousFrameIndex;
private NativeImageProvider _nativeImageProvider;
public APNGAnimationProvider(string path) : base(path)
public APngAnimationProvider(string path, NConvert meta) : base(path, meta)
{
var decoder = new APNGBitmap(path);
if (decoder.IsSimplePNG)
if (!IsAnimatedPng(path))
{
_imageMagickProvider = new NETImageProvider(path);
_nativeImageProvider = new NativeImageProvider(path, meta);
Animator = _nativeImageProvider.Animator;
return;
}
var decoder = new APNGBitmap(path);
_baseFrame = decoder.DefaultImage;
_frames = new List<FrameInfo>(decoder.Frames.Length);
_renderedFrames = new List<BitmapSource>(decoder.Frames.Length);
Enumerable.Repeat(0, decoder.Frames.Length).ForEach(_ => _renderedFrames.Add(null));
@@ -67,13 +70,16 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
{
throw new NotImplementedException();
if (_nativeImageProvider != null)
return _nativeImageProvider.GetThumbnail(size, fullSize);
return new Task<BitmapSource>(() => _baseFrame.GetBitmapSource());
}
public override Task<BitmapSource> GetRenderedFrame(int index)
{
if (_imageMagickProvider != null)
return _imageMagickProvider.GetRenderedFrame(index);
if (_nativeImageProvider != null)
return _nativeImageProvider.GetRenderedFrame(index);
if (_renderedFrames[index] != null)
return new Task<BitmapSource>(() => _renderedFrames[index]);
@@ -89,10 +95,10 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
public override void Dispose()
{
if (_imageMagickProvider != null)
if (_nativeImageProvider != null)
{
_imageMagickProvider.Dispose();
_imageMagickProvider = null;
_nativeImageProvider.Dispose();
_nativeImageProvider = null;
return;
}
@@ -119,9 +125,9 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
// when saying APNGDisposeOpPrevious, we need to find the last frame not having APNGDisposeOpPrevious.
// Only [index-2] is not correct here since that frame may also have APNGDisposeOpPrevious.
if (index > 1)
previousPreviousRendered = _renderedFrames[_lastEffecitvePreviousPreviousFrameIndex];
previousPreviousRendered = _renderedFrames[_lastEffectivePreviousPreviousFrameIndex];
if (_frames[index].DisposeOp != DisposeOps.APNGDisposeOpPrevious)
_lastEffecitvePreviousPreviousFrameIndex = Math.Max(_lastEffecitvePreviousPreviousFrameIndex, index);
_lastEffectivePreviousPreviousFrameIndex = Math.Max(_lastEffectivePreviousPreviousFrameIndex, index);
var visual = new DrawingVisual();
@@ -169,6 +175,27 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
return bitmap;
}
private static bool IsAnimatedPng(string path)
{
using (var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
while (br.BaseStream.Length - br.BaseStream.Position >= 4)
{
var window = br.ReadBytes(4);
if (window[0] == 'I' && window[1] == 'D' && window[2] == 'A' && window[3] == 'T')
return false;
if (window[0] == 'a' && window[1] == 'c' && window[2] == 'T' && window[3] == 'L')
return true;
br.BaseStream.Position -= 3;
}
return false;
}
}
private class FrameInfo
{
public readonly BlendOps BlendOp;

View File

@@ -15,18 +15,14 @@
// 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 QuickLook.Common.Annotations;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Plugin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
@@ -38,9 +34,6 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
private AnimationProvider _animation;
private bool _disposing;
public event EventHandler ImageLoaded;
public event EventHandler DoZoomToFit;
public void Dispose()
{
_disposing = true;
@@ -52,12 +45,15 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
_animation = null;
}
private static AnimationProvider LoadFullImageCore(Uri path)
public event EventHandler ImageLoaded;
public event EventHandler DoZoomToFit;
private static AnimationProvider LoadFullImageCore(Uri path, NConvert meta)
{
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.LocalPath);
var provider = type.CreateInstance<AnimationProvider>(path.LocalPath, meta);
return provider;
}
@@ -66,7 +62,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
public static readonly DependencyProperty AnimationFrameIndexProperty =
DependencyProperty.Register("AnimationFrameIndex", typeof(int), typeof(AnimatedImage),
new UIPropertyMetadata(-2, AnimationFrameIndexChanged));
new UIPropertyMetadata(-1, AnimationFrameIndexChanged));
public static readonly DependencyProperty AnimationUriProperty =
DependencyProperty.Register("AnimationUri", typeof(Uri), typeof(AnimatedImage),
@@ -80,25 +76,25 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
public int AnimationFrameIndex
{
get => (int)GetValue(AnimationFrameIndexProperty);
get => (int) GetValue(AnimationFrameIndexProperty);
set => SetValue(AnimationFrameIndexProperty, value);
}
public Uri AnimationUri
{
get => (Uri)GetValue(AnimationUriProperty);
get => (Uri) GetValue(AnimationUriProperty);
set => SetValue(AnimationUriProperty, value);
}
public NConvert Meta
{
private get => (NConvert)GetValue(MetaProperty);
private get => (NConvert) GetValue(MetaProperty);
set => SetValue(MetaProperty, value);
}
public ContextObject ContextObject
{
private get => (ContextObject)GetValue(ContextObjectProperty);
private get => (ContextObject) GetValue(ContextObjectProperty);
set => SetValue(ContextObjectProperty, value);
}
@@ -110,10 +106,27 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
//var thumbnail = instance.Meta?.GetThumbnail(true);
//instance.Source = thumbnail;
instance._animation = LoadFullImageCore((Uri)ev.NewValue);
instance._animation = LoadFullImageCore((Uri) ev.NewValue, instance.Meta);
ShowThumbnailAndStartAnimation(instance);
}
instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation.Animator);
instance.AnimationFrameIndex = -1;
private static void ShowThumbnailAndStartAnimation(AnimatedImage instance)
{
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize, instance.Meta.GetSize());
if (task == null) return;
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
if (instance._disposing)
return;
instance.Source = _.Result;
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());
instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation?.Animator);
}));
task.Start();
}
private static void AnimationFrameIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs ev)
@@ -124,32 +137,14 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
if (instance._disposing)
return;
var task = instance._animation.GetRenderedFrame((int) ev.NewValue);
if ((int)ev.NewValue == -1) // get thumbnail
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize, instance.Meta.GetSize());
if (task != null)
{
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
instance.Source = _.Result;
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());
}));
task.Start();
}
}
else // begin to loop in the animator
{
var task = instance._animation.GetRenderedFrame((int)ev.NewValue);
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
if (!instance._disposing)
instance.Source = _.Result;
}));
task.Start();
}
}));
task.Start();
}
#endregion DependencyProperty

View File

@@ -20,19 +20,21 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal abstract class AnimationProvider : IDisposable
{
protected AnimationProvider(string path)
protected AnimationProvider(string path, NConvert meta)
{
Path = path;
Meta = meta;
}
public string Path { get; }
public NConvert Meta { get; }
public Int32AnimationUsingKeyFrames Animator { get; protected set; }
public abstract void Dispose();

View File

@@ -18,11 +18,10 @@
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using QuickLook.Common.ExtensionMethods;
using Size = System.Windows.Size;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
@@ -32,11 +31,11 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
private BitmapSource _frame;
private bool _isPlaying;
public GifAnimationProvider(string path) : base(path)
public GifAnimationProvider(string path, NConvert meta) : base(path, meta)
{
_fileHandle = (Bitmap)Image.FromFile(path);
_fileHandle = (Bitmap) Image.FromFile(path);
Animator = new Int32AnimationUsingKeyFrames { RepeatBehavior = RepeatBehavior.Forever };
Animator = new Int32AnimationUsingKeyFrames {RepeatBehavior = RepeatBehavior.Forever};
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(10))));
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(2, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(20))));
@@ -54,11 +53,12 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
_frame = null;
}
public override Task<BitmapSource> GetThumbnail(System.Windows.Size size, System.Windows.Size fullSize)
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
{
return new Task<BitmapSource>(() =>
{
return _fileHandle.ToBitmapSource();
_frame = _fileHandle.ToBitmapSource();
return _frame;
});
}
@@ -82,4 +82,4 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
_frame = _fileHandle.ToBitmapSource();
}
}
}
}

View File

@@ -1,76 +0,0 @@
// Copyright © 2018 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal class NETImageProvider : AnimationProvider
{
public NETImageProvider(string path) : base(path)
{
Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.Zero)));
}
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
{
var factor = Math.Min(size.Width / 2 / fullSize.Width, size.Height / 2 / fullSize.Height);
var decode_width = fullSize.Width * factor;
return new Task<BitmapSource>(() =>
{
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(Path);
img.CacheOption = BitmapCacheOption.OnLoad;
img.DecodePixelWidth = (int)Math.Floor(decode_width);
img.EndInit();
var scaled = new TransformedBitmap(img, new ScaleTransform(1d / factor, 1d / factor));
scaled.Freeze();
return scaled;
});
}
public override Task<BitmapSource> GetRenderedFrame(int index)
{
return new Task<BitmapSource>(() =>
{
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(Path);
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
img.Freeze();
return img;
});
}
public override void Dispose()
{
}
}
}

View File

@@ -0,0 +1,95 @@
// Copyright © 2018 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using QuickLook.Common.Helpers;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal class NConvertImageProvider : AnimationProvider
{
public NConvertImageProvider(string path, NConvert meta) : base(path, meta)
{
Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.Zero)));
}
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
{
return new Task<BitmapSource>(() =>
{
try
{
using (var ms = Meta.GetTiffStream(true))
{
var img = new BitmapImage();
img.BeginInit();
img.StreamSource = ms;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
var scaled = new TransformedBitmap(img,
new ScaleTransform(fullSize.Width / img.PixelWidth, fullSize.Height / img.PixelHeight));
scaled.Freeze();
return scaled;
}
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
});
}
public override Task<BitmapSource> GetRenderedFrame(int index)
{
return new Task<BitmapSource>(() =>
{
try
{
using (var ms = Meta.GetTiffStream(false))
{
var img = new BitmapImage();
img.BeginInit();
img.StreamSource = ms;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
img.Freeze();
return img;
}
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
});
}
public override void Dispose()
{
}
}
}

View File

@@ -0,0 +1,96 @@
// Copyright © 2018 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using QuickLook.Common.Helpers;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal class NativeImageProvider : AnimationProvider
{
public NativeImageProvider(string path, NConvert meta) : base(path, meta)
{
Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.Zero)));
}
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
{
var decodeWidth = Math.Round(fullSize.Width *
Math.Min(size.Width / 2 / fullSize.Width, size.Height / 2 / fullSize.Height));
var scale = fullSize.Width / decodeWidth;
var decodeHeight = Math.Round(fullSize.Height / scale);
return new Task<BitmapSource>(() =>
{
try
{
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(Path);
img.CacheOption = BitmapCacheOption.OnLoad;
img.DecodePixelWidth = (int) decodeWidth;
img.DecodePixelHeight =
(int) decodeHeight; // specific size to avoid .net's double to int conversion
img.EndInit();
var scaled = new TransformedBitmap(img, new ScaleTransform(scale, scale));
scaled.Freeze();
return scaled;
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
});
}
public override Task<BitmapSource> GetRenderedFrame(int index)
{
return new Task<BitmapSource>(() =>
{
try
{
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(Path);
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
img.Freeze();
return img;
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
});
}
public override void Dispose()
{
}
}
}

View File

@@ -31,7 +31,6 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using QuickLook.Common.Annotations;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
@@ -42,17 +41,16 @@ namespace QuickLook.Plugin.ImageViewer
/// </summary>
public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposable
{
private ContextObject _contextObject;
private Visibility _backgroundVisibility = Visibility.Visible;
private ContextObject _contextObject;
private Point? _dragInitPos;
private Uri _imageSource;
private bool _isZoomFactorFirstSet = true;
private DateTime _lastZoomTime = DateTime.MinValue;
private double _maxZoomFactor = 3d;
private double _maxZoomFactor;
private NConvert _meta;
private Visibility _metaIconVisibility = Visibility.Visible;
private double _minZoomFactor = 0.1d;
private double _minZoomFactor;
private BitmapScalingMode _renderMode = BitmapScalingMode.HighQuality;
private bool _showZoomLevelInfo = true;
private BitmapSource _source;
@@ -92,6 +90,10 @@ namespace QuickLook.Plugin.ImageViewer
ContextObject = context;
Meta = meta;
var s = meta.GetSize();
_minZoomFactor = Math.Min(200d / s.Height, 400d / s.Width);
_maxZoomFactor = Math.Min(9000d / s.Height, 9000d / s.Width);
ShowMeta();
Theme = ContextObject.Theme;
}
@@ -202,7 +204,7 @@ namespace QuickLook.Plugin.ImageViewer
}
if (ShowZoomLevelInfo)
((Storyboard)zoomLevelInfo.FindResource("StoryboardShowZoomLevelInfo")).Begin();
((Storyboard) zoomLevelInfo.FindResource("StoryboardShowZoomLevelInfo")).Begin();
}
}
@@ -263,7 +265,7 @@ namespace QuickLook.Plugin.ImageViewer
{
Theme = Theme == Themes.Dark ? Themes.Light : Themes.Dark;
SettingHelper.Set("LastTheme", (int)Theme);
SettingHelper.Set("LastTheme", (int) Theme);
}
private void ShowMeta()
@@ -274,11 +276,12 @@ namespace QuickLook.Plugin.ImageViewer
if (string.IsNullOrWhiteSpace(m.Item1) || string.IsNullOrWhiteSpace(m.Item2))
return;
if (m.Item1 == "File name" || m.Item1 == "File size" || m.Item1 == "MIME type" || m.Item1 == "Exif comment"
if (m.Item1 == "File name" || m.Item1 == "File size" || m.Item1 == "MIME type" ||
m.Item1 == "Exif comment"
|| m.Item1 == "Thumbnail" || m.Item1 == "Exif comment")
return;
textMeta.Inlines.Add(new Run(m.Item1) { FontWeight = FontWeights.SemiBold });
textMeta.Inlines.Add(new Run(m.Item1) {FontWeight = FontWeights.SemiBold});
textMeta.Inlines.Add(": ");
textMeta.Inlines.Add(m.Item2);
textMeta.Inlines.Add("\r\n");
@@ -459,7 +462,7 @@ namespace QuickLook.Plugin.ImageViewer
viewPanel.InvalidateMeasure();
// critical for calcuating offset
// critical for calculating offset
viewPanel.ScrollToHorizontalOffset(0);
viewPanel.ScrollToVerticalOffset(0);
UpdateLayout();

View File

@@ -19,9 +19,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
namespace QuickLook.Plugin.ImageViewer
@@ -43,9 +41,9 @@ namespace QuickLook.Plugin.ImageViewer
{
private static readonly string NConvertPath =
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NConvert\\nconvert.exe");
private readonly List<Tuple<string, string>> _metaBasic = new List<Tuple<string, string>>();
private readonly List<Tuple<string, string>> _metaExif = new List<Tuple<string, string>>();
private readonly string _path;
private List<Tuple<string, string>> _metaBasic = new List<Tuple<string, string>>();
private List<Tuple<string, string>> _metaExif = new List<Tuple<string, string>>();
public NConvert(string path)
{
@@ -59,13 +57,16 @@ namespace QuickLook.Plugin.ImageViewer
return _metaExif;
}
public MemoryStream GetPngStream(bool thumbnail)
public MemoryStream GetTiffStream(bool thumbnail)
{
var temp = Path.GetTempFileName();
File.Delete(temp);
var sony = Path.GetExtension(_path)?.ToLower() == ".arw" ? "-autolevels" : "";
var thumb = thumbnail ? "-embedded_jpeg" : "";
var d = RunInternal($"-quiet {thumb} -out tiff -o \"{temp}\" \"{_path}\"", 10000);
var d = RunInternal(
$"-quiet {thumb} {sony} -raw_camerabalance -raw_autobright -icc -out tiff -o \"{temp}\" \"{_path}\"",
10000);
var ms = new MemoryStream(File.ReadAllBytes(temp));
@@ -99,10 +100,7 @@ namespace QuickLook.Plugin.ImageViewer
public Orientation GetOrientation()
{
var o = _metaExif.Find(t => t.Item1 == "Orientation")?.Item2;
if (!string.IsNullOrEmpty(o))
{
return (Orientation) int.Parse(o.Substring(o.Length - 2, 1));
}
if (!string.IsNullOrEmpty(o)) return (Orientation) int.Parse(o.Substring(o.Length - 2, 1));
return Orientation.TopLeft;
}
@@ -184,13 +182,10 @@ namespace QuickLook.Plugin.ImageViewer
{
var buffer = new byte[8192];
int count;
while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, count);
}
while ((count = stream.Read(buffer, 0, buffer.Length)) > 0) ms.Write(buffer, 0, count);
return ms.ToArray();
}
}
}
}
}

View File

@@ -16,10 +16,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Collections.Generic;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using QuickLook.Plugin.ImageViewer.AnimatedImage;
@@ -47,9 +47,18 @@ namespace QuickLook.Plugin.ImageViewer
public void Init()
{
AnimatedImage.AnimatedImage.Providers.Add(new KeyValuePair<string[], Type>(new[] { ".apng", ".png" }, typeof(APNGAnimationProvider)));
AnimatedImage.AnimatedImage.Providers.Add(new KeyValuePair<string[], Type>(new[] { ".gif" }, typeof(GifAnimationProvider)));
AnimatedImage.AnimatedImage.Providers.Add(new KeyValuePair<string[], Type>(new[] { "*" }, typeof(NETImageProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".apng", ".png"},
typeof(APngAnimationProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".gif"},
typeof(GifAnimationProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".bmp", ".jpg", ".jpeg", ".tif", ".tiff"},
typeof(NativeImageProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {"*"},
typeof(NConvertImageProvider)));
}
public bool CanHandle(string path)

View File

@@ -75,10 +75,11 @@
<Link>Properties\GitVersion.cs</Link>
</Compile>
<Compile Include="AnimatedImage\AnimatedImage.cs" />
<Compile Include="AnimatedImage\APNGAnimationProvider.cs" />
<Compile Include="AnimatedImage\APngAnimationProvider.cs" />
<Compile Include="AnimatedImage\GifAnimationProvider.cs" />
<Compile Include="AnimatedImage\AnimationProvider.cs" />
<Compile Include="AnimatedImage\ImageMagickProvider.cs" />
<Compile Include="AnimatedImage\NConvertImageProvider.cs" />
<Compile Include="AnimatedImage\NativeImageProvider.cs" />
<Compile Include="ImagePanel.xaml.cs">
<DependentUpon>ImagePanel.xaml</DependentUpon>
</Compile>