Browse Source

Add ANS entropy structs

Add JxlAnsEntry and JxlAnsSymbol.

See ans_common.h. These correspond to the Entry and Symbol structures within AliasTable.
pull/3153/head
winscripter 22 hours ago
parent
commit
490f02f080
  1. 31
      src/ImageSharp/Formats/Jxl/IO/JxlAnsEntry.cs
  2. 14
      src/ImageSharp/Formats/Jxl/IO/JxlAnsSymbol.cs

31
src/ImageSharp/Formats/Jxl/IO/JxlAnsEntry.cs

@ -0,0 +1,31 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Jxl.IO;
[StructLayout(LayoutKind.Sequential)]
internal struct JxlAnsEntry
{
// Although the Entry struct looks like this:
// uint8_t cutoff;
// uint8_t right_value;
// uint16_t freq0;
// uint16_t offsets1;
// uint16_t freq1_xor_freq0;
// and clearly uses smaller types (e.g. byte or ushort),
// prefer using int here as otherwise we have to
// introduce many casts: some to assign values, others to
// convert from unsigned to signed kinds.
//
// This struct is 20 bytes which is more than the recommended
// maximum of 16 bytes, but I believe it justifies more due to
// reduced heap allocations that would be introduced if this
// struct would be turned into a class.
public int Entry;
public int RightValue;
public int Frequency0;
public int Offsets1;
public int Frequency1XorFrequency0;
}

14
src/ImageSharp/Formats/Jxl/IO/JxlAnsSymbol.cs

@ -0,0 +1,14 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Jxl.IO;
[StructLayout(LayoutKind.Sequential)]
internal struct JxlAnsSymbol(int value, int offset, int frequency)
{
public int Value = value;
public int Offset = offset;
public int Frequency = frequency;
}
Loading…
Cancel
Save