From 7ed5f8fb52639bcb9789d44061fad24866233290 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 20 Jan 2017 12:38:09 +1100 Subject: [PATCH] Much reduce file size for output. All the other encoders were using 4:2:0 --- src/ImageSharp.Formats.Jpeg/JpegEncoder.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp.Formats.Jpeg/JpegEncoder.cs b/src/ImageSharp.Formats.Jpeg/JpegEncoder.cs index a672949c35..6f404c9bb3 100644 --- a/src/ImageSharp.Formats.Jpeg/JpegEncoder.cs +++ b/src/ImageSharp.Formats.Jpeg/JpegEncoder.cs @@ -63,7 +63,13 @@ namespace ImageSharp.Formats /// public void Encode(Image image, Stream stream) where TColor : struct, IPackedPixel, IEquatable - { + { + // Ensure that quality can be set but has a fallback. + if (image.Quality > 0) + { + this.Quality = image.Quality; + } + JpegEncoderCore encode = new JpegEncoderCore(); if (this.subsampleSet) { @@ -71,8 +77,8 @@ namespace ImageSharp.Formats } else { - // Match Photoshop and use 4:2:0 SUpsampling at quality < 51% - encode.Encode(image, stream, this.Quality, this.Quality >= 51 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420); + // Use 4:2:0 Subsampling at quality < 91% for reduced filesize. + encode.Encode(image, stream, this.Quality, this.Quality >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420); } } }