diff --git a/ImageSharp.sln b/ImageSharp.sln
index cd9e39a33..96dd8aa5d 100644
--- a/ImageSharp.sln
+++ b/ImageSharp.sln
@@ -32,8 +32,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C06
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp.Tests46", "tests\ImageSharp.Tests46\ImageSharp.Tests46.csproj", "{88C5FB74-5845-4CC0-8F1E-A25EBABC95C2}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
index bdf3468e6..44fce5cdc 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
@@ -8,77 +8,77 @@ namespace ImageSharp.Formats.Jpg
using System.Buffers;
///
- /// Represents a Huffman tree
+ /// Represents a Huffman tree
///
internal struct HuffmanTree : IDisposable
{
///
- /// The maximum (inclusive) number of codes in a Huffman tree.
+ /// The maximum (inclusive) number of codes in a Huffman tree.
///
public const int MaxNCodes = 256;
///
- /// The maximum (inclusive) number of bits in a Huffman code.
+ /// The maximum (inclusive) number of bits in a Huffman code.
///
public const int MaxCodeLength = 16;
///
- /// The maximum number of Huffman table classes
+ /// The maximum number of Huffman table classes
///
public const int MaxTc = 1;
///
- /// The maximum number of Huffman table identifiers
+ /// The maximum number of Huffman table identifiers
///
public const int MaxTh = 3;
///
- /// Row size of the Huffman table
+ /// Row size of the Huffman table
///
public const int ThRowSize = MaxTh + 1;
///
- /// Number of Hufman Trees in the Huffman table
+ /// Number of Hufman Trees in the Huffman table
///
public const int NumberOfTrees = (MaxTc + 1) * (MaxTh + 1);
///
- /// The log-2 size of the Huffman decoder's look-up table.
+ /// The log-2 size of the Huffman decoder's look-up table.
///
public const int LutSize = 8;
///
- /// Gets or sets the number of codes in the tree.
+ /// Gets or sets the number of codes in the tree.
///
public int Length;
///
- /// Gets the look-up table for the next LutSize bits in the bit-stream.
- /// The high 8 bits of the uint16 are the encoded value. The low 8 bits
- /// are 1 plus the code length, or 0 if the value is too large to fit in
- /// lutSize bits.
+ /// Gets the look-up table for the next LutSize bits in the bit-stream.
+ /// The high 8 bits of the uint16 are the encoded value. The low 8 bits
+ /// are 1 plus the code length, or 0 if the value is too large to fit in
+ /// lutSize bits.
///
public ushort[] Lut;
///
- /// Gets the the decoded values, sorted by their encoding.
+ /// Gets the the decoded values, sorted by their encoding.
///
public byte[] Values;
///
- /// Gets the array of minimum codes.
- /// MinCodes[i] is the minimum code of length i, or -1 if there are no codes of that length.
+ /// Gets the array of minimum codes.
+ /// MinCodes[i] is the minimum code of length i, or -1 if there are no codes of that length.
///
public int[] MinCodes;
///
- /// Gets the array of maximum codes.
- /// MaxCodes[i] is the maximum code of length i, or -1 if there are no codes of that length.
+ /// Gets the array of maximum codes.
+ /// MaxCodes[i] is the maximum code of length i, or -1 if there are no codes of that length.
///
public int[] MaxCodes;
///
- /// Gets the array of indices. Indices[i] is the index into Values of MinCodes[i].
+ /// Gets the array of indices. Indices[i] is the index into Values of MinCodes[i].
///
public int[] Indices;
@@ -89,7 +89,7 @@ namespace ImageSharp.Formats.Jpg
private static readonly ArrayPool IntBuffer = ArrayPool.Create(MaxCodeLength, 50);
///
- /// Creates and initializes an array of instances of size
+ /// Creates and initializes an array of instances of size
///
/// An array of instances representing the Huffman tables
public static HuffmanTree[] CreateHuffmanTrees()
@@ -107,7 +107,7 @@ namespace ImageSharp.Formats.Jpg
}
///
- /// Initializes the Huffman tree
+ /// Initializes the Huffman tree
///
private void Init()
{
@@ -119,7 +119,7 @@ namespace ImageSharp.Formats.Jpg
}
///
- /// Disposes the underlying buffers
+ /// Disposes the underlying buffers
///
public void Dispose()
{
@@ -131,7 +131,7 @@ namespace ImageSharp.Formats.Jpg
}
///
- /// Internal part of the DHT processor, whatever does it mean
+ /// Internal part of the DHT processor, whatever does it mean
///
/// The decoder instance
/// The temporal buffer that holds the data that has been read from the Jpeg stream
diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs
index 162874f02..ea2ab9230 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs
@@ -12,12 +12,12 @@ namespace ImageSharp.Formats.Jpg
internal unsafe struct JpegScanDecoder
{
///
- /// The AC table index
+ /// The AC table index
///
internal const int AcTableIndex = 1;
///
- /// The DC table index
+ /// The DC table index
///
internal const int DcTableIndex = 0;
@@ -37,9 +37,9 @@ namespace ImageSharp.Formats.Jpg
public UnzigData Unzig;
- public fixed byte ScanData [3 * JpegDecoderCore.MaxComponents];
+ public fixed byte ScanData[3 * JpegDecoderCore.MaxComponents];
- public fixed int Dc [JpegDecoderCore.MaxComponents];
+ public fixed int Dc[JpegDecoderCore.MaxComponents];
public static ComponentData Create()
{
@@ -133,7 +133,7 @@ namespace ImageSharp.Formats.Jpg
private ComponentData Data;
private ComponentPointers Pointers;
-
+
public static void Init(JpegScanDecoder* p, JpegDecoderCore decoder, int remaining)
{
p->Data = ComponentData.Create();
@@ -387,7 +387,7 @@ namespace ImageSharp.Formats.Jpg
// Reset the DC components, as per section F.2.1.3.1.
this.ResetDc();
-
+
// Reset the progressive decoder state, as per section G.1.2.2.
decoder.EobRun = 0;
}
@@ -398,7 +398,7 @@ namespace ImageSharp.Formats.Jpg
}
///
- /// Decodes a successive approximation refinement block, as specified in section G.1.2.
+ /// Decodes a successive approximation refinement block, as specified in section G.1.2.
///
/// The Huffman tree
/// The low transform offset
@@ -473,7 +473,7 @@ namespace ImageSharp.Formats.Jpg
{
break;
}
-
+
zig = this.RefineNonZeroes(decoder, zig, val0, delta);
if (zig > this.zigEnd)
{
@@ -491,13 +491,13 @@ namespace ImageSharp.Formats.Jpg
if (decoder.EobRun > 0)
{
decoder.EobRun--;
- this.RefineNonZeroes(decoder, zig,-1, delta);
+ this.RefineNonZeroes(decoder, zig, -1, delta);
}
}
///
- /// Refines non-zero entries of b in zig-zag order.
- /// If >= 0, the first zero entries are skipped over.
+ /// Refines non-zero entries of b in zig-zag order.
+ /// If >= 0, the first zero entries are skipped over.
///
/// The decoder
/// The zig-zag start index
@@ -649,5 +649,5 @@ namespace ImageSharp.Formats.Jpg
destArea.LoadColorsFrom(this.Pointers.Temp1, this.Pointers.Temp2);
}
}
-
+
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs
index a2f439c5a..a140d989c 100644
--- a/src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs
+++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs
@@ -3,23 +3,23 @@
using System.Runtime.InteropServices;
///
- /// Represents a component scan
+ /// Represents a component scan
///
[StructLayout(LayoutKind.Sequential)]
internal struct Scan
{
///
- /// Gets or sets the component index.
+ /// Gets or sets the component index.
///
public byte Index;
///
- /// Gets or sets the DC table selector
+ /// Gets or sets the DC table selector
///
public byte DcTableSelector;
///
- /// Gets or sets the AC table selector
+ /// Gets or sets the AC table selector
///
public byte AcTableSelector;
}
diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
index 4b3b26da9..541515cb4 100644
--- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
@@ -7,139 +7,82 @@ namespace ImageSharp.Formats
using System;
using System.IO;
using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ImageSharp.Formats.Jpg;
-
+
///
- /// Performs the jpeg decoding operation.
+ /// Performs the jpeg decoding operation.
///
internal unsafe class JpegDecoderCore : IDisposable
{
///
- /// The maximum number of color components
- ///
- internal const int MaxComponents = 4;
-
- ///
- /// The maximum number of quantization tables
- ///
- private const int MaxTq = 3;
-
- ///
- /// The component array
- ///
- internal Component[] ComponentArray { get; }
-
- ///
- /// The huffman trees
- ///
- internal HuffmanTree[] HuffmanTrees { get; }
-
- ///
- /// Saved state between progressive-mode scans.
+ /// The maximum number of color components
///
- internal Block8x8F[][] ProgCoeffs { get; }
+ public const int MaxComponents = 4;
///
- /// Quantization tables, in zigzag order.
- ///
- internal Block8x8F[] QuantizationTables { get; }
-
- ///
- /// A temporary buffer for holding pixels
- ///
- internal byte[] Temp { get; }
-
- // TODO: the usage of this buffer is unclean + need to move it to the stack for performance
-
- ///
- /// The App14 marker color-space
+ /// The App14 marker color-space
///
private byte adobeTransform;
///
- /// Whether the image is in CMYK format with an App14 marker
+ /// Whether the image is in CMYK format with an App14 marker
///
private bool adobeTransformValid;
///
- /// Holds the unprocessed bits that have been taken from the byte-stream.
+ /// Holds the unprocessed bits that have been taken from the byte-stream.
///
- internal Bits Bits;
-
- private JpegPixelArea blackImage;
-
- //private int blockIndex;
+ public Bits Bits;
///
- /// The byte buffer.
+ /// The byte buffer.
///
- private Bytes bytes;
-
+ public Bytes Bytes;
+
///
- /// The number of color components within the image.
+ /// End-of-Band run, specified in section G.1.2.2.
///
- internal int ComponentCount { get; private set; }
+ public ushort EobRun;
///
- /// End-of-Band run, specified in section G.1.2.2.
+ /// The black image to decode to.
///
- internal ushort EobRun;
+ private JpegPixelArea blackImage;
///
- /// A grayscale image to decode to.
+ /// A grayscale image to decode to.
///
private JpegPixelArea grayImage;
///
- /// The horizontal resolution. Calculated if the image has a JFIF header.
+ /// The horizontal resolution. Calculated if the image has a JFIF header.
///
private short horizontalResolution;
-
- ///
- /// The image height
- ///
- internal int ImageHeight { get; private set; }
-
- ///
- /// The image width
- ///
- internal int ImageWidth { get; private set; }
-
+
///
- /// The byte buffer.
+ /// The maximum number of quantization tables
///
- private Stream inputStream;
-
+ private const int MaxTq = 3;
+
///
- /// Whether the image has a JFIF header
+ /// Whether the image has a JFIF header
///
private bool isJfif;
-
- ///
- /// Whether the image is interlaced (progressive)
- ///
- public bool IsProgressive { get; private set; }
-
- ///
- /// The restart interval
- ///
- internal int RestartInterval { get; private set; }
-
+
///
- /// The vertical resolution. Calculated if the image has a JFIF header.
+ /// The vertical resolution. Calculated if the image has a JFIF header.
///
private short verticalResolution;
///
- /// The full color image to decode to.
+ /// The full color image to decode to.
///
private YCbCrImage ycbcrImage;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
public JpegDecoderCore()
{
@@ -149,56 +92,83 @@ namespace ImageSharp.Formats
this.ComponentArray = new Component[MaxComponents];
this.ProgCoeffs = new Block8x8F[MaxComponents][];
this.Bits = default(Bits);
- this.bytes = Bytes.Create();
+ this.Bytes = Bytes.Create();
}
-
+
///
- /// ReadByteStuffedByte was throwing exceptions on normal execution path (very inefficent)
- /// It's better tho have an error code for this!
+ /// ReadByteStuffedByte was throwing exceptions on normal execution path (very inefficent)
+ /// It's better tho have an error code for this!
///
internal enum ErrorCodes
{
///
- /// NoError
+ /// NoError
///
NoError,
///
- /// MissingFF00
+ /// MissingFF00
///
MissingFF00
}
+
///
- /// Gets or sets the byte buffer.
+ /// The component array
///
- public Bytes Bytes
- {
- get
- {
- return this.bytes;
- }
+ public Component[] ComponentArray { get; }
- set
- {
- this.bytes = value;
- }
- }
+ ///
+ /// The huffman trees
+ ///
+ public HuffmanTree[] HuffmanTrees { get; }
///
- /// Gets the input stream.
+ /// Saved state between progressive-mode scans.
///
- public Stream InputStream
- {
- get
- {
- return this.inputStream;
- }
- }
+ public Block8x8F[][] ProgCoeffs { get; }
+
+ ///
+ /// Quantization tables, in zigzag order.
+ ///
+ public Block8x8F[] QuantizationTables { get; }
+
+ ///
+ /// A temporary buffer for holding pixels
+ ///
+ // TODO: the usage rules of this buffer seem to be unclean + need to consider stack-allocating it for perf
+ public byte[] Temp { get; }
+ ///
+ /// The number of color components within the image.
+ ///
+ public int ComponentCount { get; private set; }
+ ///
+ /// The image height
+ ///
+ public int ImageHeight { get; private set; }
+
+ ///
+ /// The image width
+ ///
+ public int ImageWidth { get; private set; }
+
+ ///
+ /// Gets the input stream.
+ ///
+ public Stream InputStream { get; private set; }
+ ///
+ /// Whether the image is interlaced (progressive)
+ ///
+ public bool IsProgressive { get; private set; }
///
- /// Decodes the image from the specified this._stream and sets
- /// the data to image.
+ /// The restart interval
+ ///
+ public int RestartInterval { get; private set; }
+
+ ///
+ /// Decodes the image from the specified this._stream and sets
+ /// the data to image.
///
/// The pixel format.
/// The image, where the data should be set to.
@@ -207,7 +177,7 @@ namespace ImageSharp.Formats
public void Decode(Image image, Stream stream, bool configOnly)
where TColor : struct, IPackedPixel, IEquatable
{
- this.inputStream = stream;
+ this.InputStream = stream;
// Check for the Start Of Image marker.
this.ReadFull(this.Temp, 0, 2);
@@ -417,7 +387,7 @@ namespace ImageSharp.Formats
}
///
- /// Dispose
+ /// Dispose
///
public void Dispose()
{
@@ -427,23 +397,23 @@ namespace ImageSharp.Formats
}
this.ycbcrImage?.Dispose();
- this.bytes.Dispose();
+ this.Bytes.Dispose();
this.grayImage.ReturnPooled();
this.blackImage.ReturnPooled();
}
-
+
///
- /// Returns the next byte, whether buffered or not buffered. It does not care about byte stuffing.
+ /// Returns the next byte, whether buffered or not buffered. It does not care about byte stuffing.
///
/// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte ReadByte()
{
- return this.bytes.ReadByte(this.inputStream);
+ return this.Bytes.ReadByte(this.InputStream);
}
///
- /// Reads exactly length bytes into data. It does not care about byte stuffing.
+ /// Reads exactly length bytes into data. It does not care about byte stuffing.
///
/// The data to write to.
/// The offset in the source buffer
@@ -451,39 +421,39 @@ namespace ImageSharp.Formats
internal void ReadFull(byte[] data, int offset, int length)
{
// Unread the overshot bytes, if any.
- if (this.bytes.UnreadableBytes != 0)
+ if (this.Bytes.UnreadableBytes != 0)
{
if (this.Bits.UnreadBits >= 8)
{
this.UnreadByteStuffedByte();
}
- this.bytes.UnreadableBytes = 0;
+ this.Bytes.UnreadableBytes = 0;
}
while (length > 0)
{
- if (this.bytes.J - this.bytes.I >= length)
+ if (this.Bytes.J - this.Bytes.I >= length)
{
- Array.Copy(this.bytes.Buffer, this.bytes.I, data, offset, length);
- this.bytes.I += length;
+ Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, length);
+ this.Bytes.I += length;
length -= length;
}
else
{
- Array.Copy(this.bytes.Buffer, this.bytes.I, data, offset, this.bytes.J - this.bytes.I);
- offset += this.bytes.J - this.bytes.I;
- length -= this.bytes.J - this.bytes.I;
- this.bytes.I += this.bytes.J - this.bytes.I;
+ Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, this.Bytes.J - this.Bytes.I);
+ offset += this.Bytes.J - this.Bytes.I;
+ length -= this.Bytes.J - this.Bytes.I;
+ this.Bytes.I += this.Bytes.J - this.Bytes.I;
- this.bytes.Fill(this.inputStream);
+ this.Bytes.Fill(this.InputStream);
}
}
}
///
- /// Optimized method to pack bytes to the image from the YCbCr color space.
- /// This is faster than implicit casting as it avoids double packing.
+ /// Optimized method to pack bytes to the image from the YCbCr color space.
+ /// This is faster than implicit casting as it avoids double packing.
///
/// The pixel format.
/// The packed pixel.
@@ -505,7 +475,7 @@ namespace ImageSharp.Formats
}
///
- /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header.
+ /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header.
///
/// The pixel format.
/// The image to assign the resolution to.
@@ -520,7 +490,7 @@ namespace ImageSharp.Formats
}
///
- /// Converts the image from the original CMYK image pixels.
+ /// Converts the image from the original CMYK image pixels.
///
/// The pixel format.
/// The image width.
@@ -539,28 +509,28 @@ namespace ImageSharp.Formats
0,
height,
y =>
+ {
+ int yo = this.ycbcrImage.GetRowYOffset(y);
+ int co = this.ycbcrImage.GetRowCOffset(y);
+
+ for (int x = 0; x < width; x++)
{
- int yo = this.ycbcrImage.GetRowYOffset(y);
- int co = this.ycbcrImage.GetRowCOffset(y);
-
- for (int x = 0; x < width; x++)
- {
- byte cyan = this.ycbcrImage.YPixels[yo + x];
- byte magenta = this.ycbcrImage.CbPixels[co + (x / scale)];
- byte yellow = this.ycbcrImage.CrPixels[co + (x / scale)];
-
- TColor packed = default(TColor);
- this.PackCmyk(ref packed, cyan, magenta, yellow, x, y);
- pixels[x, y] = packed;
- }
- });
+ byte cyan = this.ycbcrImage.YPixels[yo + x];
+ byte magenta = this.ycbcrImage.CbPixels[co + (x / scale)];
+ byte yellow = this.ycbcrImage.CrPixels[co + (x / scale)];
+
+ TColor packed = default(TColor);
+ this.PackCmyk(ref packed, cyan, magenta, yellow, x, y);
+ pixels[x, y] = packed;
+ }
+ });
}
this.AssignResolution(image);
}
///
- /// Converts the image from the original grayscale image pixels.
+ /// Converts the image from the original grayscale image pixels.
///
/// The pixel format.
/// The image width.
@@ -578,24 +548,24 @@ namespace ImageSharp.Formats
height,
Bootstrapper.ParallelOptions,
y =>
+ {
+ int yoff = this.grayImage.GetRowOffset(y);
+ for (int x = 0; x < width; x++)
{
- int yoff = this.grayImage.GetRowOffset(y);
- for (int x = 0; x < width; x++)
- {
- byte rgb = this.grayImage.Pixels[yoff + x];
-
- TColor packed = default(TColor);
- packed.PackFromBytes(rgb, rgb, rgb, 255);
- pixels[x, y] = packed;
- }
- });
+ byte rgb = this.grayImage.Pixels[yoff + x];
+
+ TColor packed = default(TColor);
+ packed.PackFromBytes(rgb, rgb, rgb, 255);
+ pixels[x, y] = packed;
+ }
+ });
}
this.AssignResolution(image);
}
///
- /// Converts the image from the original RBG image pixels.
+ /// Converts the image from the original RBG image pixels.
///
/// The pixel format.
/// The image width.
@@ -614,28 +584,28 @@ namespace ImageSharp.Formats
height,
Bootstrapper.ParallelOptions,
y =>
+ {
+ int yo = this.ycbcrImage.GetRowYOffset(y);
+ int co = this.ycbcrImage.GetRowCOffset(y);
+
+ for (int x = 0; x < width; x++)
{
- int yo = this.ycbcrImage.GetRowYOffset(y);
- int co = this.ycbcrImage.GetRowCOffset(y);
-
- for (int x = 0; x < width; x++)
- {
- byte red = this.ycbcrImage.YPixels[yo + x];
- byte green = this.ycbcrImage.CbPixels[co + (x / scale)];
- byte blue = this.ycbcrImage.CrPixels[co + (x / scale)];
-
- TColor packed = default(TColor);
- packed.PackFromBytes(red, green, blue, 255);
- pixels[x, y] = packed;
- }
- });
+ byte red = this.ycbcrImage.YPixels[yo + x];
+ byte green = this.ycbcrImage.CbPixels[co + (x / scale)];
+ byte blue = this.ycbcrImage.CrPixels[co + (x / scale)];
+
+ TColor packed = default(TColor);
+ packed.PackFromBytes(red, green, blue, 255);
+ pixels[x, y] = packed;
+ }
+ });
}
this.AssignResolution(image);
}
///
- /// Converts the image from the original YCbCr image pixels.
+ /// Converts the image from the original YCbCr image pixels.
///
/// The pixel format.
/// The image width.
@@ -654,28 +624,28 @@ namespace ImageSharp.Formats
height,
Bootstrapper.ParallelOptions,
y =>
+ {
+ int yo = this.ycbcrImage.GetRowYOffset(y);
+ int co = this.ycbcrImage.GetRowCOffset(y);
+
+ for (int x = 0; x < width; x++)
{
- int yo = this.ycbcrImage.GetRowYOffset(y);
- int co = this.ycbcrImage.GetRowCOffset(y);
-
- for (int x = 0; x < width; x++)
- {
- byte yy = this.ycbcrImage.YPixels[yo + x];
- byte cb = this.ycbcrImage.CbPixels[co + (x / scale)];
- byte cr = this.ycbcrImage.CrPixels[co + (x / scale)];
-
- TColor packed = default(TColor);
- PackYcbCr(ref packed, yy, cb, cr);
- pixels[x, y] = packed;
- }
- });
+ byte yy = this.ycbcrImage.YPixels[yo + x];
+ byte cb = this.ycbcrImage.CbPixels[co + (x / scale)];
+ byte cr = this.ycbcrImage.CrPixels[co + (x / scale)];
+
+ TColor packed = default(TColor);
+ PackYcbCr(ref packed, yy, cb, cr);
+ pixels[x, y] = packed;
+ }
+ });
}
this.AssignResolution(image);
}
///
- /// Converts the image from the original YCCK image pixels.
+ /// Converts the image from the original YCCK image pixels.
///
/// The pixel format.
/// The image width.
@@ -694,28 +664,28 @@ namespace ImageSharp.Formats
0,
height,
y =>
+ {
+ int yo = this.ycbcrImage.GetRowYOffset(y);
+ int co = this.ycbcrImage.GetRowCOffset(y);
+
+ for (int x = 0; x < width; x++)
{
- int yo = this.ycbcrImage.GetRowYOffset(y);
- int co = this.ycbcrImage.GetRowCOffset(y);
-
- for (int x = 0; x < width; x++)
- {
- byte yy = this.ycbcrImage.YPixels[yo + x];
- byte cb = this.ycbcrImage.CbPixels[co + (x / scale)];
- byte cr = this.ycbcrImage.CrPixels[co + (x / scale)];
-
- TColor packed = default(TColor);
- this.PackYcck(ref packed, yy, cb, cr, x, y);
- pixels[x, y] = packed;
- }
- });
+ byte yy = this.ycbcrImage.YPixels[yo + x];
+ byte cb = this.ycbcrImage.CbPixels[co + (x / scale)];
+ byte cr = this.ycbcrImage.CrPixels[co + (x / scale)];
+
+ TColor packed = default(TColor);
+ this.PackYcck(ref packed, yy, cb, cr, x, y);
+ pixels[x, y] = packed;
+ }
+ });
}
this.AssignResolution(image);
}
///
- /// Decodes a single bit
+ /// Decodes a single bit
///
/// The
internal bool DecodeBit()
@@ -736,7 +706,7 @@ namespace ImageSharp.Formats
}
///
- /// Decodes the given number of bits
+ /// Decodes the given number of bits
///
/// The number of bits to decode.
/// The
@@ -759,7 +729,7 @@ namespace ImageSharp.Formats
}
///
- /// Returns the next Huffman-coded value from the bit-stream, decoded according to the given value.
+ /// Returns the next Huffman-coded value from the bit-stream, decoded according to the given value.
///
/// The huffman value
/// The
@@ -850,10 +820,10 @@ namespace ImageSharp.Formats
}
///
- /// Returns a value indicating whether the image in an RGB image.
+ /// Returns a value indicating whether the image in an RGB image.
///
///
- /// The .
+ /// The .
///
private bool IsRGB()
{
@@ -874,7 +844,7 @@ namespace ImageSharp.Formats
}
///
- /// Makes the image from the buffer.
+ /// Makes the image from the buffer.
///
/// The horizontal MCU count
/// The vertical MCU count
@@ -932,8 +902,8 @@ namespace ImageSharp.Formats
}
///
- /// Optimized method to pack bytes to the image from the CMYK color space.
- /// This is faster than implicit casting as it avoids double packing.
+ /// Optimized method to pack bytes to the image from the CMYK color space.
+ /// This is faster than implicit casting as it avoids double packing.
///
/// The pixel format.
/// The packed pixel.
@@ -957,8 +927,8 @@ namespace ImageSharp.Formats
}
///
- /// Optimized method to pack bytes to the image from the YCCK color space.
- /// This is faster than implicit casting as it avoids double packing.
+ /// Optimized method to pack bytes to the image from the YCCK color space.
+ /// This is faster than implicit casting as it avoids double packing.
///
/// The pixel format.
/// The packed pixel.
@@ -995,9 +965,9 @@ namespace ImageSharp.Formats
}
///
- /// Processes the "Adobe" APP14 segment stores image encoding information for DCT filters.
- /// This segment may be copied or deleted as a block using the Extra "Adobe" tag, but note that it is not
- /// deleted by default when deleting all metadata because it may affect the appearance of the image.
+ /// Processes the "Adobe" APP14 segment stores image encoding information for DCT filters.
+ /// This segment may be copied or deleted as a block using the Extra "Adobe" tag, but note that it is not
+ /// deleted by default when deleting all metadata because it may affect the appearance of the image.
///
/// The remaining number of bytes in the stream.
private void ProcessApp14Marker(int remaining)
@@ -1025,7 +995,7 @@ namespace ImageSharp.Formats
}
///
- /// Processes the App1 marker retrieving any stored metadata
+ /// Processes the App1 marker retrieving any stored metadata
///
/// The pixel format.
/// The remaining bytes in the segment block.
@@ -1050,7 +1020,7 @@ namespace ImageSharp.Formats
}
///
- /// Processes the application header containing the JFIF identifier plus extra data.
+ /// Processes the application header containing the JFIF identifier plus extra data.
///
/// The remaining bytes in the segment block.
private void ProcessApplicationHeader(int remaining)
@@ -1081,8 +1051,8 @@ namespace ImageSharp.Formats
}
///
- /// Processes a Define Huffman Table marker, and initializes a huffman
- /// struct from its contents. Specified in section B.2.4.2.
+ /// Processes a Define Huffman Table marker, and initializes a huffman
+ /// struct from its contents. Specified in section B.2.4.2.
///
/// The remaining bytes in the segment block.
private void ProcessDefineHuffmanTablesMarker(int remaining)
@@ -1114,8 +1084,8 @@ namespace ImageSharp.Formats
}
///
- /// Processes the DRI (Define Restart Interval Marker) Which specifies the interval between RSTn markers, in
- /// macroblocks
+ /// Processes the DRI (Define Restart Interval Marker) Which specifies the interval between RSTn markers, in
+ /// macroblocks
///
/// The remaining bytes in the segment block.
private void ProcessDefineRestartIntervalMarker(int remaining)
@@ -1130,11 +1100,11 @@ namespace ImageSharp.Formats
}
///
- /// Processes the Define Quantization Marker and tables. Specified in section B.2.4.1.
+ /// Processes the Define Quantization Marker and tables. Specified in section B.2.4.1.
///
/// The remaining bytes in the segment block.
///
- /// Thrown if the tables do not match the header
+ /// Thrown if the tables do not match the header
///
private void ProcessDqt(int remaining)
{
@@ -1201,7 +1171,7 @@ namespace ImageSharp.Formats
}
///
- /// Processes the Start of Frame marker. Specified in section B.2.2.
+ /// Processes the Start of Frame marker. Specified in section B.2.2.
///
/// The remaining bytes in the segment block.
private void ProcessStartOfFrameMarker(int remaining)
@@ -1409,52 +1379,52 @@ namespace ImageSharp.Formats
}
///
- /// Skips the next n bytes.
+ /// Skips the next n bytes.
///
/// The number of bytes to ignore.
private void Skip(int count)
{
// Unread the overshot bytes, if any.
- if (this.bytes.UnreadableBytes != 0)
+ if (this.Bytes.UnreadableBytes != 0)
{
if (this.Bits.UnreadBits >= 8)
{
this.UnreadByteStuffedByte();
}
- this.bytes.UnreadableBytes = 0;
+ this.Bytes.UnreadableBytes = 0;
}
while (true)
{
- int m = this.bytes.J - this.bytes.I;
+ int m = this.Bytes.J - this.Bytes.I;
if (m > count)
{
m = count;
}
- this.bytes.I += m;
+ this.Bytes.I += m;
count -= m;
if (count == 0)
{
break;
}
- this.bytes.Fill(this.inputStream);
+ this.Bytes.Fill(this.InputStream);
}
}
///
- /// Undoes the most recent ReadByteStuffedByte call,
- /// giving a byte of data back from bits to bytes. The Huffman look-up table
- /// requires at least 8 bits for look-up, which means that Huffman decoding can
- /// sometimes overshoot and read one or two too many bytes. Two-byte overshoot
- /// can happen when expecting to read a 0xff 0x00 byte-stuffed byte.
+ /// Undoes the most recent ReadByteStuffedByte call,
+ /// giving a byte of data back from bits to bytes. The Huffman look-up table
+ /// requires at least 8 bits for look-up, which means that Huffman decoding can
+ /// sometimes overshoot and read one or two too many bytes. Two-byte overshoot
+ /// can happen when expecting to read a 0xff 0x00 byte-stuffed byte.
///
private void UnreadByteStuffedByte()
{
- this.bytes.I -= this.bytes.UnreadableBytes;
- this.bytes.UnreadableBytes = 0;
+ this.Bytes.I -= this.Bytes.UnreadableBytes;
+ this.Bytes.UnreadableBytes = 0;
if (this.Bits.UnreadBits >= 8)
{
this.Bits.Accumulator >>= 8;
@@ -1464,22 +1434,22 @@ namespace ImageSharp.Formats
}
///
- /// The EOF (End of File exception).
- /// Thrown when the decoder encounters an EOF marker without a proceeding EOI (End Of Image) marker
+ /// The EOF (End of File exception).
+ /// Thrown when the decoder encounters an EOF marker without a proceeding EOI (End Of Image) marker
///
internal class EOFException : Exception
{
}
///
- /// The missing ff00 exception.
+ /// The missing ff00 exception.
///
internal class MissingFF00Exception : Exception
{
}
///
- /// The short huffman data exception.
+ /// The short huffman data exception.
///
private class ShortHuffmanDataException : Exception
{