mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
139 changed files with 6769 additions and 5861 deletions
@ -0,0 +1,13 @@ |
|||
--- |
|||
name: Ask question |
|||
about: Ask a question about this project. |
|||
|
|||
--- |
|||
|
|||
You should not create an issue but use Gitter instead: https://gitter.im/ImageSharp/General |
|||
|
|||
You should not create an issue but use Gitter instead: https://gitter.im/ImageSharp/General |
|||
|
|||
You should not create an issue but use Gitter instead: https://gitter.im/ImageSharp/General |
|||
|
|||
You should not create an issue but use Gitter instead: https://gitter.im/ImageSharp/General |
|||
@ -1,3 +1,9 @@ |
|||
--- |
|||
name: Bug report |
|||
about: Create a report to help us improve |
|||
|
|||
--- |
|||
|
|||
### Prerequisites |
|||
|
|||
- [ ] I have written a descriptive issue title |
|||
@ -0,0 +1,13 @@ |
|||
--- |
|||
name: Feature request |
|||
about: Suggest an idea for this project |
|||
|
|||
--- |
|||
|
|||
You should first discuss the feature on Gitter: https://gitter.im/ImageSharp/General |
|||
|
|||
You should first discuss the feature on Gitter: https://gitter.im/ImageSharp/General |
|||
|
|||
You should first discuss the feature on Gitter: https://gitter.im/ImageSharp/General |
|||
|
|||
You should first discuss the feature on Gitter: https://gitter.im/ImageSharp/General |
|||
@ -1,121 +1,137 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Processors.Drawing; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Adds extensions that allow the drawing of images to the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static class DrawImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="colorBlending">The blending mode.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelColorBlendingMode colorBlending, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Processors.Drawing; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Adds extensions that allow the drawing of images to the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static class DrawImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="colorBlending">The blending mode.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, PixelColorBlendingMode colorBlending, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="colorBlending">The color blending mode.</param>
|
|||
/// <param name="alphaComposition">The alpha composition mode.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, colorBlending, alphaComposition, opacity)); |
|||
/// <param name="alphaComposition">The alpha composition mode.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, Point.Empty, colorBlending, alphaComposition, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="options">The options, including the blending type and blending amount.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); |
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, GraphicsOptions options) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, Point location, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="colorBlending">The color blending to apply.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="colorBlending">The color blending to apply.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, PixelColorBlendingMode colorBlending, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, Point location, PixelColorBlendingMode colorBlending, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="colorBlending">The color blending to apply.</param>
|
|||
/// <param name="alphaComposition">The alpha composition mode.</param>
|
|||
/// <param name="alphaComposition">The alpha composition mode.</param>
|
|||
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, colorBlending, alphaComposition, opacity)); |
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, location, colorBlending, alphaComposition, opacity)); |
|||
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// <summary>
|
|||
/// Draws the given image together with the current one by blending their pixels.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <typeparam name="TPixelDst">The pixel format of the destination image.</typeparam>
|
|||
/// <typeparam name="TPixelSrc">The pixel format of the source image.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="image">The image to blend with the currently processing image.</param>
|
|||
/// <param name="location">The location to draw the blended image.</param>
|
|||
/// <param name="options">The options containing the blend mode and opacity.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); |
|||
} |
|||
/// <param name="options">The options containing the blend mode and opacity.</param>
|
|||
/// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixelDst> DrawImage<TPixelDst, TPixelSrc>(this IImageProcessingContext<TPixelDst> source, Image<TPixelSrc> image, Point location, GraphicsOptions options) |
|||
where TPixelDst : struct, IPixel<TPixelDst> |
|||
where TPixelSrc : struct, IPixel<TPixelSrc> |
|||
=> source.ApplyProcessor(new DrawImageProcessor<TPixelDst, TPixelSrc>(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Bmp |
|||
{ |
|||
/// <summary>
|
|||
/// Provides Bmp specific metadata information for the image.
|
|||
/// </summary>
|
|||
public class BmpMetaData : IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BmpMetaData"/> class.
|
|||
/// </summary>
|
|||
public BmpMetaData() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BmpMetaData"/> class.
|
|||
/// </summary>
|
|||
/// <param name="other">The metadata to create an instance from.</param>
|
|||
private BmpMetaData(BmpMetaData other) => this.BitsPerPixel = other.BitsPerPixel; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the number of bits per pixel.
|
|||
/// </summary>
|
|||
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => new BmpMetaData(this); |
|||
|
|||
// TODO: Colors used once we support encoding palette bmps.
|
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Gif |
|||
{ |
|||
/// <summary>
|
|||
/// Provides Gif specific metadata information for the image frame.
|
|||
/// </summary>
|
|||
public class GifFrameMetaData : IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GifFrameMetaData"/> class.
|
|||
/// </summary>
|
|||
public GifFrameMetaData() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GifFrameMetaData"/> class.
|
|||
/// </summary>
|
|||
/// <param name="other">The metadata to create an instance from.</param>
|
|||
private GifFrameMetaData(GifFrameMetaData other) |
|||
{ |
|||
this.ColorTableLength = other.ColorTableLength; |
|||
this.FrameDelay = other.FrameDelay; |
|||
this.DisposalMethod = other.DisposalMethod; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the length of the color table for paletted images.
|
|||
/// If not 0, then this field indicates the maximum number of colors to use when quantizing the
|
|||
/// image frame.
|
|||
/// </summary>
|
|||
public int ColorTableLength { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the frame delay for animated images.
|
|||
/// If not 0, when utilized in Gif animation, this field specifies the number of hundredths (1/100) of a second to
|
|||
/// wait before continuing with the processing of the Data Stream.
|
|||
/// The clock starts ticking immediately after the graphic is rendered.
|
|||
/// </summary>
|
|||
public int FrameDelay { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the disposal method for animated images.
|
|||
/// Primarily used in Gif animation, this field indicates the way in which the graphic is to
|
|||
/// be treated after being displayed.
|
|||
/// </summary>
|
|||
public GifDisposalMethod DisposalMethod { get; set; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => new GifFrameMetaData(this); |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Gif |
|||
{ |
|||
/// <summary>
|
|||
/// Provides Gif specific metadata information for the image.
|
|||
/// </summary>
|
|||
public class GifMetaData : IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GifMetaData"/> class.
|
|||
/// </summary>
|
|||
public GifMetaData() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GifMetaData"/> class.
|
|||
/// </summary>
|
|||
/// <param name="other">The metadata to create an instance from.</param>
|
|||
private GifMetaData(GifMetaData other) |
|||
{ |
|||
this.RepeatCount = other.RepeatCount; |
|||
this.ColorTableMode = other.ColorTableMode; |
|||
this.GlobalColorTableLength = other.GlobalColorTableLength; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the number of times any animation is repeated.
|
|||
/// <remarks>
|
|||
/// 0 means to repeat indefinitely, count is set as play n + 1 times
|
|||
/// </remarks>
|
|||
/// </summary>
|
|||
public ushort RepeatCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the color table mode.
|
|||
/// </summary>
|
|||
public GifColorTableMode ColorTableMode { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the length of the global color table if present.
|
|||
/// </summary>
|
|||
public int GlobalColorTableLength { get; set; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => new GifMetaData(this); |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Buffers.Binary; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Gif |
|||
{ |
|||
internal readonly struct GifNetscapeLoopingApplicationExtension : IGifExtension |
|||
{ |
|||
public GifNetscapeLoopingApplicationExtension(ushort repeatCount) => this.RepeatCount = repeatCount; |
|||
|
|||
public byte Label => GifConstants.ApplicationExtensionLabel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the repeat count.
|
|||
/// 0 means loop indefinitely. Count is set as play n + 1 times.
|
|||
/// </summary>
|
|||
public ushort RepeatCount { get; } |
|||
|
|||
public static GifNetscapeLoopingApplicationExtension Parse(ReadOnlySpan<byte> buffer) |
|||
{ |
|||
ushort repeatCount = BinaryPrimitives.ReadUInt16LittleEndian(buffer.Slice(0, 2)); |
|||
return new GifNetscapeLoopingApplicationExtension(repeatCount); |
|||
} |
|||
|
|||
public int WriteTo(Span<byte> buffer) |
|||
{ |
|||
buffer[0] = GifConstants.ApplicationBlockSize; |
|||
|
|||
// Write NETSCAPE2.0
|
|||
GifConstants.NetscapeApplicationIdentificationBytes.AsSpan().CopyTo(buffer.Slice(1, 11)); |
|||
|
|||
// Application Data ----
|
|||
buffer[12] = 3; // Application block length (always 3)
|
|||
buffer[13] = 1; // Data sub-block indentity (always 1)
|
|||
|
|||
// 0 means loop indefinitely. Count is set as play n + 1 times.
|
|||
BinaryPrimitives.WriteUInt16LittleEndian(buffer.Slice(14, 2), this.RepeatCount); |
|||
|
|||
return 16; // Length - Introducer + Label + Terminator.
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,140 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder |
|||
{ |
|||
/// <summary>
|
|||
/// Provides methods to evaluate the quality of an image.
|
|||
/// Ported from <see href="https://github.com/ImageMagick/ImageMagick/blob/f362c02083d27211b913c6e44794f0ac6edaf2bd/coders/jpeg.c#L855"/>
|
|||
/// </summary>
|
|||
internal static class QualityEvaluator |
|||
{ |
|||
private static readonly int[] Hash = new int[101] |
|||
{ |
|||
1020, 1015, 932, 848, 780, 735, 702, 679, 660, 645, |
|||
632, 623, 613, 607, 600, 594, 589, 585, 581, 571, |
|||
555, 542, 529, 514, 494, 474, 457, 439, 424, 410, |
|||
397, 386, 373, 364, 351, 341, 334, 324, 317, 309, |
|||
299, 294, 287, 279, 274, 267, 262, 257, 251, 247, |
|||
243, 237, 232, 227, 222, 217, 213, 207, 202, 198, |
|||
192, 188, 183, 177, 173, 168, 163, 157, 153, 148, |
|||
143, 139, 132, 128, 125, 119, 115, 108, 104, 99, |
|||
94, 90, 84, 79, 74, 70, 64, 59, 55, 49, |
|||
45, 40, 34, 30, 25, 20, 15, 11, 6, 4, |
|||
0 |
|||
}; |
|||
|
|||
private static readonly int[] Sums = new int[101] |
|||
{ |
|||
32640, 32635, 32266, 31495, 30665, 29804, 29146, 28599, 28104, |
|||
27670, 27225, 26725, 26210, 25716, 25240, 24789, 24373, 23946, |
|||
23572, 22846, 21801, 20842, 19949, 19121, 18386, 17651, 16998, |
|||
16349, 15800, 15247, 14783, 14321, 13859, 13535, 13081, 12702, |
|||
12423, 12056, 11779, 11513, 11135, 10955, 10676, 10392, 10208, |
|||
9928, 9747, 9564, 9369, 9193, 9017, 8822, 8639, 8458, |
|||
8270, 8084, 7896, 7710, 7527, 7347, 7156, 6977, 6788, |
|||
6607, 6422, 6236, 6054, 5867, 5684, 5495, 5305, 5128, |
|||
4945, 4751, 4638, 4442, 4248, 4065, 3888, 3698, 3509, |
|||
3326, 3139, 2957, 2775, 2586, 2405, 2216, 2037, 1846, |
|||
1666, 1483, 1297, 1109, 927, 735, 554, 375, 201, |
|||
128, 0 |
|||
}; |
|||
|
|||
private static readonly int[] Hash1 = new int[101] |
|||
{ |
|||
510, 505, 422, 380, 355, 338, 326, 318, 311, 305, |
|||
300, 297, 293, 291, 288, 286, 284, 283, 281, 280, |
|||
279, 278, 277, 273, 262, 251, 243, 233, 225, 218, |
|||
211, 205, 198, 193, 186, 181, 177, 172, 168, 164, |
|||
158, 156, 152, 148, 145, 142, 139, 136, 133, 131, |
|||
129, 126, 123, 120, 118, 115, 113, 110, 107, 105, |
|||
102, 100, 97, 94, 92, 89, 87, 83, 81, 79, |
|||
76, 74, 70, 68, 66, 63, 61, 57, 55, 52, |
|||
50, 48, 44, 42, 39, 37, 34, 31, 29, 26, |
|||
24, 21, 18, 16, 13, 11, 8, 6, 3, 2, |
|||
0 |
|||
}; |
|||
|
|||
private static readonly int[] Sums1 = new int[101] |
|||
{ |
|||
16320, 16315, 15946, 15277, 14655, 14073, 13623, 13230, 12859, |
|||
12560, 12240, 11861, 11456, 11081, 10714, 10360, 10027, 9679, |
|||
9368, 9056, 8680, 8331, 7995, 7668, 7376, 7084, 6823, |
|||
6562, 6345, 6125, 5939, 5756, 5571, 5421, 5240, 5086, |
|||
4976, 4829, 4719, 4616, 4463, 4393, 4280, 4166, 4092, |
|||
3980, 3909, 3835, 3755, 3688, 3621, 3541, 3467, 3396, |
|||
3323, 3247, 3170, 3096, 3021, 2952, 2874, 2804, 2727, |
|||
2657, 2583, 2509, 2437, 2362, 2290, 2211, 2136, 2068, |
|||
1996, 1915, 1858, 1773, 1692, 1620, 1552, 1477, 1398, |
|||
1326, 1251, 1179, 1109, 1031, 961, 884, 814, 736, |
|||
667, 592, 518, 441, 369, 292, 221, 151, 86, |
|||
64, 0 |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Returns an estimated quality of the image based on the quantization tables.
|
|||
/// </summary>
|
|||
/// <param name="quantizationTables">The quantization tables.</param>
|
|||
/// <returns>The <see cref="int"/>.</returns>
|
|||
public static int EstimateQuality(Block8x8F[] quantizationTables) |
|||
{ |
|||
int quality = 75; |
|||
float sum = 0; |
|||
|
|||
for (int i = 0; i < quantizationTables.Length; i++) |
|||
{ |
|||
ref Block8x8F qTable = ref quantizationTables[i]; |
|||
for (int j = 0; j < Block8x8F.Size; j++) |
|||
{ |
|||
sum += qTable[j]; |
|||
} |
|||
} |
|||
|
|||
ref Block8x8F qTable0 = ref quantizationTables[0]; |
|||
ref Block8x8F qTable1 = ref quantizationTables[1]; |
|||
|
|||
if (!qTable0.Equals(default)) |
|||
{ |
|||
if (!qTable1.Equals(default)) |
|||
{ |
|||
quality = (int)(qTable0[2] |
|||
+ qTable0[53] |
|||
+ qTable1[0] |
|||
+ qTable1[Block8x8F.Size - 1]); |
|||
|
|||
for (int i = 0; i < 100; i++) |
|||
{ |
|||
if (quality < Hash[i] && sum < Sums[i]) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
if (((quality <= Hash[i]) && (sum <= Sums[i])) || (i >= 50)) |
|||
{ |
|||
return i + 1; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
quality = (int)(qTable0[2] + qTable0[53]); |
|||
|
|||
for (int i = 0; i < 100; i++) |
|||
{ |
|||
if (quality < Hash1[i] && sum < Sums1[i]) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
if (((quality <= Hash1[i]) && (sum <= Sums1[i])) || (i >= 50)) |
|||
{ |
|||
return i + 1; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return quality; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg |
|||
{ |
|||
/// <summary>
|
|||
/// Provides Jpeg specific metadata information for the image.
|
|||
/// </summary>
|
|||
public class JpegMetaData : IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="JpegMetaData"/> class.
|
|||
/// </summary>
|
|||
public JpegMetaData() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="JpegMetaData"/> class.
|
|||
/// </summary>
|
|||
/// <param name="other">The metadata to create an instance from.</param>
|
|||
private JpegMetaData(JpegMetaData other) => this.Quality = other.Quality; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the encoded quality.
|
|||
/// </summary>
|
|||
public int Quality { get; set; } = 75; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => new JpegMetaData(this); |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Png |
|||
{ |
|||
/// <summary>
|
|||
/// Provides Png specific metadata information for the image.
|
|||
/// </summary>
|
|||
public class PngMetaData : IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PngMetaData"/> class.
|
|||
/// </summary>
|
|||
public PngMetaData() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PngMetaData"/> class.
|
|||
/// </summary>
|
|||
/// <param name="other">The metadata to create an instance from.</param>
|
|||
private PngMetaData(PngMetaData other) |
|||
{ |
|||
this.BitDepth = other.BitDepth; |
|||
this.ColorType = other.ColorType; |
|||
this.Gamma = other.Gamma; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the number of bits per sample or per palette index (not per pixel).
|
|||
/// Not all values are allowed for all <see cref="ColorType"/> values.
|
|||
/// </summary>
|
|||
public PngBitDepth BitDepth { get; set; } = PngBitDepth.Bit8; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the color type.
|
|||
/// </summary>
|
|||
public PngColorType ColorType { get; set; } = PngColorType.RgbWithAlpha; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the gamma value for the image.
|
|||
/// </summary>
|
|||
public float Gamma { get; set; } |
|||
|
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => new PngMetaData(this); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// A generic interface for a deeply cloneable type.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of object to clone.</typeparam>
|
|||
public interface IDeepCloneable<out T> |
|||
where T : class |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new <typeparamref name="T"/> that is a deep copy of the current instance.
|
|||
/// </summary>
|
|||
/// <returns>The <typeparamref name="T"/>.</returns>
|
|||
T DeepClone(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// An interface for objects that can be cloned. This creates a deep copy of the object.
|
|||
/// </summary>
|
|||
public interface IDeepCloneable |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new object that is a deep copy of the current instance.
|
|||
/// </summary>
|
|||
/// <returns>The <see cref="IDeepCloneable"/>.</returns>
|
|||
IDeepCloneable DeepClone(); |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.Formats.Gif; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// The static collection of all the default image formats
|
|||
/// </summary>
|
|||
public static class ImageFormats |
|||
{ |
|||
/// <summary>
|
|||
/// The format details for the jpegs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Jpeg = new JpegFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the pngs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Png = new PngFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the gifs.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Gif = new GifFormat(); |
|||
|
|||
/// <summary>
|
|||
/// The format details for the bitmaps.
|
|||
/// </summary>
|
|||
public static readonly IImageFormat Bmp = new BmpFormat(); |
|||
} |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Gif |
|||
namespace SixLabors.ImageSharp.MetaData |
|||
{ |
|||
/// <summary>
|
|||
/// Enumerated frame process modes to apply to multi-frame images.
|
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue