mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 125 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||
= WebP Format |
|||
Reference implementation, specification and stuff like that: |
|||
https://developers.google.com/speed/webp |
|||
|
|||
@ -0,0 +1,20 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.WebP |
|||
{ |
|||
internal static class WebPConstants |
|||
{ |
|||
/// <summary>
|
|||
/// The list of file extensions that equate to WebP.
|
|||
/// </summary>
|
|||
public static readonly IEnumerable<string> FileExtensions = new[] { "webp" }; |
|||
|
|||
/// <summary>
|
|||
/// The list of mimetypes that equate to a jpeg.
|
|||
/// </summary>
|
|||
public static readonly IEnumerable<string> MimeTypes = new[] { "image/webp", }; |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.WebP |
|||
{ |
|||
public sealed class WebPDecoder : IImageDecoder |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.WebP |
|||
{ |
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the WebP format
|
|||
/// </summary>
|
|||
public sealed class WebPFormat : IImageFormat<WebPMetadata> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the current instance.
|
|||
/// </summary>
|
|||
public static WebPFormat Instance { get; } = new WebPFormat(); |
|||
|
|||
/// <inheritdoc/>
|
|||
public string Name => "WebP"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public string DefaultMimeType => "image/webp"; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> MimeTypes => WebPConstants.MimeTypes; |
|||
|
|||
/// <inheritdoc/>
|
|||
public IEnumerable<string> FileExtensions => WebPConstants.FileExtensions; |
|||
|
|||
/// <inheritdoc/>
|
|||
public WebPMetadata CreateDefaultFormatMetadata() => new WebPMetadata(); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.WebP |
|||
{ |
|||
/// <summary>
|
|||
/// Detects WebP file headers
|
|||
/// </summary>
|
|||
public sealed class WebPImageFormatDetector : IImageFormatDetector |
|||
{ |
|||
/// <inheritdoc />
|
|||
public int HeaderSize => 12; |
|||
|
|||
/// <inheritdoc />
|
|||
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) |
|||
{ |
|||
return this.IsSupportedFileFormat(header) ? WebPFormat.Instance : null; |
|||
} |
|||
|
|||
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) |
|||
{ |
|||
return header.Length >= this.HeaderSize && |
|||
this.IsRiffContainer(header) && |
|||
this.IsWebPFile(header); |
|||
} |
|||
|
|||
private bool IsRiffContainer(ReadOnlySpan<byte> header) |
|||
{ |
|||
return header[0] == 0x52 && // R
|
|||
header[1] == 0x49 && // I
|
|||
header[2] == 0x46 && // F
|
|||
header[3] == 0x46; // F
|
|||
} |
|||
|
|||
private bool IsWebPFile(ReadOnlySpan<byte> header) |
|||
{ |
|||
return header[8] == 0x57 && // W
|
|||
header[9] == 0x45 && // E
|
|||
header[10] == 0x42 && // B
|
|||
header[11] == 0x50; // P
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.WebP |
|||
{ |
|||
/// <summary>
|
|||
/// Provides WebP specific metadata information for the image.
|
|||
/// </summary>
|
|||
public class WebPMetadata : IDeepCloneable |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public IDeepCloneable DeepClone() => throw new NotImplementedException(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue