diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config new file mode 100644 index 000000000..67f8ea046 --- /dev/null +++ b/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.nuget/NuGet.exe.REMOVED.git-id b/.nuget/NuGet.exe.REMOVED.git-id new file mode 100644 index 000000000..3379f42e0 --- /dev/null +++ b/.nuget/NuGet.exe.REMOVED.git-id @@ -0,0 +1 @@ +9ca66594f912a1fe7aec510819006fb1a80bc1a9 \ No newline at end of file diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets new file mode 100644 index 000000000..3f8c37b22 --- /dev/null +++ b/.nuget/NuGet.targets @@ -0,0 +1,144 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + + + + + $(SolutionDir).nuget + + + + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config + + + + $(MSBuildProjectDirectory)\packages.config + $(PackagesProjectConfig) + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 "$(NuGetExePath)" + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ImageProcessor.sln b/ImageProcessor.sln index 4be37800d..b2056a4ad 100644 --- a/ImageProcessor.sln +++ b/ImageProcessor.sln @@ -9,6 +9,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Tests", "tes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3D5BCCE2-A7EB-4453-9A86-A9C55CCFDCDF}" ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets .nuget\packages.config = .nuget\packages.config EndProjectSection EndProject diff --git a/src/ImageProcessor/Colors/Color.cs b/src/ImageProcessor/Colors/Color.cs index f7335e4aa..0b7785d22 100644 --- a/src/ImageProcessor/Colors/Color.cs +++ b/src/ImageProcessor/Colors/Color.cs @@ -12,7 +12,6 @@ namespace ImageProcessor { using System; using System.ComponentModel; - using System.Globalization; using System.Runtime.InteropServices; /// @@ -222,6 +221,29 @@ namespace ImageProcessor return !left.Equals(right); } + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator Color(YCbCrColor color) + { + float y = color.Y; + float cb = color.Cb - 128; + float cr = color.Cr - 128; + + byte r = Convert.ToByte((y + (1.402 * cr)).Clamp(0, 255)); + byte g = Convert.ToByte((y - (0.34414 * cb) - (0.71414 * cr)).Clamp(0, 255)); + byte b = Convert.ToByte((y + (1.772 * cb)).Clamp(0, 255)); + + return new Color(b, g, r, 255); + } + /// /// Indicates whether this instance and a specified object are equal. /// @@ -260,10 +282,12 @@ namespace ImageProcessor /// public override string ToString() { - return "{B=" + this.B.ToString(CultureInfo.CurrentCulture) - + ",G=" + this.G.ToString(CultureInfo.CurrentCulture) - + ",R=" + this.R.ToString(CultureInfo.CurrentCulture) - + ",A=" + this.A.ToString(CultureInfo.CurrentCulture) + "}"; + if (this.IsEmpty) + { + return "Color [Empty]"; + } + + return string.Format("Color [ B={0}, G={1}, R={2}, A={3} ]", this.B, this.G, this.R, this.A); } /// diff --git a/src/ImageProcessor/Colors/YCbCrColor.cs b/src/ImageProcessor/Colors/YCbCrColor.cs new file mode 100644 index 000000000..5fa4eaa0c --- /dev/null +++ b/src/ImageProcessor/Colors/YCbCrColor.cs @@ -0,0 +1,223 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. +// +// +// Represents an YCbCr (luminance, chroma, chroma) color conforming to the +// ITU-R BT.601 standard used in digital imaging systems. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor +{ + using System; + using System.ComponentModel; + + /// + /// Represents an YCbCr (luminance, chroma, chroma) color conforming to the + /// ITU-R BT.601 standard used in digital imaging systems. + /// + /// + public struct YCbCrColor : IEquatable + { + /// + /// Represents a that has Y, Cb, and Cr values set to zero. + /// + public static readonly YCbCrColor Empty = new YCbCrColor(); + + /// + /// Holds the Y luminance component. + /// A value ranging between 0 and 255. + /// + public float Y; + + /// + /// Holds the Cb chroma component. + /// A value ranging between 0 and 255. + /// + public float Cb; + + /// + /// Holds the Cr chroma component. + /// A value ranging between 0 and 255. + /// + public float Cr; + + /// + /// The epsilon for comparing floating point numbers. + /// + private const float Epsilon = 0.0001f; + + /// + /// Initializes a new instance of the struct. + /// + /// The y luminance component. + /// The cb chroma component. + /// The cr chroma component. + public YCbCrColor(float y, float cb, float cr) + { + this.Y = y.Clamp(0, 255); + this.Cb = cb.Clamp(0, 255); + this.Cr = cr.Clamp(0, 255); + } + + /// + /// Gets a value indicating whether this is empty. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsEmpty + { + get + { + return Math.Abs(this.Y) < Epsilon + && Math.Abs(this.Cb) < Epsilon + && Math.Abs(this.Cr) < Epsilon; + } + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are equal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + public static bool operator ==(YCbCrColor left, YCbCrColor right) + { + return left.Equals(right); + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are unequal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is unequal to the parameter; otherwise, false. + /// + public static bool operator !=(YCbCrColor left, YCbCrColor right) + { + return !left.Equals(right); + } + + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator YCbCrColor(Color color) + { + byte r = color.R; + byte g = color.G; + byte b = color.B; + + float y = (float)((0.299 * r) + (0.587 * g) + (0.114 * b)); + float cb = 128 + (float)((-0.168736 * r) - (0.331264 * g) + (0.5 * b)); + float cr = 128 + (float)((0.5 * r) - (0.418688 * g) - (0.081312 * b)); + + return new YCbCrColor(y, cb, cr); + } + + /// + /// Indicates whether this instance and a specified object are equal. + /// + /// + /// true if and this instance are the same type and represent the same value; otherwise, false. + /// + /// Another object to compare to. + public override bool Equals(object obj) + { + if (obj is YCbCrColor) + { + YCbCrColor color = (YCbCrColor)obj; + + return Math.Abs(this.Y - color.Y) < Epsilon + && Math.Abs(this.Cb - color.Cb) < Epsilon + && Math.Abs(this.Cr - color.Cr) < Epsilon; + } + + return false; + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() + { + return this.GetHashCode(this); + } + + /// + /// Returns the fully qualified type name of this instance. + /// + /// + /// A containing a fully qualified type name. + /// + public override string ToString() + { + if (this.IsEmpty) + { + return "YCbCrColor [Empty]"; + } + + return string.Format("YCbCrColor [ Y={0:#0.##}, Cb={1:#0.##}, Cr={2:#0.##}]", this.Y, this.Cb, this.Cr); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// True if the current object is equal to the parameter; otherwise, false. + /// + /// An object to compare with this object. + public bool Equals(YCbCrColor other) + { + return this.Y.Equals(other.Y) + && this.Cb.Equals(other.Cb) + && this.Cr.Equals(other.Cr); + } + + /// + /// Returns the hash code for the given instance. + /// + /// + /// The instance of to return the hash code for. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + private int GetHashCode(YCbCrColor color) + { + unchecked + { + int hashCode = color.Y.GetHashCode(); + hashCode = (hashCode * 397) ^ color.Cb.GetHashCode(); + hashCode = (hashCode * 397) ^ color.Cr.GetHashCode(); + return hashCode; + } + } + } +} diff --git a/src/ImageProcessor/Common/Extensions/ComparableExtensions.cs b/src/ImageProcessor/Common/Extensions/ComparableExtensions.cs index cc6fd6052..3bf82c25f 100644 --- a/src/ImageProcessor/Common/Extensions/ComparableExtensions.cs +++ b/src/ImageProcessor/Common/Extensions/ComparableExtensions.cs @@ -32,5 +32,30 @@ namespace ImageProcessor { return (value.CompareTo(min) > 0) && (value.CompareTo(max) < 0); } + + /// + /// Restricts a value to be within a specified range. + /// + /// The The value to clamp. + /// The minimum value. If value is less than min, min will be returned. + /// The maximum value. If value is greater than max, max will be returned. + /// The to clamp. + /// + /// The representing the clamped value. + /// + public static T Clamp(this T value, T min, T max) where T : IComparable + { + if (value.CompareTo(min) < 0) + { + return min; + } + + if (value.CompareTo(max) > 0) + { + return max; + } + + return value; + } } } diff --git a/src/ImageProcessor/Common/Helpers/Guard.cs b/src/ImageProcessor/Common/Helpers/Guard.cs index fcf85907d..f3983bd68 100644 --- a/src/ImageProcessor/Common/Helpers/Guard.cs +++ b/src/ImageProcessor/Common/Helpers/Guard.cs @@ -95,6 +95,27 @@ namespace ImageProcessor } } + /// + /// Verifies that the specified value is less than or equal to a maximum value + /// and throws an exception if it is not. + /// + /// The target value, which should be validated. + /// The maximum value. + /// The name of the parameter that is to be checked. + /// The type of the value. + /// + /// is greater than the maximum value. + /// + public static void LessEquals(TValue value, TValue max, string parameterName) where TValue : IComparable + { + if (value.CompareTo(max) > 0) + { + throw new ArgumentOutOfRangeException( + parameterName, + string.Format(CultureInfo.CurrentCulture, "Value must be less than or equal to {0}", max)); + } + } + /// /// Verifies that the specified value is greater than a minimum value /// and throws an exception if it is not. @@ -115,5 +136,26 @@ namespace ImageProcessor string.Format(CultureInfo.CurrentCulture, "Value must be greater than {0}", min)); } } + + /// + /// Verifies that the specified value is greater than or equal to a minimum value + /// and throws an exception if it is not. + /// + /// The target value, which should be validated. + /// The minimum value. + /// The name of the parameter that is to be checked. + /// The type of the value. + /// + /// is less than the minimum value. + /// + public static void GreaterEquals(TValue value, TValue min, string parameterName) where TValue : IComparable + { + if (value.CompareTo(min) < 0) + { + throw new ArgumentOutOfRangeException( + parameterName, + string.Format(CultureInfo.CurrentCulture, "Value must be greater than or equal to {0}", min)); + } + } } } diff --git a/src/ImageProcessor/Formats/Gif/GifDecoder.cs b/src/ImageProcessor/Formats/Gif/GifDecoder.cs index 056aee7e4..15bca5e40 100644 --- a/src/ImageProcessor/Formats/Gif/GifDecoder.cs +++ b/src/ImageProcessor/Formats/Gif/GifDecoder.cs @@ -165,11 +165,12 @@ if (_descriptor.Width > ImageBase.MaxWidth || _descriptor.Height > ImageBase.MaxHeight) { throw new ArgumentOutOfRangeException( - string.Format("The input gif '{0}x{1}' is bigger then the max allowed size '{2}x{3}'", - _descriptor.Width, - _descriptor.Height, - ImageBase.MaxWidth, - ImageBase.MaxHeight)); + string.Format( + "The input gif '{0}x{1}' is bigger then the max allowed size '{2}x{3}'", + _descriptor.Width, + _descriptor.Height, + ImageBase.MaxWidth, + ImageBase.MaxHeight)); } } @@ -341,7 +342,7 @@ if (_graphicsControl != null && _graphicsControl.DelayTime > 0) { - _image.DelayTime = _graphicsControl.DelayTime; + _image.FrameDelay = _graphicsControl.DelayTime; } } else diff --git a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs index f0fec8d04..c7d81cd19 100644 --- a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs +++ b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs @@ -188,8 +188,8 @@ namespace ImageProcessor.Formats Array.Reverse(data, 0, 4); Array.Reverse(data, 4, 4); - this.currentImage.DensityX = BitConverter.ToInt32(data, 0) / 39.3700787d; - this.currentImage.DensityY = BitConverter.ToInt32(data, 4) / 39.3700787d; + this.currentImage.HorizontalResolution = BitConverter.ToInt32(data, 0) / 39.3700787d; + this.currentImage.VerticalResolution = BitConverter.ToInt32(data, 4) / 39.3700787d; } /// diff --git a/src/ImageProcessor/Formats/Png/PngEncoder.cs b/src/ImageProcessor/Formats/Png/PngEncoder.cs index a4e64d6f5..750ef0313 100644 --- a/src/ImageProcessor/Formats/Png/PngEncoder.cs +++ b/src/ImageProcessor/Formats/Png/PngEncoder.cs @@ -203,10 +203,10 @@ namespace ImageProcessor.Formats private void WritePhysicalChunk(Stream stream, ImageBase imageBase) { Image image = imageBase as Image; - if (image != null && image.DensityX > 0 && image.DensityY > 0) + if (image != null && image.HorizontalResolution > 0 && image.VerticalResolution > 0) { - int dpmX = (int)Math.Round(image.DensityX * 39.3700787d); - int dpmY = (int)Math.Round(image.DensityY * 39.3700787d); + int dpmX = (int)Math.Round(image.HorizontalResolution * 39.3700787d); + int dpmY = (int)Math.Round(image.VerticalResolution * 39.3700787d); byte[] chunkData = new byte[9]; diff --git a/src/ImageProcessor/Image.cs b/src/ImageProcessor/Image.cs index 6e8d116ab..48fbffeb8 100644 --- a/src/ImageProcessor/Image.cs +++ b/src/ImageProcessor/Image.cs @@ -1,4 +1,15 @@ -namespace ImageProcessor +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. +// +// +// Image class which stores the pixels and provides common functionality +// such as loading images from files and streams or operation like resizing or cropping. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor { using System; using System.Collections.Generic; @@ -10,87 +21,172 @@ using ImageProcessor.Formats; /// - /// Image class with stores the pixels and provides common functionality - /// such as loading images from files and streams or operation like resizing or cutting. + /// Image class which stores the pixels and provides common functionality + /// such as loading images from files and streams or operation like resizing or cropping. /// - /// The image data is alway stored in RGBA format, where the red, the blue, the - /// alpha values are simple bytes. - [DebuggerDisplay("Image: {PixelWidth}x{PixelHeight}")] + /// + /// The image data is always stored in BGRA format, where the blue, green, red, and + /// alpha values are simple bytes. + /// + [DebuggerDisplay("Image: {Width}x{Height}")] public class Image : ImageBase { - #region Constants - /// - /// The default density value (dots per inch) in x direction. The default value is 75 dots per inch. + /// The default horizontal resolution value (dots per inch) in x direction. + /// The default value is 96 dots per inch. /// - public const double DefaultDensityX = 75; + public const double DefaultHorizontalResolution = 96; + /// - /// The default density value (dots per inch) in y direction. The default value is 75 dots per inch. + /// The default vertical resolution value (dots per inch) in y direction. + /// The default value is 96 dots per inch. /// - public const double DefaultDensityY = 75; + public const double DefaultVerticalResolution = 96; - private static readonly Lazy> defaultDecoders = new Lazy>(() => new List + /// + /// The default collection of . + /// + private static readonly Lazy> DefaultDecoders = + new Lazy>(() => new List { - //new BmpDecoder(), - //new JpegDecoder(), - //new PngDecoder(), - new GifDecoder(), + // new BmpDecoder(), + // new JpegDecoder(), + new PngDecoder(), + // new GifDecoder(), }); - private static readonly Lazy> defaultEncoders = new Lazy>(() => new List + /// + /// The default collection of . + /// + private static readonly Lazy> DefaultEncoders = + new Lazy>(() => new List { - //new BmpEncoder(), - //new JpegEncoder(), - //new PngEncoder(), + // new BmpEncoder(), + // new JpegEncoder(), + new PngEncoder(), }); /// - /// Gets a list of default decoders. + /// The collection of image frames. /// - public static IList Decoders + private readonly IList frames = new List(); + + /// + /// The collection of image properties. + /// + private readonly IList properties = new List(); + + /// + /// Initializes a new instance of the class. + /// + public Image() { - get { return defaultDecoders.Value; } + this.HorizontalResolution = DefaultHorizontalResolution; + this.VerticalResolution = DefaultVerticalResolution; } /// - /// Gets a list of default encoders. + /// Initializes a new instance of the class + /// with the height and the width of the image. /// - public static IList Encoders + /// The width of the image in pixels. + /// The height of the image in pixels. + public Image(int width, int height) + : base(width, height) { - get { return defaultEncoders.Value; } + this.HorizontalResolution = DefaultHorizontalResolution; + this.VerticalResolution = DefaultVerticalResolution; } - #endregion + /// + /// Initializes a new instance of the class + /// by making a copy from another image. + /// + /// The other image, where the clone should be made from. + /// is null + /// (Nothing in Visual Basic). + public Image(Image other) + : base(other) + { + Guard.NotNull(other, "other", "Other image cannot be null."); + + foreach (ImageFrame frame in other.Frames) + { + if (frame != null) + { + this.Frames.Add(new ImageFrame(frame)); + } + } + + this.HorizontalResolution = DefaultHorizontalResolution; + this.VerticalResolution = DefaultVerticalResolution; + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The stream containing image information. + /// + public Image(Stream stream) + { + Guard.NotNull(stream, "stream"); + this.Load(stream, Decoders); + } - #region Fields + /// + /// Initializes a new instance of the class. + /// + /// + /// The stream containing image information. + /// + /// + /// The collection of . + /// + public Image(Stream stream, params IImageDecoder[] decoders) + { + Guard.NotNull(stream, "stream"); + this.Load(stream, decoders); + } - private readonly object _lockObject = new object(); + /// + /// Gets a list of default decoders. + /// + public static IList Decoders + { + get { return DefaultDecoders.Value; } + } - #endregion + /// + /// Gets a list of default encoders. + /// + public static IList Encoders + { + get { return DefaultEncoders.Value; } + } /// + /// Gets or sets the frame delay. /// If not 0, this field specifies the number of hundredths (1/100) of a second to /// wait before continuing with the processing of the Data Stream. /// The clock starts ticking immediately after the graphic is rendered. /// This field may be used in conjunction with the User Input Flag field. /// - public int? DelayTime { get; set; } - - #region Properties + public int? FrameDelay { get; set; } /// - /// Gets or sets the resolution of the image in x direction. It is defined as + /// Gets or sets the resolution of the image in x- direction. It is defined as /// number of dots per inch and should be an positive value. /// - /// The density of the image in x direction. - public double DensityX { get; set; } + /// The density of the image in x- direction. + public double HorizontalResolution { get; set; } /// - /// Gets or sets the resolution of the image in y direction. It is defined as + /// Gets or sets the resolution of the image in y- direction. It is defined as /// number of dots per inch and should be an positive value. /// - /// The density of the image in y direction. - public double DensityY { get; set; } + /// The density of the image in y- direction. + public double VerticalResolution { get; set; } /// /// Gets the width of the image in inches. It is calculated as the width of the image @@ -102,14 +198,14 @@ { get { - double densityX = DensityX; + double resolution = this.HorizontalResolution; - if (densityX <= 0) + if (resolution <= 0) { - densityX = DefaultDensityX; + resolution = DefaultHorizontalResolution; } - return Width / densityX; + return this.Width / resolution; } } @@ -123,14 +219,14 @@ { get { - double densityY = DensityY; + double resolution = this.VerticalResolution; - if (densityY <= 0) + if (resolution <= 0) { - densityY = DefaultDensityY; + resolution = DefaultVerticalResolution; } - return Height / densityY; + return this.Height / resolution; } } @@ -142,109 +238,39 @@ /// public bool IsAnimated { - get { return _frames.Count > 0; } + get { return this.frames.Count > 0; } } - private IList _frames = new List(); /// - /// Get the other frames for the animation. + /// Gets the other frames for the animation. /// /// The list of frame images. public IList Frames { - get { return _frames; } + get { return this.frames; } } - private IList _properties = new List(); /// /// Gets the list of properties for storing meta information about this image. /// /// A list of image properties. public IList Properties { - get { return _properties; } + get { return this.properties; } } - #endregion - - #region Constructors - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. + /// Loads the image from the given stream. /// - /// The width of the image in pixels. - /// The height of the image in pixels. - public Image(int width, int height) - : base(width, height) - { - DensityX = DefaultDensityX; - DensityY = DefaultDensityY; - } - - /// - /// Initializes a new instance of the class - /// by making a copy from another image. - /// - /// The other image, where the clone should be made from. - /// is null - /// (Nothing in Visual Basic). - public Image(Image other) - : base(other) - { - if (other == null) throw new ArgumentNullException("Other image cannot be null."); - - foreach (ImageFrame frame in other.Frames) - { - if (frame != null) - { - Frames.Add(new ImageFrame(frame)); - } - } - - DensityX = DefaultDensityX; - DensityY = DefaultDensityY; - } - - /// - /// Initializes a new instance of the class. - /// - public Image() - { - DensityX = DefaultDensityX; - DensityY = DefaultDensityY; - } - - /// - /// Initializes a new instance of the class. - /// - public Image(Stream stream) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - Load(stream, Decoders); - } - - /// - /// Initializes a new instance of the class. - /// - public Image(Stream stream, params IImageDecoder[] decoders) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - Load(stream, decoders); - } - - #endregion Constructors - - #region Methods - + /// + /// The stream containing image information. + /// + /// + /// The collection of . + /// + /// + /// Thrown if the stream is not readable nor seekable. + /// private void Load(Stream stream, IList decoders) { try @@ -269,7 +295,7 @@ stream.Read(header, 0, maxHeaderSize); stream.Position = 0; - var decoder = decoders.FirstOrDefault(x => x.IsSupportedFileFormat(header)); + IImageDecoder decoder = decoders.FirstOrDefault(x => x.IsSupportedFileFormat(header)); if (decoder != null) { decoder.Decode(this, stream); @@ -293,7 +319,5 @@ stream.Dispose(); } } - - #endregion Methods } } diff --git a/src/ImageProcessor/ImageBase.cs b/src/ImageProcessor/ImageBase.cs index 951a6af9d..e6c280e44 100644 --- a/src/ImageProcessor/ImageBase.cs +++ b/src/ImageProcessor/ImageBase.cs @@ -17,7 +17,7 @@ namespace ImageProcessor /// The base class of all images. Encapsulates the basic properties and methods /// required to manipulate images. /// - public abstract class ImageBase + public abstract class ImageBase { /// /// The maximum allowable width in pixels. @@ -50,15 +50,8 @@ namespace ImageProcessor /// protected ImageBase(int width, int height) { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width", "Width must be greater than or equals than zero."); - } - - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height", "Height must be greater than or equal than zero."); - } + Guard.GreaterThan(width, 0, "width"); + Guard.GreaterThan(height, 0, "height"); this.Width = width; this.Height = height; @@ -77,10 +70,7 @@ namespace ImageProcessor /// protected ImageBase(ImageBase other) { - if (other == null) - { - throw new ArgumentNullException("other", "Other image cannot be null."); - } + Guard.NotNull(other, "other", "Other image cannot be null."); byte[] pixels = other.Pixels; diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 1553528c3..eec1241b1 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -15,6 +15,8 @@ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Profile78 v4.5 + ..\..\ + true true @@ -36,8 +38,10 @@ + + @@ -82,6 +86,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +