mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 02:09:05 +00:00
better NConvert decoding
This commit is contained in:
@@ -36,6 +36,11 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
|||||||
|
|
||||||
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
|
public override Task<BitmapSource> GetThumbnail(Size size, Size fullSize)
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
return new Task<BitmapSource>(() =>
|
return new Task<BitmapSource>(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -46,11 +51,14 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
|||||||
img.BeginInit();
|
img.BeginInit();
|
||||||
img.StreamSource = ms;
|
img.StreamSource = ms;
|
||||||
img.CacheOption = BitmapCacheOption.OnLoad;
|
img.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
img.DecodePixelWidth = decodeWidth;
|
||||||
|
img.DecodePixelHeight = decodeHeight; // specific size to avoid .net's double to int conversion
|
||||||
img.EndInit();
|
img.EndInit();
|
||||||
|
|
||||||
var scaled = new TransformedBitmap(img,
|
var scaled = new TransformedBitmap(img,
|
||||||
new ScaleTransform(fullSize.Width / img.PixelWidth, fullSize.Height / img.PixelHeight));
|
new ScaleTransform(fullSize.Width / img.PixelWidth, fullSize.Height / img.PixelHeight));
|
||||||
scaled.Freeze();
|
scaled.Freeze();
|
||||||
|
|
||||||
return scaled;
|
return scaled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -49,13 +49,12 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
|
|||||||
img.BeginInit();
|
img.BeginInit();
|
||||||
img.UriSource = new Uri(Path);
|
img.UriSource = new Uri(Path);
|
||||||
img.CacheOption = BitmapCacheOption.OnLoad;
|
img.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
img.DecodePixelWidth = (int) decodeWidth;
|
img.DecodePixelWidth = decodeWidth;
|
||||||
img.DecodePixelHeight =
|
img.DecodePixelHeight = decodeHeight; // specific size to avoid .net's double to int conversion
|
||||||
(int) decodeHeight; // specific size to avoid .net's double to int conversion
|
|
||||||
img.EndInit();
|
img.EndInit();
|
||||||
|
|
||||||
var scaled = new TransformedBitmap(img,
|
var scaled = new TransformedBitmap(img,
|
||||||
new ScaleTransform(fullSize.Width / decodeWidth, fullSize.Height / decodeHeight));
|
new ScaleTransform(fullSize.Width / img.PixelWidth, fullSize.Height / img.PixelHeight));
|
||||||
scaled.Freeze();
|
scaled.Freeze();
|
||||||
return scaled;
|
return scaled;
|
||||||
}
|
}
|
||||||
|
@@ -88,7 +88,7 @@ namespace QuickLook.Plugin.ImageViewer
|
|||||||
context.ViewerContent = _ip;
|
context.ViewerContent = _ip;
|
||||||
context.Title = size.IsEmpty
|
context.Title = size.IsEmpty
|
||||||
? $"{Path.GetFileName(path)}"
|
? $"{Path.GetFileName(path)}"
|
||||||
: $"{Path.GetFileName(path)} ({size.Width}×{size.Height})";
|
: $"{size.Width}×{size.Height}: {Path.GetFileName(path)}";
|
||||||
|
|
||||||
_ip.ImageUriSource = new Uri(path);
|
_ip.ImageUriSource = new Uri(path);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user