From 9ad02108f331abab74d824c16285d31c93d7fdb0 Mon Sep 17 00:00:00 2001
From: winscripter <142818255+winscripter@users.noreply.github.com>
Date: Wed, 2 Sep 2026 20:25:37 +0400
Subject: [PATCH] Add IJxlImageOutput
---
.../Jxl/Processing/Decoder/JxlDecoderCore.cs | 3 +-
.../Jxl/Processing/Image/IJxlImageOutput.cs | 54 +++++++++++++++++++
.../Jxl/Processing/Primitives/Delegates.cs | 25 ---------
3 files changed, 55 insertions(+), 27 deletions(-)
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/Image/IJxlImageOutput.cs
delete mode 100644 src/ImageSharp/Formats/Jxl/Processing/Primitives/Delegates.cs
diff --git a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
index 6a850d8288..4606b6d338 100644
--- a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
@@ -1928,8 +1928,7 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable
new PixelCallback(
this.imageOutputInitCallback,
this.imageOutputRunCallback,
- this.imageOutputDestroyCallback,
- this.imageOutputInitOpaque),
+ this.imageOutputDestroyCallback),
this.imageOutBuffer,
this.imageOutputSize,
dimensions.Width,
diff --git a/src/ImageSharp/Formats/Jxl/Processing/Image/IJxlImageOutput.cs b/src/ImageSharp/Formats/Jxl/Processing/Image/IJxlImageOutput.cs
new file mode 100644
index 0000000000..72d631ff3b
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/Image/IJxlImageOutput.cs
@@ -0,0 +1,54 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives;
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Image;
+
+///
+/// Abstracts a way for the codec to output images during decoding.
+///
+internal interface IJxlImageOutput : IDisposable
+{
+ ///
+ /// Gets or sets the pixel format for the output pixels.
+ ///
+ public JxlPixelFormat PixelFormat { get; set; }
+
+ ///
+ /// Gets or sets the output bit depth for unsigned data types.
+ ///
+ public int BitsPerSample { get; set; }
+
+ ///
+ /// Gets or sets the pixel buffer for image output.
+ ///
+ public Memory Buffer { get; set; }
+
+ ///
+ /// Gets or sets length of a row of image buffer in bytes.
+ ///
+ public int Stride { get; set; }
+
+ ///
+ /// Outputs the image.
+ ///
+ /// Data where the image should be output.
+ /// X offset
+ /// Y offset
+ /// Pixels to output.
+ public void Output(
+ Span data,
+ int x,
+ int y,
+ Span pixels);
+
+ ///
+ /// Initializes image data.
+ ///
+ /// Output image data.
+ /// Number of pixels a thread processes.
+ public void Initialize(
+ Span data,
+ int numPixelsPerThread);
+}
diff --git a/src/ImageSharp/Formats/Jxl/Processing/Primitives/Delegates.cs b/src/ImageSharp/Formats/Jxl/Processing/Primitives/Delegates.cs
deleted file mode 100644
index e0f7c78a33..0000000000
--- a/src/ImageSharp/Formats/Jxl/Processing/Primitives/Delegates.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Six Labors Split License.
-
-namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives;
-
-internal delegate void JxlImageOutputCallback(
- Span data,
- int x,
- int y,
- int numPixels,
- Span pixels);
-
-internal delegate void JxlImageOutputInitializeCallback(
- Span data,
- int numThreads,
- int numPixelsPerThread);
-
-internal delegate void JxlImageOutputRunCallback(
- Span data,
- int x,
- int y,
- int numPixels,
- Span pixels);
-
-internal delegate void JxlImageOutputDestroyCallback(Span data);