aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Drawing')
-rw-r--r--Emby.Drawing/Common/ImageHeader.cs42
-rw-r--r--Emby.Drawing/ImageProcessor.cs22
-rw-r--r--Emby.Drawing/Properties/AssemblyInfo.cs18
3 files changed, 44 insertions, 38 deletions
diff --git a/Emby.Drawing/Common/ImageHeader.cs b/Emby.Drawing/Common/ImageHeader.cs
index 7b819c2fd..3aa0cac25 100644
--- a/Emby.Drawing/Common/ImageHeader.cs
+++ b/Emby.Drawing/Common/ImageHeader.cs
@@ -50,12 +50,13 @@ namespace Emby.Drawing.Common
/// <exception cref="ArgumentException">The image was of an unrecognised format.</exception>
public static ImageSize GetDimensions(string path, ILogger logger, IFileSystem fileSystem)
{
- var extension = Path.GetExtension(path);
-
- if (string.IsNullOrEmpty(extension))
+ if (string.IsNullOrEmpty(path))
{
- throw new ArgumentException("ImageHeader doesn't support image file");
+ throw new ArgumentNullException(nameof(path));
}
+
+ string extension = Path.GetExtension(path).ToLower();
+
if (!SupportedExtensions.Contains(extension))
{
throw new ArgumentException("ImageHeader doesn't support " + extension);
@@ -94,7 +95,7 @@ namespace Emby.Drawing.Common
}
}
- throw new ArgumentException(ErrorMessage, "binaryReader");
+ throw new ArgumentException(ErrorMessage, nameof(binaryReader));
}
/// <summary>
@@ -121,7 +122,7 @@ namespace Emby.Drawing.Common
/// </summary>
/// <param name="binaryReader">The binary reader.</param>
/// <returns>System.Int16.</returns>
- private static short ReadLittleEndianInt16(BinaryReader binaryReader)
+ private static short ReadLittleEndianInt16(this BinaryReader binaryReader)
{
var bytes = new byte[sizeof(short)];
@@ -137,7 +138,7 @@ namespace Emby.Drawing.Common
/// </summary>
/// <param name="binaryReader">The binary reader.</param>
/// <returns>System.Int32.</returns>
- private static int ReadLittleEndianInt32(BinaryReader binaryReader)
+ private static int ReadLittleEndianInt32(this BinaryReader binaryReader)
{
var bytes = new byte[sizeof(int)];
for (int i = 0; i < sizeof(int); i += 1)
@@ -205,25 +206,30 @@ namespace Emby.Drawing.Common
/// <exception cref="System.ArgumentException"></exception>
private static ImageSize DecodeJfif(BinaryReader binaryReader)
{
+ // A JPEG image consists of a sequence of segments,
+ // each beginning with a marker, each of which begins with a 0xFF byte
+ // followed by a byte indicating what kind of marker it is.
+ // Source: https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure
while (binaryReader.ReadByte() == 0xff)
{
byte marker = binaryReader.ReadByte();
- short chunkLength = ReadLittleEndianInt16(binaryReader);
- if (marker == 0xc0)
+ short chunkLength = binaryReader.ReadLittleEndianInt16();
+ // SOF0: Indicates that this is a baseline DCT-based JPEG,
+ // and specifies the width, height, number of components, and component subsampling
+ // SOF2: Indicates that this is a progressive DCT-based JPEG,
+ // and specifies the width, height, number of components, and component subsampling
+ if (marker == 0xc0 || marker == 0xc2)
{
- binaryReader.ReadByte();
- int height = ReadLittleEndianInt16(binaryReader);
- int width = ReadLittleEndianInt16(binaryReader);
- return new ImageSize
- {
- Width = width,
- Height = height
- };
+ // https://help.accusoft.com/ImageGear/v18.2/Windows/ActiveX/IGAX-10-12.html
+ binaryReader.ReadByte(); // We don't care about the first byte
+ int height = binaryReader.ReadLittleEndianInt16();
+ int width = binaryReader.ReadLittleEndianInt16();
+ return new ImageSize(width, height);
}
if (chunkLength < 0)
{
- var uchunkLength = (ushort)chunkLength;
+ ushort uchunkLength = (ushort)chunkLength;
binaryReader.ReadBytes(uchunkLength - 2);
}
else
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index 6a67be56d..4e4b36507 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -80,7 +80,7 @@ namespace Emby.Drawing
{
if (value == null)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
_imageEncoder = value;
@@ -103,7 +103,7 @@ namespace Emby.Drawing
"crw",
// Remove until supported
- //"nef",
+ //"nef",
"orf",
"pef",
"arw",
@@ -179,7 +179,7 @@ namespace Emby.Drawing
{
if (options == null)
{
- throw new ArgumentNullException("options");
+ throw new ArgumentNullException(nameof(options));
}
var originalImage = options.Image;
@@ -491,7 +491,7 @@ namespace Emby.Drawing
{
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentNullException("path");
+ throw new ArgumentNullException(nameof(path));
}
try
@@ -691,12 +691,12 @@ namespace Emby.Drawing
{
if (string.IsNullOrEmpty(originalImagePath))
{
- throw new ArgumentNullException("originalImagePath");
+ throw new ArgumentNullException(nameof(originalImagePath));
}
if (item == null)
{
- throw new ArgumentNullException("item");
+ throw new ArgumentNullException(nameof(item));
}
var treatmentRequiresTransparency = false;
@@ -779,16 +779,16 @@ namespace Emby.Drawing
{
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentNullException("path");
+ throw new ArgumentNullException(nameof(path));
}
if (string.IsNullOrEmpty(uniqueName))
{
- throw new ArgumentNullException("uniqueName");
+ throw new ArgumentNullException(nameof(uniqueName));
}
if (string.IsNullOrEmpty(fileExtension))
{
- throw new ArgumentNullException("fileExtension");
+ throw new ArgumentNullException(nameof(fileExtension));
}
var filename = uniqueName.GetMD5() + fileExtension;
@@ -811,11 +811,11 @@ namespace Emby.Drawing
{
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentNullException("path");
+ throw new ArgumentNullException(nameof(path));
}
if (string.IsNullOrEmpty(filename))
{
- throw new ArgumentNullException("filename");
+ throw new ArgumentNullException(nameof(filename));
}
var prefix = filename.Substring(0, 1);
diff --git a/Emby.Drawing/Properties/AssemblyInfo.cs b/Emby.Drawing/Properties/AssemblyInfo.cs
index b9e9c2ff7..8dfefe0af 100644
--- a/Emby.Drawing/Properties/AssemblyInfo.cs
+++ b/Emby.Drawing/Properties/AssemblyInfo.cs
@@ -1,20 +1,20 @@
-using System.Reflection;
+using System.Reflection;
using System.Runtime.InteropServices;
-// General Information about an assembly is controlled through the following
+// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Emby.Drawing")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Emby.Drawing")]
-[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyCompany("Jellyfin Project")]
+[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
@@ -24,7 +24,7 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values:
//
// Major Version
-// Minor Version
+// Minor Version
// Build Number
// Revision
-// \ No newline at end of file
+//