diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
index 8c014ecda5..e9d67d1ba9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/QualityEvaluator.cs
@@ -72,15 +72,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
};
///
- /// Returns an estimated quality of the image based on the quantization tables.
+ /// Returns a jpeg quality parameter based on the quantization tables.
///
/// The quantization tables.
- /// The .
- public static int EstimateQuality(Block8x8F[] quantizationTables)
+ /// Jpeg quality parameter
+ /// indicating if given quantization tables are equal to standard ITU spec.
+ 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;
}
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
index 8131f74d26..b95dd5644e 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
+++ b/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 75.
///
- public int? Quality { get; set; }
+ public int? Quality { get; set; } = 75;
///
/// Gets or sets the subsample ration, that will be used to encode the image.