Browse Source

EstimateQuality now return if given tables are standard

pull/1706/head
Dmitry Pentin 5 years ago
parent
commit
15d77ddf26
  1. 24
      src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

24
src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs

@ -72,15 +72,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
};
/// <summary>
/// Returns an estimated quality of the image based on the quantization tables.
/// Returns a jpeg quality parameter based on the quantization tables.
/// </summary>
/// <param name="quantizationTables">The quantization tables.</param>
/// <returns>The <see cref="int"/>.</returns>
public static int EstimateQuality(Block8x8F[] quantizationTables)
/// <param name="quality">Jpeg quality parameter</param>
/// <returns><see cref="bool"/> indicating if given quantization tables are equal to standard ITU spec.</returns>
public static bool EstimateQuality(Block8x8F[] quantizationTables, out int quality)
{
DebugGuard.MustBeGreaterThan(quantizationTables.Length, 2, nameof(quantizationTables));
int quality = 75;
quality = 75;
float sum = 0;
for (int i = 0; i < quantizationTables.Length; i++)
@ -115,9 +117,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
continue;
}
if (((quality <= Hash[i]) && (sum <= Sums[i])) || (i >= 50))
bool sumHashCondition = (quality <= Hash[i]) && (sum <= Sums[i]);
if (sumHashCondition || (i >= 50))
{
return i + 1;
quality = i + 1;
return sumHashCondition;
}
}
}
@ -132,15 +136,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
continue;
}
if (((quality <= Hash1[i]) && (sum <= Sums1[i])) || (i >= 50))
bool sumHashCondition = (quality <= Hash1[i]) && (sum <= Sums1[i]);
if (sumHashCondition || (i >= 50))
{
return i + 1;
quality = i + 1;
return sumHashCondition;
}
}
}
}
return quality;
return false;
}
}
}

2
src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// index must be between 0 and 100 (compression from max to min).
/// Defaults to <value>75</value>.
/// </summary>
public int? Quality { get; set; }
public int? Quality { get; set; } = 75;
/// <summary>
/// Gets or sets the subsample ration, that will be used to encode the image.

Loading…
Cancel
Save