diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs
index e0886e134..4cd852f10 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs
@@ -3,7 +3,6 @@
// Licensed under the Apache License, Version 2.0.
//
// ReSharper disable InconsistentNaming
-
namespace ImageSharp.Formats
{
using System;
@@ -19,6 +18,7 @@ namespace ImageSharp.Formats
internal partial struct Block8x8F
{
#pragma warning disable SA1204 // Static members must appear before non-static members
+
///
/// Vector count
///
@@ -116,7 +116,7 @@ namespace ImageSharp.Formats
float* fPtr = (float*)blockPtr;
for (int i = 0; i < ScalarCount; i++)
{
- dest[i] = (byte) *fPtr;
+ dest[i] = (byte)*fPtr;
fPtr++;
}
}
@@ -146,7 +146,7 @@ namespace ImageSharp.Formats
Marshal.Copy((IntPtr)ptr, dest.Data, dest.Offset, ScalarCount);
}
}
-
+
///
/// Copy raw 32bit floating point data to dest
///
diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
index 7d5932b21..744ed363b 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
diff --git a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffIndex.cs b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffIndex.cs
index a4265ea8e..d53ac90a8 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffIndex.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffIndex.cs
@@ -1,4 +1,8 @@
-namespace ImageSharp.Formats.Jpg.Components.Encoder
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+namespace ImageSharp.Formats.Jpg.Components.Encoder
{
///
/// Enumerates the Huffman tables
diff --git a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanLut.cs
index 93b412b25..ec6c86041 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanLut.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanLut.cs
@@ -1,4 +1,9 @@
-namespace ImageSharp.Formats.Jpg.Components.Encoder
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Formats.Jpg.Components.Encoder
{
///
/// A compiled look-up table representation of a huffmanSpec.
@@ -9,9 +14,26 @@
internal struct HuffmanLut
{
///
- /// Initializes a new instance of the class.
+ /// The compiled representations of theHuffmanSpec.
+ ///
+ public static readonly HuffmanLut[] TheHuffmanLut = new HuffmanLut[4];
+
+ ///
+ /// Initializes static members of the struct.
+ ///
+ static HuffmanLut()
+ {
+ // Initialize the Huffman tables
+ for (int i = 0; i < HuffmanSpec.TheHuffmanSpecs.Length; i++)
+ {
+ TheHuffmanLut[i] = new HuffmanLut(HuffmanSpec.TheHuffmanSpecs[i]);
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
///
- /// The encoding specifications.
+ /// dasd
public HuffmanLut(HuffmanSpec spec)
{
int maxValue = 0;
@@ -43,26 +65,9 @@
}
}
- ///
- /// Initialize static members
- ///
- static HuffmanLut()
- {
- // Initialize the Huffman tables
- for (int i = 0; i < HuffmanSpec.TheHuffmanSpecs.Length; i++)
- {
- HuffmanLut.TheHuffmanLut[i] = new HuffmanLut(HuffmanSpec.TheHuffmanSpecs[i]);
- }
- }
-
///
/// Gets the collection of huffman values.
///
public uint[] Values { get; }
-
- ///
- /// The compiled representations of theHuffmanSpec.
- ///
- public static readonly HuffmanLut[] TheHuffmanLut = new HuffmanLut[4];
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanSpec.cs
index 2e856628a..25d0fcfb1 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanSpec.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Encoder/HuffmanSpec.cs
@@ -1,35 +1,19 @@
-namespace ImageSharp.Formats.Jpg.Components.Encoder
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+namespace ImageSharp.Formats.Jpg.Components.Encoder
{
///
- /// The Huffman encoding specifications.
+ /// The Huffman encoding specifications.
///
internal struct HuffmanSpec
{
- ///
- /// Gets count[i] - The number of codes of length i bits.
- ///
- public readonly byte[] Count;
-
- ///
- /// Gets value[i] - The decoded value of the codeword at the given index.
- ///
- public readonly byte[] Values;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The number of codes.
- /// The decoded values.
- public HuffmanSpec(byte[] count, byte[] values)
- {
- this.Count = count;
- this.Values = values;
- }
-
#pragma warning disable SA1118 // ParameterMustNotSpanMultipleLines
+
///
- /// The Huffman encoding specifications.
- /// This encoder uses the same Huffman encoding for all images.
+ /// The Huffman encoding specifications.
+ /// This encoder uses the same Huffman encoding for all images.
///
public static readonly HuffmanSpec[] TheHuffmanSpecs =
{
@@ -37,76 +21,116 @@
new HuffmanSpec(
new byte[]
{
- 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
+ 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
+ 0, 0, 0
},
new byte[]
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
- }),
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+ }),
new HuffmanSpec(
new byte[]
{
- 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125
+ 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0,
+ 0, 1, 125
},
new byte[]
{
- 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21,
- 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71,
- 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1,
- 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72,
- 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
- 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
- 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
- 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
- 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,
- 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93,
- 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3,
- 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3,
- 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
- 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3,
- 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
- 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1,
- 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa
+ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
+ 0x05,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0, 0, 0
},
new byte[]
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
- }),
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+ }),
// Chrominance AC.
new HuffmanSpec(
new byte[]
{
- 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119
+ 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0,
+ 1, 2, 119
},
new byte[]
{
- 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31,
- 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22,
- 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1,
- 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1,
- 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18,
- 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36,
- 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
- 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
- 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a,
- 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
- 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
- 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba,
- 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca,
- 0xd2, 0xd3, 0xd4, 0xd5, 0xd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
+ 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa
})
};
#pragma warning restore SA1118 // ParameterMustNotSpanMultipleLines
+ ///
+ /// Gets count[i] - The number of codes of length i bits.
+ ///
+ public readonly byte[] Count;
+
+ ///
+ /// Gets value[i] - The decoded value of the codeword at the given index.
+ ///
+ public readonly byte[] Values;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ ///
+ /// The number of codes.
+ ///
+ ///
+ /// The decoded values.
+ ///
+ public HuffmanSpec(byte[] count, byte[] values)
+ {
+ this.Count = count;
+ this.Values = values;
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Jpg/Components/Encoder/QuantIndex.cs b/src/ImageSharp/Formats/Jpg/Components/Encoder/QuantIndex.cs
index 192e29f08..5efd1a321 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Encoder/QuantIndex.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Encoder/QuantIndex.cs
@@ -1,17 +1,21 @@
-namespace ImageSharp.Formats.Jpg.Components.Encoder
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+namespace ImageSharp.Formats.Jpg.Components.Encoder
{
///
- /// Enumerates the quantization tables
+ /// Enumerates the quantization tables
///
internal enum QuantIndex
{
///
- /// The luminance quantization table index
+ /// The luminance quantization table index
///
Luminance = 0,
///
- /// The chrominance quantization table index
+ /// The chrominance quantization table index
///
Chrominance = 1,
}
diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
index 06e722024..42b9d7814 100644
--- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
+++ b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
@@ -10,22 +10,21 @@ namespace ImageSharp.Formats
using System.Numerics;
using System.Runtime.CompilerServices;
- using ImageSharp.Formats.Jpg.Components;
using ImageSharp.Formats.Jpg.Components.Encoder;
using ImageSharp.Formats.Jpg.Utils;
///
- /// Image encoder for writing an image to a stream as a jpeg.
+ /// Image encoder for writing an image to a stream as a jpeg.
///
internal unsafe class JpegEncoderCore
{
///
- /// The number of quantization tables.
+ /// The number of quantization tables.
///
private const int QuantizationTableCount = 2;
///
- /// Counts the number of bits needed to hold an integer.
+ /// Counts the number of bits needed to hold an integer.
///
private static readonly uint[] BitCountLut =
{
@@ -45,15 +44,15 @@ namespace ImageSharp.Formats
};
///
- /// The SOS (Start Of Scan) marker "\xff\xda" followed by 12 bytes:
- /// - the marker length "\x00\x0c",
- /// - the number of components "\x03",
- /// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
- /// - component 2 uses DC table 1 and AC table 1 "\x02\x11",
- /// - component 3 uses DC table 1 and AC table 1 "\x03\x11",
- /// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
- /// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
- /// should be 0x00, 0x3f, 0x00<<4 | 0x00.
+ /// The SOS (Start Of Scan) marker "\xff\xda" followed by 12 bytes:
+ /// - the marker length "\x00\x0c",
+ /// - the number of components "\x03",
+ /// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
+ /// - component 2 uses DC table 1 and AC table 1 "\x02\x11",
+ /// - component 3 uses DC table 1 and AC table 1 "\x03\x11",
+ /// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
+ /// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
+ /// should be 0x00, 0x3f, 0x00<<4 | 0x00.
///
private static readonly byte[] SosHeaderYCbCr =
{
@@ -78,10 +77,10 @@ namespace ImageSharp.Formats
};
///
- /// The unscaled quantization tables in zig-zag order. Each
- /// encoder copies and scales the tables according to its quality parameter.
- /// The values are derived from section K.1 after converting from natural to
- /// zig-zag order.
+ /// The unscaled quantization tables in zig-zag order. Each
+ /// encoder copies and scales the tables according to its quality parameter.
+ /// The values are derived from section K.1 after converting from natural to
+ /// zig-zag order.
///
private static readonly byte[,] UnscaledQuant =
{
@@ -104,58 +103,69 @@ namespace ImageSharp.Formats
};
///
- /// A scratch buffer to reduce allocations.
+ /// A scratch buffer to reduce allocations.
///
private readonly byte[] buffer = new byte[16];
///
- /// A buffer for reducing the number of stream writes when emitting Huffman tables. 64 seems to be enough.
+ /// A buffer for reducing the number of stream writes when emitting Huffman tables. 64 seems to be enough.
///
private readonly byte[] emitBuffer = new byte[64];
///
- /// A buffer for reducing the number of stream writes when emitting Huffman tables. Max combined table lengths + identifier.
+ /// A buffer for reducing the number of stream writes when emitting Huffman tables. Max combined table lengths +
+ /// identifier.
///
private readonly byte[] huffmanBuffer = new byte[179];
///
- /// The accumulated bits to write to the stream.
+ /// The accumulated bits to write to the stream.
///
private uint accumulatedBits;
///
- /// The accumulated bit count.
+ /// The accumulated bit count.
///
private uint bitCount;
///
- /// The scaled chrominance table, in zig-zag order.
+ /// The scaled chrominance table, in zig-zag order.
///
private Block8x8F chrominanceQuantTable;
///
- /// The scaled luminance table, in zig-zag order.
+ /// The scaled luminance table, in zig-zag order.
///
private Block8x8F luminanceQuantTable;
///
- /// The output stream. All attempted writes after the first error become no-ops.
+ /// The output stream. All attempted writes after the first error become no-ops.
///
private Stream outputStream;
///
- /// The subsampling method to use.
+ /// The subsampling method to use.
///
private JpegSubsample subsample;
///
/// Encode writes the image to the jpeg baseline format with the given options.
///
- /// The pixel format.
- /// The image to write from.
- /// The stream to write to.
- /// The quality.
- /// The subsampling mode.
+ ///
+ /// The pixel format.
+ ///
+ ///
+ /// The image to write from.
+ ///
+ ///
+ /// The stream to write to.
+ ///
+ ///
+ /// The quality.
+ ///
+ ///
+ /// The subsampling mode.
+ ///
public void Encode(Image image, Stream stream, int quality, JpegSubsample sample)
where TColor : struct, IPackedPixel, IEquatable
{
@@ -249,14 +259,30 @@ namespace ImageSharp.Formats
///
/// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values.
///
- /// The pixel format.
- /// The pixel accessor.
- /// The x-position within the image.
- /// The y-position within the image.
- /// The luminance block.
- /// The red chroma block.
- /// The blue chroma block.
- /// Temporal provided by the caller
+ ///
+ /// The pixel format.
+ ///
+ ///
+ /// The pixel accessor.
+ ///
+ ///
+ /// The x-position within the image.
+ ///
+ ///
+ /// The y-position within the image.
+ ///
+ ///
+ /// The luminance block.
+ ///
+ ///
+ /// The red chroma block.
+ ///
+ ///
+ /// The blue chroma block.
+ ///
+ ///
+ /// Temporal provided by the caller
+ ///
private static void ToYCbCr(
PixelAccessor pixels,
int x,
@@ -264,7 +290,8 @@ namespace ImageSharp.Formats
Block8x8F* yBlock,
Block8x8F* cbBlock,
Block8x8F* crBlock,
- PixelArea rgbBytes) where TColor : struct, IPackedPixel, IEquatable
+ PixelArea rgbBytes)
+ where TColor : struct, IPackedPixel, IEquatable
{
float* yBlockRaw = (float*)yBlock;
float* cbBlockRaw = (float*)cbBlock;
@@ -300,10 +327,18 @@ namespace ImageSharp.Formats
///
/// Emits the least significant count of bits of bits to the bit-stream.
- /// The precondition is bits < 1<<nBits && nBits <= 16.
+ /// The precondition is bits
+ ///
+ /// < 1<<nBits && nBits <= 16
+ ///
+ /// .
///
- /// The packed bits.
- /// The number of bits
+ ///
+ /// The packed bits.
+ ///
+ ///
+ /// The number of bits
+ ///
private void Emit(uint bits, uint count)
{
count += this.bitCount;
@@ -341,8 +376,12 @@ namespace ImageSharp.Formats
///
/// Emits the given value with the given Huffman encoder.
///
- /// The index of the Huffman encoder
- /// The value to encode.
+ ///
+ /// The index of the Huffman encoder
+ ///
+ ///
+ /// The value to encode.
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EmitHuff(HuffIndex index, int value)
{
@@ -353,9 +392,15 @@ namespace ImageSharp.Formats
///
/// Emits a run of runLength copies of value encoded with the given Huffman encoder.
///
- /// The index of the Huffman encoder
- /// The number of copies to encode.
- /// The value to encode.
+ ///
+ /// The index of the Huffman encoder
+ ///
+ ///
+ /// The number of copies to encode.
+ ///
+ ///
+ /// The value to encode.
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EmitHuffRLE(HuffIndex index, int runLength, int value)
{
@@ -387,8 +432,12 @@ namespace ImageSharp.Formats
///
/// Encodes the image with no subsampling.
///
- /// The pixel format.
- /// The pixel accessor providing access to the image pixels.
+ ///
+ /// The pixel format.
+ ///
+ ///
+ /// The pixel accessor providing access to the image pixels.
+ ///
private void Encode444(PixelAccessor pixels)
where TColor : struct, IPackedPixel, IEquatable
{
@@ -448,8 +497,12 @@ namespace ImageSharp.Formats
///
/// Writes the application header containing the JFIF identifier plus extra data.
///
- /// The resolution of the image in the x- direction.
- /// The resolution of the image in the y- direction.
+ ///
+ /// The resolution of the image in the x- direction.
+ ///
+ ///
+ /// The resolution of the image in the y- direction.
+ ///
private void WriteApplicationHeader(short horizontalResolution, short verticalResolution)
{
// Write the start of image marker. Markers are always prefixed with with 0xff.
@@ -487,17 +540,33 @@ namespace ImageSharp.Formats
///
/// Writes a block of pixel data using the given quantization table,
- /// returning the post-quantized DC value of the DCT-transformed block.
- /// The block is in natural (not zig-zag) order.
+ /// returning the post-quantized DC value of the DCT-transformed block.
+ /// The block is in natural (not zig-zag) order.
///
- /// The quantization table index.
- /// The previous DC value.
- /// Source block
- /// Temporal block to be used as FDCT Destination
- /// Temporal block 2
- /// Quantization table
- /// The 8x8 Unzig block ptr
- /// The
+ ///
+ /// The quantization table index.
+ ///
+ ///
+ /// The previous DC value.
+ ///
+ ///
+ /// Source block
+ ///
+ ///
+ /// Temporal block to be used as FDCT Destination
+ ///
+ ///
+ /// Temporal block 2
+ ///
+ ///
+ /// Quantization table
+ ///
+ ///
+ /// The 8x8 Unzig block ptr
+ ///
+ ///
+ /// The
+ ///
private float WriteBlock(
QuantIndex index,
float prevDC,
@@ -554,7 +623,9 @@ namespace ImageSharp.Formats
///
/// Writes the Define Huffman Table marker and tables.
///
- /// The number of components to write.
+ ///
+ /// The number of components to write.
+ ///
private void WriteDefineHuffmanTables(int componentCount)
{
// Table identifiers.
@@ -601,7 +672,7 @@ namespace ImageSharp.Formats
}
///
- /// Writes the Define Quantization Marker and tables.
+ /// Writes the Define Quantization Marker and tables.
///
private void WriteDefineQuantizationTables()
{
@@ -625,7 +696,9 @@ namespace ImageSharp.Formats
///
/// Writes the EXIF profile.
///
- /// The exif profile.
+ ///
+ /// The exif profile.
+ ///
///
/// Thrown if the EXIF profile size exceeds the limit
///
@@ -657,9 +730,14 @@ namespace ImageSharp.Formats
///
/// Writes the metadata profiles to the image.
///
- /// The image.
- /// The pixel format.
- private void WriteProfiles(Image image) where TColor : struct, IPackedPixel, IEquatable
+ ///
+ /// The image.
+ ///
+ ///
+ /// The pixel format.
+ ///
+ private void WriteProfiles(Image image)
+ where TColor : struct, IPackedPixel, IEquatable
{
this.WriteProfile(image.ExifProfile);
}
@@ -667,9 +745,15 @@ namespace ImageSharp.Formats
///
/// Writes the Start Of Frame (Baseline) marker
///
- /// The width of the image
- /// The height of the image
- /// The number of components in a pixel
+ ///
+ /// The width of the image
+ ///
+ ///
+ /// The height of the image
+ ///
+ ///
+ /// The number of components in a pixel
+ ///
private void WriteStartOfFrame(int width, int height, int componentCount)
{
// "default" to 4:2:0
@@ -723,7 +807,9 @@ namespace ImageSharp.Formats
///
/// Writes the StartOfScan marker.
///
- /// The pixel format.
+ ///
+ /// The pixel format.
+ ///
///
/// The pixel accessor providing access to the image pixels.
///
@@ -751,8 +837,9 @@ namespace ImageSharp.Formats
#pragma warning disable SA1201 // MethodShouldNotFollowAStruct
///
- /// Poor man's stackalloc for Encode420.
- /// This struct belongs to Encode420. Much easeier to understand code if they are close to each other. Why should I move it Up? :P
+ /// Poor man's stackalloc for Encode420.
+ /// This struct belongs to Encode420. Much easeier to understand code if they are close to each other. Why should I
+ /// move it Up? :P
///
private struct BlockQuad
{
@@ -761,10 +848,14 @@ namespace ImageSharp.Formats
///
/// Encodes the image with subsampling. The Cb and Cr components are each subsampled
- /// at a factor of 2 both horizontally and vertically.
+ /// at a factor of 2 both horizontally and vertically.
///
- /// The pixel format.
- /// The pixel accessor providing access to the image pixels.
+ ///
+ /// The pixel format.
+ ///
+ ///
+ /// The pixel accessor providing access to the image pixels.
+ ///
private void Encode420(PixelAccessor pixels)
where TColor : struct, IPackedPixel, IEquatable
{
@@ -838,8 +929,12 @@ namespace ImageSharp.Formats
///
/// Writes the header for a marker with the given length.
///
- /// The marker to write.
- /// The marker length.
+ ///
+ /// The marker to write.
+ ///
+ ///
+ /// The marker length.
+ ///
private void WriteMarkerHeader(byte marker, int length)
{
// Markers are always prefixed with with 0xff.
diff --git a/src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs b/src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs
index f4c2fa2c4..3a87723bc 100644
--- a/src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs
+++ b/src/ImageSharp/Formats/Jpg/Utils/JpegUtils.cs
@@ -10,18 +10,29 @@ namespace ImageSharp.Formats.Jpg.Utils
using ImageSharp.Formats.Jpg.Components.Encoder;
///
- /// Jpeg specific utilities and extension methods
+ /// Jpeg specific utilities and extension methods
///
internal static unsafe class JpegUtils
{
///
- /// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of the image.
+ /// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of
+ /// the image.
///
- /// The pixel type
- /// The input pixel acessor
- /// The destination
- /// Starting Y coord
- /// Starting X coord
+ ///
+ /// The pixel type
+ ///
+ ///
+ /// The input pixel acessor
+ ///
+ ///
+ /// The destination
+ ///
+ ///
+ /// Starting Y coord
+ ///
+ ///
+ /// Starting X coord
+ ///
public static void CopyRGBBytesStretchedTo(
this PixelAccessor pixels,
PixelArea dest,
@@ -38,8 +49,12 @@ namespace ImageSharp.Formats.Jpg.Utils
///
/// Copy an RGB value
///
- /// Source pointer
- /// Destination pointer
+ ///
+ /// Source pointer
+ ///
+ ///
+ /// Destination pointer
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void CopyRgb(byte* source, byte* dest)
{
@@ -48,6 +63,37 @@ namespace ImageSharp.Formats.Jpg.Utils
*dest = *source; // B
}
+ ///
+ /// Writes data to "Define Quantization Tables" block for QuantIndex
+ ///
+ ///
+ /// The "Define Quantization Tables" block
+ ///
+ ///
+ /// Offset in dqt
+ ///
+ ///
+ /// The quantization index
+ ///
+ ///
+ /// The quantazation table to copy data from
+ ///
+ internal static void WriteDataToDqt(byte[] dqt, ref int offset, QuantIndex i, ref Block8x8F q)
+ {
+ dqt[offset++] = (byte)i;
+ for (int j = 0; j < Block8x8F.ScalarCount; j++)
+ {
+ dqt[offset++] = (byte)q[j];
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static bool IsInvalidStretchArea(PixelArea area, int fromX, int fromY)
+ where TColor : struct, IPackedPixel, IEquatable
+ {
+ return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height;
+ }
+
private static void StretchPixels(PixelArea area, int fromX, int fromY)
where TColor : struct, IPackedPixel, IEquatable
{
@@ -84,21 +130,5 @@ namespace ImageSharp.Formats.Jpg.Utils
}
}
}
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsInvalidStretchArea(PixelArea area, int fromX, int fromY)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height;
- }
-
- internal static void WriteDataToDqt(byte[] dqt, ref int offset, QuantIndex i, ref Block8x8F q)
- {
- dqt[offset++] = (byte)i;
- for (int j = 0; j < Block8x8F.ScalarCount; j++)
- {
- dqt[offset++] = (byte)q[j];
- }
- }
}
}
\ No newline at end of file