Compare commits

..

3 Commits

Author SHA1 Message Date
ema
5cedcff912 Support .pdn in ThumbnailViewer #1708
Some checks failed
MSBuild / build (push) Has been cancelled
MSBuild / publish (push) Has been cancelled
Implementation still under adjustment.
2025-08-02 02:34:32 +08:00
Copilot
9fe37520d3 Support Mermaid diagram rendering in MarkdownViewer (#1730)
* Implement Mermaid diagram support for MarkdownViewer

Co-authored-by: emako <24737061+emako@users.noreply.github.com>

* Replace the mermaid.min.js

https://cdn.jsdelivr.net/npm/mermaid@11.4.1/dist/mermaid.min.js

* Fix Mermaid diagram rendering by updating markdown-it highlight function

Co-authored-by: emako <24737061+emako@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Co-authored-by: ema <mccoy39082@163.com>
2025-08-02 02:09:52 +08:00
ema
67b5dbf310 Add UseNativeProvider option #1726
Use following option in `QuickLook.Plugin.ImageViewer.config` to fix the issue:
```xml
<?xml version="1.0" encoding="utf-8"?>
<Settings>
  <UseColorProfile>false</UseColorProfile>
  <UseNativeProvider>false</UseNativeProvider>
</Settings>
```
2025-08-02 01:36:13 +08:00
7 changed files with 142 additions and 121 deletions

View File

@@ -17,6 +17,7 @@
using LibAPNG;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using System;
using System.Collections.Generic;
@@ -30,20 +31,28 @@ using System.Windows.Media.Imaging;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers;
/// <summary>
/// This provider is only for Animated PNG.
/// The others will fall back to another provider.
/// </summary>
internal class APngProvider : AnimationProvider
{
private readonly Frame _baseFrame;
private readonly List<FrameInfo> _frames;
private readonly List<BitmapSource> _renderedFrames;
private int _lastEffectivePreviousPreviousFrameIndex;
private NativeProvider _nativeImageProvider;
private AnimationProvider _fallbackImageProvider;
public APngProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{
if (!IsAnimatedPng(path.LocalPath))
{
_nativeImageProvider = new NativeProvider(path, meta, contextObject);
Animator = _nativeImageProvider.Animator;
var useNativeProvider = SettingHelper.Get("UseNativeProvider", true, "QuickLook.Plugin.ImageViewer");
_fallbackImageProvider = useNativeProvider ?
new NativeProvider(path, meta, contextObject) :
new ImageMagickProvider(path, meta, contextObject);
Animator = _fallbackImageProvider.Animator;
return;
}
@@ -71,8 +80,8 @@ internal class APngProvider : AnimationProvider
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
if (_nativeImageProvider != null)
return _nativeImageProvider.GetThumbnail(renderSize);
if (_fallbackImageProvider != null)
return _fallbackImageProvider.GetThumbnail(renderSize);
return new Task<BitmapSource>(() =>
{
@@ -85,8 +94,8 @@ internal class APngProvider : AnimationProvider
public override Task<BitmapSource> GetRenderedFrame(int index)
{
if (_nativeImageProvider != null)
return _nativeImageProvider.GetRenderedFrame(index);
if (_fallbackImageProvider != null)
return _fallbackImageProvider.GetRenderedFrame(index);
if (_renderedFrames[index] != null)
return new Task<BitmapSource>(() => _renderedFrames[index]);
@@ -102,10 +111,10 @@ internal class APngProvider : AnimationProvider
public override void Dispose()
{
if (_nativeImageProvider != null)
if (_fallbackImageProvider != null)
{
_nativeImageProvider.Dispose();
_nativeImageProvider = null;
_fallbackImageProvider.Dispose();
_fallbackImageProvider = null;
return;
}
@@ -214,7 +223,7 @@ internal class APngProvider : AnimationProvider
return false;
}
uint ToUInt32BE(byte[] data)
static uint ToUInt32BE(byte[] data)
{
Array.Reverse(data);
return BitConverter.ToUInt32(data, 0);

View File

@@ -40,11 +40,6 @@ internal class NativeProvider : AnimationProvider
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
var fullSize = Meta.GetSize();
//var decodeWidth = (int) Math.Round(fullSize.Width *
// Math.Min(renderSize.Width / 2 / fullSize.Width,
// renderSize.Height / 2 / fullSize.Height));
//var decodeHeight = (int) Math.Round(fullSize.Height / fullSize.Width * decodeWidth);
var decodeWidth =
(int)Math.Round(Math.Min(Meta.GetSize().Width, Math.Max(1d, Math.Floor(renderSize.Width))));
var decodeHeight =

View File

@@ -1,104 +0,0 @@
// Copyright © 2017-2025 QL-Win Contributors
//
// 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 QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers;
internal class PdnProvider : AnimationProvider
{
public PdnProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject)
{
Animator = new Int32AnimationUsingKeyFrames();
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.Zero)));
}
public override Task<BitmapSource> GetThumbnail(Size renderSize)
{
// Skip thumbnail
return new Task<BitmapSource>(() => null);
}
public override Task<BitmapSource> GetRenderedFrame(int index)
{
return new Task<BitmapSource>(() =>
{
try
{
using TextReader reader = new StreamReader(Path.LocalPath, Encoding.UTF8);
string line = reader.ReadLine();
if (!line.StartsWith("PDN"))
return null;
int indexOfStart = line.IndexOf("<");
int indexOfEnd = line.LastIndexOf(">");
if (indexOfStart < 0 || indexOfEnd < 0)
return null;
string xml = line.Substring(indexOfStart, indexOfEnd - indexOfStart + 1);
// <pdnImage>
// <custom>
// <thumb png="..." />
// </custom>
// </pdnImage>
XDocument doc = XDocument.Parse(xml);
var pngBase64 = doc.Root
?.Element("custom")
?.Element("thumb")
?.Attribute("png")
?.Value;
if (pngBase64 != null)
{
byte[] imageBytes = Convert.FromBase64String(pngBase64);
MemoryStream ms = new(imageBytes);
BitmapImage bitmap = new();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = ms;
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
return null;
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
});
}
public override void Dispose()
{
}
}

View File

@@ -65,8 +65,16 @@ public class Plugin : IViewer
public void Init()
{
// Option of UseColorProfile:
// Default is False (disable color profile conversion)
// Note that enabling this feature will slow down image previewing, especially on large images.
var useColorProfile = SettingHelper.Get("UseColorProfile", false, "QuickLook.Plugin.ImageViewer");
// Option of UseNativeProvider:
// Default is True (disable precise colors and choose faster response)
// Note that disabling this feature may slightly slow down image previewing but you can get precise colors.
var useNativeProvider = SettingHelper.Get("UseNativeProvider", true, "QuickLook.Plugin.ImageViewer");
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(
useColorProfile ? [".apng"] : [".apng", ".png"],
@@ -76,7 +84,7 @@ public class Plugin : IViewer
typeof(GifProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>(
useColorProfile ? [] : [".bmp", ".jpg", ".jpeg", ".jfif", ".tif", ".tiff"],
useColorProfile ? [] : (useNativeProvider ? [".bmp", ".jpg", ".jpeg", ".jfif", ".tif", ".tiff"] : []),
typeof(NativeProvider)));
AnimatedImage.AnimatedImage.Providers.Add(
new KeyValuePair<string[], Type>([".jxr"],

View File

@@ -21,6 +21,7 @@ using PureSharpCompress.Readers;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
@@ -30,8 +31,18 @@ namespace QuickLook.Plugin.ThumbnailViewer;
internal static class Handler
{
// List<Pair<formats, type>>
public static List<KeyValuePair<string[], Type>> Providers = [];
public static void Prepare(string path, ContextObject context)
{
// Temporary codes
if (path.EndsWith(".pdn", StringComparison.OrdinalIgnoreCase))
{
new PdnProvider().Prepare(path, context);
return;
}
try
{
using Stream imageData = ViewImage(path);
@@ -47,6 +58,12 @@ internal static class Handler
public static Stream ViewImage(string path)
{
// Temporary codes
if (path.EndsWith(".pdn", StringComparison.OrdinalIgnoreCase))
{
return new PdnProvider().ViewImage(path);
}
try
{
using ZipArchive archive = ZipArchive.Open(path, new());

View File

@@ -34,6 +34,7 @@ public class Plugin : IViewer
".cdr", // CorelDraw
".fig", // Figma
".kra", // Krita
".pdn", // Paint.NET
".pip", ".pix", // Pixso
".sketch", // Sketch
".xd", // AdobeXD
@@ -46,6 +47,8 @@ public class Plugin : IViewer
public void Init()
{
Handler.Providers.Add(new KeyValuePair<string[], Type>(
[".pdn"], typeof(PdnProvider)));
}
public bool CanHandle(string path)

View File

@@ -0,0 +1,93 @@
// Copyright © 2017-2025 QL-Win Contributors
//
// 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 QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using QuickLook.Plugin.ImageViewer;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
namespace QuickLook.Plugin.ThumbnailViewer;
internal class PdnProvider
{
public void Prepare(string path, ContextObject context)
{
try
{
using Stream imageData = ViewImage(path);
BitmapImage bitmap = imageData.ReadAsBitmapImage();
context.SetPreferredSizeFit(new Size(bitmap.PixelWidth, bitmap.PixelHeight), 0.8d);
}
catch (Exception ex)
{
Debug.WriteLine($"Error reading thumbnail from {path}: {ex.Message}");
context.PreferredSize = new Size { Width = 800, Height = 600 };
}
}
public Stream ViewImage(string path)
{
try
{
using TextReader reader = new StreamReader(path, Encoding.UTF8);
string line = reader.ReadLine();
if (!line.StartsWith("PDN"))
return null;
int indexOfStart = line.IndexOf("<");
int indexOfEnd = line.LastIndexOf(">");
if (indexOfStart < 0 || indexOfEnd < 0)
return null;
string xml = line.Substring(indexOfStart, indexOfEnd - indexOfStart + 1);
// <pdnImage>
// <custom>
// <thumb png="..." />
// </custom>
// </pdnImage>
XDocument doc = XDocument.Parse(xml);
var pngBase64 = doc.Root
?.Element("custom")
?.Element("thumb")
?.Attribute("png")
?.Value;
if (pngBase64 != null)
{
byte[] imageBytes = Convert.FromBase64String(pngBase64);
MemoryStream ms = new(imageBytes);
return ms;
}
return null;
}
catch (Exception e)
{
ProcessHelper.WriteLog(e.ToString());
return null;
}
}
}