Browse Source

Add missing types, rename JxlBitDepth metadata to JxlBitDepthMetadata, reduce errors in JxlDecoderCore

pull/3153/head
winscripter 1 week ago
parent
commit
c079cf9165
  1. 6
      src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepthMetadata.cs
  2. 2
      src/ImageSharp/Formats/Jxl/IO/Metadata/JxlExtraChannelInfo.cs
  3. 2
      src/ImageSharp/Formats/Jxl/IO/Metadata/JxlImageMetadata.cs
  4. 36
      src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs
  5. 27
      src/ImageSharp/Formats/Jxl/Processing/JxlBitDepth.cs
  6. 35
      src/ImageSharp/Formats/Jxl/Processing/JxlBitDepthType.cs
  7. 31
      src/ImageSharp/Formats/Jxl/Processing/JxlDataType.cs
  8. 25
      src/ImageSharp/Formats/Jxl/Processing/JxlEndianness.cs
  9. 34
      src/ImageSharp/Formats/Jxl/Processing/JxlPixelFormat.cs

6
src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepth.cs → src/ImageSharp/Formats/Jxl/IO/Metadata/JxlBitDepthMetadata.cs

@ -8,15 +8,15 @@ namespace SixLabors.ImageSharp.Formats.Jxl.IO.Metadata;
/// <summary>
/// Represents the JPEG XL Bit Depth image metadata.
/// </summary>
internal sealed class JxlBitDepth : IJxlFields
internal sealed class JxlBitDepthMetadata : IJxlFields
{
private uint bitsPerSample;
private uint exponentBitsPerSample;
/// <summary>
/// Initializes a new instance of the <see cref="JxlBitDepth"/> class.
/// Initializes a new instance of the <see cref="JxlBitDepthMetadata"/> class.
/// </summary>
public JxlBitDepth() => JxlBundle.Init(this);
public JxlBitDepthMetadata() => JxlBundle.Init(this);
/// <summary>
/// Gets or sets a value indicating whether

2
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; }

2
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

36
src/ImageSharp/Formats/Jxl/Processing/Decoder/JxlDecoderCore.cs

@ -442,7 +442,7 @@ internal sealed class JxlDecoderCore : ImageDecoderCore, IDisposable
/// <summary>
/// Bit depth for image output.
/// </summary>
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
}
/// <summary>
/// Represents a data type.
/// </summary>
private enum JxlDataType : byte
{
/// <summary>
/// <see cref="byte"/>
/// </summary>
UInt8,
/// <summary>
/// <see cref="ushort"/>
/// </summary>
UInt16,
/// <summary>
/// <see cref="float"/>
/// </summary>
Float,
/// <summary>
/// <see cref="Half"/>
/// </summary>
Float16
}
/// <summary>
/// Frame stage for this decoder.
/// </summary>
@ -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
};

27
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;
/// <summary>
/// Describes the interpretation of the input and output
/// buffers.
/// </summary>
internal struct JxlBitDepth
{
/// <summary>
/// Gets or sets the kind of bit depth.
/// </summary>
public JxlBitDepthType Type { get; set; }
/// <summary>
/// Gets or sets the number of bits per sample when the
/// bit depth type is custom.
/// </summary>
public uint BitsPerSample { get; set; }
/// <summary>
/// Gets or sets the custom exponent bits per sample.
/// </summary>
public uint ExponentBitsPerSample { get; set; }
}

35
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;
/// <summary>
/// Specifies the kind of bit depth.
/// </summary>
internal enum JxlBitDepthType : byte
{
/// <summary>
/// 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.
/// </summary>
FromPixelFormat,
/// <summary>
/// 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.
/// </summary>
FromCodeStream,
/// <summary>
/// Specifies custom ranges for pixel outputs.
/// </summary>
Custom = 2,
}

31
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;
/// <summary>
/// Specifies which data type to use for sample values
/// per channel per pixel.
/// </summary>
internal enum JxlDataType : byte
{
/// <summary>
/// Use float
/// </summary>
Single = 0,
/// <summary>
/// Use byte. May clip wide color gamut data.
/// </summary>
Byte = 2,
/// <summary>
/// Use ushort. May clip wide color gamut data.
/// </summary>
UInt16 = 3,
/// <summary>
/// Use 16-bit IEEE 754 half-precision floating-point values.
/// </summary>
Half = 5
}

25
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;
/// <summary>
/// Specifies the ordering of multi-byte data.
/// </summary>
internal enum JxlEndianness : byte
{
/// <summary>
/// Use endianness of the CPU/system.
/// </summary>
Native,
/// <summary>
/// Force little endian.
/// </summary>
Little,
/// <summary>
/// Force big endian.
/// </summary>
Big
}

34
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;
/// <summary>
/// Data type for the sample values per channel per pixel
/// for the output buffer for pixels.
/// </summary>
internal struct JxlPixelFormat
{
/// <summary>
/// Gets or sets the amount of channels available in a pixel buffer.
/// </summary>
public int Channels { get; set; }
/// <summary>
/// Gets or sets the data type of each channel.
/// </summary>
public JxlDataType DataType { get; set; }
/// <summary>
/// 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.
/// </summary>
public JxlEndianness Endianness { get; set; }
/// <summary>
/// Gets or sets the alignment of scanlines to a multiple of
/// align bytes.
/// </summary>
public int Align { get; set; }
}
Loading…
Cancel
Save