mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 76 additions and 362 deletions
@ -1,95 +0,0 @@ |
|||
// 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="Image"/> and <see cref="IImageFormat"/> for return from async overloads.
|
|||
/// </summary>
|
|||
public readonly struct FormattedImage : IEquatable<FormattedImage> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="FormattedImage"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="Image"/>.</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) |
|||
=> (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) |
|||
=> new FormattedImage(value.image, value.format); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImage"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImage"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImage"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(FormattedImage left, FormattedImage right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImage"/> objects for inequality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImage"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImage"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(FormattedImage left, FormattedImage right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is FormattedImage image && this.Equals(image); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(FormattedImage other) |
|||
=> EqualityComparer<Image>.Default.Equals(this.Image, other.Image) |
|||
&& EqualityComparer<IImageFormat>.Default.Equals(this.Format, other.Format); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => HashCode.Combine(this.Image, this.Format); |
|||
|
|||
/// <summary>
|
|||
/// Deconstructs <see cref="FormattedImage"/> into component parts.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="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; |
|||
} |
|||
} |
|||
} |
|||
@ -1,93 +0,0 @@ |
|||
// 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 : IEquatable<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) |
|||
=> (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) |
|||
=> new FormattedImageInfo(value.imageInfo, value.format); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImageInfo"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImageInfo"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImageInfo"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(FormattedImageInfo left, FormattedImageInfo right) => left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImageInfo"/> objects for inequality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImageInfo"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImageInfo"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(FormattedImageInfo left, FormattedImageInfo right) => !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is FormattedImageInfo info && this.Equals(info); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(FormattedImageInfo other) |
|||
=> EqualityComparer<IImageInfo>.Default.Equals(this.ImageInfo, other.ImageInfo) |
|||
&& EqualityComparer<IImageFormat>.Default.Equals(this.Format, other.Format); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => 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; |
|||
} |
|||
} |
|||
} |
|||
@ -1,98 +0,0 @@ |
|||
// 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="Image{TPixel}"/> and <see cref="IImageFormat"/> for return from async overloads.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
public readonly struct FormattedImage<TPixel> : IEquatable<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="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) |
|||
=> (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) |
|||
=> new FormattedImage<TPixel>(value.image, value.format); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImage{TPixel}"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImage{TPixel}"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImage{TPixel}"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(FormattedImage<TPixel> left, FormattedImage<TPixel> right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="FormattedImage{TPixel}"/> objects for inequality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="FormattedImage{TPixel}"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="FormattedImage{TPixel}"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(FormattedImage<TPixel> left, FormattedImage<TPixel> right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is FormattedImage<TPixel> image && this.Equals(image); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(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() => HashCode.Combine(this.Image, this.Format); |
|||
|
|||
/// <summary>
|
|||
/// Deconstructs <see cref="FormattedImage"/> into component parts.
|
|||
/// </summary>
|
|||
/// <param name="image">The <see cref="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