From 3c604453118e06f11052b10c672d726393996c34 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 May 2017 15:56:59 -0400 Subject: [PATCH 1/6] update skia --- Emby.Drawing.Skia/SkiaEncoder.cs | 19 +++++++++++++++++-- .../ImageEncoderHelper.cs | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index d52ad4734..64c2afe0e 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -192,17 +192,32 @@ namespace Emby.Drawing.Skia } } + private SKBitmap Decode(string path) + { + using (var stream = new SKFileStream(path)) + { + var codec = SKCodec.Create(stream); + + // create the bitmap + var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height); + // decode + codec.GetPixels(bitmap.Info, bitmap.GetPixels()); + + return bitmap; + } + } + private SKBitmap GetBitmap(string path, bool cropWhitespace) { if (cropWhitespace) { - using (var bitmap = SKBitmap.Decode(path)) + using (var bitmap = Decode(path)) { return CropWhiteSpace(bitmap); } } - return SKBitmap.Decode(path); + return Decode(path); } public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) diff --git a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs index 99ccdbbe8..8c3d8d213 100644 --- a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs +++ b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Startup.Common { try { - //return new SkiaEncoder(logManager.GetLogger("ImageMagick"), appPaths, httpClient, fileSystem); + return new SkiaEncoder(logManager.GetLogger("ImageMagick"), appPaths, httpClient, fileSystem); } catch { From aae64e6b87c195994d85ec4ccc8405e723fadd9f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 May 2017 15:57:55 -0400 Subject: [PATCH 2/6] update skia --- Emby.Drawing.Skia/SkiaEncoder.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index 64c2afe0e..d2a771be9 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -243,10 +243,7 @@ namespace Emby.Drawing.Skia using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType)) { // scale image - var resizeMethod = options.Image.Type == MediaBrowser.Model.Entities.ImageType.Logo || - options.Image.Type == MediaBrowser.Model.Entities.ImageType.Art - ? SKBitmapResizeMethod.Lanczos3 - : SKBitmapResizeMethod.Lanczos3; + var resizeMethod = SKBitmapResizeMethod.Lanczos3; bitmap.Resize(resizedBitmap, resizeMethod); From 0f198dc818300b6d8b8e85858274b0821ec70a20 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 May 2017 22:57:25 -0400 Subject: [PATCH 3/6] fix image resizing --- Emby.Drawing/ImageProcessor.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index accabcf14..9dc5f75ee 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -225,8 +225,8 @@ namespace Emby.Drawing if (!_fileSystem.FileExists(cacheFilePath)) { - var newWidth = Convert.ToInt32(newSize.Width); - var newHeight = Convert.ToInt32(newSize.Height); + var newWidth = Convert.ToInt32(Math.Round(newSize.Width)); + var newHeight = Convert.ToInt32(Math.Round(newSize.Height)); _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath)); var tmpPath = Path.ChangeExtension(Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N")), Path.GetExtension(cacheFilePath)); @@ -339,13 +339,13 @@ namespace Emby.Drawing if (width.HasValue) { - var heightValue = aspect / width.Value; - return new ImageSize(width.Value, Convert.ToInt32(heightValue)); + var heightValue = width.Value / aspect; + return new ImageSize(width.Value, heightValue); } var height = options.Height ?? options.MaxHeight ?? 200; var widthValue = aspect * height; - return new ImageSize(Convert.ToInt32(widthValue), height); + return new ImageSize(widthValue, height); } private double GetEstimatedAspectRatio(ImageType type) From e915ceda1b1b57f8b04f7f28b3efe2a84bd4cdd9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 May 2017 22:57:48 -0400 Subject: [PATCH 4/6] dummy up audio bitrates when needed --- .../Probing/ProbeResultNormalizer.cs | 34 +++++++++++++++++++ MediaBrowser.Model/Drawing/ImageSize.cs | 6 ++++ 2 files changed, 40 insertions(+) diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 8b20dca1b..6270b87c6 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -176,6 +176,14 @@ namespace MediaBrowser.MediaEncoding.Probing info.Video3DFormat = Video3DFormat.FullSideBySide; } + foreach (var mediaStream in info.MediaStreams) + { + if (mediaStream.Type == MediaStreamType.Audio && !mediaStream.BitRate.HasValue) + { + mediaStream.BitRate = GetEstimatedAudioBitrate(mediaStream.Codec, mediaStream.Channels); + } + } + var videoStreamsBitrate = info.MediaStreams.Where(i => i.Type == MediaStreamType.Video).Select(i => i.BitRate ?? 0).Sum(); // If ffprobe reported the container bitrate as being the same as the video stream bitrate, then it's wrong if (videoStreamsBitrate == (info.Bitrate ?? 0)) @@ -187,6 +195,32 @@ namespace MediaBrowser.MediaEncoding.Probing return info; } + private int? GetEstimatedAudioBitrate(string codec, int? channels) + { + if (!channels.HasValue) + { + return null; + } + + var channelsValue = channels.Value; + + if (string.Equals(codec, "aac", StringComparison.OrdinalIgnoreCase) || + string.Equals(codec, "mp3", StringComparison.OrdinalIgnoreCase)) + { + if (channelsValue <= 2) + { + return 192000; + } + + if (channelsValue >= 5) + { + return 320000; + } + } + + return null; + } + private void FetchFromItunesInfo(string xml, MediaInfo info) { // Make things simpler and strip out the dtd diff --git a/MediaBrowser.Model/Drawing/ImageSize.cs b/MediaBrowser.Model/Drawing/ImageSize.cs index 8cf09da18..c2b0291bd 100644 --- a/MediaBrowser.Model/Drawing/ImageSize.cs +++ b/MediaBrowser.Model/Drawing/ImageSize.cs @@ -61,6 +61,12 @@ namespace MediaBrowser.Model.Drawing _height = height; } + public ImageSize(double width, double height) + { + _width = width; + _height = height; + } + private void ParseValue(string value) { if (!string.IsNullOrEmpty(value)) From 3feeb04ffc0552570ca7c56fa3b39362c7020076 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 May 2017 23:23:16 -0400 Subject: [PATCH 5/6] update skia --- Emby.Drawing.Skia/SkiaEncoder.cs | 51 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index d2a771be9..74ceb7591 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -6,6 +6,8 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using SkiaSharp; using System; +using System.IO; +using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -120,8 +122,6 @@ namespace Emby.Drawing.Skia private SKBitmap CropWhiteSpace(SKBitmap bitmap) { - CheckDisposed(); - var topmost = 0; for (int row = 0; row < bitmap.Height; ++row) { @@ -175,8 +175,6 @@ namespace Emby.Drawing.Skia public ImageSize GetImageSize(string path) { - CheckDisposed(); - using (var s = new SKFileStream(path)) { using (var codec = SKCodec.Create(s)) @@ -192,19 +190,27 @@ namespace Emby.Drawing.Skia } } + private string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" }; private SKBitmap Decode(string path) { - using (var stream = new SKFileStream(path)) + var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty); + + if (requiresTransparencyHack) { - var codec = SKCodec.Create(stream); + using (var stream = new SKFileStream(path)) + { + var codec = SKCodec.Create(stream); - // create the bitmap - var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height); - // decode - codec.GetPixels(bitmap.Info, bitmap.GetPixels()); + // create the bitmap + var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height); + // decode + codec.GetPixels(bitmap.Info, bitmap.GetPixels()); - return bitmap; + return bitmap; + } } + + return SKBitmap.Decode(path); } private SKBitmap GetBitmap(string path, bool cropWhitespace) @@ -215,7 +221,7 @@ namespace Emby.Drawing.Skia { return CropWhiteSpace(bitmap); } - } + } return Decode(path); } @@ -236,11 +242,11 @@ namespace Emby.Drawing.Skia var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor); var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer); var blur = options.Blur ?? 0; - var hasIndicator = !options.AddPlayedIndicator && !options.UnplayedCount.HasValue && options.PercentPlayed.Equals(0); + var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0); using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace)) { - using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType)) + using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { // scale image var resizeMethod = SKBitmapResizeMethod.Lanczos3; @@ -258,7 +264,7 @@ namespace Emby.Drawing.Skia } // create bitmap to use for canvas drawing - using (var saveBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType)) + using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { // create canvas used to draw into bitmap using (var canvas = new SKCanvas(saveBitmap)) @@ -275,7 +281,7 @@ namespace Emby.Drawing.Skia using (var paint = new SKPaint()) { // create image from resized bitmap to apply blur - using (var filter = SKImageFilter.CreateBlur(5, 5)) + using (var filter = SKImageFilter.CreateBlur(blur, blur)) { paint.ImageFilter = filter; canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint); @@ -294,8 +300,7 @@ namespace Emby.Drawing.Skia Double opacity; if (!Double.TryParse(options.ForegroundLayer, out opacity)) opacity = .4; - var foregroundColor = String.Format("#{0:X2}000000", (Byte)((1 - opacity) * 0xFF)); - canvas.DrawColor(SKColor.Parse(foregroundColor), SKBlendMode.SrcOver); + canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver); } if (hasIndicator) @@ -365,18 +370,8 @@ namespace Emby.Drawing.Skia get { return "Skia"; } } - private bool _disposed; public void Dispose() { - _disposed = true; - } - - private void CheckDisposed() - { - if (_disposed) - { - throw new ObjectDisposedException(GetType().Name); - } } public bool SupportsImageCollageCreation From 5d027aabd91131afb53ce530c5c7cc9f23274258 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 May 2017 01:16:46 -0400 Subject: [PATCH 6/6] 3.2.15.4 --- SharedVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SharedVersion.cs b/SharedVersion.cs index 8a2e19849..42c165086 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.15.3")] +[assembly: AssemblyVersion("3.2.15.4")]