-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Ico Decoder - Ico Detector - Ico Detector UnitTest - Cur Decoder - Cur Detector - Cur Detector UnitTest Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
- Loading branch information
Showing
33 changed files
with
1,018 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Registers the image encoders, decoders and mime type detectors for the Ico format. | ||
/// </summary> | ||
public sealed class CurConfigurationModule : IImageFormatConfigurationModule | ||
{ | ||
/// <inheritdoc/> | ||
public void Configure(Configuration configuration) | ||
{ | ||
// TODO: CurEncoder | ||
// configuration.ImageFormatsManager.SetEncoder(CurFormat.Instance, new CurEncoder()); | ||
configuration.ImageFormatsManager.SetDecoder(CurFormat.Instance, CurDecoder.Instance); | ||
configuration.ImageFormatsManager.AddImageFormatDetector(new IconImageFormatDetector()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Defines constants relating to ICOs | ||
/// </summary> | ||
internal static class CurConstants | ||
{ | ||
/// <summary> | ||
/// The list of mimetypes that equate to a ico. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://en.wikipedia.org/wiki/ICO_(file_format)#MIME_type"/> | ||
/// </remarks> | ||
public static readonly IEnumerable<string> MimeTypes = new[] | ||
{ | ||
"application/octet-stream", | ||
}; | ||
|
||
/// <summary> | ||
/// The list of file extensions that equate to a ico. | ||
/// </summary> | ||
public static readonly IEnumerable<string> FileExtensions = new[] { "cur" }; | ||
|
||
public const uint FileHeader = 0x00_02_00_00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Decoder for generating an image out of a ico encoded stream. | ||
/// </summary> | ||
public sealed class CurDecoder : ImageDecoder | ||
{ | ||
private CurDecoder() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the shared instance. | ||
/// </summary> | ||
public static CurDecoder Instance { get; } = new(); | ||
|
||
/// <inheritdoc/> | ||
protected override Image<TPixel> Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
{ | ||
Guard.NotNull(options, nameof(options)); | ||
Guard.NotNull(stream, nameof(stream)); | ||
|
||
Image<TPixel> image = new CurDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken); | ||
|
||
ScaleToTargetSize(options, image); | ||
|
||
return image; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
=> this.Decode<Rgba32>(options, stream, cancellationToken); | ||
|
||
/// <inheritdoc/> | ||
protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) | ||
{ | ||
Guard.NotNull(options, nameof(options)); | ||
Guard.NotNull(stream, nameof(stream)); | ||
|
||
return new CurDecoderCore(options).Identify(options.Configuration, stream, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp.Metadata; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
internal sealed class CurDecoderCore : IconDecoderCore | ||
{ | ||
public CurDecoderCore(DecoderOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
protected override IconFrameMetadata GetFrameMetadata(ImageFrameMetadata metadata) => metadata.GetCurMetadata(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Registers the image encoders, decoders and mime type detectors for the ICO format. | ||
/// </summary> | ||
public sealed class CurFormat : IImageFormat<CurMetadata, CurFrameMetadata> | ||
{ | ||
private CurFormat() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the shared instance. | ||
/// </summary> | ||
public static CurFormat Instance { get; } = new(); | ||
|
||
/// <inheritdoc/> | ||
public string Name => "ICO"; | ||
|
||
/// <inheritdoc/> | ||
public string DefaultMimeType => CurConstants.MimeTypes.First(); | ||
|
||
/// <inheritdoc/> | ||
public IEnumerable<string> MimeTypes => CurConstants.MimeTypes; | ||
|
||
/// <inheritdoc/> | ||
public IEnumerable<string> FileExtensions => CurConstants.FileExtensions; | ||
|
||
/// <inheritdoc/> | ||
public CurMetadata CreateDefaultFormatMetadata() => new(); | ||
|
||
/// <inheritdoc/> | ||
public CurFrameMetadata CreateDefaultFormatFrameMetadata() => new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// IcoFrameMetadata | ||
/// </summary> | ||
public class CurFrameMetadata : IconFrameMetadata, IDeepCloneable<CurFrameMetadata>, IDeepCloneable | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CurFrameMetadata"/> class. | ||
/// </summary> | ||
public CurFrameMetadata() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CurFrameMetadata"/> class. | ||
/// </summary> | ||
/// <param name="metadata">metadata</param> | ||
public CurFrameMetadata(IconFrameMetadata metadata) | ||
: base(metadata) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CurFrameMetadata"/> class. | ||
/// </summary> | ||
/// <param name="width">width</param> | ||
/// <param name="height">height</param> | ||
/// <param name="colorCount">colorCount</param> | ||
/// <param name="field1">field1</param> | ||
/// <param name="field2">field2</param> | ||
public CurFrameMetadata(byte width, byte height, byte colorCount, ushort field1, ushort field2) | ||
: base(width, height, colorCount, field1, field2) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets Specifies the horizontal coordinates of the hotspot in number of pixels from the left. | ||
/// </summary> | ||
public ushort HotspotX { get => this.Field1; set => this.Field1 = value; } | ||
|
||
/// <summary> | ||
/// Gets or sets Specifies the vertical coordinates of the hotspot in number of pixels from the top. | ||
/// </summary> | ||
public ushort HotspotY { get => this.Field2; set => this.Field2 = value; } | ||
|
||
/// <inheritdoc/> | ||
public override CurFrameMetadata DeepClone() => new(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Provides Ico specific metadata information for the image. | ||
/// </summary> | ||
public class CurMetadata : IDeepCloneable<CurMetadata>, IDeepCloneable | ||
{ | ||
/// <inheritdoc/> | ||
public CurMetadata DeepClone() => new(); | ||
|
||
/// <inheritdoc/> | ||
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using SixLabors.ImageSharp.Metadata; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Cur; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="ImageMetadata"/> type. | ||
/// </summary> | ||
public static class MetadataExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the Icon format specific metadata for the image. | ||
/// </summary> | ||
/// <param name="source">The metadata this method extends.</param> | ||
/// <returns>The <see cref="CurMetadata"/>.</returns> | ||
public static CurMetadata GetCurMetadata(this ImageMetadata source) | ||
=> source.GetFormatMetadata(CurFormat.Instance); | ||
|
||
/// <summary> | ||
/// Gets the Icon format specific metadata for the image frame. | ||
/// </summary> | ||
/// <param name="source">The metadata this method extends.</param> | ||
/// <returns>The <see cref="CurFrameMetadata"/>.</returns> | ||
public static CurFrameMetadata GetCurMetadata(this ImageFrameMetadata source) | ||
=> source.GetFormatMetadata(CurFormat.Instance); | ||
|
||
/// <summary> | ||
/// Gets the Icon format specific metadata for the image frame. | ||
/// </summary> | ||
/// <param name="source">The metadata this method extends.</param> | ||
/// <param name="metadata"> | ||
/// When this method returns, contains the metadata associated with the specified frame, | ||
/// if found; otherwise, the default value for the type of the metadata parameter. | ||
/// This parameter is passed uninitialized. | ||
/// </param> | ||
/// <returns> | ||
/// <see langword="true"/> if the Icon frame metadata exists; otherwise, <see langword="false"/>. | ||
/// </returns> | ||
public static bool TryGetCurMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out CurFrameMetadata? metadata) | ||
=> source.TryGetFormatMetadata(CurFormat.Instance, out metadata); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Ico; | ||
|
||
/// <summary> | ||
/// Registers the image encoders, decoders and mime type detectors for the Ico format. | ||
/// </summary> | ||
public sealed class IcoConfigurationModule : IImageFormatConfigurationModule | ||
{ | ||
/// <inheritdoc/> | ||
public void Configure(Configuration configuration) | ||
{ | ||
// TODO: IcoEncoder | ||
// configuration.ImageFormatsManager.SetEncoder(IcoFormat.Instance, new IcoEncoder()); | ||
configuration.ImageFormatsManager.SetDecoder(IcoFormat.Instance, IcoDecoder.Instance); | ||
configuration.ImageFormatsManager.AddImageFormatDetector(new IconImageFormatDetector()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Icon.Ico; | ||
|
||
/// <summary> | ||
/// Defines constants relating to ICOs | ||
/// </summary> | ||
internal static class IcoConstants | ||
{ | ||
/// <summary> | ||
/// The list of mimetypes that equate to a ico. | ||
/// </summary> | ||
/// <remarks> | ||
/// See <see href="https://en.wikipedia.org/wiki/ICO_(file_format)#MIME_type"/> | ||
/// </remarks> | ||
public static readonly IEnumerable<string> MimeTypes = new[] | ||
{ | ||
// IANA-registered | ||
"image/vnd.microsoft.icon", | ||
|
||
// ICO & CUR types used by Windows | ||
"image/x-icon", | ||
|
||
// Erroneous types but have been used | ||
"image/ico", | ||
"image/icon", | ||
"text/ico", | ||
"application/ico", | ||
}; | ||
|
||
/// <summary> | ||
/// The list of file extensions that equate to a ico. | ||
/// </summary> | ||
public static readonly IEnumerable<string> FileExtensions = new[] { "ico" }; | ||
|
||
public const uint FileHeader = 0x00_01_00_00; | ||
} |
Oops, something went wrong.