diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index a1bf048521..63276babd8 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Six Labors and contributors.
+// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
@@ -28,6 +28,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
}
+ ///
+ public Image Decode(Configuration configuration, Stream stream)
+ {
+ Guard.NotNull(stream, nameof(stream));
+
+ using (var decoder = new JpegDecoderCore(configuration, this))
+ {
+ return decoder.Decode(stream);
+ }
+ }
+
///
public IImageInfo Identify(Configuration configuration, Stream stream)
{
@@ -38,8 +49,5 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
return decoder.Identify(stream);
}
}
-
- ///
- public Image Decode(Configuration configuration, Stream stream) => this.Decode(configuration, stream);
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index c15fe5e274..bcdc37798e 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -204,6 +204,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
return new JpegFileMarker(marker[1], stream.Position - 2, true);
}
+ ///
+ /// Decodes the image from the specified and sets the data to image.
+ ///
+ /// The stream, where the image should be.
+ /// The decoded image.
+ public Image Decode(Stream stream)
+ {
+ this.ParseStream(stream);
+ this.InitExifProfile();
+ this.InitIccProfile();
+ this.InitDerivedMetadataProperties();
+ return this.ColorSpace == JpegColorSpace.Grayscale
+ ? (Image)this.PostProcessIntoImage()
+ : this.PostProcessIntoImage();
+ }
+
///
/// Decodes the image from the specified and sets the data to image.
///
@@ -649,48 +665,51 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
switch (quantizationTableSpec >> 4)
{
case 0:
+ {
+ // 8 bit values
+ if (remaining < 64)
{
- // 8 bit values
- if (remaining < 64)
- {
- done = true;
- break;
- }
+ done = true;
+ break;
+ }
- this.InputStream.Read(this.temp, 0, 64);
- remaining -= 64;
+ this.InputStream.Read(this.temp, 0, 64);
+ remaining -= 64;
- ref Block8x8F table = ref this.QuantizationTables[tableIndex];
- for (int j = 0; j < 64; j++)
- {
- table[j] = this.temp[j];
- }
+ ref Block8x8F table = ref this.QuantizationTables[tableIndex];
+ for (int j = 0; j < 64; j++)
+ {
+ table[j] = this.temp[j];
}
+ }
- break;
+ break;
case 1:
+ {
+ // 16 bit values
+ if (remaining < 128)
{
- // 16 bit values
- if (remaining < 128)
- {
- done = true;
- break;
- }
+ done = true;
+ break;
+ }
- this.InputStream.Read(this.temp, 0, 128);
- remaining -= 128;
+ this.InputStream.Read(this.temp, 0, 128);
+ remaining -= 128;
- ref Block8x8F table = ref this.QuantizationTables[tableIndex];
- for (int j = 0; j < 64; j++)
- {
- table[j] = (this.temp[2 * j] << 8) | this.temp[(2 * j) + 1];
- }
+ ref Block8x8F table = ref this.QuantizationTables[tableIndex];
+ for (int j = 0; j < 64; j++)
+ {
+ table[j] = (this.temp[2 * j] << 8) | this.temp[(2 * j) + 1];
}
+ }
+
+ break;
- break;
default:
+ {
JpegThrowHelper.ThrowBadQuantizationTable();
break;
+ }
}
if (done)