Skip to content

Commit

Permalink
changes on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
denisivan0v committed Jan 19, 2018
1 parent e88e138 commit 61c9caf
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 188 deletions.
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Bmp/BmpDecoder.cs
Expand Up @@ -34,7 +34,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
}

/// <inheritdoc/>
public IImage Identify(Configuration configuration, Stream stream)
public IImageInfo Identify(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");

Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
Expand Up @@ -141,10 +141,10 @@ public Image<TPixel> Decode<TPixel>(Stream stream)
}

/// <summary>
/// Reads the image base information from the specified stream.
/// Reads the raw image information from the specified stream.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
public IImage Identify(Stream stream)
public IImageInfo Identify(Stream stream)
{
this.ReadImageHeaders(stream, out _, out _);
return new ImageInfo(new PixelTypeInfo(this.infoHeader.BitsPerPixel), this.infoHeader.Width, this.infoHeader.Height, new ImageMetaData());
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Gif/GifDecoder.cs
Expand Up @@ -36,7 +36,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
}

/// <inheritdoc/>
public IImage Identify(Configuration configuration, Stream stream)
public IImageInfo Identify(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");

Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/Gif/GifDecoderCore.cs
Expand Up @@ -165,10 +165,10 @@ public Image<TPixel> Decode<TPixel>(Stream stream)
}

/// <summary>
/// Reads the image base information from the specified stream.
/// Reads the raw image information from the specified stream.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
public IImage Identify(Stream stream)
public IImageInfo Identify(Stream stream)
{
try
{
Expand Down Expand Up @@ -425,7 +425,7 @@ private void ReadFrameColors<TPixel>(ref Image<TPixel> image, ref ImageFrame<TPi
if (previousFrame == null)
{
// This initializes the image to become fully transparent because the alpha channel is zero.
image = new Image<TPixel>(this.configuration, new PixelTypeInfo(this.logicalScreenDescriptor.BitsPerPixel), imageWidth, imageHeight, this.metaData);
image = new Image<TPixel>(this.configuration, imageWidth, imageHeight, this.metaData);

this.SetFrameMetaData(image.Frames.RootFrame.MetaData);

Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/IImageInfoDetector.cs
Expand Up @@ -6,16 +6,16 @@
namespace SixLabors.ImageSharp.Formats
{
/// <summary>
/// Used for detecting the image base information without decoding it.
/// Used for detecting the raw image information without decoding it.
/// </summary>
public interface IImageInfoDetector
{
/// <summary>
/// Reads the image base information from the specified stream.
/// Reads the raw image information from the specified stream.
/// </summary>
/// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <returns>The <see cref="PixelTypeInfo"/> object</returns>
IImage Identify(Configuration configuration, Stream stream);
IImageInfo Identify(Configuration configuration, Stream stream);
}
}
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoder.cs
Expand Up @@ -29,7 +29,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
}

/// <inheritdoc/>
public IImage Identify(Configuration configuration, Stream stream)
public IImageInfo Identify(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");

Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs
Expand Up @@ -198,10 +198,10 @@ public Image<TPixel> Decode<TPixel>(Stream stream)
}

/// <summary>
/// Reads the image base information from the specified stream.
/// Reads the raw image information from the specified stream.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
public IImage Identify(Stream stream)
public IImageInfo Identify(Stream stream)
{
this.ParseStream(stream, true);
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData);
Expand Down Expand Up @@ -789,7 +789,7 @@ private Image<TPixel> PostProcessIntoImage<TPixel>()
{
using (var postProcessor = new JpegImagePostProcessor(this))
{
var image = new Image<TPixel>(this.configuration, new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData);
var image = new Image<TPixel>(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData);
postProcessor.PostProcess(image.Frames.RootFrame);
return image;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
Expand Up @@ -31,7 +31,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
}

/// <inheritdoc/>
public IImage Identify(Configuration configuration, Stream stream)
public IImageInfo Identify(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, "stream");

Expand Down
Expand Up @@ -159,7 +159,7 @@ public Image<TPixel> Decode<TPixel>(Stream stream)

this.QuantizeAndInverseAllComponents();

var image = new Image<TPixel>(this.configuration, null, this.ImageWidth, this.ImageHeight, metadata);
var image = new Image<TPixel>(this.configuration, this.ImageWidth, this.ImageHeight, metadata);
this.FillPixelData(image.Frames.RootFrame);
this.AssignResolution(image);
return image;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/PixelTypeInfo.cs
@@ -1,7 +1,7 @@
namespace SixLabors.ImageSharp.Formats
{
/// <summary>
/// Stores information about pixel.
/// Stores the raw image pixel type information.
/// </summary>
public class PixelTypeInfo
{
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Png/PngDecoder.cs
Expand Up @@ -54,7 +54,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
}

/// <inheritdoc/>
public IImage Identify(Configuration configuration, Stream stream)
public IImageInfo Identify(Configuration configuration, Stream stream)
{
var decoder = new PngDecoderCore(configuration, this);
return decoder.Identify(stream);
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/Png/PngDecoderCore.cs
Expand Up @@ -279,10 +279,10 @@ public Image<TPixel> Decode<TPixel>(Stream stream)
}

/// <summary>
/// Reads the image base information from the specified stream.
/// Reads the raw image information from the specified stream.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
public IImage Identify(Stream stream)
public IImageInfo Identify(Stream stream)
{
var metadata = new ImageMetaData();
this.currentStream = stream;
Expand Down Expand Up @@ -426,7 +426,7 @@ private void ReadPhysicalChunk(ImageMetaData metadata, byte[] data)
private void InitializeImage<TPixel>(ImageMetaData metadata, out Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
image = new Image<TPixel>(this.configuration, new PixelTypeInfo(this.CalculateBitsPerPixel()), this.header.Width, this.header.Height, metadata);
image = new Image<TPixel>(this.configuration, this.header.Width, this.header.Height, metadata);
this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;
this.bytesPerSample = 1;
Expand Down
26 changes: 2 additions & 24 deletions src/ImageSharp/Image/IImage.cs
@@ -1,31 +1,9 @@
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData;

namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp
{
/// <summary>
/// Represents the base image abstraction.
/// </summary>
public interface IImage
public interface IImage : IImageInfo
{
/// <summary>
/// Gets information about pixel.
/// </summary>
PixelTypeInfo PixelType { get; }

/// <summary>
/// Gets the width.
/// </summary>
int Width { get; }

/// <summary>
/// Gets the height.
/// </summary>
int Height { get; }

/// <summary>
/// Gets the meta data of the image.
/// </summary>
ImageMetaData MetaData { get; }
}
}
31 changes: 31 additions & 0 deletions src/ImageSharp/Image/IImageInfo.cs
@@ -0,0 +1,31 @@
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData;

namespace SixLabors.ImageSharp
{
/// <summary>
/// Represents raw image information.
/// </summary>
public interface IImageInfo
{
/// <summary>
/// Gets the raw image pixel type information.
/// </summary>
PixelTypeInfo PixelType { get; }

/// <summary>
/// Gets the width.
/// </summary>
int Width { get; }

/// <summary>
/// Gets the height.
/// </summary>
int Height { get; }

/// <summary>
/// Gets the meta data of the image.
/// </summary>
ImageMetaData MetaData { get; }
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Image/Image.Decode.cs
Expand Up @@ -86,9 +86,9 @@ private static (Image<TPixel> img, IImageFormat format) Decode<TPixel>(Stream st
/// <param name="stream">The stream.</param>
/// <param name="config">the configuration.</param>
/// <returns>
/// The <see cref="IImage"/> or null if suitable info detector not found.
/// The <see cref="IImageInfo"/> or null if suitable info detector not found.
/// </returns>
private static IImage InternalIdentity(Stream stream, Configuration config)
private static IImageInfo InternalIdentity(Stream stream, Configuration config)
{
var detector = DiscoverDecoder(stream, config, out IImageFormat _) as IImageInfoDetector;
return detector?.Identify(config, stream);
Expand Down
12 changes: 6 additions & 6 deletions src/ImageSharp/Image/Image.FromStream.cs
Expand Up @@ -37,32 +37,32 @@ public static IImageFormat DetectFormat(Configuration config, Stream stream)
}

/// <summary>
/// By reading the header on the provided stream this reads the image base information.
/// By reading the header on the provided stream this reads the raw image information.
/// </summary>
/// <param name="stream">The image stream to read the header from.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>
/// The <see cref="IImage"/> or null if suitable info detector not found.
/// The <see cref="IImageInfo"/> or null if suitable info detector not found.
/// </returns>
public static IImage Identify(Stream stream)
public static IImageInfo Identify(Stream stream)
{
return Identify(null, stream);
}

/// <summary>
/// By reading the header on the provided stream this reads the image base information.
/// By reading the header on the provided stream this reads the raw image information.
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="stream">The image stream to read the header from.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>
/// The <see cref="IImage"/> or null if suitable info detector not found.
/// The <see cref="IImageInfo"/> or null if suitable info detector not found.
/// </returns>
public static IImage Identify(Configuration config, Stream stream)
public static IImageInfo Identify(Configuration config, Stream stream)
{
return WithSeekableStream(stream, s => InternalIdentity(s, config ?? Configuration.Default));
}
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/Image/ImageFrameCollection.cs
Expand Up @@ -129,15 +129,15 @@ public Image<TPixel> ExportFrame(int index)

this.frames.Remove(frame);

return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.PixelType, this.parent.MetaData.Clone(), new[] { frame });
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { frame });
}

/// <inheritdoc/>
public Image<TPixel> CloneFrame(int index)
{
ImageFrame<TPixel> frame = this[index];
ImageFrame<TPixel> clonedFrame = frame.Clone();
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.PixelType, this.parent.MetaData.Clone(), new[] { clonedFrame });
return new Image<TPixel>(this.parent.GetConfiguration(), this.parent.MetaData.Clone(), new[] { clonedFrame });
}

/// <inheritdoc/>
Expand Down
16 changes: 15 additions & 1 deletion src/ImageSharp/Image/ImageInfo.cs
Expand Up @@ -3,8 +3,18 @@

namespace SixLabors.ImageSharp
{
internal sealed class ImageInfo : IImage
/// <summary>
/// Stores the raw image information.
/// </summary>
internal sealed class ImageInfo : IImageInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageInfo"/> class.
/// </summary>
/// <param name="pixelType">The raw image pixel type information.</param>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metaData">The images metadata.</param>
public ImageInfo(PixelTypeInfo pixelType, int width, int height, ImageMetaData metaData)
{
this.PixelType = pixelType;
Expand All @@ -13,12 +23,16 @@ public ImageInfo(PixelTypeInfo pixelType, int width, int height, ImageMetaData m
this.MetaData = metaData;
}

/// <inheritdoc />
public PixelTypeInfo PixelType { get; }

/// <inheritdoc />
public int Width { get; }

/// <inheritdoc />
public int Height { get; }

/// <inheritdoc />
public ImageMetaData MetaData { get; }
}
}

0 comments on commit 61c9caf

Please sign in to comment.