diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index f6da9cb2e..5bfe88cc6 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
/// The only supported precision
///
- public const int SupportedPrecision = 8;
+ public readonly int[] SupportedPrecisions = { 8, 12 };
///
/// The global configuration
@@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
/// Gets the color depth, in number of bits per pixel.
///
- public int BitsPerPixel => this.ComponentCount * SupportedPrecision;
+ public int BitsPerPixel => this.ComponentCount * this.Frame.Precision;
///
/// Gets the input stream.
@@ -720,10 +720,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
this.InputStream.Read(this.temp, 0, remaining);
- // We only support 8-bit precision.
- if (this.temp[0] != SupportedPrecision)
+ // We only support 8-bit and 12-bit precision.
+ if (!SupportedPrecisions.Contains(this.temp[0]))
{
- throw new ImageFormatException("Only 8-Bit precision supported.");
+ throw new ImageFormatException("Only 8-Bit and 12-Bit precision supported.");
}
this.Frame = new JpegFrame
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
index 40de25b30..03f1826ed 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
@@ -28,7 +28,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Issues.ExifResizeOutOfRange696,
TestImages.Jpeg.Issues.InvalidAPP0721,
TestImages.Jpeg.Issues.ExifGetString750Load,
- TestImages.Jpeg.Issues.ExifGetString750Transform
+ TestImages.Jpeg.Issues.ExifGetString750Transform,
+
+ // High depth images
+ TestImages.Jpeg.Baseline.Testorig12bit,
};
public static string[] ProgressiveTestJpegs =
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 1144a3f7c..46f9459c5 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -135,12 +135,14 @@ namespace SixLabors.ImageSharp.Tests
public const string Testorig420 = "Jpg/baseline/testorig.jpg";
public const string MultiScanBaselineCMYK = "Jpg/baseline/MultiScanBaselineCMYK.jpg";
public const string Ratio1x1 = "Jpg/baseline/ratio-1x1.jpg";
+ public const string Testorig12bit = "Jpg/baseline/testorig12.jpg";
public static readonly string[] All =
{
Cmyk, Ycck, Exif, Floorplan,
Calliphora, Turtle, GammaDalaiLamaGray,
- Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444, Ratio1x1
+ Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444,
+ Ratio1x1, Testorig12bit
};
}
diff --git a/tests/Images/Input/Jpg/baseline/testorig12.jpg b/tests/Images/Input/Jpg/baseline/testorig12.jpg
new file mode 100644
index 000000000..5cc7a0ada
--- /dev/null
+++ b/tests/Images/Input/Jpg/baseline/testorig12.jpg
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:34790770f76db8e60a7765b52ca4edf5f16bc21bcb8c6045ca2efef39a8a013e
+size 12394