From 78ad5c91f1f05f46e38def9b8f59418afbb6669d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 2 Sep 2017 01:33:04 -0400 Subject: [PATCH 1/6] update image orientation --- Emby.Drawing.Skia/SkiaEncoder.cs | 130 ++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index 24f586d96e..d25030397c 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -76,7 +76,7 @@ namespace Emby.Drawing.Skia private static bool IsTransparent(SKColor color) { - + return (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0; } @@ -267,7 +267,7 @@ namespace Emby.Drawing.Skia { using (bitmap) { - return RotateAndFlip(bitmap, origin); + return OrientImage(bitmap, origin); } } } @@ -278,6 +278,132 @@ namespace Emby.Drawing.Skia return GetBitmap(path, cropWhitespace, false, out origin); } + private SKBitmap OrientImage(SKBitmap bitmap, SKCodecOrigin origin) + { + //var transformations = { + // 2: { rotate: 0, flip: true}, + // 3: { rotate: 180, flip: false}, + // 4: { rotate: 180, flip: true}, + // 5: { rotate: 90, flip: true}, + // 6: { rotate: 90, flip: false}, + // 7: { rotate: 270, flip: true}, + // 8: { rotate: 270, flip: false}, + //} + + switch (origin) + { + + case SKCodecOrigin.TopRight: + { + var rotated = new SKBitmap(bitmap.Width, bitmap.Height); + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(rotated.Width, 0); + surface.Scale(-1, 1); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.BottomRight: + { + var rotated = new SKBitmap(bitmap.Width, bitmap.Height); + using (var surface = new SKCanvas(rotated)) + { + float px = bitmap.Width; + px /= 2; + + float py = bitmap.Height; + py /= 2; + + surface.RotateDegrees(180, px, py); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.BottomLeft: + { + var rotated = new SKBitmap(bitmap.Width, bitmap.Height); + using (var surface = new SKCanvas(rotated)) + { + float px = bitmap.Width; + px /= 2; + + float py = bitmap.Height; + py /= 2; + + surface.Translate(rotated.Width, 0); + surface.Scale(-1, 1); + + surface.RotateDegrees(180, px, py); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.LeftTop: + { + // TODO: Flip + var rotated = new SKBitmap(bitmap.Height, bitmap.Width); + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(rotated.Width, 0); + surface.RotateDegrees(90); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.RightTop: + { + var rotated = new SKBitmap(bitmap.Height, bitmap.Width); + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(rotated.Width, 0); + surface.RotateDegrees(90); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.RightBottom: + { + // TODO: Flip + var rotated = new SKBitmap(bitmap.Height, bitmap.Width); + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(0, rotated.Height); + surface.RotateDegrees(270); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + case SKCodecOrigin.LeftBottom: + { + var rotated = new SKBitmap(bitmap.Height, bitmap.Width); + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(0, rotated.Height); + surface.RotateDegrees(270); + surface.DrawBitmap(bitmap, 0, 0); + } + + return rotated; + } + + default: + return RotateAndFlip(bitmap, origin); + } + } + private SKBitmap RotateAndFlip(SKBitmap original, SKCodecOrigin origin) { // these are the origins that represent a 90 degree turn in some fashion From 0fd4b0ffca3d409eecc6da5988db874333ad955d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 2 Sep 2017 01:44:47 -0400 Subject: [PATCH 2/6] update image rotation --- Emby.Drawing.Skia/SkiaEncoder.cs | 55 ++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index d25030397c..c3030a2085 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -347,16 +347,29 @@ namespace Emby.Drawing.Skia case SKCodecOrigin.LeftTop: { - // TODO: Flip - var rotated = new SKBitmap(bitmap.Height, bitmap.Width); - using (var surface = new SKCanvas(rotated)) + // TODO: Remove dual canvases, had trouble with flipping + using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width)) { - surface.Translate(rotated.Width, 0); - surface.RotateDegrees(90); - surface.DrawBitmap(bitmap, 0, 0); - } + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(rotated.Width, 0); - return rotated; + surface.RotateDegrees(90); + + surface.DrawBitmap(bitmap, 0, 0); + + } + + var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height); + using (var flippedCanvas = new SKCanvas(flippedBitmap)) + { + flippedCanvas.Translate(flippedBitmap.Width, 0); + flippedCanvas.Scale(-1, 1); + flippedCanvas.DrawBitmap(rotated, 0, 0); + } + + return flippedBitmap; + } } case SKCodecOrigin.RightTop: @@ -374,16 +387,26 @@ namespace Emby.Drawing.Skia case SKCodecOrigin.RightBottom: { - // TODO: Flip - var rotated = new SKBitmap(bitmap.Height, bitmap.Width); - using (var surface = new SKCanvas(rotated)) + // TODO: Remove dual canvases, had trouble with flipping + using (var rotated = new SKBitmap(bitmap.Height, bitmap.Width)) { - surface.Translate(0, rotated.Height); - surface.RotateDegrees(270); - surface.DrawBitmap(bitmap, 0, 0); - } + using (var surface = new SKCanvas(rotated)) + { + surface.Translate(0, rotated.Height); + surface.RotateDegrees(270); + surface.DrawBitmap(bitmap, 0, 0); + } - return rotated; + var flippedBitmap = new SKBitmap(rotated.Width, rotated.Height); + using (var flippedCanvas = new SKCanvas(flippedBitmap)) + { + flippedCanvas.Translate(flippedBitmap.Width, 0); + flippedCanvas.Scale(-1, 1); + flippedCanvas.DrawBitmap(rotated, 0, 0); + } + + return flippedBitmap; + } } case SKCodecOrigin.LeftBottom: From e5c2e4b28d2f3c7141491c910ac5b455a07ec5d8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 2 Sep 2017 15:22:01 -0400 Subject: [PATCH 3/6] add try/catch around service check --- MediaBrowser.ServerApplication/MainStartup.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 6635cddb7b..1429824ff1 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -196,30 +196,37 @@ namespace MediaBrowser.ServerApplication private static bool IsAlreadyRunningAsService(string applicationPath) { - var serviceName = BackgroundService.GetExistingServiceName(); - - WqlObjectQuery wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE State = 'Running' AND Name = '{0}'", serviceName)); - ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery); - ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get(); - - foreach (ManagementObject managementObject in managementObjectCollection) + try { - var obj = managementObject.GetPropertyValue("PathName"); - if (obj == null) - { - continue; - } - var path = obj.ToString(); + var serviceName = BackgroundService.GetExistingServiceName(); - _logger.Info("Service path: {0}", path); - // Need to use indexOf instead of equality because the path will have the full service command line - if (path.IndexOf(applicationPath, StringComparison.OrdinalIgnoreCase) != -1) + WqlObjectQuery wqlObjectQuery = new WqlObjectQuery(string.Format("SELECT * FROM Win32_Service WHERE State = 'Running' AND Name = '{0}'", serviceName)); + ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery); + ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get(); + + foreach (ManagementObject managementObject in managementObjectCollection) { - _logger.Info("The windows service is already running"); - MessageBox.Show("Emby Server is already running as a Windows Service. Only one instance is allowed at a time. To run as a tray icon, shut down the Windows Service."); - return true; + var obj = managementObject.GetPropertyValue("PathName"); + if (obj == null) + { + continue; + } + var path = obj.ToString(); + + _logger.Info("Service path: {0}", path); + // Need to use indexOf instead of equality because the path will have the full service command line + if (path.IndexOf(applicationPath, StringComparison.OrdinalIgnoreCase) != -1) + { + _logger.Info("The windows service is already running"); + MessageBox.Show("Emby Server is already running as a Windows Service. Only one instance is allowed at a time. To run as a tray icon, shut down the Windows Service."); + return true; + } } } + catch (COMException) + { + // Catch errors thrown due to WMI not being initialized + } return false; } From 5c982dab355bb1436acb99f81143ae7be676cb59 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 2 Sep 2017 15:22:19 -0400 Subject: [PATCH 4/6] update image orientation --- Emby.Drawing.Skia/SkiaEncoder.cs | 80 +------------------ .../ApplicationHost.cs | 1 + 2 files changed, 2 insertions(+), 79 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index c3030a2085..b5d6010b07 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -423,88 +423,10 @@ namespace Emby.Drawing.Skia } default: - return RotateAndFlip(bitmap, origin); + return bitmap; } } - private SKBitmap RotateAndFlip(SKBitmap original, SKCodecOrigin origin) - { - // these are the origins that represent a 90 degree turn in some fashion - var differentOrientations = new SKCodecOrigin[] - { - SKCodecOrigin.LeftBottom, - SKCodecOrigin.LeftTop, - SKCodecOrigin.RightBottom, - SKCodecOrigin.RightTop - }; - - // check if we need to turn the image - bool isDifferentOrientation = differentOrientations.Any(o => o == origin); - - // define new width/height - var width = isDifferentOrientation ? original.Height : original.Width; - var height = isDifferentOrientation ? original.Width : original.Height; - - var bitmap = new SKBitmap(width, height, true); - - // todo: the stuff in this switch statement should be rewritten to use pointers - switch (origin) - { - case SKCodecOrigin.LeftBottom: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(y, original.Width - 1 - x, original.GetPixel(x, y)); - break; - - case SKCodecOrigin.RightTop: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(original.Height - 1 - y, x, original.GetPixel(x, y)); - break; - - case SKCodecOrigin.RightBottom: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(original.Height - 1 - y, original.Width - 1 - x, original.GetPixel(x, y)); - - break; - - case SKCodecOrigin.LeftTop: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(y, x, original.GetPixel(x, y)); - break; - - case SKCodecOrigin.BottomLeft: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(x, original.Height - 1 - y, original.GetPixel(x, y)); - break; - - case SKCodecOrigin.BottomRight: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(original.Width - 1 - x, original.Height - 1 - y, original.GetPixel(x, y)); - break; - - case SKCodecOrigin.TopRight: - - for (var x = 0; x < original.Width; x++) - for (var y = 0; y < original.Height; y++) - bitmap.SetPixel(original.Width - 1 - x, y, original.GetPixel(x, y)); - break; - - } - - return bitmap; - } - public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { if (string.IsNullOrWhiteSpace(inputPath)) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index a9d3247e65..b3d39a5206 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1073,6 +1073,7 @@ namespace Emby.Server.Implementations builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion)); builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem)); builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess)); + builder.AppendLine(string.Format("User Interactive: {0}", Environment.UserInteractive)); Type type = Type.GetType("Mono.Runtime"); if (type != null) From 650692dc5e1b08e9cd463f9297e8d34abf3675ba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 2 Sep 2017 16:34:09 -0400 Subject: [PATCH 5/6] update ImageMagickSharp --- Emby.Drawing.ImageMagick/Emby.Drawing.ImageMagick.csproj | 9 ++++----- Emby.Drawing.ImageMagick/packages.config | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Emby.Drawing.ImageMagick/Emby.Drawing.ImageMagick.csproj b/Emby.Drawing.ImageMagick/Emby.Drawing.ImageMagick.csproj index 98e99c92b1..c4cef629ad 100644 --- a/Emby.Drawing.ImageMagick/Emby.Drawing.ImageMagick.csproj +++ b/Emby.Drawing.ImageMagick/Emby.Drawing.ImageMagick.csproj @@ -31,8 +31,7 @@ - ..\packages\ImageMagickSharp.1.0.0.18\lib\net45\ImageMagickSharp.dll - True + ..\packages\ImageMagickSharp.1.0.0.19\lib\net45\ImageMagickSharp.dll @@ -55,9 +54,6 @@ - - - {9142eefa-7570-41e1-bfcc-468bb571af2f} @@ -72,6 +68,9 @@ MediaBrowser.Model + + +