@ -0,0 +1,24 @@ |
|||||
|
{ |
||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558 |
||||
|
// for the documentation about the tasks.json format |
||||
|
"version": "0.1.0", |
||||
|
"command": "dotnet", |
||||
|
"isShellCommand": true, |
||||
|
"args": [], |
||||
|
"tasks": [ |
||||
|
{ |
||||
|
"taskName": "build", |
||||
|
"args": [ "src/*/project.json", "-f", "netstandard1.1" ], |
||||
|
"isBuildCommand": true, |
||||
|
"showOutput": "always", |
||||
|
"problemMatcher": "$msCompile" |
||||
|
}, |
||||
|
{ |
||||
|
"taskName": "test", |
||||
|
"args": ["tests/ImageSharp.Tests/project.json", "-f", "netcoreapp1.1"], |
||||
|
"isTestCommand": true, |
||||
|
"showOutput": "always", |
||||
|
"problemMatcher": "$msCompile" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 979 B After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 22 KiB |
@ -0,0 +1,45 @@ |
|||||
|
// <copyright file="BmpEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="BmpEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class BmpEncoderOptions : EncoderOptions, IBmpEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="BmpEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public BmpEncoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="BmpEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
private BmpEncoderOptions(IEncoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the number of bits per pixel.
|
||||
|
/// </summary>
|
||||
|
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IBmpEncoderOptions"/> instance with a cast
|
||||
|
/// or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
/// <returns>The options for the <see cref="BmpEncoder"/>.</returns>
|
||||
|
internal static IBmpEncoderOptions Create(IEncoderOptions options) |
||||
|
{ |
||||
|
return options as IBmpEncoderOptions ?? new BmpEncoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// <copyright file="IBmpEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="BmpEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IBmpEncoderOptions : IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the number of bits per pixel.
|
||||
|
/// </summary>
|
||||
|
BmpBitsPerPixel BitsPerPixel { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
// <copyright file="GifDecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="GifDecoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class GifDecoderOptions : DecoderOptions, IGifDecoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GifDecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public GifDecoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GifDecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the decoder.</param>
|
||||
|
private GifDecoderOptions(IDecoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the encoding that should be used when reading comments.
|
||||
|
/// </summary>
|
||||
|
public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IGifDecoderOptions"/> instance with a cast
|
||||
|
/// or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the decoder.</param>
|
||||
|
/// <returns>The options for the <see cref="GifDecoder"/>.</returns>
|
||||
|
internal static IGifDecoderOptions Create(IDecoderOptions options) |
||||
|
{ |
||||
|
return options as IGifDecoderOptions ?? new GifDecoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
// <copyright file="GifEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
using Quantizers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="GifEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class GifEncoderOptions : EncoderOptions, IGifEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GifEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public GifEncoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="GifEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
private GifEncoderOptions(IEncoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the encoding that should be used when writing comments.
|
||||
|
/// </summary>
|
||||
|
public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the quality of output for images.
|
||||
|
/// </summary>
|
||||
|
/// <remarks>For gifs the value ranges from 1 to 256.</remarks>
|
||||
|
public int Quality { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the transparency threshold.
|
||||
|
/// </summary>
|
||||
|
public byte Threshold { get; set; } = 128; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the quantizer for reducing the color count.
|
||||
|
/// </summary>
|
||||
|
public IQuantizer Quantizer { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IGifEncoderOptions"/> instance with a
|
||||
|
/// cast or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
/// <returns>The options for the <see cref="GifEncoder"/>.</returns>
|
||||
|
internal static IGifEncoderOptions Create(IEncoderOptions options) |
||||
|
{ |
||||
|
return options as IGifEncoderOptions ?? new GifEncoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// <copyright file="IGifDecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="GifDecoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IGifDecoderOptions : IDecoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the encoding that should be used when reading comments.
|
||||
|
/// </summary>
|
||||
|
Encoding TextEncoding { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
// <copyright file="IGifEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
using Quantizers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="GifEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IGifEncoderOptions : IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the encoding that should be used when writing comments.
|
||||
|
/// </summary>
|
||||
|
Encoding TextEncoding { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the quality of output for images.
|
||||
|
/// </summary>
|
||||
|
/// <remarks>For gifs the value ranges from 1 to 256.</remarks>
|
||||
|
int Quality { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the transparency threshold.
|
||||
|
/// </summary>
|
||||
|
byte Threshold { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the quantizer for reducing the color count.
|
||||
|
/// </summary>
|
||||
|
IQuantizer Quantizer { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
// <copyright file="IJpegEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="JpegEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IJpegEncoderOptions : IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the quality, that will be used to encode the image. Quality
|
||||
|
/// index must be between 0 and 100 (compression from max to min).
|
||||
|
/// </summary>
|
||||
|
/// <value>The quality of the jpg image from 0 to 100.</value>
|
||||
|
int Quality { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the subsample ration, that will be used to encode the image.
|
||||
|
/// </summary>
|
||||
|
/// <value>The subsample ratio of the jpg image.</value>
|
||||
|
JpegSubsample? Subsample { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
// <copyright file="JpegEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="JpegEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class JpegEncoderOptions : EncoderOptions, IJpegEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="JpegEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public JpegEncoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="JpegEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
private JpegEncoderOptions(IEncoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the quality, that will be used to encode the image. Quality
|
||||
|
/// index must be between 0 and 100 (compression from max to min).
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// If the quality is less than or equal to 90, the subsampling ratio will switch to <see cref="JpegSubsample.Ratio420"/>
|
||||
|
/// </remarks>
|
||||
|
/// <value>The quality of the jpg image from 0 to 100.</value>
|
||||
|
public int Quality { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the subsample ration, that will be used to encode the image.
|
||||
|
/// </summary>
|
||||
|
/// <value>The subsample ratio of the jpg image.</value>
|
||||
|
public JpegSubsample? Subsample { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IJpegEncoderOptions"/> instance with a
|
||||
|
/// cast or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
/// <returns>The options for the <see cref="JpegEncoder"/>.</returns>
|
||||
|
internal static IJpegEncoderOptions Create(IEncoderOptions options) |
||||
|
{ |
||||
|
return options as IJpegEncoderOptions ?? new JpegEncoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// <copyright file="IPngDecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="PngDecoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IPngDecoderOptions : IDecoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the encoding that should be used when reading text chunks.
|
||||
|
/// </summary>
|
||||
|
Encoding TextEncoding { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
// <copyright file="IPngEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using Quantizers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="PngEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IPngEncoderOptions : IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the quality of output for images.
|
||||
|
/// </summary>
|
||||
|
int Quality { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the png color type
|
||||
|
/// </summary>
|
||||
|
PngColorType PngColorType { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the compression level 1-9.
|
||||
|
/// </summary>
|
||||
|
int CompressionLevel { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the gamma value, that will be written
|
||||
|
/// the the stream, when the <see cref="WriteGamma"/> property
|
||||
|
/// is set to true.
|
||||
|
/// </summary>
|
||||
|
/// <value>The gamma value of the image.</value>
|
||||
|
float Gamma { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets quantizer for reducing the color count.
|
||||
|
/// </summary>
|
||||
|
IQuantizer Quantizer { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the transparency threshold.
|
||||
|
/// </summary>
|
||||
|
byte Threshold { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets a value indicating whether this instance should write
|
||||
|
/// gamma information to the stream.
|
||||
|
/// </summary>
|
||||
|
bool WriteGamma { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
// <copyright file="PngDecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using System.Text; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="PngDecoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class PngDecoderOptions : DecoderOptions, IPngDecoderOptions |
||||
|
{ |
||||
|
private static readonly Encoding DefaultEncoding = Encoding.GetEncoding("ASCII"); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="PngDecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public PngDecoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="PngDecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the decoder.</param>
|
||||
|
private PngDecoderOptions(IDecoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the encoding that should be used when reading text chunks.
|
||||
|
/// </summary>
|
||||
|
public Encoding TextEncoding { get; set; } = DefaultEncoding; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IPngDecoderOptions"/> instance with a cast
|
||||
|
/// or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the decoder.</param>
|
||||
|
/// <returns>The options for the <see cref="PngDecoder"/>.</returns>
|
||||
|
internal static IPngDecoderOptions Create(IDecoderOptions options) |
||||
|
{ |
||||
|
return options as IPngDecoderOptions ?? new PngDecoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
// <copyright file="PngEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Formats |
||||
|
{ |
||||
|
using Quantizers; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the options for the <see cref="PngEncoder"/>.
|
||||
|
/// </summary>
|
||||
|
public sealed class PngEncoderOptions : EncoderOptions, IPngEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="PngEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public PngEncoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="PngEncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
private PngEncoderOptions(IEncoderOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the quality of output for images.
|
||||
|
/// </summary>
|
||||
|
public int Quality { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the png color type
|
||||
|
/// </summary>
|
||||
|
public PngColorType PngColorType { get; set; } = PngColorType.RgbWithAlpha; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the compression level 1-9.
|
||||
|
/// <remarks>Defaults to 6.</remarks>
|
||||
|
/// </summary>
|
||||
|
public int CompressionLevel { get; set; } = 6; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the gamma value, that will be written
|
||||
|
/// the the stream, when the <see cref="WriteGamma"/> property
|
||||
|
/// is set to true. The default value is 2.2F.
|
||||
|
/// </summary>
|
||||
|
/// <value>The gamma value of the image.</value>
|
||||
|
public float Gamma { get; set; } = 2.2F; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets quantizer for reducing the color count.
|
||||
|
/// </summary>
|
||||
|
public IQuantizer Quantizer { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the transparency threshold.
|
||||
|
/// </summary>
|
||||
|
public byte Threshold { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets a value indicating whether this instance should write
|
||||
|
/// gamma information to the stream. The default value is false.
|
||||
|
/// </summary>
|
||||
|
public bool WriteGamma { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Converts the options to a <see cref="IPngEncoderOptions"/> instance with a
|
||||
|
/// cast or by creating a new instance with the specfied options.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The options for the encoder.</param>
|
||||
|
/// <returns>The options for the <see cref="PngEncoder"/>.</returns>
|
||||
|
internal static IPngEncoderOptions Create(IEncoderOptions options) |
||||
|
{ |
||||
|
return options as IPngEncoderOptions ?? new PngEncoderOptions(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
// <copyright file="DecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the shared decoder options.
|
||||
|
/// </summary>
|
||||
|
public class DecoderOptions : IDecoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="DecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public DecoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="DecoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The decoder options</param>
|
||||
|
protected DecoderOptions(IDecoderOptions options) |
||||
|
{ |
||||
|
if (options != null) |
||||
|
{ |
||||
|
this.IgnoreMetadata = options.IgnoreMetadata; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded.
|
||||
|
/// </summary>
|
||||
|
public bool IgnoreMetadata { get; set; } = false; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
// <copyright file="EncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the shared encoder options.
|
||||
|
/// </summary>
|
||||
|
public class EncoderOptions : IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="EncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
public EncoderOptions() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="EncoderOptions"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="options">The encoder options</param>
|
||||
|
protected EncoderOptions(IEncoderOptions options) |
||||
|
{ |
||||
|
if (options != null) |
||||
|
{ |
||||
|
this.IgnoreMetadata = options.IgnoreMetadata; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets a value indicating whether the metadata should be ignored when the image is being encoded.
|
||||
|
/// </summary>
|
||||
|
public bool IgnoreMetadata { get; set; } = false; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// <copyright file="IDecoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the shared decoder options.
|
||||
|
/// </summary>
|
||||
|
public interface IDecoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets a value indicating whether the metadata should be ignored when the image is being decoded.
|
||||
|
/// </summary>
|
||||
|
bool IgnoreMetadata { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// <copyright file="IEncoderOptions.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Encapsulates the shared encoder options.
|
||||
|
/// </summary>
|
||||
|
public interface IEncoderOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets a value indicating whether the metadata should be ignored when the image is being encoded.
|
||||
|
/// </summary>
|
||||
|
bool IgnoreMetadata { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
// <copyright file="GifDecoderTests.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Tests |
||||
|
{ |
||||
|
using System.Text; |
||||
|
using Xunit; |
||||
|
|
||||
|
using ImageSharp.Formats; |
||||
|
|
||||
|
public class GifDecoderTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() |
||||
|
{ |
||||
|
var options = new DecoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = false |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(1, image.MetaData.Properties.Count); |
||||
|
Assert.Equal("Comments", image.MetaData.Properties[0].Name); |
||||
|
Assert.Equal("ImageSharp", image.MetaData.Properties[0].Value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Decode_IgnoreMetadataIsTrue_CommentsAreIgnored() |
||||
|
{ |
||||
|
var options = new DecoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = true |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(0, image.MetaData.Properties.Count); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Decode_TextEncodingSetToUnicode_TextIsReadWithCorrectEncoding() |
||||
|
{ |
||||
|
var options = new GifDecoderOptions() |
||||
|
{ |
||||
|
TextEncoding = Encoding.Unicode |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(1, image.MetaData.Properties.Count); |
||||
|
Assert.Equal("浉条卥慨灲", image.MetaData.Properties[0].Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
// <copyright file="GifEncoderTests.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Tests |
||||
|
{ |
||||
|
using System.IO; |
||||
|
using Xunit; |
||||
|
|
||||
|
using ImageSharp.Formats; |
||||
|
|
||||
|
public class GifEncoderTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Encode_IgnoreMetadataIsFalse_CommentsAreWritten() |
||||
|
{ |
||||
|
var options = new EncoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = false |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
||||
|
|
||||
|
using (Image input = testFile.CreateImage()) |
||||
|
{ |
||||
|
using (MemoryStream memStream = new MemoryStream()) |
||||
|
{ |
||||
|
input.Save(memStream, new GifFormat(), options); |
||||
|
|
||||
|
memStream.Position = 0; |
||||
|
using (Image output = new Image(memStream)) |
||||
|
{ |
||||
|
Assert.Equal(1, output.MetaData.Properties.Count); |
||||
|
Assert.Equal("Comments", output.MetaData.Properties[0].Name); |
||||
|
Assert.Equal("ImageSharp", output.MetaData.Properties[0].Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Encode_IgnoreMetadataIsTrue_CommentsAreNotWritten() |
||||
|
{ |
||||
|
var options = new GifEncoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = true |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
||||
|
|
||||
|
using (Image input = testFile.CreateImage()) |
||||
|
{ |
||||
|
using (MemoryStream memStream = new MemoryStream()) |
||||
|
{ |
||||
|
input.SaveAsGif(memStream, options); |
||||
|
|
||||
|
memStream.Position = 0; |
||||
|
using (Image output = new Image(memStream)) |
||||
|
{ |
||||
|
Assert.Equal(0, output.MetaData.Properties.Count); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Encode_CommentIsToLong_CommentIsTrimmed() |
||||
|
{ |
||||
|
using (Image input = new Image(1, 1)) |
||||
|
{ |
||||
|
string comments = new string('c', 256); |
||||
|
input.MetaData.Properties.Add(new ImageProperty("Comments", comments)); |
||||
|
|
||||
|
using (MemoryStream memStream = new MemoryStream()) |
||||
|
{ |
||||
|
input.Save(memStream, new GifFormat()); |
||||
|
|
||||
|
memStream.Position = 0; |
||||
|
using (Image output = new Image(memStream)) |
||||
|
{ |
||||
|
Assert.Equal(1, output.MetaData.Properties.Count); |
||||
|
Assert.Equal("Comments", output.MetaData.Properties[0].Name); |
||||
|
Assert.Equal(255, output.MetaData.Properties[0].Value.Length); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
// <copyright file="PngDecoderTests.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Tests |
||||
|
{ |
||||
|
using System.Text; |
||||
|
using Xunit; |
||||
|
|
||||
|
using ImageSharp.Formats; |
||||
|
|
||||
|
public class PngDecoderTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Decode_IgnoreMetadataIsFalse_TextChunckIsRead() |
||||
|
{ |
||||
|
var options = new PngDecoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = false |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Png.Blur); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(1, image.MetaData.Properties.Count); |
||||
|
Assert.Equal("Software", image.MetaData.Properties[0].Name); |
||||
|
Assert.Equal("paint.net 4.0.6", image.MetaData.Properties[0].Value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Decode_IgnoreMetadataIsTrue_TextChunksAreIgnored() |
||||
|
{ |
||||
|
var options = new PngDecoderOptions() |
||||
|
{ |
||||
|
IgnoreMetadata = true |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Png.Blur); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(0, image.MetaData.Properties.Count); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Decode_TextEncodingSetToUnicode_TextIsReadWithCorrectEncoding() |
||||
|
{ |
||||
|
var options = new PngDecoderOptions() |
||||
|
{ |
||||
|
TextEncoding = Encoding.Unicode |
||||
|
}; |
||||
|
|
||||
|
TestFile testFile = TestFile.Create(TestImages.Png.Blur); |
||||
|
|
||||
|
using (Image image = testFile.CreateImage(options)) |
||||
|
{ |
||||
|
Assert.Equal(1, image.MetaData.Properties.Count); |
||||
|
Assert.Equal("潓瑦慷敲", image.MetaData.Properties[0].Name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 12 KiB |