Browse Source

Initial Commit towards WebP

pull/1025/head
Peter Amrehn 6 years ago
parent
commit
dc849681dd
  1. 4
      src/ImageSharp/Formats/WebP/Readme.md
  2. 20
      src/ImageSharp/Formats/WebP/WebPConstants.cs
  3. 10
      src/ImageSharp/Formats/WebP/WebPDecoder.cs
  4. 33
      src/ImageSharp/Formats/WebP/WebPFormat.cs
  5. 42
      src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs
  6. 16
      src/ImageSharp/Formats/WebP/WebPMetadata.cs

4
src/ImageSharp/Formats/WebP/Readme.md

@ -0,0 +1,4 @@
= WebP Format
Reference implementation, specification and stuff like that:
https://developers.google.com/speed/webp

20
src/ImageSharp/Formats/WebP/WebPConstants.cs

@ -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", };
}
}

10
src/ImageSharp/Formats/WebP/WebPDecoder.cs

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SixLabors.ImageSharp.Formats.WebP
{
public sealed class WebPDecoder : IImageDecoder
{
}
}

33
src/ImageSharp/Formats/WebP/WebPFormat.cs

@ -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();
}
}

42
src/ImageSharp/Formats/WebP/WebPImageFormatDetector.cs

@ -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
}
}
}

16
src/ImageSharp/Formats/WebP/WebPMetadata.cs

@ -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…
Cancel
Save