From c079cf9165a30b24764ea6a6e64218236b6074a7 Mon Sep 17 00:00:00 2001
From: winscripter <142818255+winscripter@users.noreply.github.com>
Date: Mon, 24 Aug 2026 23:49:27 +0400
Subject: [PATCH] Add missing types, rename JxlBitDepth metadata to
JxlBitDepthMetadata, reduce errors in JxlDecoderCore
---
...{JxlBitDepth.cs => JxlBitDepthMetadata.cs} | 6 ++--
.../Jxl/IO/Metadata/JxlExtraChannelInfo.cs | 2 +-
.../Jxl/IO/Metadata/JxlImageMetadata.cs | 2 +-
.../Jxl/Processing/Decoder/JxlDecoderCore.cs | 36 +++----------------
.../Formats/Jxl/Processing/JxlBitDepth.cs | 27 ++++++++++++++
.../Formats/Jxl/Processing/JxlBitDepthType.cs | 35 ++++++++++++++++++
.../Formats/Jxl/Processing/JxlDataType.cs | 31 ++++++++++++++++
.../Formats/Jxl/Processing/JxlEndianness.cs | 25 +++++++++++++
.../Formats/Jxl/Processing/JxlPixelFormat.cs | 34 ++++++++++++++++++
9 files changed, 162 insertions(+), 36 deletions(-)
rename src/ImageSharp/Formats/Jxl/IO/Metadata/{JxlBitDepth.cs => JxlBitDepthMetadata.cs} (96%)
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/JxlBitDepth.cs
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/JxlBitDepthType.cs
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/JxlDataType.cs
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/JxlEndianness.cs
create mode 100644 src/ImageSharp/Formats/Jxl/Processing/JxlPixelFormat.cs
diff --git a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepth.cs b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepthMetadata.cs
similarity index 96%
rename from src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepth.cs
rename to src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepthMetadata.cs
index 0a9db0f57..a6c9f7248 100644
--- a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepth.cs
+++ b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepthMetadata.cs
@@ -8,15 +8,15 @@ namespace SixLabors.ImageSharp.Formats.Jxl.IO.Metadata;
///
/// Represents the JPEG XL Bit Depth image metadata.
///
-internal sealed class JxlBitDepth : IJxlFields
+internal sealed class JxlBitDepthMetadata : IJxlFields
{
private uint bitsPerSample;
private uint exponentBitsPerSample;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- public JxlBitDepth() => JxlBundle.Init(this);
+ public JxlBitDepthMetadata() => JxlBundle.Init(this);
///
/// Gets or sets a value indicating whether
diff --git a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlExtraChannelInfo.cs b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlExtraChannelInfo.cs
index 5b492b102..16e149d1d 100644
--- a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlExtraChannelInfo.cs
+++ b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlExtraChannelInfo.cs
@@ -11,7 +11,7 @@ internal sealed class JxlExtraChannelInfo : IJxlFields
public JxlExtraChannel Type { get; set; }
- public JxlBitDepth? BitDepth { get; set; }
+ public JxlBitDepthMetadata? BitDepth { get; set; }
public int DimensionShift { get; set; }
diff --git a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlImageMetadata.cs b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlImageMetadata.cs
index 1fcf00b6f..e05bb0951 100644
--- a/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlImageMetadata.cs
+++ b/src/ImageSharp/Formats/Jxl/IO/Metadata/JxlImageMetadata.cs
@@ -10,7 +10,7 @@ internal sealed class JxlImageMetadata : IJxlFields
{
public bool AllDefault { get; set; }
- public JxlBitDepth? BitDepth { get; set; }
+ public JxlBitDepthMetadata? BitDepth { get; set; }
public bool Modular16BitBufferSufficient { get; set; } // Otherwise, 32 is
diff --git a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
index 30dc630ff..35c52cc46 100644
--- a/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
@@ -442,7 +442,7 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable
///
/// Bit depth for image output.
///
- private JxlBitDepth imageOutputBitDepth = new();
+ private JxlBitDepthMetadata imageOutputBitDepth = new();
public JxlDecoderCore(DecoderOptions options)
: base(options)
@@ -595,32 +595,6 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable
Container
}
- ///
- /// Represents a data type.
- ///
- private enum JxlDataType : byte
- {
- ///
- ///
- ///
- UInt8,
-
- ///
- ///
- ///
- UInt16,
-
- ///
- ///
- ///
- Float,
-
- ///
- ///
- ///
- Float16
- }
-
///
/// Frame stage for this decoder.
///
@@ -858,12 +832,12 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable
return JxlSignature.Invalid;
}
- private static int BitsPerChannel(JxlDataType dataType)
+ private static uint BitsPerChannel(JxlDataType dataType)
=> dataType switch
{
- JxlDataType.UInt8 => 8,
- JxlDataType.UInt16 or JxlDataType.Float16 => 16,
- JxlDataType.Float => 32,
+ JxlDataType.Byte => 8,
+ JxlDataType.UInt16 or JxlDataType.Half => 16,
+ JxlDataType.Single => 32,
_ => 0
};
diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepth.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepth.cs
new file mode 100644
index 000000000..52b384bb9
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepth.cs
@@ -0,0 +1,27 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing;
+
+///
+/// Describes the interpretation of the input and output
+/// buffers.
+///
+internal struct JxlBitDepth
+{
+ ///
+ /// Gets or sets the kind of bit depth.
+ ///
+ public JxlBitDepthType Type { get; set; }
+
+ ///
+ /// Gets or sets the number of bits per sample when the
+ /// bit depth type is custom.
+ ///
+ public uint BitsPerSample { get; set; }
+
+ ///
+ /// Gets or sets the custom exponent bits per sample.
+ ///
+ public uint ExponentBitsPerSample { get; set; }
+}
diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepthType.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepthType.cs
new file mode 100644
index 000000000..e942d57a4
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/JxlBitDepthType.cs
@@ -0,0 +1,35 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing;
+
+///
+/// Specifies the kind of bit depth.
+///
+internal enum JxlBitDepthType : byte
+{
+ ///
+ /// Default setting, where the encoder expects the
+ /// input pixels to use the full range of the pixel format
+ /// data type (e.g. for ushort, the input range is 0..65535
+ /// and the value 65535 is mapped to 1.0 when converting
+ /// to float), and the decoder uses the full range to output
+ /// pixels.
+ ///
+ FromPixelFormat,
+
+ ///
+ /// When selected, the encoder expects the input pixels
+ /// to be in the range defined by the bits per sample value of the
+ /// basic info (e.g., for 12-bit images using ushort data types
+ /// the range is 0..4095 and the 4095 value is mapped to 1.0 when
+ /// converting to float), and the decoder outputs pixels in
+ /// this range.
+ ///
+ FromCodeStream,
+
+ ///
+ /// Specifies custom ranges for pixel outputs.
+ ///
+ Custom = 2,
+}
diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlDataType.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlDataType.cs
new file mode 100644
index 000000000..a9c8057e6
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/JxlDataType.cs
@@ -0,0 +1,31 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing;
+
+///
+/// Specifies which data type to use for sample values
+/// per channel per pixel.
+///
+internal enum JxlDataType : byte
+{
+ ///
+ /// Use float
+ ///
+ Single = 0,
+
+ ///
+ /// Use byte. May clip wide color gamut data.
+ ///
+ Byte = 2,
+
+ ///
+ /// Use ushort. May clip wide color gamut data.
+ ///
+ UInt16 = 3,
+
+ ///
+ /// Use 16-bit IEEE 754 half-precision floating-point values.
+ ///
+ Half = 5
+}
diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlEndianness.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlEndianness.cs
new file mode 100644
index 000000000..a7c9dbc1a
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/JxlEndianness.cs
@@ -0,0 +1,25 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing;
+
+///
+/// Specifies the ordering of multi-byte data.
+///
+internal enum JxlEndianness : byte
+{
+ ///
+ /// Use endianness of the CPU/system.
+ ///
+ Native,
+
+ ///
+ /// Force little endian.
+ ///
+ Little,
+
+ ///
+ /// Force big endian.
+ ///
+ Big
+}
diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlPixelFormat.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlPixelFormat.cs
new file mode 100644
index 000000000..15aa58715
--- /dev/null
+++ b/src/ImageSharp/Formats/Jxl/Processing/JxlPixelFormat.cs
@@ -0,0 +1,34 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.Formats.Jxl.Processing;
+
+///
+/// Data type for the sample values per channel per pixel
+/// for the output buffer for pixels.
+///
+internal struct JxlPixelFormat
+{
+ ///
+ /// Gets or sets the amount of channels available in a pixel buffer.
+ ///
+ public int Channels { get; set; }
+
+ ///
+ /// Gets or sets the data type of each channel.
+ ///
+ public JxlDataType DataType { get; set; }
+
+ ///
+ /// Gets or sets a value that denotes whether multi-byte data types are represented in
+ /// big-endian or little-endian format. Applies to ushort
+ /// and float data types.
+ ///
+ public JxlEndianness Endianness { get; set; }
+
+ ///
+ /// Gets or sets the alignment of scanlines to a multiple of
+ /// align bytes.
+ ///
+ public int Align { get; set; }
+}