From 396cd8d2cb3c7f325518075cb6d2101301ec1562 Mon Sep 17 00:00:00 2001 From: winscripter <142818255+winscripter@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:53:33 +0400 Subject: [PATCH] Implement JxlAnsHelper.GetPopulationCountPrecision See ans_common.h --- src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs diff --git a/src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs b/src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs new file mode 100644 index 0000000000..babbfe8fd5 --- /dev/null +++ b/src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Buffers; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Formats.Jxl.IO.JxlAnsConstants; + +namespace SixLabors.ImageSharp.Formats.Jxl.IO; + +internal static class JxlAnsHelper +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetPopulationCountPrecision(int logCount, int shift) + { + int r = Math.Min(logCount, shift - ((AnsLogTableSize - logCount) >> 1)); + + if (r < 0) + { + return 0; + } + + return r; + } +}