Browse Source

Move Bounds/Size to IImageInfo extension methods

af/merge-core
James Jackson-South 8 years ago
parent
commit
3d8f9c23e9
  1. 12
      src/ImageSharp/IImage.cs
  2. 27
      src/ImageSharp/ImageInfoExtensions.cs
  3. 9
      src/ImageSharp/Image{TPixel}.cs
  4. 2
      src/ImageSharp/MetaData/ImageMetaData.cs
  5. 34
      tests/ImageSharp.Tests/ImageInfoTests.cs

12
src/ImageSharp/IImage.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
@ -11,16 +10,5 @@ namespace SixLabors.ImageSharp
/// </summary>
public interface IImage : IImageInfo, IDisposable
{
/// <summary>
/// Gets the size of the image.
/// </summary>
/// <returns>The <see cref="Size"/></returns>
Size Size();
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <returns>The <see cref="Rectangle"/></returns>
Rectangle Bounds();
}
}

27
src/ImageSharp/ImageInfoExtensions.cs

@ -0,0 +1,27 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods that allow the addition of geometry calculating methods to the <see cref="IImageInfo"/> type
/// </summary>
public static class ImageInfoExtensions
{
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Size"/></returns>
public static Size Size(this IImageInfo info) => new Size(info.Width, info.Height);
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Rectangle"/></returns>
public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height);
}
}

9
src/ImageSharp/Image{TPixel}.cs

@ -10,7 +10,6 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed partial class Image<TPixel> : IImage, IConfigurable
public sealed class Image<TPixel> : IImage, IConfigurable
where TPixel : struct, IPixel<TPixel>
{
private readonly Configuration configuration;
@ -123,12 +122,6 @@ namespace SixLabors.ImageSharp
set => this.PixelSource.PixelBuffer[x, y] = value;
}
/// <inheritdoc/>
public Size Size() => new Size(this.Width, this.Height);
/// <inheritdoc/>
public Rectangle Bounds() => new Rectangle(0, 0, this.Width, this.Height);
/// <summary>
/// Saves the image to the given stream using the given image encoder.
/// </summary>

2
src/ImageSharp/MetaData/ImageMetaData.cs

@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.MetaData.Profiles.Icc;

34
tests/ImageSharp.Tests/ImageInfoTests.cs

@ -0,0 +1,34 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
public class ImageInfoTests
{
[Fact]
public void ImageInfoInitializesCorrectly()
{
const int Width = 50;
const int Height = 60;
var size = new Size(Width, Height);
var rectangle = new Rectangle(0, 0, Width, Height);
var pixelType = new PixelTypeInfo(8);
var meta = new ImageMetaData();
var info = new ImageInfo(pixelType, Width, Height, meta);
Assert.Equal(pixelType, info.PixelType);
Assert.Equal(Width, info.Width);
Assert.Equal(Height, info.Height);
Assert.Equal(size, info.Size());
Assert.Equal(rectangle, info.Bounds());
Assert.Equal(meta, info.MetaData);
}
}
}
Loading…
Cancel
Save