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