aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-11 01:17:42 -0400
committerGitHub <noreply@github.com>2017-05-11 01:17:42 -0400
commite06563831e0f7a5e9a6120ab16decb05a0cde8f7 (patch)
treed4fc4e8ea083d796e598f157ec3c326cc7e706f1
parent6ee9da3717a563d110fc56c93478885d19449cce (diff)
parent5d027aabd91131afb53ce530c5c7cc9f23274258 (diff)
Merge pull request #2629 from MediaBrowser/dev
Dev
-rw-r--r--Emby.Drawing.Skia/SkiaEncoder.cs61
-rw-r--r--Emby.Drawing/ImageProcessor.cs10
-rw-r--r--MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs34
-rw-r--r--MediaBrowser.Model/Drawing/ImageSize.cs6
-rw-r--r--MediaBrowser.ServerApplication/ImageEncoderHelper.cs2
-rw-r--r--SharedVersion.cs2
6 files changed, 81 insertions, 34 deletions
diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs
index d52ad4734..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,17 +190,40 @@ namespace Emby.Drawing.Skia
}
}
+ private string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
+ private SKBitmap Decode(string path)
+ {
+ var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty);
+
+ if (requiresTransparencyHack)
+ {
+ 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;
+ }
+ }
+
+ return SKBitmap.Decode(path);
+ }
+
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)
@@ -221,17 +242,14 @@ 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 = 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);
@@ -246,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))
@@ -263,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);
@@ -282,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)
@@ -353,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
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)
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))
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
{
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")]