Browse Source

Add patch dictionary stage

pull/3153/head
winscripter 1 month ago
parent
commit
64edab5721
  1. 2
      src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlPatchDictionary.cs
  2. 40
      src/ImageSharp/Formats/Jxl/Processing/RenderPipeline/PatchDictionaryStage.cs
  3. 6
      src/ImageSharp/Formats/Jxl/Processing/RenderPipeline/RenderPipelineStageBase.cs

2
src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlPatchDictionary.cs

@ -53,7 +53,7 @@ internal sealed class JxlPatchDictionary
this.blendingsStride = (int)(numExtraChannels + 1);
List<byte> contextMap = [];
var code = new JxlAnsCode();
JxlAnsCode code = new();
var status = DecodeHistograms(
memoryManager,

40
src/ImageSharp/Formats/Jxl/Processing/RenderPipeline/PatchDictionaryStage.cs

@ -0,0 +1,40 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Drawing;
using SixLabors.ImageSharp.Formats.Jxl.IO.Metadata;
using SixLabors.ImageSharp.Formats.Jxl.Processing.Decoder;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.RenderPipeline;
internal sealed class PatchDictionaryStage(Configuration configuration, JxlPatchDictionary patches, List<JxlExtraChannelInfo> extraChannelInfos)
: RenderPipelineStageBase(configuration)
{
/// <inheritdoc />
public override string Name => "Patches";
/// <inheritdoc />
public override void ProcessRow(Buffer2D<Memory<float>> inputRows, Buffer2D<Memory<float>> outputRows, int xExtraLeft, int xExtraRight, int width, int xPos, int yPos)
{
int channels = 3 + extraChannelInfos.Count;
Span<Memory<float>> rowPtrs = new Memory<float>[channels];
for (int i = 0; i < channels; i++)
{
rowPtrs[i] = this.GetInputRowMemory(inputRows, i, 0, xExtraLeft);
}
return patches.AddOneRow(rowPtrs, yPos, xPos - xExtraLeft, width + xExtraLeft + xExtraRight, extraChannelInfos);
}
/// <inheritdoc />
public override RenderPipelineChannelMode GetChannelMode(int channel)
{
int numChannels = 3 + extraChannelInfos.Count;
return channel < numChannels
? RenderPipelineChannelMode.InPlace
: RenderPipelineChannelMode.Ignored;
}
}

6
src/ImageSharp/Formats/Jxl/Processing/RenderPipeline/RenderPipelineStageBase.cs

@ -71,9 +71,15 @@ internal abstract class RenderPipelineStageBase(Configuration configuration) : I
public Span<float> GetInputRow(Buffer2D<Memory<float>> inputRows, int c, int offset)
=> inputRows[c, this.Settings.BorderY + offset].Span[RenderPipelineXOffset..];
public Span<float> GetInputRow(Buffer2D<Memory<float>> inputRows, int c, int offset, int xExtraLeft)
=> inputRows[c, this.Settings.BorderY + offset].Span[(RenderPipelineXOffset - xExtraLeft)..];
public Memory<float> GetInputRowMemory(Buffer2D<Memory<float>> inputRows, int c, int offset)
=> inputRows[c, this.Settings.BorderY + offset][RenderPipelineXOffset..];
public Memory<float> GetInputRowMemory(Buffer2D<Memory<float>> inputRows, int c, int offset, int xExtraLeft)
=> inputRows[c, this.Settings.BorderY + offset][(RenderPipelineXOffset - xExtraLeft)..];
public static Span<float> GetOutputRow(Buffer2D<Memory<float>> outputRows, int c, int offset)
=> outputRows[c, offset].Span[RenderPipelineXOffset..];

Loading…
Cancel
Save