Browse Source

Start work on jpeg 12 bit support

pull/784/head
Stephan Vedder 7 years ago
parent
commit
5ee5da8f81
  1. 10
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  2. 5
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
  3. 4
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Jpg/baseline/testorig12.jpg

10
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <summary> /// <summary>
/// The only supported precision /// The only supported precision
/// </summary> /// </summary>
public const int SupportedPrecision = 8; public readonly int[] SupportedPrecisions = { 8, 12 };
/// <summary> /// <summary>
/// The global configuration /// The global configuration
@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <summary> /// <summary>
/// Gets the color depth, in number of bits per pixel. /// Gets the color depth, in number of bits per pixel.
/// </summary> /// </summary>
public int BitsPerPixel => this.ComponentCount * SupportedPrecision; public int BitsPerPixel => this.ComponentCount * this.Frame.Precision;
/// <summary> /// <summary>
/// Gets the input stream. /// Gets the input stream.
@ -720,10 +720,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
this.InputStream.Read(this.temp, 0, remaining); this.InputStream.Read(this.temp, 0, remaining);
// We only support 8-bit precision. // We only support 8-bit and 12-bit precision.
if (this.temp[0] != SupportedPrecision) 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 this.Frame = new JpegFrame

5
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.ExifResizeOutOfRange696,
TestImages.Jpeg.Issues.InvalidAPP0721, TestImages.Jpeg.Issues.InvalidAPP0721,
TestImages.Jpeg.Issues.ExifGetString750Load, TestImages.Jpeg.Issues.ExifGetString750Load,
TestImages.Jpeg.Issues.ExifGetString750Transform TestImages.Jpeg.Issues.ExifGetString750Transform,
// High depth images
TestImages.Jpeg.Baseline.Testorig12bit,
}; };
public static string[] ProgressiveTestJpegs = public static string[] ProgressiveTestJpegs =

4
tests/ImageSharp.Tests/TestImages.cs

@ -135,12 +135,14 @@ namespace SixLabors.ImageSharp.Tests
public const string Testorig420 = "Jpg/baseline/testorig.jpg"; public const string Testorig420 = "Jpg/baseline/testorig.jpg";
public const string MultiScanBaselineCMYK = "Jpg/baseline/MultiScanBaselineCMYK.jpg"; public const string MultiScanBaselineCMYK = "Jpg/baseline/MultiScanBaselineCMYK.jpg";
public const string Ratio1x1 = "Jpg/baseline/ratio-1x1.jpg"; public const string Ratio1x1 = "Jpg/baseline/ratio-1x1.jpg";
public const string Testorig12bit = "Jpg/baseline/testorig12.jpg";
public static readonly string[] All = public static readonly string[] All =
{ {
Cmyk, Ycck, Exif, Floorplan, Cmyk, Ycck, Exif, Floorplan,
Calliphora, Turtle, GammaDalaiLamaGray, Calliphora, Turtle, GammaDalaiLamaGray,
Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444, Ratio1x1 Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444,
Ratio1x1, Testorig12bit
}; };
} }

BIN
tests/Images/Input/Jpg/baseline/testorig12.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save