mirror of https://github.com/SixLabors/ImageSharp
18 changed files with 481 additions and 100 deletions
@ -0,0 +1,79 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the GNU Affero General Public License, Version 3.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using SixLabors.ImageSharp.Formats; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Struct to curry <see cref="ImageSharp.Image"/> and <see cref="IImageFormat"/> for return from async overloads.
|
|||
/// </summary>
|
|||
public readonly struct FormattedImage |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FormattedImage"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="FormattedImage"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public FormattedImage(Image image, IImageFormat format) |
|||
{ |
|||
this.Image = image; |
|||
this.Format = format; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the Image.
|
|||
/// </summary>
|
|||
public readonly Image Image { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the Format.
|
|||
/// </summary>
|
|||
public readonly IImageFormat Format { get; } |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="FormattedImage"/> to <see cref="ValueTuple"/>
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="FormattedImage"/> to convert.</param>
|
|||
public static implicit operator (Image image, IImageFormat format)(FormattedImage value) |
|||
{ |
|||
return (value.Image, value.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="ValueTuple"/> to <see cref="FormattedImage"/>
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="ValueTuple"/> to convert.</param>
|
|||
public static implicit operator FormattedImage((Image image, IImageFormat format) value) |
|||
{ |
|||
return new FormattedImage(value.image, value.format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return obj is FormattedImage other && |
|||
EqualityComparer<Image>.Default.Equals(this.Image, other.Image) && |
|||
EqualityComparer<IImageFormat>.Default.Equals(this.Format, other.Format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return HashCode.Combine(this.Image, this.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Deconstructs <see cref="FormattedImage"/> into component parts.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="ImageSharp.Image"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public void Deconstruct(out Image image, out IImageFormat format) |
|||
{ |
|||
image = this.Image; |
|||
format = this.Format; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the GNU Affero General Public License, Version 3.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using SixLabors.ImageSharp.Formats; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Struct to curry <see cref="IImageInfo"/> and <see cref="IImageFormat"/> for return from async overloads.
|
|||
/// </summary>
|
|||
public readonly struct FormattedImageInfo |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FormattedImageInfo"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="imageInfo">The <see cref="FormattedImageInfo"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public FormattedImageInfo(IImageInfo imageInfo, IImageFormat format) |
|||
{ |
|||
this.ImageInfo = imageInfo; |
|||
this.Format = format; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the Image Info.
|
|||
/// </summary>
|
|||
public readonly IImageInfo ImageInfo { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the Format.
|
|||
/// </summary>
|
|||
public readonly IImageFormat Format { get; } |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="FormattedImageInfo"/> to a <see cref="ValueTuple"/>
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="FormattedImageInfo"/> to convert.</param>
|
|||
public static implicit operator (IImageInfo imageInfo, IImageFormat format)(FormattedImageInfo value) |
|||
{ |
|||
return (value.ImageInfo, value.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="ValueTuple"/> to <see cref="FormattedImageInfo"/>
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="ValueTuple"/> to convert.</param>
|
|||
public static implicit operator FormattedImageInfo((IImageInfo imageInfo, IImageFormat format) value) |
|||
{ |
|||
return new FormattedImageInfo(value.imageInfo, value.format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return obj is FormattedImageInfo other && |
|||
EqualityComparer<IImageInfo>.Default.Equals(this.ImageInfo, other.ImageInfo) && |
|||
EqualityComparer<IImageFormat>.Default.Equals(this.Format, other.Format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return HashCode.Combine(this.ImageInfo, this.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Deconstructs <see cref="FormattedImageInfo"/> into component parts.
|
|||
/// </summary>
|
|||
/// <param name="imageInfo">The <see cref="FormattedImageInfo"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public void Deconstruct(out IImageInfo imageInfo, out IImageFormat format) |
|||
{ |
|||
imageInfo = this.ImageInfo; |
|||
format = this.Format; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the GNU Affero General Public License, Version 3.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Struct to curry <see cref="ImageSharp.Image{TPixel}"/> and <see cref="IImageFormat"/> for return from async overloads.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
public readonly struct FormattedImage<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FormattedImage{TPixel}"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="ImageSharp.Image{TPixel}"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public FormattedImage(Image<TPixel> image, IImageFormat format) |
|||
{ |
|||
this.Image = image; |
|||
this.Format = format; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the Image.
|
|||
/// </summary>
|
|||
public readonly Image<TPixel> Image { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the Format.
|
|||
/// </summary>
|
|||
public readonly IImageFormat Format { get; } |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="FormattedImage{TPixel}"/> to <see cref="ValueTuple"/>.
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="FormattedImage{TPixel}"/> to convert.</param>
|
|||
public static implicit operator (Image<TPixel> image, IImageFormat format)(FormattedImage<TPixel> value) |
|||
{ |
|||
return (value.Image, value.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts <see cref="ValueTuple"/> to <see cref="FormattedImage{TPixel}"/>
|
|||
/// </summary>
|
|||
/// <param name="value">The <see cref="ValueTuple"/> to convert.</param>
|
|||
public static implicit operator FormattedImage<TPixel>((Image<TPixel> image, IImageFormat format) value) |
|||
{ |
|||
return new FormattedImage<TPixel>(value.image, value.format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return obj is FormattedImage<TPixel> other && |
|||
EqualityComparer<Image<TPixel>>.Default.Equals(this.Image, other.Image) && |
|||
EqualityComparer<IImageFormat>.Default.Equals(this.Format, other.Format); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return HashCode.Combine(this.Image, this.Format); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Deconstructs <see cref="FormattedImage"/> into component parts.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="ImageSharp.Image{TPixel}"/>.</param>
|
|||
/// <param name="format">The <see cref="IImageFormat"/>.</param>
|
|||
public void Deconstruct(out Image<TPixel> image, out IImageFormat format) |
|||
{ |
|||
image = this.Image; |
|||
format = this.Format; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue