From b16301b631520a778f2af29acfbeeeebad177bcc Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Sat, 17 Jul 2021 10:19:09 +0300 Subject: [PATCH] Simplified quantization table scaling in the encoder --- src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 135048aa4..60c209c52 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -702,19 +702,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg for (int j = 0; j < Block8x8F.Size; j++) { - int x = unscaledQuant[j]; - x = ((x * scale) + 50) / 100; - if (x < 1) - { - x = 1; - } - - if (x > 255) - { - x = 255; - } - - quant[j] = x; + int scaled = ((unscaledQuant[j] * scale) + 50) / 100; + quant[j] = Math.Clamp(scaled, 1, 255); } } }