use taglibsharp to read image sizes

This commit is contained in:
Luke Pulverenti
2015-09-14 13:39:35 -04:00
parent 960d45587d
commit 11d7585aa3
5 changed files with 102 additions and 328 deletions

View File

@@ -1,5 +1,4 @@
using Emby.Drawing.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Drawing;
@@ -399,6 +398,8 @@ namespace Emby.Drawing
{
size = GetImageSizeInternal(path, allowSlowMethod);
StartSaveImageSizeTimer();
_cachedImagedSizes.AddOrUpdate(cacheHash, size, (keyName, oldValue) => size);
}
@@ -413,28 +414,18 @@ namespace Emby.Drawing
/// <returns>ImageSize.</returns>
private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod)
{
ImageSize size;
using (var file = TagLib.File.Create(path))
{
var image = file as TagLib.Image.File;
try
{
size = ImageHeader.GetDimensions(path, _logger, _fileSystem);
}
catch
{
if (!allowSlowMethod)
var properties = image.Properties;
return new ImageSize
{
throw;
}
//_logger.Info("Failed to read image header for {0}. Doing it the slow way.", path);
CheckDisposed();
size = _imageEncoder.GetImageSize(path);
Height = properties.PhotoHeight,
Width = properties.PhotoWidth
};
}
StartSaveImageSizeTimer();
return size;
}
private readonly Timer _saveImageSizeTimer;