mirror of https://github.com/SixLabors/ImageSharp
140 changed files with 949 additions and 1662 deletions
@ -1,156 +0,0 @@ |
|||
// <copyright file="Brushes.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Brushes |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// A collection of methods for creating brushes. Brushes use <see cref="Rgba32"/> for painting.
|
|||
/// </summary>
|
|||
public class Brushes |
|||
{ |
|||
/// <summary>
|
|||
/// Create as brush that will paint a solid color
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static SolidBrush Solid(Rgba32 color) |
|||
=> new SolidBrush(color); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Percent10 Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Percent10(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Percent10 Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Percent20 Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Percent20(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Percent20 Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Horizontal Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Horizontal(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Horizontal Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Min Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Min(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Min Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Vertical Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Vertical(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Vertical Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush ForwardDiagonal(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, backColor)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with
|
|||
/// in the specified foreground color and a transparent background
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush BackwardDiagonal(Rgba32 foreColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, Rgba32.Transparent)); |
|||
|
|||
/// <summary>
|
|||
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with
|
|||
/// in the specified foreground and background colors
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the foreground.</param>
|
|||
/// <param name="backColor">Color of the background.</param>
|
|||
/// <returns>A Brush</returns>
|
|||
public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 backColor) |
|||
=> new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, backColor)); |
|||
} |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
// <copyright file="ImageBrush.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Brushes |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Provides an implementation of a solid brush for painting with repeating images. The brush uses <see cref="Rgba32"/> for painting.
|
|||
/// </summary>
|
|||
public class ImageBrush : ImageBrush<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ImageBrush" /> class.
|
|||
/// </summary>
|
|||
/// <param name="image">The image to paint.</param>
|
|||
public ImageBrush(IImageBase<Rgba32> image) |
|||
: base(image) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
// <copyright file="PatternBrush.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Brushes |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Provides an implementation of a pattern brush for painting patterns. The brush use <see cref="Rgba32"/> for painting.
|
|||
/// </summary>
|
|||
public class PatternBrush : PatternBrush<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
|
|||
/// </summary>
|
|||
/// <param name="foreColor">Color of the fore.</param>
|
|||
/// <param name="backColor">Color of the back.</param>
|
|||
/// <param name="pattern">The pattern.</param>
|
|||
public PatternBrush(Rgba32 foreColor, Rgba32 backColor, bool[,] pattern) |
|||
: base(foreColor, backColor, pattern) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
internal PatternBrush(PatternBrush<Rgba32> brush) |
|||
: base(brush) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
// <copyright file="RecolorBrush.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Brushes |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Provides an implementation of a recolor brush for painting color changes.
|
|||
/// </summary>
|
|||
public class RecolorBrush : RecolorBrush<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RecolorBrush" /> class.
|
|||
/// </summary>
|
|||
/// <param name="sourceColor">Color of the source.</param>
|
|||
/// <param name="targeTPixel">Color of the target.</param>
|
|||
/// <param name="threshold">The threshold.</param>
|
|||
public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold) |
|||
: base(sourceColor, targeTPixel, threshold) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
// <copyright file="SolidBrush.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Brushes |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Provides an implementation of a solid brush for painting solid color areas. The brush uses <see cref="Rgba32"/> for painting.
|
|||
/// </summary>
|
|||
public class SolidBrush : SolidBrush<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="SolidBrush" /> class.
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
public SolidBrush(Rgba32 color) |
|||
: base(color) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
// <copyright file="Pen.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Pens |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="Pen{TPixel}"/> in the <see cref="Rgba32"/> color space.
|
|||
/// </summary>
|
|||
public class Pen : Pen<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Pen"/> class.
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
public Pen(Rgba32 color, float width) |
|||
: base(color, width) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Pen"/> class.
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
public Pen(IBrush<Rgba32> brush, float width) |
|||
: base(brush, width) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Pen"/> class.
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <param name="pattern">The pattern.</param>
|
|||
public Pen(IBrush<Rgba32> brush, float width, float[] pattern) |
|||
: base(brush, width, pattern) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Pen"/> class.
|
|||
/// </summary>
|
|||
/// <param name="pen">The pen.</param>
|
|||
internal Pen(Pen<Rgba32> pen) |
|||
: base(pen) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,95 +0,0 @@ |
|||
// <copyright file="Pens.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing.Pens |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Common Pen styles
|
|||
/// </summary>
|
|||
public class Pens |
|||
{ |
|||
/// <summary>
|
|||
/// Create a solid pen with out any drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Solid(Rgba32 color, float width) => new Pen(color, width); |
|||
|
|||
/// <summary>
|
|||
/// Create a solid pen with out any drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Solid(IBrush<Rgba32> brush, float width) => new Pen(brush, width); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Dash(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dash(color, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Dash(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dash(brush, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Dot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dot(color, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen Dot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dot(brush, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDot(color, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen DashDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDot(brush, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash Dot Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDotDot(color, width)); |
|||
|
|||
/// <summary>
|
|||
/// Create a pen with a 'Dash Dot Dot' drawing patterns
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="width">The width.</param>
|
|||
/// <returns>The Pen</returns>
|
|||
public static Pen DashDotDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDotDot(brush, width)); |
|||
} |
|||
} |
|||
@ -1,62 +0,0 @@ |
|||
// <copyright file="Image.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
|
|||
/// packed into a single unsigned integer value.
|
|||
/// </summary>
|
|||
public sealed partial class Image |
|||
{ |
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class
|
|||
/// with the height and the width of the image.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="metadata">The images matadata to preload.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
|
|||
/// </returns>
|
|||
internal static Image<TPixel> Create<TPixel>(int width, int height, ImageMetaData metadata, Configuration configuration) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
if (typeof(TPixel) == typeof(Rgba32)) |
|||
{ |
|||
return new Image(width, height, metadata, configuration) as Image<TPixel>; |
|||
} |
|||
else |
|||
{ |
|||
return new Image<TPixel>(width, height, metadata, configuration); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class
|
|||
/// with the height and the width of the image.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
|
|||
/// </returns>
|
|||
internal static Image<TPixel> Create<TPixel>(int width, int height, Configuration configuration) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Image.Create<TPixel>(width, height, null, configuration); |
|||
} |
|||
} |
|||
} |
|||
@ -1,214 +0,0 @@ |
|||
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using Formats; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
|
|||
/// packed into a single unsigned integer value.
|
|||
/// </summary>
|
|||
public sealed partial class Image |
|||
{ |
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(byte[] data) |
|||
{ |
|||
return Load(null, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(byte[] data, IDecoderOptions options) |
|||
{ |
|||
return Load(null, data, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, byte[] data) |
|||
{ |
|||
return Load(config, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(byte[] data, IImageDecoder decoder) |
|||
{ |
|||
return Load(data, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, byte[] data, IDecoderOptions options) |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load(config, ms, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load(ms, decoder, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(byte[] data) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(byte[] data, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, data, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(config, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(data, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load<TPixel>(config, ms, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given byte array.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load<TPixel>(ms, decoder, options); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,215 +0,0 @@ |
|||
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
#if !NETSTANDARD1_1
|
|||
using System; |
|||
using System.IO; |
|||
using Formats; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
|
|||
/// packed into a single unsigned integer value.
|
|||
/// </summary>
|
|||
public sealed partial class Image |
|||
{ |
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(string path) |
|||
{ |
|||
return Load(null, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(string path, IDecoderOptions options) |
|||
{ |
|||
return Load(null, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, string path) |
|||
{ |
|||
return Load(config, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(string path, IImageDecoder decoder) |
|||
{ |
|||
return Load(path, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
return new Image(Load<Rgba32>(path, decoder, options)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, string path, IDecoderOptions options) |
|||
{ |
|||
config = config ?? Configuration.Default; |
|||
using (Stream s = config.FileSystem.OpenRead(path)) |
|||
{ |
|||
return Load(config, s, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(string path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(string path, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, string path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(config, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(path, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, string path, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
config = config ?? Configuration.Default; |
|||
using (Stream s = config.FileSystem.OpenRead(path)) |
|||
{ |
|||
return Load<TPixel>(config, s, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given file.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Configuration config = Configuration.Default; |
|||
using (Stream s = config.FileSystem.OpenRead(path)) |
|||
{ |
|||
return Load<TPixel>(s, decoder, options); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
@ -1,249 +0,0 @@ |
|||
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using System.Numerics; |
|||
using System.Text; |
|||
using Formats; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
|
|||
/// packed into a single unsigned integer value.
|
|||
/// </summary>
|
|||
public sealed partial class Image |
|||
{ |
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Stream stream) |
|||
{ |
|||
return Load(null, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Stream stream, IDecoderOptions options) |
|||
{ |
|||
return Load(null, stream, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, Stream stream) |
|||
{ |
|||
return Load(config, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Stream stream, IImageDecoder decoder) |
|||
{ |
|||
return Load(stream, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Configuration config, Stream stream, IDecoderOptions options) |
|||
{ |
|||
Image<Rgba32> image = Load<Rgba32>(config, stream, options); |
|||
|
|||
return image as Image ?? new Image(image); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
Image<Rgba32> image = new Image(Load<Rgba32>(stream, decoder, options)); |
|||
|
|||
return image as Image ?? new Image(image); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Stream stream) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Stream stream, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(null, stream, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(config, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Load<TPixel>(stream, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return WithSeekableStream(stream, s => decoder.Decode<TPixel>(Configuration.Default, s, options)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the image from the given stream.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream, IDecoderOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
config = config ?? Configuration.Default; |
|||
|
|||
Image<TPixel> img = WithSeekableStream(stream, s => Decode<TPixel>(s, options, config)); |
|||
|
|||
if (img != null) |
|||
{ |
|||
return img; |
|||
} |
|||
|
|||
StringBuilder stringBuilder = new StringBuilder(); |
|||
stringBuilder.AppendLine("Image cannot be loaded. Available formats:"); |
|||
|
|||
foreach (IImageFormat format in config.ImageFormats) |
|||
{ |
|||
stringBuilder.AppendLine("-" + format); |
|||
} |
|||
|
|||
throw new NotSupportedException(stringBuilder.ToString()); |
|||
} |
|||
|
|||
private static T WithSeekableStream<T>(Stream stream, Func<Stream, T> action) |
|||
{ |
|||
if (!stream.CanRead) |
|||
{ |
|||
throw new NotSupportedException("Cannot read from the stream."); |
|||
} |
|||
|
|||
if (stream.CanSeek) |
|||
{ |
|||
return action(stream); |
|||
} |
|||
else |
|||
{ |
|||
// We want to be able to load images from things like HttpContext.Request.Body
|
|||
using (MemoryStream ms = new MemoryStream()) |
|||
{ |
|||
stream.CopyTo(ms); |
|||
ms.Position = 0; |
|||
|
|||
return action(ms); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,69 +0,0 @@ |
|||
// <copyright file="Image.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.Diagnostics; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <summary>
|
|||
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
|
|||
/// packed into a single unsigned integer value.
|
|||
/// </summary>
|
|||
[DebuggerDisplay("Image: {Width}x{Height}")] |
|||
public sealed partial class Image : Image<Rgba32> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Image"/> class
|
|||
/// with the height and the width of the image.
|
|||
/// </summary>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
public Image(int width, int height, Configuration configuration) |
|||
: base(width, height, configuration) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Image"/> class
|
|||
/// with the height and the width of the image.
|
|||
/// </summary>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
public Image(int width, int height) |
|||
: this(width, height, null) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Image"/> class
|
|||
/// by making a copy from another image.
|
|||
/// </summary>
|
|||
/// <param name="other">The other image, where the clone should be made from.</param>
|
|||
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
|
|||
public Image(Image<Rgba32> other) |
|||
: base(other) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Image"/> class
|
|||
/// with the height and the width of the image.
|
|||
/// </summary>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="metadata">The metadata.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
internal Image(int width, int height, ImageMetaData metadata, Configuration configuration) |
|||
: base(width, height, metadata, configuration) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
// <copyright file="Image.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content>
|
|||
/// Adds static methods allowing the creation of new images from given dimensions.
|
|||
/// </content>
|
|||
public partial class Image<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class with the given height and the width.
|
|||
/// </summary>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// A new <see cref="Image{TPixel}"/>.
|
|||
/// </returns>
|
|||
internal static Image<TPixel> Create(int width, int height, Configuration configuration) |
|||
{ |
|||
return Create(width, height, null, configuration); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class with the given height and the width.
|
|||
/// </summary>
|
|||
/// <param name="width">The width of the image in pixels.</param>
|
|||
/// <param name="height">The height of the image in pixels.</param>
|
|||
/// <param name="metadata">The images matadata to preload.</param>
|
|||
/// <param name="configuration">
|
|||
/// The configuration providing initialization code which allows extending the library.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// A new <see cref="Image{TPixel}"/>.
|
|||
/// </returns>
|
|||
internal static Image<TPixel> Create(int width, int height, ImageMetaData metadata, Configuration configuration) |
|||
{ |
|||
return new Image<TPixel>(width, height, metadata, configuration); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
// <copyright file="Image{TPixel}.FromBytes.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.IO; |
|||
using Formats; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content>
|
|||
/// Adds static methods allowing the creation of new image from a byte array.
|
|||
/// </content>
|
|||
public partial class Image<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(byte[] data) |
|||
{ |
|||
return Load(null, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(byte[] data, IDecoderOptions options) |
|||
{ |
|||
return Load(null, data, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(Configuration config, byte[] data) |
|||
{ |
|||
return Load(config, data, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(byte[] data, IImageDecoder decoder) |
|||
{ |
|||
return Load(data, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(Configuration config, byte[] data, IDecoderOptions options) |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load(config, ms, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
|
|||
/// </summary>
|
|||
/// <param name="data">The byte array containing image data.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
using (MemoryStream ms = new MemoryStream(data)) |
|||
{ |
|||
return Load(ms, decoder, options); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
#if !NETSTANDARD1_1
|
|||
using System; |
|||
using System.IO; |
|||
using Formats; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content>
|
|||
/// Adds static methods allowing the creation of new image from a given file.
|
|||
/// </content>
|
|||
public partial class Image<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(string path) |
|||
{ |
|||
return Load(null, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(string path, IDecoderOptions options) |
|||
{ |
|||
return Load(null, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(Configuration config, string path) |
|||
{ |
|||
return Load(config, path, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(string path, IImageDecoder decoder) |
|||
{ |
|||
return Load(path, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(Configuration config, string path, IDecoderOptions options) |
|||
{ |
|||
config = config ?? Configuration.Default; |
|||
using (Stream s = config.FileSystem.OpenRead(path)) |
|||
{ |
|||
return Load(config, s, options); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
|
|||
/// </summary>
|
|||
/// <param name="path">The file path to the image.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|||
public static Image<TPixel> Load(string path, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
Configuration config = Configuration.Default; |
|||
using (Stream s = config.FileSystem.OpenRead(path)) |
|||
{ |
|||
return Load(s, decoder, options); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
@ -0,0 +1,144 @@ |
|||
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using System.Text; |
|||
using Formats; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content>
|
|||
/// Adds static methods allowing the creation of new image from a given stream.
|
|||
/// </content>
|
|||
public partial class Image<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Stream stream) |
|||
{ |
|||
return Load(null, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Stream stream, IDecoderOptions options) |
|||
{ |
|||
return Load(null, stream, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="config">The config for the decoder.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Configuration config, Stream stream) |
|||
{ |
|||
return Load(config, stream, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Stream stream, IImageDecoder decoder) |
|||
{ |
|||
return Load(stream, decoder, null); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="decoder">The decoder.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) |
|||
{ |
|||
return WithSeekableStream(stream, s => decoder.Decode<TPixel>(Configuration.Default, s, options)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
|
|||
/// </summary>
|
|||
/// <param name="config">The configuration options.</param>
|
|||
/// <param name="stream">The stream containing image information.</param>
|
|||
/// <param name="options">The options for the decoder.</param>
|
|||
/// <exception cref="NotSupportedException">
|
|||
/// Thrown if the stream is not readable nor seekable.
|
|||
/// </exception>
|
|||
/// <returns>The image</returns>
|
|||
public static Image<TPixel> Load(Configuration config, Stream stream, IDecoderOptions options) |
|||
{ |
|||
config = config ?? Configuration.Default; |
|||
Image<TPixel> img = WithSeekableStream(stream, s => Decode(s, options, config)); |
|||
|
|||
if (img != null) |
|||
{ |
|||
return img; |
|||
} |
|||
|
|||
StringBuilder stringBuilder = new StringBuilder(); |
|||
stringBuilder.AppendLine("Image cannot be loaded. Available formats:"); |
|||
|
|||
foreach (IImageFormat format in config.ImageFormats) |
|||
{ |
|||
stringBuilder.AppendLine("-" + format); |
|||
} |
|||
|
|||
throw new NotSupportedException(stringBuilder.ToString()); |
|||
} |
|||
|
|||
private static T WithSeekableStream<T>(Stream stream, Func<Stream, T> action) |
|||
{ |
|||
if (!stream.CanRead) |
|||
{ |
|||
throw new NotSupportedException("Cannot read from the stream."); |
|||
} |
|||
|
|||
if (stream.CanSeek) |
|||
{ |
|||
return action(stream); |
|||
} |
|||
|
|||
// We want to be able to load images from things like HttpContext.Request.Body
|
|||
using (MemoryStream ms = new MemoryStream()) |
|||
{ |
|||
stream.CopyTo(ms); |
|||
ms.Position = 0; |
|||
|
|||
return action(ms); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue