Fix #329: respect monitor ICC

This commit is contained in:
Paddy
2022-02-13 15:01:32 +01:00
parent b39a58f1b9
commit 22c08f62fa
10 changed files with 40 additions and 18 deletions

View File

@@ -48,12 +48,12 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
public event EventHandler ImageLoaded; public event EventHandler ImageLoaded;
public event EventHandler DoZoomToFit; public event EventHandler DoZoomToFit;
private static AnimationProvider InitAnimationProvider(Uri path, MetaProvider meta) private static AnimationProvider InitAnimationProvider(Uri path, MetaProvider meta, ContextObject contextObject)
{ {
var ext = Path.GetExtension(path.LocalPath).ToLower(); var ext = Path.GetExtension(path.LocalPath).ToLower();
var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value; var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value;
var provider = type.CreateInstance<AnimationProvider>(path, meta); var provider = type.CreateInstance<AnimationProvider>(path, meta, contextObject);
return provider; return provider;
} }
@@ -106,7 +106,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
//var thumbnail = instance.Meta?.GetThumbnail(true); //var thumbnail = instance.Meta?.GetThumbnail(true);
//instance.Source = thumbnail; //instance.Source = thumbnail;
instance._animation = InitAnimationProvider((Uri) ev.NewValue, instance.Meta); instance._animation = InitAnimationProvider((Uri) ev.NewValue, instance.Meta, instance.ContextObject);
ShowThumbnailAndStartAnimation(instance); ShowThumbnailAndStartAnimation(instance);
} }

View File

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

View File

@@ -26,6 +26,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using LibAPNG; using LibAPNG;
using QuickLook.Common.ExtensionMethods; using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{ {
@@ -37,11 +38,11 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
private int _lastEffectivePreviousPreviousFrameIndex; private int _lastEffectivePreviousPreviousFrameIndex;
private NativeProvider _nativeImageProvider; private NativeProvider _nativeImageProvider;
public APngProvider(Uri path, MetaProvider meta) : base(path, meta) public APngProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{ {
if (!IsAnimatedPng(path.LocalPath)) if (!IsAnimatedPng(path.LocalPath))
{ {
_nativeImageProvider = new NativeProvider(path, meta); _nativeImageProvider = new NativeProvider(path, meta, contextObject);
Animator = _nativeImageProvider.Animator; Animator = _nativeImageProvider.Animator;
return; return;
} }

View File

@@ -16,12 +16,13 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System; using System;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{ {
internal class DcrawProvider : NativeProvider internal class DcrawProvider : NativeProvider
{ {
public DcrawProvider(Uri path, MetaProvider meta) : base(path, meta) public DcrawProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -22,6 +22,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using QuickLook.Common.ExtensionMethods; using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers; using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using Size = System.Windows.Size; using Size = System.Windows.Size;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
@@ -33,11 +34,11 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
private bool _isPlaying; private bool _isPlaying;
private NativeProvider _nativeProvider; private NativeProvider _nativeProvider;
public GifProvider(Uri path, MetaProvider meta) : base(path, meta) public GifProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{ {
if (!ImageAnimator.CanAnimate(Image.FromFile(path.LocalPath))) if (!ImageAnimator.CanAnimate(Image.FromFile(path.LocalPath)))
{ {
_nativeProvider = new NativeProvider(path, meta); _nativeProvider = new NativeProvider(path, meta, contextObject);
return; return;
} }

View File

@@ -25,12 +25,13 @@ using System.Windows.Media.Imaging;
using ImageMagick; using ImageMagick;
using ImageMagick.Formats; using ImageMagick.Formats;
using QuickLook.Common.Helpers; using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{ {
internal class ImageMagickProvider : AnimationProvider internal class ImageMagickProvider : AnimationProvider
{ {
public ImageMagickProvider(Uri path, MetaProvider meta) : base(path, meta) public ImageMagickProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{ {
Animator = new Int32AnimationUsingKeyFrames(); Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
@@ -93,11 +94,15 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{ {
using (var mi = new MagickImage(Path.LocalPath, settings)) using (var mi = new MagickImage(Path.LocalPath, settings))
{ {
var profile = mi.GetColorProfile(); if (SettingHelper.Get("UseColorProfile", false, "QuickLook.Plugin.ImageViewer"))
if (mi.ColorSpace == ColorSpace.RGB || mi.ColorSpace == ColorSpace.sRGB || {
mi.ColorSpace == ColorSpace.scRGB) if (mi.ColorSpace == ColorSpace.RGB || mi.ColorSpace == ColorSpace.sRGB || mi.ColorSpace == ColorSpace.scRGB)
if (profile?.Description != null && !profile.Description.Contains("sRGB")) {
mi.SetProfile(ColorProfile.SRGB); mi.SetProfile(ColorProfile.SRGB);
if (ContextObject.ColorProfileName != null)
mi.SetProfile(new ColorProfile(ContextObject.ColorProfileName)); // map to monitor color
}
}
mi.AutoOrient(); mi.AutoOrient();

View File

@@ -22,12 +22,13 @@ using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using QuickLook.Common.Helpers; using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{ {
internal class NativeProvider : AnimationProvider internal class NativeProvider : AnimationProvider
{ {
public NativeProvider(Uri path, MetaProvider meta) : base(path, meta) public NativeProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{ {
Animator = new Int32AnimationUsingKeyFrames(); Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,

View File

@@ -59,14 +59,18 @@ namespace QuickLook.Plugin.ImageViewer
public void Init() public void Init()
{ {
var useColorProfile = SettingHelper.Get("UseColorProfile", false, "QuickLook.Plugin.ImageViewer");
AnimatedImage.AnimatedImage.Providers.Add( AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".apng", ".png"}, new KeyValuePair<string[], Type>(
useColorProfile ? new[] { ".apng" } : new[] { ".apng", ".png" },
typeof(APngProvider))); typeof(APngProvider)));
AnimatedImage.AnimatedImage.Providers.Add( AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".gif"}, new KeyValuePair<string[], Type>(new[] {".gif"},
typeof(GifProvider))); typeof(GifProvider)));
AnimatedImage.AnimatedImage.Providers.Add( AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {".bmp", ".jpg", ".jpeg", ".jfif", ".tif", ".tiff"}, new KeyValuePair<string[], Type>(
useColorProfile ? new string[0] : new[] { ".bmp", ".jpg", ".jpeg", ".jfif", ".tif", ".tiff" },
typeof(NativeProvider))); typeof(NativeProvider)));
AnimatedImage.AnimatedImage.Providers.Add( AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(new[] {"*"}, new KeyValuePair<string[], Type>(new[] {"*"},

View File

@@ -171,6 +171,11 @@ namespace QuickLook
_path = path; _path = path;
Plugin = matchedPlugin; Plugin = matchedPlugin;
ContextObject.Reset();
// assign monitor color profile
ContextObject.ColorProfileName = DisplayDeviceHelper.GetMonitorColorProfileFromWindow(this);
// get window size before showing it // get window size before showing it
try try
{ {