mirror of https://github.com/SixLabors/ImageSharp
11 changed files with 416 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
/// <summary>
|
|||
/// Abstracts enumeration of all fields into a visitor.
|
|||
/// </summary>
|
|||
internal interface IJxlFields |
|||
{ |
|||
/// <summary>
|
|||
/// Visits all fields into the specified JXL visitor.
|
|||
/// </summary>
|
|||
/// <param name="visitor">The visitor to use to visit all fields.</param>
|
|||
/// <returns>Status of the visit operation.</returns>
|
|||
public bool Visit(JxlVisitor visitor); |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
|
|||
#pragma warning disable SA1649 // File name should match first type name
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
[InlineArray(3)] |
|||
internal struct InlineArray3<T> |
|||
{ |
|||
private T first; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Used by JxlCustomTransformData
|
|||
/// </summary>
|
|||
[InlineArray(15)] |
|||
internal struct InlineArray15<T> |
|||
{ |
|||
private T first; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Used by JxlCustomTransformData
|
|||
/// </summary>
|
|||
[InlineArray(55)] |
|||
internal struct InlineArray55<T> |
|||
{ |
|||
private T first; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Used by JxlCustomTransformData
|
|||
/// </summary>
|
|||
[InlineArray(210)] |
|||
internal struct InlineArray210<T> |
|||
{ |
|||
private T first; |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlBitDepth : IJxlFields |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets a value indicating whether
|
|||
/// the original (uncompressed) samples are floating point or
|
|||
/// unsigned integer.
|
|||
/// </summary>
|
|||
public bool FloatingPointSample { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the bit depth of the original (uncompressed) image samples.
|
|||
/// Must be in the range [1, 32].
|
|||
/// </summary>
|
|||
public int BitsPerSample { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// <para>
|
|||
/// Gets or sets floating point exponent bits of the original (uncompressed) image samples,
|
|||
/// only used if <see cref="FloatingPointSample"/> is <see langword="true"/>.
|
|||
/// </para>
|
|||
/// <para>
|
|||
/// If used, the samples are floating point with:
|
|||
/// <list type="bullet">
|
|||
/// <item>1 sign bit</item>
|
|||
/// <item><see cref="ExponentBitsPerSample"/> exponent bits</item>
|
|||
/// <item>(<see cref="BitsPerSample"/> - <see cref="ExponentBitsPerSample"/> - 1) mantissa bits</item>
|
|||
/// </list>
|
|||
/// If used, <see cref="ExponentBitsPerSample"/> must be in the range
|
|||
/// [2, 8] and amount of mantissa bits must be in the range [2, 23].
|
|||
/// </para>
|
|||
/// </summary>
|
|||
public int ExponentBitsPerSample { get; set; } |
|||
|
|||
public bool Visit(JxlVisitor visitor) => throw new NotImplementedException(); |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlCodecMetadata |
|||
{ |
|||
public JxlImageMetadata? ImageMetadata { get; set; } |
|||
|
|||
public SizeHeader Size { get; set; } |
|||
|
|||
public JxlCustomTransformData? CustomTransformData { get; set; } |
|||
|
|||
public int XSize => this.Size.XSize; |
|||
|
|||
public int YSize => this.Size.YSize; |
|||
|
|||
public int GetOrientedPreviewXSize(bool keepOrientation) |
|||
{ |
|||
if (this.ImageMetadata!.Orientation > 4 && !keepOrientation) |
|||
{ |
|||
return this.ImageMetadata.PreviewSize.YSize; |
|||
} |
|||
|
|||
return this.ImageMetadata.PreviewSize.XSize; |
|||
} |
|||
|
|||
public int GetOrientedPreviewYSize(bool keepOrientation) |
|||
{ |
|||
if (this.ImageMetadata!.Orientation > 4 && !keepOrientation) |
|||
{ |
|||
return this.ImageMetadata.PreviewSize.XSize; |
|||
} |
|||
|
|||
return this.ImageMetadata.PreviewSize.YSize; |
|||
} |
|||
|
|||
public int GetOrientedXSize(bool keepOrientation) |
|||
{ |
|||
if (this.ImageMetadata!.Orientation > 4 && !keepOrientation) |
|||
{ |
|||
return this.YSize; |
|||
} |
|||
|
|||
return this.XSize; |
|||
} |
|||
|
|||
public int GetOrientedYSize(bool keepOrientation) |
|||
{ |
|||
if (this.ImageMetadata!.Orientation > 4 && !keepOrientation) |
|||
{ |
|||
return this.XSize; |
|||
} |
|||
|
|||
return this.YSize; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlCustomTransformData : IJxlFields |
|||
{ |
|||
public bool NonserializedXybEncoded { get; set; } |
|||
|
|||
public bool AllDefault { get; set; } |
|||
|
|||
public JxlOpsinInverseMatrix? OpsinInverseMatrix { get; set; } |
|||
|
|||
public int CustomWeightsMask { get; set; } |
|||
|
|||
public InlineArray15<float> Upsampling2Weights { get; set; } |
|||
|
|||
public InlineArray55<float> Upsampling4Weights { get; set; } |
|||
|
|||
public InlineArray210<float> Upsampling8Weights { get; set; } |
|||
|
|||
public bool Visit(JxlVisitor visitor) => throw new NotImplementedException(); |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal enum JxlExifOrientation |
|||
{ |
|||
Identity = 1, |
|||
FlipHorizontal = 2, |
|||
Rotate180 = 3, |
|||
FlipVertical = 4, |
|||
Transponse = 5, |
|||
Rotate90 = 6, |
|||
AntiTranspose = 7, |
|||
Rotate270 = 8 |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal enum JxlExtraChannel |
|||
{ |
|||
Alpha, |
|||
Depth, |
|||
SpotColor, |
|||
SelectionMask, |
|||
Black, |
|||
Cfa, |
|||
Thermal, |
|||
Reserved0, |
|||
Reserved1, |
|||
Reserved2, |
|||
Reserved3, |
|||
Reserved4, |
|||
Reserved5, |
|||
Reserved6, |
|||
Reserved7, |
|||
Unknown, |
|||
Optional |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlExtraChannelInfo : IJxlFields |
|||
{ |
|||
public bool AllDefault { get; set; } |
|||
|
|||
public JxlExtraChannel Type { get; set; } |
|||
|
|||
public JxlBitDepth? BitDepth { get; set; } |
|||
|
|||
public int DimensionShift { get; set; } |
|||
|
|||
public string? Name { get; set; } |
|||
|
|||
public bool AlphaAssociated { get; set; } |
|||
|
|||
public InlineArray4<float> SpotColor { get; set; } |
|||
|
|||
public int CfaChannel { get; set; } |
|||
|
|||
public bool Visit(JxlVisitor visitor) => throw new NotImplementedException(); |
|||
} |
|||
@ -0,0 +1,126 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Diagnostics; |
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlImageMetadata : IJxlFields |
|||
{ |
|||
public bool AllDefault { get; set; } |
|||
|
|||
public JxlBitDepth? BitDepth { get; set; } |
|||
|
|||
public bool Modular16BitBufferSufficient { get; set; } // Otherwise, 32 is
|
|||
|
|||
public bool XybEncoded { get; set; } |
|||
|
|||
public JxlColorEncoding? ColorEncoding { get; set; } |
|||
|
|||
public int Orientation { get; set; } = 1; |
|||
|
|||
public bool HavePreview { get; set; } |
|||
|
|||
public bool HaveAnimation { get; set; } |
|||
|
|||
public bool HaveIntrinsicSize { get; set; } |
|||
|
|||
public JxlSizeHeader IntrinsicSize { get; set; } |
|||
|
|||
public JxlToneMapping? ToneMapping { get; set; } |
|||
|
|||
public int ExtraChannelCount { get; set; } |
|||
|
|||
public List<JxlExtraChannelInfo> ExtraChannels { get; set; } = []; |
|||
|
|||
public JxlPreviewHeader PreviewSize { get; set; } |
|||
|
|||
public JxlAnimationHeader Animation { get; set; } |
|||
|
|||
public long Extensions { get; set; } |
|||
|
|||
public bool NonserializedOnlyParseBasicInfos { get; set; } |
|||
|
|||
public float IntensityTarget |
|||
{ |
|||
get |
|||
{ |
|||
float intensityTarget = this.ToneMapping?.IntensityTarget ?? 0f; |
|||
|
|||
Debug.Assert(intensityTarget != 0f, "Intensity target should be present"); |
|||
|
|||
return intensityTarget; |
|||
} |
|||
|
|||
set |
|||
{ |
|||
if (this.ToneMapping != null) |
|||
{ |
|||
this.ToneMapping.IntensityTarget = value; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public int AlphaBits |
|||
{ |
|||
get |
|||
{ |
|||
JxlExtraChannelInfo? ec = this.FindExtraChannel(JxlExtraChannel.Alpha); |
|||
|
|||
if (ec == null) |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
return ec.BitDepth?.BitsPerSample ?? 0; |
|||
} |
|||
|
|||
set |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public bool HasAlpha => this.AlphaBits != 0; |
|||
|
|||
public JxlExtraChannelInfo? FindExtraChannel(JxlExtraChannel type) |
|||
=> this.ExtraChannels.FirstOrDefault(eci => eci.Type == type); |
|||
|
|||
public JxlExifOrientation GetExifOrientation() => (JxlExifOrientation)this.Orientation; |
|||
|
|||
public void SetFloat16Samples() |
|||
{ |
|||
if (this.BitDepth != null) |
|||
{ |
|||
this.BitDepth.BitsPerSample = 16; |
|||
this.BitDepth.ExponentBitsPerSample = 5; |
|||
this.BitDepth.FloatingPointSample = true; |
|||
} |
|||
|
|||
this.Modular16BitBufferSufficient = false; |
|||
} |
|||
|
|||
public void SetFloat32Samples() |
|||
{ |
|||
if (this.BitDepth != null) |
|||
{ |
|||
this.BitDepth.BitsPerSample = 32; |
|||
this.BitDepth.ExponentBitsPerSample = 8; |
|||
this.BitDepth.FloatingPointSample = true; |
|||
} |
|||
|
|||
this.Modular16BitBufferSufficient = false; |
|||
} |
|||
|
|||
public void SetUIntSamples(int bits) |
|||
{ |
|||
if (this.BitDepth != null) |
|||
{ |
|||
this.BitDepth.BitsPerSample = bits; |
|||
this.BitDepth.ExponentBitsPerSample = 0; |
|||
this.BitDepth.FloatingPointSample = false; |
|||
} |
|||
|
|||
this.Modular16BitBufferSufficient = bits <= 12; |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlOpsinInverseMatrix : IJxlFields |
|||
{ |
|||
public bool AllDefault { get; set; } |
|||
|
|||
public JxlMatrix3x3 InverseMatrix { get; set; } |
|||
|
|||
public InlineArray3<float> OpsinBiases { get; set; } |
|||
|
|||
public InlineArray4<float> QuantBiases { get; set; } |
|||
|
|||
public bool Visit(JxlVisitor visitor) => throw new NotImplementedException(); |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Jxl.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jxl.Metadata; |
|||
|
|||
internal sealed class JxlToneMapping : IJxlFields |
|||
{ |
|||
public bool AllDefault { get; set; } |
|||
|
|||
public float IntensityTarget { get; set; } |
|||
|
|||
public float LowerBoundIntensityLevel { get; set; } |
|||
|
|||
public bool RelativeToMaxDisplay { get; set; } |
|||
|
|||
public float LinearBelow { get; set;} |
|||
|
|||
public bool Visit(JxlVisitor visitor) => throw new NotImplementedException(); |
|||
} |
|||
Loading…
Reference in new issue