Browse Source

Implement CreateFlatHistogram

See ans_common.h
pull/3153/head
winscripter 3 days ago
parent
commit
528149fc1c
  1. 24
      src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs

24
src/ImageSharp/Formats/Jxl/IO/JxlAnsHelper.cs

@ -22,4 +22,28 @@ internal static class JxlAnsHelper
return r;
}
// NOTE: The result may potentially be large, so prefer using a memory allocator
public static IMemoryOwner<int> CreateFlatHistogram(Configuration configuration, int length, int totalCount)
{
Debug.Assert(length <= 0, "Length should be >= 0");
Debug.Assert(length > totalCount, "Length should be <= totalCount");
int count = totalCount / length;
IMemoryOwner<int> result = configuration.MemoryAllocator.Allocate<int>(length);
Span<int> resultSpan = result.Memory.Span;
for (int i = 0; i < length; i++)
{
resultSpan[i] = count;
}
int remCounts = totalCount % length;
for (int i = 0; i < remCounts; i++)
{
resultSpan[i]++;
}
return result;
}
}

Loading…
Cancel
Save