Browse Source

Optimizer png decoder

Former-commit-id: 6afd500e211d77bca5af0c73d92a3ceaab4878ab
Former-commit-id: 66438d73c511f56b5fb456f7c45936a7bb2a36a1
Former-commit-id: 00b0db078bba8ba8aa474759bb6252af5a0bc056
af/merge-core
James Jackson-South 11 years ago
parent
commit
0805029dbf
  1. 19
      src/ImageProcessor/Common/Extensions/ComparableExtensions.cs
  2. 6
      src/ImageProcessor/Formats/Png/PngDecoderCore.cs

19
src/ImageProcessor/Common/Extensions/ComparableExtensions.cs

@ -17,22 +17,6 @@ namespace ImageProcessor
/// </summary> /// </summary>
internal static class ComparableExtensions internal static class ComparableExtensions
{ {
/// <summary>
/// Returns value indicating whether the given number is with in the minimum and maximum
/// given range.
/// </summary>
/// <param name="value">The value to to check. </param>
/// <param name="min">The minimum range value.</param>
/// <param name="max">The maximum range value.</param>
/// <typeparam name="T">The <see cref="System.Type"/> to test.</typeparam>
/// <returns>
/// True if the value falls within the maximum and minimum; otherwise, false.
/// </returns>
public static bool IsBetween<T>(this T value, T min, T max) where T : IComparable<T>
{
return (value.CompareTo(min) > 0) && (value.CompareTo(max) < 0);
}
/// <summary> /// <summary>
/// Restricts a value to be within a specified range. /// Restricts a value to be within a specified range.
/// </summary> /// </summary>
@ -43,7 +27,8 @@ namespace ImageProcessor
/// <returns> /// <returns>
/// The <see cref="IComparable{T}"/> representing the clamped value. /// The <see cref="IComparable{T}"/> representing the clamped value.
/// </returns> /// </returns>
public static T Clamp<T>(this T value, T min, T max) where T : IComparable<T> public static T Clamp<T>(this T value, T min, T max)
where T : IComparable<T>
{ {
if (value.CompareTo(min) < 0) if (value.CompareTo(min) < 0)
{ {

6
src/ImageProcessor/Formats/Png/PngDecoderCore.cs

@ -449,7 +449,7 @@ namespace ImageProcessor.Formats
byte[] crcBuffer = new byte[4]; byte[] crcBuffer = new byte[4];
int numBytes = this.currentStream.Read(crcBuffer, 0, 4); int numBytes = this.currentStream.Read(crcBuffer, 0, 4);
if (numBytes.IsBetween(1, 3)) if (numBytes >= 1 && numBytes <= 3)
{ {
throw new ImageFormatException("Image stream is not valid!"); throw new ImageFormatException("Image stream is not valid!");
} }
@ -501,7 +501,7 @@ namespace ImageProcessor.Formats
byte[] typeBuffer = new byte[4]; byte[] typeBuffer = new byte[4];
int numBytes = this.currentStream.Read(typeBuffer, 0, 4); int numBytes = this.currentStream.Read(typeBuffer, 0, 4);
if (numBytes.IsBetween(1, 3)) if (numBytes >= 1 && numBytes <= 3)
{ {
throw new ImageFormatException("Image stream is not valid!"); throw new ImageFormatException("Image stream is not valid!");
} }
@ -532,7 +532,7 @@ namespace ImageProcessor.Formats
byte[] lengthBuffer = new byte[4]; byte[] lengthBuffer = new byte[4];
int numBytes = this.currentStream.Read(lengthBuffer, 0, 4); int numBytes = this.currentStream.Read(lengthBuffer, 0, 4);
if (numBytes.IsBetween(1, 3)) if (numBytes >= 1 && numBytes <= 3)
{ {
throw new ImageFormatException("Image stream is not valid!"); throw new ImageFormatException("Image stream is not valid!");
} }

Loading…
Cancel
Save