From c53589347240c2ed797d8da3656686560a7b57e6 Mon Sep 17 00:00:00 2001 From: winscripter <142818255+winscripter@users.noreply.github.com> Date: Tue, 18 Aug 2026 22:34:14 +0400 Subject: [PATCH] Zero-copy input access (prototype 3) --- .../Jxl/Processing/Decoder/JxlDecoderCore.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs index 6466c8226..d1edd36b9 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs @@ -858,12 +858,6 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable return JxlSignature.Invalid; } - private static JxlSignature DetectSignature(ReadOnlySpan buffer, int length) - { - int position = 0; - return DetectSignature(buffer, length, ref position); - } - private static int BitsPerChannel(JxlDataType dataType) => dataType switch { @@ -1146,9 +1140,8 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable return false; } - this.codestreamCopy.Write(this.nextInput!.Memory.Span[..(int)avail]); - - this.AdvanceInput(avail); + using IMemoryOwner codestreamPending = this.Options.Configuration.MemoryAllocator.Allocate((int)avail); + this.codestreamCopy.Write(codestreamPending.Memory.Span); } else { @@ -1170,7 +1163,7 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable { long avail = this.AvailableCodeStream(); long skip = Math.Min(this.codestreamPos, avail); - this.AdvanceInput(skip); + this.Skip(skip); this.codestreamPos -= skip; if (this.codestreamPos > 0) @@ -2235,7 +2228,8 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable if (this.storeExif == 1 || this.storeXmp == 1) { - IMemoryOwner metadata = (this.storeExif == 1 ? this.exifMetadata : this.xmpMetadata) ?? throw new InvalidOperationException("Metadata is missing, but should be present"); + IMemoryOwner metadata = (this.storeExif == 1 ? this.exifMetadata : this.xmpMetadata) + ?? throw new InvalidOperationException("Metadata is missing, but should be present"); // Boxes should not contain more than 64MiB data. const long blockSizeLimit = 64L << 20;