mirror of https://github.com/SixLabors/ImageSharp
77 changed files with 285 additions and 50 deletions
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Jpeg.Data; |
namespace SixLabors.ImageSharp.Formats.Jxl.IO.Jpeg.Data; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Identifies the kind of APP marker in a JPEG file.
|
/// Identifies the kind of APP marker in a JPEG file.
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Jpeg.Data; |
namespace SixLabors.ImageSharp.Formats.Jxl.IO.Jpeg.Data; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Constants used in parsed JPEG data.
|
/// Constants used in parsed JPEG data.
|
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.IO.Jpeg.Data; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Representation of quantization values for an 8x8 pixel block.
|
||||
|
/// </summary>
|
||||
|
internal struct JpegQuantizationTable() |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Quantization values
|
||||
|
/// </summary>
|
||||
|
public InlineArray64<int> Values; |
||||
|
|
||||
|
public int Precision { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the index of the quantization table
|
||||
|
/// as it was parsed from the input JPEG.
|
||||
|
/// </summary>
|
||||
|
public int Index { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets a value indicating whether this table
|
||||
|
/// is the last one within its marker segment.
|
||||
|
/// </summary>
|
||||
|
public bool IsLast { get; set; } = true; |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.IO.Jpeg; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Decodes Huffman codes in a JPEG file for JPEG to JPEG XL encoder.
|
||||
|
/// </summary>
|
||||
|
internal static class JpegHuffmanDecoder |
||||
|
{ |
||||
|
private const int RootTableBits = 8; |
||||
|
private const int LookupSize = 8; |
||||
|
|
||||
|
private static int NextTableBitSize(Span<int> count, int length) |
||||
|
{ |
||||
|
int left = 1 << (length - RootTableBits); |
||||
|
while (length < MaxBitLength) |
||||
|
{ |
||||
|
left -= count[length]; |
||||
|
|
||||
|
if (left <= 0) |
||||
|
{ |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
length++; |
||||
|
left <<= 1; |
||||
|
} |
||||
|
|
||||
|
return length - RootTableBits; |
||||
|
} |
||||
|
|
||||
|
public struct HuffmanTableEntry() |
||||
|
{ |
||||
|
public byte Bits = 0; |
||||
|
public ushort Value = 0xFFFF; |
||||
|
} |
||||
|
} |
||||
@ -1,7 +1,9 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
using SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.AcStrategy; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Base DCT AC coefficient image
|
/// Base DCT AC coefficient image
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.AcStrategy; |
||||
|
|
||||
internal enum JxlAcStrategyType : ushort |
internal enum JxlAcStrategyType : ushort |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Blending; |
||||
|
|
||||
internal sealed class JxlAlphaBlendingInputLayer |
internal sealed class JxlAlphaBlendingInputLayer |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Blending; |
||||
|
|
||||
internal sealed class JxlAlphaBlendingOutput |
internal sealed class JxlAlphaBlendingOutput |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Pointer to DCT AC coefficients
|
/// Pointer to DCT AC coefficients
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Bit size for DCT AC coefficient
|
/// Bit size for DCT AC coefficient
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
internal sealed class JxlDctQuantWeightParameters |
internal sealed class JxlDctQuantWeightParameters |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Pointer to DCT AC coefficients. (Read-only)
|
/// Pointer to DCT AC coefficients. (Read-only)
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Read-only cosine lookups for the Discrete Cosine Transform (DCT),
|
/// Read-only cosine lookups for the Discrete Cosine Transform (DCT),
|
||||
@ -0,0 +1,72 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Encoder.AuxiliaryOutput; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Provides statistics gathered during compression or decompression.
|
||||
|
/// </summary>
|
||||
|
internal sealed class JxlAuxiliaryOutput |
||||
|
{ |
||||
|
public JxlLayerTotals[] Layers { get; set; } = new JxlLayerTotals[JxlAuxiliaryOutputConstants.NumberOfImageLayers]; |
||||
|
|
||||
|
public long NumberOfBlocks { get; set; } |
||||
|
|
||||
|
public long NumberOfSmallBlocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct4x8Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfAfvBlocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct8Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct8x16Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct8x32Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct16Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct16x32Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct32Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct32x64Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfDct64Blocks { get; set; } |
||||
|
|
||||
|
public long NumberOfButteraugliIterations { get; set; } |
||||
|
|
||||
|
public long TotalBits => this.Layers.Sum(x => x.TotalBits); |
||||
|
|
||||
|
public static string GetLayerName(JxlLayerType layer) => layer switch |
||||
|
{ |
||||
|
JxlLayerType.Header => "Headers", |
||||
|
JxlLayerType.Toc => "TOC", |
||||
|
JxlLayerType.Dictionary => "Patches", |
||||
|
JxlLayerType.Splines => "Splines", |
||||
|
JxlLayerType.Noise => "Noise", |
||||
|
JxlLayerType.Quant => "Quantizer", |
||||
|
JxlLayerType.ModularTree => "ModularTree", |
||||
|
JxlLayerType.ModularGlobal => "ModularGlobal", |
||||
|
JxlLayerType.Dc => "DC", |
||||
|
JxlLayerType.ModularDcGroup => "ModularDcGroup", |
||||
|
JxlLayerType.ControlFields => "ControlFields", |
||||
|
JxlLayerType.Order => "CoeffOrder", |
||||
|
JxlLayerType.Ac => "ACHistograms", |
||||
|
JxlLayerType.AcTokens => "ACTokens", |
||||
|
JxlLayerType.ModularAcGroup => "ModularAcGroup", |
||||
|
_ => "Invalid", |
||||
|
}; |
||||
|
|
||||
|
public void Assimilate(JxlAuxiliaryOutput victim) |
||||
|
{ |
||||
|
for (int i = 0; i < JxlAuxiliaryOutputConstants.NumberOfImageLayers; i++) |
||||
|
{ |
||||
|
this.Layers[i].Assimilate(victim.Layers[i]); |
||||
|
} |
||||
|
|
||||
|
this.NumberOfBlocks += victim.NumberOfBlocks; |
||||
|
this.NumberOfSmallBlocks += victim.NumberOfSmallBlocks; |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Encoder.AuxiliaryOutput; |
||||
|
|
||||
|
internal class JxlAuxiliaryOutputConstants |
||||
|
{ |
||||
|
public const int NumberOfImageLayers = (int)JxlLayerType.ModularAcGroup + 1; |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Encoder.AuxiliaryOutput; |
||||
|
|
||||
|
internal struct JxlLayerTotals |
||||
|
{ |
||||
|
public int NumberOfClusteredHistograms; |
||||
|
public int ExtraBits; |
||||
|
public int HistogramBits; |
||||
|
public int TotalBits; |
||||
|
public double ClusteredEntropy; |
||||
|
|
||||
|
public void Assimilate(in JxlLayerTotals victim) |
||||
|
{ |
||||
|
this.NumberOfClusteredHistograms += victim.NumberOfClusteredHistograms; |
||||
|
this.HistogramBits += victim.HistogramBits; |
||||
|
this.ExtraBits += victim.ExtraBits; |
||||
|
this.TotalBits += victim.TotalBits; |
||||
|
this.ClusteredEntropy += victim.ClusteredEntropy; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Encoder.AuxiliaryOutput; |
||||
|
|
||||
|
internal enum JxlLayerType : byte |
||||
|
{ |
||||
|
Header = 0, |
||||
|
Toc, |
||||
|
Dictionary, |
||||
|
Splines, |
||||
|
Noise, |
||||
|
Quant, |
||||
|
ModularTree, |
||||
|
ModularGlobal, |
||||
|
Dc, |
||||
|
ModularDcGroup, |
||||
|
ControlFields, |
||||
|
Order, |
||||
|
Ac, |
||||
|
AcTokens, |
||||
|
ModularAcGroup, |
||||
|
} |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Noise; |
||||
|
|
||||
internal sealed class JxlNoiseParameters |
internal sealed class JxlNoiseParameters |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Describes the interpretation of the input and output
|
/// Describes the interpretation of the input and output
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Specifies the kind of bit depth.
|
/// Specifies the kind of bit depth.
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Specifies which data type to use for sample values
|
/// Specifies which data type to use for sample values
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Inverse Move to Front implementation
|
/// Inverse Move to Front implementation
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Represents a boolean which can be overriden to be a default
|
/// Represents a boolean which can be overriden to be a default
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Override utilities.
|
/// Override utilities.
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Data type for the sample values per channel per pixel
|
/// Data type for the sample values per channel per pixel
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Primitives; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Defines how quickly or slowly to encode an image. Slower
|
/// Defines how quickly or slowly to encode an image. Slower
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Quantization; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Specifies which algorithm should be used to quantize coefficients.
|
/// Specifies which algorithm should be used to quantize coefficients.
|
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Quantization; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Specifies which quantization table to use depending on
|
/// Specifies which quantization table to use depending on
|
||||
@ -1,7 +1,9 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
using SixLabors.ImageSharp.Formats.Jxl.Processing.AcStrategy; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Quantization; |
||||
|
|
||||
internal static class JxlQuantWeights |
internal static class JxlQuantWeights |
||||
{ |
{ |
||||
@ -1,7 +1,7 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Quantization; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Shared constants used by the quantizer.
|
/// Shared constants used by the quantizer.
|
||||
@ -1,7 +1,9 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
using SixLabors.ImageSharp.Formats.Jxl.Processing.Dct; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Quantization; |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Specifies weights and quantizer modes.
|
/// Specifies weights and quantizer modes.
|
||||
Loading…
Reference in new issue