From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id BC9564E84F for <ffmpegdev@gitmailbox.com>; Mon, 17 Mar 2025 10:46:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1975C68BE32; Mon, 17 Mar 2025 12:44:20 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3B3968B722 for <ffmpeg-devel@ffmpeg.org>; Mon, 17 Mar 2025 12:44:06 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id 51C5744634; Mon, 17 Mar 2025 11:44:04 +0100 (CET) From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Mar 2025 11:43:56 +0100 Message-ID: <20250317104357.307832-10-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250317104357.307832-1-ffmpeg@haasn.xyz> References: <20250317104357.307832-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/11] tests/swscale: constrain reference SSIM for low bit depth formats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Niklas Haas <git@haasn.dev> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250317104357.307832-10-ffmpeg@haasn.xyz/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> From: Niklas Haas <git@haasn.dev> Sometimes, the reference SSIM is significantly higher than the SSIM level expected for the test. This is the case when the source format has a much lower bit depth than the destination format. In this case, the fact that legacy swscale does not accurately preserve the source dither pattern gives it an unfair advantage in a direct comparison, leading to false positives. For example, conversion like rgb4 -> rgb565 should be lossless, but swscale low passes / downscales the input chroma, throwing away massive amounts of detail. This gives it a higher SSIM score since the lowpassed result removes some of the dither noise that was present in the source. --- libswscale/tests/swscale.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index bce495db90..117ed2144e 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -321,6 +321,18 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, goto error; get_ssim(ssim_sws, out, ref, comps); + + /* Legacy swscale does not perform bit accurate upconversions of low + * bit depth RGB. This artificially improves the SSIM score because the + * resulting error deletes some of the input dither noise. This gives + * it an unfair advantage when compared against a bit exact reference. + * Work around this by ensuring that the reference SSIM score is not + * higher than it theoretically "should" be. */ + if (src_var > dst_var) { + const float src_loss = (2 * ref_var + c1) / (2 * ref_var + src_var + c1); + ssim_sws[0] = FFMIN(ssim_sws[0], src_loss); + } + ssim_ref = ssim_sws; } -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".