feature: add supports for .webp image format (#421)

This commit is contained in:
leo 2024-08-28 18:58:01 +08:00
parent 3d57398d15
commit a573436b67
No known key found for this signature in database
3 changed files with 8 additions and 7 deletions

View file

@ -536,7 +536,7 @@ namespace SourceGit.ViewModels
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>() private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
{ {
".ico", ".bmp", ".jpg", ".png", ".jpeg" ".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"
}; };
private Repository _repo = null; private Repository _repo = null;

View file

@ -139,7 +139,7 @@ namespace SourceGit.ViewModels
else if (latest.IsBinary) else if (latest.IsBinary)
{ {
var oldPath = string.IsNullOrEmpty(_option.OrgPath) ? _option.Path : _option.OrgPath; var oldPath = string.IsNullOrEmpty(_option.OrgPath) ? _option.Path : _option.OrgPath;
var ext = Path.GetExtension(oldPath); var ext = Path.GetExtension(_option.Path);
if (IMG_EXTS.Contains(ext)) if (IMG_EXTS.Contains(ext))
{ {
@ -147,13 +147,14 @@ namespace SourceGit.ViewModels
if (_option.Revisions.Count == 2) if (_option.Revisions.Count == 2)
{ {
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath); (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath);
(imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[1], oldPath); (imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[1], _option.Path);
} }
else else
{ {
var fullPath = Path.Combine(_repo, _option.Path); if (!oldPath.Equals("/dev/null", StringComparison.Ordinal))
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath); (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath);
var fullPath = Path.Combine(_repo, _option.Path);
if (File.Exists(fullPath)) if (File.Exists(fullPath))
{ {
imgDiff.New = new Bitmap(fullPath); imgDiff.New = new Bitmap(fullPath);
@ -226,7 +227,7 @@ namespace SourceGit.ViewModels
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>() private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
{ {
".ico", ".bmp", ".jpg", ".png", ".jpeg" ".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"
}; };
private readonly string _repo; private readonly string _repo;

View file

@ -186,7 +186,7 @@ namespace SourceGit.ViewModels
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>() private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
{ {
".ico", ".bmp", ".jpg", ".png", ".jpeg" ".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"
}; };
private readonly Repository _repo = null; private readonly Repository _repo = null;