mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-01-13 07:05:24 +08:00
Add built-in ThumbnailViewer plugin
This commit is contained in:
@@ -20,13 +20,50 @@ using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace QuickLook.Plugin.ImageViewer;
|
||||
|
||||
internal class Helper
|
||||
internal static class Helper
|
||||
{
|
||||
public static void DpiHack(BitmapSource img)
|
||||
public static BitmapSource InvertColors(this BitmapSource source)
|
||||
{
|
||||
WriteableBitmap writableBitmap = new(source);
|
||||
writableBitmap.Lock();
|
||||
|
||||
nint pBackBuffer = writableBitmap.BackBuffer;
|
||||
int stride = writableBitmap.BackBufferStride;
|
||||
int width = writableBitmap.PixelWidth;
|
||||
int height = writableBitmap.PixelHeight;
|
||||
int bytesPerPixel = (writableBitmap.Format.BitsPerPixel + 7) / 8;
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* pPixels = (byte*)pBackBuffer;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
Span<byte> row = new(pPixels + y * stride, width * bytesPerPixel);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
int index = x * bytesPerPixel;
|
||||
|
||||
row[index] = (byte)(255 - row[index]);
|
||||
row[index + 1] = (byte)(255 - row[index + 1]);
|
||||
row[index + 2] = (byte)(255 - row[index + 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
|
||||
writableBitmap.Unlock();
|
||||
|
||||
return writableBitmap;
|
||||
}
|
||||
|
||||
public static void DpiHack(this BitmapSource img)
|
||||
{
|
||||
// a dirty hack... but is the fastest
|
||||
|
||||
|
||||
@@ -102,7 +102,24 @@
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=CopyIconVisibility}" />
|
||||
|
||||
<Button x:Name="buttonSaveAs"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,8,8,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=SaveAsVisibility}" />
|
||||
<Button x:Name="buttonReverseColor"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,8,8,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=ReverseColorVisibility}" />
|
||||
<Button x:Name="buttonMeta"
|
||||
Width="24"
|
||||
Height="24"
|
||||
@@ -110,7 +127,6 @@
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=MetaIconVisibility}" />
|
||||
|
||||
<Button x:Name="buttonBackgroundColour"
|
||||
Width="24"
|
||||
Height="24"
|
||||
@@ -119,7 +135,6 @@
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=BackgroundVisibility}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Name="textMeta"
|
||||
Margin="0,40,8,0"
|
||||
Padding="5,5,5,5"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// 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 Microsoft.Win32;
|
||||
using QuickLook.Common.Annotations;
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Helpers;
|
||||
@@ -23,6 +24,7 @@ using QuickLook.Plugin.ImageViewer.NativeMethods;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
@@ -47,9 +49,7 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
private bool _isZoomFactorFirstSet = true;
|
||||
private DateTime _lastZoomTime = DateTime.MinValue;
|
||||
private double _maxZoomFactor = 3d;
|
||||
private Visibility _copyIconVisibility = Visibility.Visible;
|
||||
private MetaProvider _meta;
|
||||
private Visibility _metaIconVisibility = Visibility.Visible;
|
||||
private double _minZoomFactor = 0.1d;
|
||||
private BitmapScalingMode _renderMode = BitmapScalingMode.Linear;
|
||||
private bool _showZoomLevelInfo = true;
|
||||
@@ -60,6 +60,11 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
private double _zoomToFitFactor;
|
||||
private bool _zoomWithControlKey;
|
||||
|
||||
private Visibility _copyIconVisibility = Visibility.Visible;
|
||||
private Visibility _saveAsVisibility = Visibility.Collapsed;
|
||||
private Visibility _reverseColorVisibility = Visibility.Collapsed;
|
||||
private Visibility _metaIconVisibility = Visibility.Visible;
|
||||
|
||||
public ImagePanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -68,6 +73,10 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
|
||||
buttonCopy.Click += OnCopyOnClick;
|
||||
|
||||
buttonSaveAs.Click += OnSaveAsOnClick;
|
||||
|
||||
buttonReverseColor.Click += OnReverseColorOnClick;
|
||||
|
||||
buttonMeta.Click += (sender, e) =>
|
||||
textMeta.Visibility = textMeta.Visibility == Visibility.Collapsed
|
||||
? Visibility.Visible
|
||||
@@ -153,16 +162,6 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility MetaIconVisibility
|
||||
{
|
||||
get => _metaIconVisibility;
|
||||
set
|
||||
{
|
||||
_metaIconVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility CopyIconVisibility
|
||||
{
|
||||
get => _copyIconVisibility;
|
||||
@@ -173,6 +172,36 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility SaveAsVisibility
|
||||
{
|
||||
get => _saveAsVisibility;
|
||||
set
|
||||
{
|
||||
_saveAsVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility ReverseColorVisibility
|
||||
{
|
||||
get => _reverseColorVisibility;
|
||||
set
|
||||
{
|
||||
_reverseColorVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility MetaIconVisibility
|
||||
{
|
||||
get => _metaIconVisibility;
|
||||
set
|
||||
{
|
||||
_metaIconVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility BackgroundVisibility
|
||||
{
|
||||
get => _backgroundVisibility;
|
||||
@@ -307,6 +336,51 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSaveAsOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dialog = new SaveFileDialog()
|
||||
{
|
||||
Filter = "PNG Image|*.png",
|
||||
DefaultExt = ".png",
|
||||
FileName = Path.GetFileNameWithoutExtension(ContextObject.Title)
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(dialog.FileName))
|
||||
{
|
||||
File.Delete(dialog.FileName);
|
||||
}
|
||||
|
||||
PngBitmapEncoder encoder = new();
|
||||
encoder.Frames.Add(BitmapFrame.Create(_source));
|
||||
using FileStream stream = new(dialog.FileName, FileMode.Create, FileAccess.Write);
|
||||
encoder.Save(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
///
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReverseColorOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Source = _source.InvertColors();
|
||||
}
|
||||
|
||||
private void OnBackgroundColourOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Theme = Theme == Themes.Dark ? Themes.Light : Themes.Dark;
|
||||
|
||||
@@ -64,6 +64,12 @@
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3296.44">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Memory" Version="4.6.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(DefineConstants)' != '' and $(DefineConstants.Contains('USESVGSKIA')) ">
|
||||
|
||||
Reference in New Issue
Block a user