Browse Source

Implement spline abstractions

Implementation of spline.h
pull/3153/head
winscripter 1 day ago
parent
commit
9b58f4b9d5
  1. 2
      src/ImageSharp/Formats/Jxl/InlineArrays.cs
  2. 26
      src/ImageSharp/Formats/Jxl/Splines/JxlQuantizedSpline.cs
  3. 13
      src/ImageSharp/Formats/Jxl/Splines/JxlSpline.cs
  4. 13
      src/ImageSharp/Formats/Jxl/Splines/JxlSplineDataView.cs
  5. 15
      src/ImageSharp/Formats/Jxl/Splines/JxlSplineEntropyContext.cs
  6. 17
      src/ImageSharp/Formats/Jxl/Splines/JxlSplineSegment.cs
  7. 11
      src/ImageSharp/Formats/Jxl/Splines/JxlSplineSegmentSpan.cs

2
src/ImageSharp/Formats/Jxl/Metadata/InlineArrays.cs → src/ImageSharp/Formats/Jxl/InlineArrays.cs

@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
#pragma warning disable SA1649 // File name should match first type name
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata;
namespace SixLabors.ImageSharp.Formats.Jxl;
[InlineArray(3)]
internal struct InlineArray3<T>

26
src/ImageSharp/Formats/Jxl/Splines/JxlQuantizedSpline.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal sealed class JxlQuantizedSpline
{
public JxlQuantizedSpline()
{
for (int i = 0; i < 3; i++)
{
this.ColorDct[i] = new int[32];
}
}
public Dictionary<long, long> ControlPoints { get; set; } = [];
// NOTE: Do not use Configuration.MemoryAllocator.Allocate2D. This is
// a 3x32 array, and renting memory introduces too much overhead for
// 384 bytes of memory.
// Additionally, prefer jagged arrays instead of multidimensional arrays
// for performance.
public int[][] ColorDct { get; set; } = new int[3][];
public int[] SigmaDct { get; set; } = new int[32];
}

13
src/ImageSharp/Formats/Jxl/Splines/JxlSpline.cs

@ -0,0 +1,13 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal sealed class JxlSpline
{
public List<PointF> ControlPoints { get; set; } = [];
public JxlDct32[] ColorDct { get; set; } = [];
public JxlDct32 SigmaDct { get; set; }
}

13
src/ImageSharp/Formats/Jxl/Splines/JxlSplineDataView.cs

@ -0,0 +1,13 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal sealed class JxlSplineDataView
{
public List<JxlQuantizedSpline> Splines { get; set; } = [];
public List<PointF> StartingPoints { get; set; } = [];
public bool HasAny => this.Splines.Count > 0;
}

15
src/ImageSharp/Formats/Jxl/Splines/JxlSplineEntropyContext.cs

@ -0,0 +1,15 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal enum JxlSplineEntropyContext
{
QuantizationAdjustment,
StartingPosition,
NumSplines,
NumControlPoints,
ControlPoints,
Dct,
NumSplineContexts
}

17
src/ImageSharp/Formats/Jxl/Splines/JxlSplineSegment.cs

@ -0,0 +1,17 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal struct JxlSplineSegment
{
public PointF Center { get; set; }
public float MaximumDistance { get; set; }
public float InverseSigma { get; set; }
public float SigmaOver4TimesIntensity { get; set; }
public InlineArray3<float> Color { get; set; }
}

11
src/ImageSharp/Formats/Jxl/Splines/JxlSplineSegmentSpan.cs

@ -0,0 +1,11 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jxl.Splines;
internal struct JxlSplineSegmentSpan(int startInclusive, int endInclusive)
{
public int StartInclusive { get; set; } = startInclusive;
public int EndInclusive { get; set; } = endInclusive;
}
Loading…
Cancel
Save