mirror of https://github.com/SixLabors/ImageSharp
54 changed files with 606 additions and 874 deletions
@ -1,20 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the bmp format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="BmpMetadata"/>.</returns>
|
|||
public static BmpMetadata GetBmpMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(BmpFormat.Instance); |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats; |
|||
|
|||
/// <summary>
|
|||
/// Provides a way to specify the type of encoding to be used.
|
|||
/// </summary>
|
|||
public enum EncodingType |
|||
{ |
|||
/// <summary>
|
|||
/// Lossless encoding, which compresses data without any loss of information.
|
|||
/// </summary>
|
|||
Lossless, |
|||
|
|||
/// <summary>
|
|||
/// Lossy encoding, which compresses data by discarding some of it.
|
|||
/// </summary>
|
|||
Lossy |
|||
} |
|||
@ -1,97 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Diagnostics.CodeAnalysis; |
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.Formats.Gif; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the gif format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="GifMetadata"/>.</returns>
|
|||
public static GifMetadata GetGifMetadata(this ImageMetadata source) |
|||
=> source.GetFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the gif format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">
|
|||
/// When this method returns, contains the metadata associated with the specified image,
|
|||
/// if found; otherwise, the default value for the type of the metadata parameter.
|
|||
/// This parameter is passed uninitialized.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the gif metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetGifMetadata(this ImageMetadata source, [NotNullWhen(true)] out GifMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(GifFormat.Instance, out metadata); |
|||
|
|||
/// <summary>
|
|||
/// Gets the gif format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="GifFrameMetadata"/>.</returns>
|
|||
public static GifFrameMetadata GetGifMetadata(this ImageFrameMetadata source) |
|||
=> source.GetFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the gif format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">
|
|||
/// When this method returns, contains the metadata associated with the specified frame,
|
|||
/// if found; otherwise, the default value for the type of the metadata parameter.
|
|||
/// This parameter is passed uninitialized.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the gif frame metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetGifMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out GifFrameMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(GifFormat.Instance, out metadata); |
|||
|
|||
internal static AnimatedImageMetadata ToAnimatedImageMetadata(this GifMetadata source) |
|||
{ |
|||
Color background = Color.Transparent; |
|||
if (source.GlobalColorTable != null) |
|||
{ |
|||
background = source.GlobalColorTable.Value.Span[source.BackgroundColorIndex]; |
|||
} |
|||
|
|||
return new() |
|||
{ |
|||
ColorTable = source.GlobalColorTable, |
|||
ColorTableMode = source.ColorTableMode, |
|||
RepeatCount = source.RepeatCount, |
|||
BackgroundColor = background, |
|||
}; |
|||
} |
|||
|
|||
internal static AnimatedImageFrameMetadata ToAnimatedImageFrameMetadata(this GifFrameMetadata source) |
|||
{ |
|||
// For most scenarios we would consider the blend method to be 'Over' however if a frame has a disposal method of 'RestoreToBackground' or
|
|||
// has a local palette with 256 colors and is not transparent we should use 'Source'.
|
|||
bool blendSource = source.DisposalMode == FrameDisposalMode.RestoreToBackground || (source.LocalColorTable?.Length == 256 && !source.HasTransparency); |
|||
|
|||
// If the color table is global and frame has no transparency. Consider it 'Source' also.
|
|||
blendSource |= source.ColorTableMode == FrameColorTableMode.Global && !source.HasTransparency; |
|||
|
|||
return new() |
|||
{ |
|||
ColorTable = source.LocalColorTable, |
|||
ColorTableMode = source.ColorTableMode, |
|||
Duration = TimeSpan.FromMilliseconds(source.FrameDelay * 10), |
|||
DisposalMode = source.DisposalMode, |
|||
BlendMode = blendSource ? FrameBlendMode.Source : FrameBlendMode.Over, |
|||
}; |
|||
} |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Text; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the jpeg format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="JpegMetadata"/>.</returns>
|
|||
public static JpegMetadata GetJpegMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(JpegFormat.Instance); |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Pbm; |
|||
|
|||
/// <summary>
|
|||
/// Configuration options for use during PBM encoding.
|
|||
/// </summary>
|
|||
internal interface IPbmEncoderOptions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the encoding of the pixels.
|
|||
/// </summary>
|
|||
PbmEncoding? Encoding { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the Color type of the resulting image.
|
|||
/// </summary>
|
|||
PbmColorType? ColorType { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the Data Type of the pixel components.
|
|||
/// </summary>
|
|||
PbmComponentType? ComponentType { get; } |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Pbm; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the pbm format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="PbmMetadata"/>.</returns>
|
|||
public static PbmMetadata GetPbmMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(PbmFormat.Instance); |
|||
} |
|||
@ -1,84 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Diagnostics.CodeAnalysis; |
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the png format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="PngMetadata"/>.</returns>
|
|||
public static PngMetadata GetPngMetadata(this ImageMetadata source) => source.GetFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the png format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">The metadata.</param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the png metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetPngMetadata(this ImageMetadata source, [NotNullWhen(true)] out PngMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(PngFormat.Instance, out metadata); |
|||
|
|||
/// <summary>
|
|||
/// Gets the png format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="PngFrameMetadata"/>.</returns>
|
|||
public static PngFrameMetadata GetPngMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the png format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">The metadata.</param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the png frame metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetPngMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out PngFrameMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(PngFormat.Instance, out metadata); |
|||
|
|||
internal static AnimatedImageMetadata ToAnimatedImageMetadata(this PngMetadata source) |
|||
=> new() |
|||
{ |
|||
ColorTable = source.ColorTable, |
|||
ColorTableMode = FrameColorTableMode.Global, |
|||
RepeatCount = (ushort)Numerics.Clamp(source.RepeatCount, 0, ushort.MaxValue), |
|||
}; |
|||
|
|||
internal static AnimatedImageFrameMetadata ToAnimatedImageFrameMetadata(this PngFrameMetadata source) |
|||
{ |
|||
double delay = source.FrameDelay.ToDouble(); |
|||
if (double.IsNaN(delay)) |
|||
{ |
|||
delay = 0; |
|||
} |
|||
|
|||
return new() |
|||
{ |
|||
ColorTableMode = FrameColorTableMode.Global, |
|||
Duration = TimeSpan.FromMilliseconds(delay * 1000), |
|||
DisposalMode = GetMode(source.DisposalMode), |
|||
BlendMode = source.BlendMode, |
|||
}; |
|||
} |
|||
|
|||
private static FrameDisposalMode GetMode(FrameDisposalMode method) => method switch |
|||
{ |
|||
FrameDisposalMode.DoNotDispose => FrameDisposalMode.DoNotDispose, |
|||
FrameDisposalMode.RestoreToBackground => FrameDisposalMode.RestoreToBackground, |
|||
FrameDisposalMode.RestoreToPrevious => FrameDisposalMode.RestoreToPrevious, |
|||
_ => FrameDisposalMode.DoNotDispose, |
|||
}; |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Qoi; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the qoi format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="QoiMetadata"/>.</returns>
|
|||
public static QoiMetadata GetQoiMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(QoiFormat.Instance); |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Tga; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the tga format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="TgaMetadata"/>.</returns>
|
|||
public static TgaMetadata GetTgaMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(TgaFormat.Instance); |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using SixLabors.ImageSharp.Formats.Tiff; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the tiff format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="TiffMetadata"/>.</returns>
|
|||
public static TiffMetadata GetTiffMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(TiffFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the tiff format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="TiffFrameMetadata"/>.</returns>
|
|||
public static TiffFrameMetadata GetTiffMetadata(this ImageFrameMetadata metadata) => metadata.GetFormatMetadata(TiffFormat.Instance); |
|||
} |
|||
@ -1,75 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Diagnostics.CodeAnalysis; |
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.Formats.Webp; |
|||
using SixLabors.ImageSharp.Metadata; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> type.
|
|||
/// </summary>
|
|||
public static partial class MetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the webp format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="WebpMetadata"/>.</returns>
|
|||
public static WebpMetadata GetWebpMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(WebpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the webp format specific metadata for the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">The metadata.</param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the webp metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetWebpMetadata(this ImageMetadata source, [NotNullWhen(true)] out WebpMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(WebpFormat.Instance, out metadata); |
|||
|
|||
/// <summary>
|
|||
/// Gets the webp format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="metadata">The metadata this method extends.</param>
|
|||
/// <returns>The <see cref="WebpFrameMetadata"/>.</returns>
|
|||
public static WebpFrameMetadata GetWebpMetadata(this ImageFrameMetadata metadata) => metadata.GetFormatMetadata(WebpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the webp format specific metadata for the image frame.
|
|||
/// </summary>
|
|||
/// <param name="source">The metadata this method extends.</param>
|
|||
/// <param name="metadata">The metadata.</param>
|
|||
/// <returns>
|
|||
/// <see langword="true"/> if the webp frame metadata exists; otherwise, <see langword="false"/>.
|
|||
/// </returns>
|
|||
public static bool TryGetWebpFrameMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out WebpFrameMetadata? metadata) |
|||
=> source.TryGetFormatMetadata(WebpFormat.Instance, out metadata); |
|||
|
|||
internal static AnimatedImageMetadata ToAnimatedImageMetadata(this WebpMetadata source) |
|||
=> new() |
|||
{ |
|||
ColorTableMode = FrameColorTableMode.Global, |
|||
RepeatCount = source.RepeatCount, |
|||
BackgroundColor = source.BackgroundColor |
|||
}; |
|||
|
|||
internal static AnimatedImageFrameMetadata ToAnimatedImageFrameMetadata(this WebpFrameMetadata source) |
|||
=> new() |
|||
{ |
|||
ColorTableMode = FrameColorTableMode.Global, |
|||
Duration = TimeSpan.FromMilliseconds(source.FrameDelay), |
|||
DisposalMode = GetMode(source.DisposalMethod), |
|||
BlendMode = source.BlendMethod == WebpBlendMethod.Over ? FrameBlendMode.Over : FrameBlendMode.Source, |
|||
}; |
|||
|
|||
private static FrameDisposalMode GetMode(WebpDisposalMethod method) => method switch |
|||
{ |
|||
WebpDisposalMethod.RestoreToBackground => FrameDisposalMode.RestoreToBackground, |
|||
WebpDisposalMethod.DoNotDispose => FrameDisposalMode.DoNotDispose, |
|||
_ => FrameDisposalMode.DoNotDispose, |
|||
}; |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Webp; |
|||
|
|||
/// <summary>
|
|||
/// Indicates how transparent pixels of the current frame are to be blended with corresponding pixels of the previous canvas.
|
|||
/// </summary>
|
|||
public enum WebpBlendMethod |
|||
{ |
|||
/// <summary>
|
|||
/// Do not blend. After disposing of the previous frame,
|
|||
/// render the current frame on the canvas by overwriting the rectangle covered by the current frame.
|
|||
/// </summary>
|
|||
Source = 0, |
|||
|
|||
/// <summary>
|
|||
/// Use alpha blending. After disposing of the previous frame, render the current frame on the canvas using alpha-blending.
|
|||
/// If the current frame does not have an alpha channel, assume alpha value of 255, effectively replacing the rectangle.
|
|||
/// </summary>
|
|||
Over = 1, |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Webp; |
|||
|
|||
/// <summary>
|
|||
/// Indicates how the current frame is to be treated after it has been displayed (before rendering the next frame) on the canvas.
|
|||
/// </summary>
|
|||
public enum WebpDisposalMethod |
|||
{ |
|||
/// <summary>
|
|||
/// Do not dispose. Leave the canvas as is.
|
|||
/// </summary>
|
|||
DoNotDispose = 0, |
|||
|
|||
/// <summary>
|
|||
/// Dispose to background color. Fill the rectangle on the canvas covered by the current frame with background color specified in the ANIM chunk.
|
|||
/// </summary>
|
|||
RestoreToBackground = 1 |
|||
} |
|||
@ -1,25 +1,8 @@ |
|||
<#@ template language="C#" #> |
|||
<#@include file="_Formats.ttinclude" #> |
|||
<#@ import namespace="System.Text" #> |
|||
<#@ import namespace="System.Collections.Generic" #> |
|||
// Copyright (c) Six Labors. |
|||
// Licensed under the Six Labors Split License. |
|||
|
|||
// <auto-generated /> |
|||
using SixLabors.ImageSharp.Advanced; |
|||
|
|||
<# |
|||
var formats = new []{ |
|||
"Bmp", |
|||
"Gif", |
|||
"Jpeg", |
|||
"Pbm", |
|||
"Png", |
|||
"Qoi", |
|||
"Tga", |
|||
"Tiff", |
|||
"Webp", |
|||
}; |
|||
|
|||
foreach (string fmt in formats) |
|||
{ |
|||
#> |
|||
@ -0,0 +1,283 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
// <auto-generated />
|
|||
using SixLabors.ImageSharp.Metadata; |
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.Formats.Gif; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
using SixLabors.ImageSharp.Formats.Pbm; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
using SixLabors.ImageSharp.Formats.Qoi; |
|||
using SixLabors.ImageSharp.Formats.Tga; |
|||
using SixLabors.ImageSharp.Formats.Tiff; |
|||
using SixLabors.ImageSharp.Formats.Webp; |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="ImageMetadata"/> and <see cref="ImageFrameMetadata"/> types.
|
|||
/// </summary>
|
|||
public static class ImageMetadataExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the <see cref="BmpMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="BmpMetadata"/>
|
|||
/// </returns>
|
|||
public static BmpMetadata GetBmpMetadata(this ImageMetadata source) => source.GetFormatMetadata(BmpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="BmpMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetBmpMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="BmpMetadata"/></returns>
|
|||
public static BmpMetadata CloneBmpMetadata(this ImageMetadata source) => source.CloneFormatMetadata(BmpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="GifMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="GifMetadata"/>
|
|||
/// </returns>
|
|||
public static GifMetadata GetGifMetadata(this ImageMetadata source) => source.GetFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="GifMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetGifMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="GifMetadata"/></returns>
|
|||
public static GifMetadata CloneGifMetadata(this ImageMetadata source) => source.CloneFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="JpegMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="JpegMetadata"/>
|
|||
/// </returns>
|
|||
public static JpegMetadata GetJpegMetadata(this ImageMetadata source) => source.GetFormatMetadata(JpegFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="JpegMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetJpegMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="JpegMetadata"/></returns>
|
|||
public static JpegMetadata CloneJpegMetadata(this ImageMetadata source) => source.CloneFormatMetadata(JpegFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="PbmMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="PbmMetadata"/>
|
|||
/// </returns>
|
|||
public static PbmMetadata GetPbmMetadata(this ImageMetadata source) => source.GetFormatMetadata(PbmFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="PbmMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetPbmMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="PbmMetadata"/></returns>
|
|||
public static PbmMetadata ClonePbmMetadata(this ImageMetadata source) => source.CloneFormatMetadata(PbmFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="PngMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="PngMetadata"/>
|
|||
/// </returns>
|
|||
public static PngMetadata GetPngMetadata(this ImageMetadata source) => source.GetFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="PngMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetPngMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="PngMetadata"/></returns>
|
|||
public static PngMetadata ClonePngMetadata(this ImageMetadata source) => source.CloneFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="QoiMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="QoiMetadata"/>
|
|||
/// </returns>
|
|||
public static QoiMetadata GetQoiMetadata(this ImageMetadata source) => source.GetFormatMetadata(QoiFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="QoiMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetQoiMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="QoiMetadata"/></returns>
|
|||
public static QoiMetadata CloneQoiMetadata(this ImageMetadata source) => source.CloneFormatMetadata(QoiFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="TgaMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="TgaMetadata"/>
|
|||
/// </returns>
|
|||
public static TgaMetadata GetTgaMetadata(this ImageMetadata source) => source.GetFormatMetadata(TgaFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="TgaMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetTgaMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="TgaMetadata"/></returns>
|
|||
public static TgaMetadata CloneTgaMetadata(this ImageMetadata source) => source.CloneFormatMetadata(TgaFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="TiffMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="TiffMetadata"/>
|
|||
/// </returns>
|
|||
public static TiffMetadata GetTiffMetadata(this ImageMetadata source) => source.GetFormatMetadata(TiffFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="TiffMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetTiffMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="TiffMetadata"/></returns>
|
|||
public static TiffMetadata CloneTiffMetadata(this ImageMetadata source) => source.CloneFormatMetadata(TiffFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="WebpMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="WebpMetadata"/>
|
|||
/// </returns>
|
|||
public static WebpMetadata GetWebpMetadata(this ImageMetadata source) => source.GetFormatMetadata(WebpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="WebpMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetWebpMetadata(ImageMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image metadata.</param>
|
|||
/// <returns>The new <see cref="WebpMetadata"/></returns>
|
|||
public static WebpMetadata CloneWebpMetadata(this ImageMetadata source) => source.CloneFormatMetadata(WebpFormat.Instance); |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="GifFrameMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="GifFrameMetadata"/>
|
|||
/// </returns>
|
|||
public static GifFrameMetadata GetGifMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="GifMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetGifMetadata(ImageFrameMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>The new <see cref="GifFrameMetadata"/></returns>
|
|||
public static GifFrameMetadata CloneGifMetadata(this ImageFrameMetadata source) => source.CloneFormatMetadata(GifFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="PngFrameMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="PngFrameMetadata"/>
|
|||
/// </returns>
|
|||
public static PngFrameMetadata GetPngMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="PngMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetPngMetadata(ImageFrameMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>The new <see cref="PngFrameMetadata"/></returns>
|
|||
public static PngFrameMetadata ClonePngMetadata(this ImageFrameMetadata source) => source.CloneFormatMetadata(PngFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="TiffFrameMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="TiffFrameMetadata"/>
|
|||
/// </returns>
|
|||
public static TiffFrameMetadata GetTiffMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(TiffFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="TiffMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetTiffMetadata(ImageFrameMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>The new <see cref="TiffFrameMetadata"/></returns>
|
|||
public static TiffFrameMetadata CloneTiffMetadata(this ImageFrameMetadata source) => source.CloneFormatMetadata(TiffFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Gets the <see cref="WebpFrameMetadata"/> from <paramref name="source"/>.<br/>
|
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata
|
|||
/// or the requested format default constructor.
|
|||
/// This instance will be added to the metadata for future requests.
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="WebpFrameMetadata"/>
|
|||
/// </returns>
|
|||
public static WebpFrameMetadata GetWebpMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(WebpFormat.Instance); |
|||
|
|||
/// <summary>
|
|||
/// Creates a new cloned instance of <see cref="WebpMetadata"/> from the <paramref name="source"/>.
|
|||
/// The instance is created via <see cref="GetWebpMetadata(ImageFrameMetadata)"/>
|
|||
/// </summary>
|
|||
/// <param name="source">The image frame metadata.</param>
|
|||
/// <returns>The new <see cref="WebpFrameMetadata"/></returns>
|
|||
public static WebpFrameMetadata CloneWebpMetadata(this ImageFrameMetadata source) => source.CloneFormatMetadata(WebpFormat.Instance); |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
<#@include file="_Formats.ttinclude" #> |
|||
<#@ import namespace="System.Text" #> |
|||
<#@ import namespace="System.Collections.Generic" #> |
|||
// <auto-generated /> |
|||
using SixLabors.ImageSharp.Metadata; |
|||
<# |
|||
foreach (string fmt in formats) |
|||
{ |
|||
#> |
|||
using SixLabors.ImageSharp.Formats.<#= fmt #>; |
|||
<# |
|||
|
|||
} |
|||
#> |
|||
|
|||
namespace SixLabors.ImageSharp; |
|||
|
|||
/// <summary> |
|||
/// Extension methods for the <see cref="ImageMetadata"/> and <see cref="ImageFrameMetadata"/> types. |
|||
/// </summary> |
|||
public static class ImageMetadataExtensions |
|||
{ |
|||
<# |
|||
foreach (string fmt in formats) |
|||
{ |
|||
#> |
|||
/// <summary> |
|||
/// Gets the <see cref="<#= fmt #>Metadata"/> from <paramref name="source"/>.<br/> |
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata |
|||
/// or the requested format default constructor. |
|||
/// This instance will be added to the metadata for future requests. |
|||
/// </summary> |
|||
/// <param name="source">The image metadata.</param> |
|||
/// <returns> |
|||
/// The <see cref="<#= fmt #>Metadata"/> |
|||
/// </returns> |
|||
public static <#= fmt #>Metadata Get<#= fmt #>Metadata(this ImageMetadata source) => source.GetFormatMetadata(<#= fmt #>Format.Instance); |
|||
|
|||
/// <summary> |
|||
/// Creates a new cloned instance of <see cref="<#= fmt #>Metadata"/> from the <paramref name="source"/>. |
|||
/// The instance is created via <see cref="Get<#= fmt #>Metadata(ImageMetadata)"/> |
|||
/// </summary> |
|||
/// <param name="source">The image metadata.</param> |
|||
/// <returns>The new <see cref="<#= fmt #>Metadata"/></returns> |
|||
public static <#= fmt #>Metadata Clone<#= fmt #>Metadata(this ImageMetadata source) => source.CloneFormatMetadata(<#= fmt #>Format.Instance); |
|||
|
|||
<# |
|||
} |
|||
#> |
|||
<# |
|||
foreach (string fmt in frameFormats) |
|||
{ |
|||
#> |
|||
|
|||
/// <summary> |
|||
/// Gets the <see cref="<#= fmt #>FrameMetadata"/> from <paramref name="source"/>.<br/> |
|||
/// If none is found, an instance is created either by conversion from the decoded image format metadata |
|||
/// or the requested format default constructor. |
|||
/// This instance will be added to the metadata for future requests. |
|||
/// </summary> |
|||
/// <param name="source">The image frame metadata.</param> |
|||
/// <returns> |
|||
/// The <see cref="<#= fmt #>FrameMetadata"/> |
|||
/// </returns> |
|||
public static <#= fmt #>FrameMetadata Get<#= fmt #>Metadata(this ImageFrameMetadata source) => source.GetFormatMetadata(<#= fmt #>Format.Instance); |
|||
|
|||
/// <summary> |
|||
/// Creates a new cloned instance of <see cref="<#= fmt #>Metadata"/> from the <paramref name="source"/>. |
|||
/// The instance is created via <see cref="Get<#= fmt #>Metadata(ImageFrameMetadata)"/> |
|||
/// </summary> |
|||
/// <param name="source">The image frame metadata.</param> |
|||
/// <returns>The new <see cref="<#= fmt #>FrameMetadata"/></returns> |
|||
public static <#= fmt #>FrameMetadata Clone<#= fmt #>Metadata(this ImageFrameMetadata source) => source.CloneFormatMetadata(<#= fmt #>Format.Instance); |
|||
<# |
|||
} |
|||
#> |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<#@ template debug="false" hostspecific="false" language="C#" #> |
|||
<#@ assembly name="System.Core" #> |
|||
// Copyright (c) Six Labors. |
|||
// Licensed under the Six Labors Split License. |
|||
<#+ |
|||
private static readonly string[] formats = new []{ |
|||
"Bmp", |
|||
"Gif", |
|||
"Jpeg", |
|||
"Pbm", |
|||
"Png", |
|||
"Qoi", |
|||
"Tga", |
|||
"Tiff", |
|||
"Webp", |
|||
}; |
|||
|
|||
private static readonly string[] frameFormats = new []{ |
|||
"Gif", |
|||
"Png", |
|||
"Tiff", |
|||
"Webp", |
|||
}; |
|||
#> |
|||
Loading…
Reference in new issue