diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index bdd15c2d7..ee6676f5a 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -39,14 +39,14 @@ namespace ImageSharp.Formats
}
///
- public int DetectPixelSize(Configuration configuration, Stream stream)
+ public PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");
byte[] buffer = new byte[2];
stream.Skip(28);
stream.Read(buffer, 0, 2);
- return BitConverter.ToInt16(buffer, 0);
+ return new PixelTypeInfo(BitConverter.ToInt16(buffer, 0));
}
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 4d847c9fe..63eb2eaf4 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -35,14 +35,15 @@ namespace ImageSharp.Formats
}
///
- public int DetectPixelSize(Configuration configuration, Stream stream)
+ public PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");
byte[] buffer = new byte[1];
stream.Skip(10); // Skip the identifier and size
stream.Read(buffer, 0, 1); // Skip the identifier and size
- return (buffer[0] & 0x07) + 1; // The lowest 3 bits represent the bit depth minus 1
+ int bitsPerPixel = (buffer[0] & 0x07) + 1; // The lowest 3 bits represent the bit depth minus 1
+ return new PixelTypeInfo(bitsPerPixel);
}
}
}
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index a16ef2612..6befafb39 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -31,7 +31,7 @@ namespace ImageSharp.Formats
///
/// The configuration for the image.
/// The containing image data.
- /// The color depth, in number of bits per pixel
- int DetectPixelSize(Configuration configuration, Stream stream);
+ /// The object
+ PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream);
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index 8bdbdfe0c..66e303c01 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -34,13 +34,13 @@ namespace ImageSharp.Formats
}
///
- public int DetectPixelSize(Configuration configuration, Stream stream)
+ public PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");
using (JpegDecoderCore decoder = new JpegDecoderCore(configuration, this))
{
- return decoder.DetectPixelSize(stream);
+ return new PixelTypeInfo(decoder.DetectPixelSize(stream));
}
}
}
diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs
new file mode 100644
index 000000000..c33154351
--- /dev/null
+++ b/src/ImageSharp/Formats/PixelTypeInfo.cs
@@ -0,0 +1,22 @@
+namespace ImageSharp.Formats
+{
+ ///
+ /// Stores information about pixel
+ ///
+ public class PixelTypeInfo
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// color depth, in number of bits per pixel
+ internal PixelTypeInfo(int bitsPerPixel)
+ {
+ this.BitsPerPixel = bitsPerPixel;
+ }
+
+ ///
+ /// Gets color depth, in number of bits per pixel
+ ///
+ public int BitsPerPixel { get; }
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index dd71b70cc..b7ffe8e72 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -63,10 +63,10 @@ namespace ImageSharp.Formats
/// The configuration for the image.
/// The containing image data.
/// The color depth, in number of bits per pixel
- public int DetectPixelSize(Configuration configuration, Stream stream)
+ public PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream)
{
var decoder = new PngDecoderCore(configuration, this);
- return decoder.DetectPixelSize(stream);
+ return new PixelTypeInfo(decoder.DetectPixelSize(stream));
}
}
}
diff --git a/src/ImageSharp/Image/Image.Decode.cs b/src/ImageSharp/Image/Image.Decode.cs
index 05a01d825..313224c5f 100644
--- a/src/ImageSharp/Image/Image.Decode.cs
+++ b/src/ImageSharp/Image/Image.Decode.cs
@@ -88,12 +88,12 @@ namespace ImageSharp
/// The stream.
/// the configuration.
///
- /// The color depth, in number of bits per pixel or null if suitable decoder not found.
+ /// The or null if suitable decoder not found.
///
- private static int? InternalDetectPixelSize(Stream stream, Configuration config)
+ private static PixelTypeInfo InternalDetectPixelType(Stream stream, Configuration config)
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat _);
- return decoder?.DetectPixelSize(config, stream);
+ return decoder?.DetectPixelType(config, stream);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Image/Image.FromStream.cs b/src/ImageSharp/Image/Image.FromStream.cs
index 032c81c33..e84d89a91 100644
--- a/src/ImageSharp/Image/Image.FromStream.cs
+++ b/src/ImageSharp/Image/Image.FromStream.cs
@@ -46,10 +46,12 @@ namespace ImageSharp
///
/// Thrown if the stream is not readable nor seekable.
///
- /// The color depth, in number of bits per pixel or null if suitable decoder not found
- public static int? DetectPixelSize(Stream stream)
+ ///
+ /// The or null if suitable decoder not found.
+ ///
+ public static PixelTypeInfo DetectPixelType(Stream stream)
{
- return DetectPixelSize(null, stream);
+ return DetectPixelType(null, stream);
}
///
@@ -60,10 +62,12 @@ namespace ImageSharp
///
/// Thrown if the stream is not readable nor seekable.
///
- /// The color depth, in number of bits per pixel or null if suitable decoder not found
- public static int? DetectPixelSize(Configuration config, Stream stream)
+ ///
+ /// The or null if suitable decoder not found.
+ ///
+ public static PixelTypeInfo DetectPixelType(Configuration config, Stream stream)
{
- return WithSeekableStream(stream, s => InternalDetectPixelSize(s, config ?? Configuration.Default));
+ return WithSeekableStream(stream, s => InternalDetectPixelType(s, config ?? Configuration.Default));
}
///
diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
index a2eaf6df6..84edca001 100644
--- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
@@ -22,7 +22,7 @@ namespace ImageSharp.Tests
TestFile testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
- Assert.Equal(expectedPixelSize, Image.DetectPixelSize(stream));
+ Assert.Equal(expectedPixelSize, Image.DetectPixelType(stream)?.BitsPerPixel);
}
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
index c952cd799..b7af4525e 100644
--- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
@@ -92,7 +92,7 @@ namespace ImageSharp.Tests
TestFile testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
- Assert.Equal(expectedPixelSize, Image.DetectPixelSize(stream));
+ Assert.Equal(expectedPixelSize, Image.DetectPixelType(stream)?.BitsPerPixel);
}
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
index 4a9eb4325..4ac7c5c5b 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
@@ -165,7 +165,7 @@ namespace ImageSharp.Tests
TestFile testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
- Assert.Equal(expectedPixelSize, Image.DetectPixelSize(stream));
+ Assert.Equal(expectedPixelSize, Image.DetectPixelType(stream)?.BitsPerPixel);
}
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
index c7147b226..f9b34e7c7 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
@@ -97,7 +97,7 @@ namespace ImageSharp.Tests
TestFile testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
- Assert.Equal(expectedPixelSize, Image.DetectPixelSize(stream));
+ Assert.Equal(expectedPixelSize, Image.DetectPixelType(stream)?.BitsPerPixel);
}
}
diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs
index 6c2bca367..c760b9b98 100644
--- a/tests/ImageSharp.Tests/TestFormat.cs
+++ b/tests/ImageSharp.Tests/TestFormat.cs
@@ -204,7 +204,7 @@ namespace ImageSharp.Tests
return this.testFormat.Sample();
}
- public int DetectPixelSize(Configuration configuration, Stream stream)
+ public PixelTypeInfo DetectPixelType(Configuration configuration, Stream stream)
{
throw new NotImplementedException();
}