Skip to content

Commit

Permalink
Merge pull request #7 from QL-Win/master
Browse files Browse the repository at this point in the history
Merge from latest
  • Loading branch information
Jethro-Alter authored May 17, 2020
2 parents 666f4df + 99ce6c0 commit 431bf8e
Show file tree
Hide file tree
Showing 94 changed files with 612 additions and 5,693 deletions.
Binary file modified Build/Assets/LargeTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/LargeTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/LargeTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/LargeTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/LargeTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/SmallTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/SmallTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/SmallTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/SmallTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/SmallTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square150x150Logo.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square150x150Logo.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square150x150Logo.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square150x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square150x150Logo.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.altform-unplated_targetsize-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.altform-unplated_targetsize-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.altform-unplated_targetsize-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.altform-unplated_targetsize-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.altform-unplated_targetsize-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Build/Assets/Square44x44Logo.targetsize-16.png
Binary file modified Build/Assets/Square44x44Logo.targetsize-24.png
Binary file modified Build/Assets/Square44x44Logo.targetsize-256.png
Binary file modified Build/Assets/Square44x44Logo.targetsize-32.png
Binary file modified Build/Assets/Square44x44Logo.targetsize-48.png
Binary file modified Build/Assets/Wide310x150Logo.scale-100.png
Binary file modified Build/Assets/Wide310x150Logo.scale-125.png
Binary file modified Build/Assets/Wide310x150Logo.scale-150.png
Binary file modified Build/Assets/Wide310x150Logo.scale-200.png
Binary file modified Build/Assets/Wide310x150Logo.scale-400.png
Binary file modified Build/Assets/storelogo.scale-100.png
Binary file modified Build/Assets/storelogo.scale-125.png
Binary file modified Build/Assets/storelogo.scale-150.png
Binary file modified Build/Assets/storelogo.scale-200.png
Binary file modified Build/Assets/storelogo.scale-400.png
2 changes: 1 addition & 1 deletion QuickLook.Common
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DataGrid x:Name="dataGrid" AlternationCount="2" BorderThickness="0" Background="Transparent"
<DataGrid x:Name="dataGrid" AlternationCount="2" BorderThickness="0" Background="Transparent" Foreground="{DynamicResource WindowTextForeground}"
RowBackground="Transparent" IsReadOnly="True" HeadersVisibility="None" AutoGenerateColumns="False"
CanUserReorderColumns="False" ItemsSource="{Binding Path=Rows,ElementName=csvViewer}"
AlternatingRowBackground="#99D8D8D8" HorizontalGridLinesBrush="#FFBDBDBD" VerticalGridLinesBrush="#FFBDBDBD" />
AlternatingRowBackground="#1900FF70" HorizontalGridLinesBrush="#19000000" VerticalGridLinesBrush="#19000000" />

</Grid>
</UserControl>
7 changes: 4 additions & 3 deletions QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Paddy Xu
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
Expand Down Expand Up @@ -26,7 +26,8 @@ namespace QuickLook.Plugin.HtmlViewer
{
public class Plugin : IViewer
{
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html", ".svg", ".url" };
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html" };
private static readonly string[] SupportedProtocols = { "http", "https" };

private WebpagePanel _panel;

Expand All @@ -39,7 +40,7 @@ public void Init()

public bool CanHandle(string path)
{
return !Directory.Exists(path) && Extensions.Any(path.ToLower().EndsWith);
return !Directory.Exists(path) && (Extensions.Any(path.ToLower().EndsWith) || (path.ToLower().EndsWith(".url") && SupportedProtocols.Contains(Helper.GetUrlPath(path).Split(':')[0].ToLower())));
}

public void Prepare(string path, ContextObject context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Dispose()
public event EventHandler ImageLoaded;
public event EventHandler DoZoomToFit;

private static AnimationProvider LoadFullImageCore(Uri path, NConvert meta)
private static AnimationProvider InitAnimationProvider(Uri path, MetaProvider meta)
{
var ext = Path.GetExtension(path.LocalPath).ToLower();
var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value;
Expand All @@ -69,7 +69,7 @@ private static AnimationProvider LoadFullImageCore(Uri path, NConvert meta)
new UIPropertyMetadata(null, AnimationUriChanged));

public static readonly DependencyProperty MetaProperty =
DependencyProperty.Register("Meta", typeof(NConvert), typeof(AnimatedImage));
DependencyProperty.Register("Meta", typeof(MetaProvider), typeof(AnimatedImage));

public static readonly DependencyProperty ContextObjectProperty =
DependencyProperty.Register("ContextObject", typeof(ContextObject), typeof(AnimatedImage));
Expand All @@ -86,9 +86,9 @@ public Uri AnimationUri
set => SetValue(AnimationUriProperty, value);
}

public NConvert Meta
public MetaProvider Meta
{
private get => (NConvert) GetValue(MetaProperty);
private get => (MetaProvider) GetValue(MetaProperty);
set => SetValue(MetaProperty, value);
}

Expand All @@ -106,13 +106,13 @@ private static void AnimationUriChanged(DependencyObject obj, DependencyProperty
//var thumbnail = instance.Meta?.GetThumbnail(true);
//instance.Source = thumbnail;

instance._animation = LoadFullImageCore((Uri) ev.NewValue, instance.Meta);
instance._animation = InitAnimationProvider((Uri) ev.NewValue, instance.Meta);
ShowThumbnailAndStartAnimation(instance);
}

private static void ShowThumbnailAndStartAnimation(AnimatedImage instance)
{
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize, instance.Meta.GetSize());
var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize);
if (task == null) return;

task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
Expand All @@ -121,8 +121,12 @@ private static void ShowThumbnailAndStartAnimation(AnimatedImage instance)
return;

instance.Source = _.Result;
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());

if (_.Result != null)
{
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());
}

instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation?.Animator);
}));
Expand All @@ -141,8 +145,18 @@ private static void AnimationFrameIndexChanged(DependencyObject obj, DependencyP

task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
if (!instance._disposing)
instance.Source = _.Result;
if (instance._disposing)
return;

var firstLoad = instance.Source == null;

instance.Source = _.Result;

if (firstLoad)
{
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());
}
}));
task.Start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
{
internal abstract class AnimationProvider : IDisposable
{
protected AnimationProvider(string path, NConvert meta)
protected AnimationProvider(string path, MetaProvider meta)
{
Path = path;
Meta = meta;
}

public string Path { get; }

public NConvert Meta { get; }
public MetaProvider Meta { get; }

public Int32AnimationUsingKeyFrames Animator { get; protected set; }

public abstract void Dispose();

public abstract Task<BitmapSource> GetThumbnail(Size size, Size fullSize);
public abstract Task<BitmapSource> GetThumbnail(Size renderSize);

public abstract Task<BitmapSource> GetRenderedFrame(int index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
using LibAPNG;
using QuickLook.Common.ExtensionMethods;

namespace QuickLook.Plugin.ImageViewer.AnimatedImage
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{
internal class APngAnimationProvider : AnimationProvider
internal class APngProvider : AnimationProvider
{
private readonly Frame _baseFrame;
private readonly List<FrameInfo> _frames;
private readonly List<BitmapSource> _renderedFrames;
private int _lastEffectivePreviousPreviousFrameIndex;
private NativeImageProvider _nativeImageProvider;
private NativeProvider _nativeImageProvider;

public APngAnimationProvider(string path, NConvert meta) : base(path, meta)
public APngProvider(string path, MetaProvider meta) : base(path, meta)
{
if (!IsAnimatedPng(path))
{
_nativeImageProvider = new NativeImageProvider(path, meta);
_nativeImageProvider = new NativeProvider(path, meta);
Animator = _nativeImageProvider.Animator;
return;
}
Expand All @@ -68,12 +68,18 @@ public APngAnimationProvider(string path, NConvert meta) : base(path, meta)
}
}

public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
if (_nativeImageProvider != null)
return _nativeImageProvider.GetThumbnail(size, fullSize);
return _nativeImageProvider.GetThumbnail(renderSize);

return new Task<BitmapSource>(() => _baseFrame.GetBitmapSource());
return new Task<BitmapSource>(() =>
{
var bs = _baseFrame.GetBitmapSource();

bs.Freeze();
return bs;
});
}

public override Task<BitmapSource> GetRenderedFrame(int index)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2020 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;

namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{
internal class DcrawProvider : NativeProvider
{
public DcrawProvider(string path, MetaProvider meta) : base(path, meta)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using Size = System.Windows.Size;

namespace QuickLook.Plugin.ImageViewer.AnimatedImage
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{
internal class GifAnimationProvider : AnimationProvider
internal class GifProvider : AnimationProvider
{
private Bitmap _fileHandle;
private BitmapSource _frame;
private bool _isPlaying;

public GifAnimationProvider(string path, NConvert meta) : base(path, meta)
public GifProvider(string path, MetaProvider meta) : base(path, meta)
{
_fileHandle = (Bitmap) Image.FromFile(path);

_fileHandle.SetResolution(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

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))));
Expand All @@ -53,7 +57,7 @@ public override void Dispose()
_frame = null;
}

public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
return new Task<BitmapSource>(() =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2018 Paddy Xu
// Copyright © 2020 Paddy Xu
//
// This file is part of QuickLook program.
//
Expand All @@ -16,49 +16,54 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using ImageMagick;
using ImageMagick.Formats.Dng;
using QuickLook.Common.Helpers;

namespace QuickLook.Plugin.ImageViewer.AnimatedImage
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
{
internal class NConvertImageProvider : AnimationProvider
internal class ImageMagickProvider : AnimationProvider
{
public NConvertImageProvider(string path, NConvert meta) : base(path, meta)
public ImageMagickProvider(string path, MetaProvider 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)
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
var decodeWidth = (int) Math.Round(fullSize.Width *
Math.Min(size.Width / 2 / fullSize.Width,
size.Height / 2 / fullSize.Height));
var decodeHeight = (int) Math.Round(fullSize.Height / fullSize.Width * decodeWidth);
var fullSize = Meta.GetSize();

return new Task<BitmapSource>(() =>
{
try
{
using (var ms = Meta.GetTiffStream(true))
using (var buffer = new MemoryStream(Meta.GetThumbnail()))
{
if (buffer.Length == 0)
return null;

var img = new BitmapImage();
img.BeginInit();
img.StreamSource = ms;
img.StreamSource = buffer;
img.CacheOption = BitmapCacheOption.OnLoad;
img.DecodePixelWidth = decodeWidth;
img.DecodePixelHeight = decodeHeight; // specific size to avoid .net's double to int conversion
//// specific renderSize to avoid .net's double to int conversion
//img.DecodePixelWidth = Math.Max(1, (int) Math.Floor(renderSize.Width));
//img.DecodePixelHeight = Math.Max(1, (int) Math.Floor(renderSize.Height));
img.EndInit();

var scaled = new TransformedBitmap(img,
new ScaleTransform(fullSize.Width / img.PixelWidth, fullSize.Height / img.PixelHeight));
scaled.Freeze();

Helper.DpiHack(scaled);
scaled.Freeze();
return scaled;
}
}
Expand All @@ -72,17 +77,37 @@ public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)

public override Task<BitmapSource> GetRenderedFrame(int index)
{
var fullSize = Meta.GetSize();

return new Task<BitmapSource>(() =>
{
var settings = new MagickReadSettings
{
Defines = new DngReadDefines
{
OutputColor = DngOutputColor.SRGB,
UseCameraWhitebalance = true,
DisableAutoBrightness = false
}
};

try
{
using (var ms = Meta.GetTiffStream(false))
using (var mi = new MagickImage(Path, settings))
{
var img = new BitmapImage();
img.BeginInit();
img.StreamSource = ms;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
var profile = mi.GetColorProfile();
if (profile?.Description != null && !profile.Description.Contains("sRGB"))
mi.SetProfile(ColorProfile.SRGB);

mi.AutoOrient();

if (mi.Width != (int) fullSize.Width || mi.Height != (int) fullSize.Height)
mi.Resize((int) fullSize.Width, (int) fullSize.Height);

mi.Density = new Density(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

var img = mi.ToBitmapSource(BitmapDensity.Use);

img.Freeze();
return img;
Expand Down
Loading

0 comments on commit 431bf8e

Please sign in to comment.