소스 검색

use image magick for auto-orientation

Luke Pulverenti 9 년 전
부모
커밋
f380ddc558

+ 1 - 1
Emby.Drawing/Emby.Drawing.csproj

@@ -37,7 +37,7 @@
     </Reference>
     <Reference Include="ImageMagickSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\packages\ImageMagickSharp.1.0.0.17\lib\net45\ImageMagickSharp.dll</HintPath>
+      <HintPath>..\packages\ImageMagickSharp.1.0.0.18\lib\net45\ImageMagickSharp.dll</HintPath>
     </Reference>
     <Reference Include="Patterns.Logging">
       <HintPath>..\packages\Patterns.Logging.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\Patterns.Logging.dll</HintPath>

+ 1 - 1
Emby.Drawing/GDI/GDIImageEncoder.cs

@@ -89,7 +89,7 @@ namespace Emby.Drawing.GDI
             }
         }
 
-        public void EncodeImage(string inputPath, string cacheFilePath, int rotationAngle, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
+        public void EncodeImage(string inputPath, string cacheFilePath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
         {
             var hasPostProcessing = !string.IsNullOrEmpty(options.BackgroundColor) || options.UnplayedCount.HasValue || options.AddPlayedIndicator || options.PercentPlayed > 0;
 

+ 2 - 2
Emby.Drawing/IImageEncoder.cs

@@ -27,13 +27,13 @@ namespace Emby.Drawing
         /// </summary>
         /// <param name="inputPath">The input path.</param>
         /// <param name="outputPath">The output path.</param>
-        /// <param name="rotationAngle">The rotation angle.</param>
+        /// <param name="autoOrient">if set to <c>true</c> [automatic orient].</param>
         /// <param name="width">The width.</param>
         /// <param name="height">The height.</param>
         /// <param name="quality">The quality.</param>
         /// <param name="options">The options.</param>
         /// <param name="outputFormat">The output format.</param>
-        void EncodeImage(string inputPath, string outputPath, int rotationAngle, int width, int height, int quality, ImageProcessingOptions options, ImageFormat outputFormat);
+        void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat outputFormat);
 
         /// <summary>
         /// Creates the image collage.

+ 10 - 5
Emby.Drawing/ImageMagick/ImageMagickEncoder.cs

@@ -139,7 +139,7 @@ namespace Emby.Drawing.ImageMagick
                 string.Equals(ext, ".webp", StringComparison.OrdinalIgnoreCase);
         }
 
-        public void EncodeImage(string inputPath, string outputPath, int rotationAngle, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
+        public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
         {
             // Even if the caller specified 100, don't use it because it takes forever
             quality = Math.Min(quality, 99);
@@ -150,9 +150,9 @@ namespace Emby.Drawing.ImageMagick
                 {
                     ScaleImage(originalImage, width, height);
 
-                    if (rotationAngle > 0)
+                    if (autoOrient)
                     {
-                        RotateImage(originalImage, rotationAngle);
+                        AutoOrientImage(originalImage);
                     }
 
                     DrawIndicator(originalImage, width, height, options);
@@ -171,9 +171,9 @@ namespace Emby.Drawing.ImageMagick
                     {
                         ScaleImage(originalImage, width, height);
 
-                        if (rotationAngle > 0)
+                        if (autoOrient)
                         {
-                            RotateImage(originalImage, rotationAngle);
+                            AutoOrientImage(originalImage);
                         }
 
                         wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0);
@@ -189,6 +189,11 @@ namespace Emby.Drawing.ImageMagick
             SaveDelay();
         }
 
+        private void AutoOrientImage(MagickWand wand)
+        {
+            wand.CurrentImage.AutoOrientImage();
+        }
+
         public static void RotateImage(MagickWand wand, float angle)
         {
             using (var pixelWand = new PixelWand("none", 1))

+ 19 - 22
Emby.Drawing/ImageProcessor.cs

@@ -257,7 +257,7 @@ namespace Emby.Drawing
 
                     imageProcessingLockTaken = true;
 
-                    _imageEncoder.EncodeImage(originalImagePath, cacheFilePath, GetRotationAngle(options.Item), newWidth, newHeight, quality, options, outputFormat);
+                    _imageEncoder.EncodeImage(originalImagePath, cacheFilePath, AutoOrient(options.Item), newWidth, newHeight, quality, options, outputFormat);
                 }
 
                 return new Tuple<string, string>(cacheFilePath, GetMimeType(outputFormat, cacheFilePath));
@@ -281,35 +281,32 @@ namespace Emby.Drawing
             }
         }
 
-        private int GetRotationAngle(IHasImages item)
+        private bool AutoOrient(IHasImages item)
         {
             var photo = item as Photo;
             if (photo != null && photo.Orientation.HasValue)
             {
-                switch (photo.Orientation.Value)
-                {
-                    case ImageOrientation.TopLeft:
-                        return 0;
-                    case ImageOrientation.TopRight:
-                        return 0;
-                    case ImageOrientation.BottomLeft:
-                        return 270;
-                    case ImageOrientation.BottomRight:
-                        return 180;
-                    case ImageOrientation.LeftBottom:
-                        return -90;
-                    case ImageOrientation.LeftTop:
-                        return 0;
-                    case ImageOrientation.RightBottom:
-                        return 0;
-                    case ImageOrientation.RightTop:
-                        return 90;
-                }
+                return true;
             }
 
-            return 0;
+            return false;
         }
 
+        //private static  int[][] OPERATIONS = new int[][] {
+        // TopLeft
+        //new int[] {  0, NONE},
+        // TopRight
+        //new int[] {  0, HORIZONTAL},
+        //new int[] {180, NONE},
+        // LeftTop
+        //new int[] {  0, VERTICAL},
+        //new int[] { 90, HORIZONTAL},
+        // RightTop
+        //new int[] { 90, NONE},
+        //new int[] {-90, HORIZONTAL},
+        //new int[] {-90, NONE},
+        //};
+
         private string GetMimeType(ImageFormat format, string path)
         {
             if (format == ImageFormat.Bmp)

+ 1 - 1
Emby.Drawing/NullImageEncoder.cs

@@ -32,7 +32,7 @@ namespace Emby.Drawing
             throw new NotImplementedException();
         }
 
-        public void EncodeImage(string inputPath, string outputPath, int rotationAngle, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
+        public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
         {
             throw new NotImplementedException();
         }

+ 1 - 1
Emby.Drawing/packages.config

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="CommonIO" version="1.0.0.7" targetFramework="net45" />
-  <package id="ImageMagickSharp" version="1.0.0.17" targetFramework="net45" />
+  <package id="ImageMagickSharp" version="1.0.0.18" targetFramework="net45" />
   <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
 </packages>

+ 1 - 1
MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj

@@ -67,7 +67,7 @@
     </Reference>
     <Reference Include="ImageMagickSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\packages\ImageMagickSharp.1.0.0.17\lib\net45\ImageMagickSharp.dll</HintPath>
+      <HintPath>..\packages\ImageMagickSharp.1.0.0.18\lib\net45\ImageMagickSharp.dll</HintPath>
     </Reference>
     <Reference Include="MediaBrowser.IsoMounter">
       <HintPath>..\packages\MediaBrowser.IsoMounting.3.0.69\lib\net45\MediaBrowser.IsoMounter.dll</HintPath>

+ 1 - 1
MediaBrowser.ServerApplication/packages.config

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="CommonIO" version="1.0.0.7" targetFramework="net45" />
-  <package id="ImageMagickSharp" version="1.0.0.17" targetFramework="net45" />
+  <package id="ImageMagickSharp" version="1.0.0.18" targetFramework="net45" />
   <package id="MediaBrowser.IsoMounting" version="3.0.69" targetFramework="net45" />
   <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
   <package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net45" />