19
19
using System . Collections . Generic ;
20
20
using System . IO ;
21
21
using System . Windows ;
22
+ using ImageMagick ;
22
23
using QuickLook . Common . Helpers ;
23
24
using QuickLook . Common . Plugin ;
24
25
using QuickLook . Plugin . ImageViewer . AnimatedImage . Providers ;
@@ -27,17 +28,28 @@ namespace QuickLook.Plugin.ImageViewer
27
28
{
28
29
public class Plugin : IViewer
29
30
{
30
- private static readonly HashSet < string > Formats = new HashSet < string > ( new [ ]
31
+ private static readonly HashSet < string > WellKnownImageExtensions = new HashSet < string > ( new [ ]
31
32
{
32
- // camera raw ,add dds - add by gh
33
- ".apng" , ".ari" , ".arw" , ".avif" , ".bay" , ".crw" , ".cr2" , ".cr3" , ".cap" , ".dcs" , ".dcr" , ".dng" , ".drf" , ".eip" , ".erf" , ".exr" , ".fff" ,
34
- ".iiq" , ".k25" , ".kdc" , ".mdc" , ".mef" , ".mos" , ".mrw" , ".nef" , ".nrw" , ".obm" , ".orf" , ".pef" , ".ptx" ,
35
- ".pxn" , ".r3d" , ".raf" , ".raw" , ".rwl" , ".rw2" , ".rwz" , ".sr2" , ".srf" , ".srw" , ".x3f" , ".dds" ,
36
- // normal
37
- ".bmp" , ".hdr" , ".heic" , ".heif" , ".ico" , ".icon" , ".jpg" , ".jpeg" , ".jfif" , ".psd" , ".wdp" , ".tif" , ".tiff" , ".tga" ,
38
- ".webp" , ".pbm" , ".pgm" , ".ppm" , ".pnm" , ".svg" , ".emf" , ".wmf" ,
39
- // animated
40
- ".png" , ".apng" , ".gif"
33
+ ".apng" , ".ari" , ".arw" , ".avif" ,
34
+ ".svg" , ".tga" , ".tif" , ".tiff" , ".webp" , ".wmf" , ".bay" , ".bmp" ,
35
+ ".cap" , ".cr2" , ".cr3" , ".crw" ,
36
+ ".dcr" , ".dcs" , ".dng" , ".drf" ,
37
+ ".eip" , ".emf" , ".erf" , ".exr" ,
38
+ ".fff" ,
39
+ ".gif" ,
40
+ ".hdr" , ".heic" , ".heif" ,
41
+ ".ico" , ".icon" , ".iiq" ,
42
+ ".jfif" , ".jp2" , ".jpeg" , ".jpg" , ".jxl" ,
43
+ ".k25" , ".kdc" ,
44
+ ".mdc" , ".mef" , ".mos" , ".mrw" ,
45
+ ".nef" , ".nrw" ,
46
+ ".obm" , ".orf" ,
47
+ ".pbm" , ".pef" , ".pgm" , ".png" , ".pnm" , ".ppm" , ".psd" , ".ptx" , ".pxn" ,
48
+ ".r3d" , ".raf" , ".raw" , ".rw2" , ".rwl" , ".rwz" ,
49
+ ".sr2" , ".srf" , ".srw" , ".svg" ,
50
+ ".tga" , ".tif" , ".tiff" ,
51
+ ".wdp" , ".webp" , ".wmf" ,
52
+ ".x3f"
41
53
} ) ;
42
54
private ImagePanel _ip ;
43
55
private MetaProvider _meta ;
@@ -59,10 +71,29 @@ public void Init()
59
71
new KeyValuePair < string [ ] , Type > ( new [ ] { "*" } ,
60
72
typeof ( ImageMagickProvider ) ) ) ;
61
73
}
74
+ private bool IsWellKnownImageExtension ( string path )
75
+ {
76
+ return WellKnownImageExtensions . Contains ( Path . GetExtension ( path . ToLower ( ) ) ) ;
77
+ }
78
+
79
+ private bool IsImageMagickSupported ( string path )
80
+ {
81
+ try
82
+ {
83
+ return new MagickImageInfo ( path ) . Format != MagickFormat . Unknown ;
84
+ }
85
+ catch
86
+ {
87
+ return false ;
88
+ }
89
+ }
62
90
63
91
public bool CanHandle ( string path )
64
92
{
65
- return ! Directory . Exists ( path ) && Formats . Contains ( Path . GetExtension ( path . ToLower ( ) ) ) ;
93
+ // Disabled due mishandling text file types e.g., "*.config".
94
+ // Only check extension for well known image and animated image types.
95
+ // For other image formats, let ImageMagick try to detect by file content.
96
+ return ! Directory . Exists ( path ) && ( IsWellKnownImageExtension ( path ) ) ; // || IsImageMagickSupported(path));
66
97
}
67
98
68
99
public void Prepare ( string path , ContextObject context )
0 commit comments