Browse Source

Adding QOI metadata and constants

I'm starting to need help because I don't understand the project structure

Everything I added was taken from the specification and structured similarly to PNG and BMP
qoi
Luis Alfredo Figueroa Bracamontes 3 years ago
parent
commit
9a07ee9473
No known key found for this signature in database GPG Key ID: 13A8436905993B8F
  1. 20
      src/ImageSharp/Formats/Qoi/QoiChannels.cs
  2. 22
      src/ImageSharp/Formats/Qoi/QoiColorSpace.cs
  3. 26
      src/ImageSharp/Formats/Qoi/QoiConstants.cs
  4. 45
      src/ImageSharp/Formats/Qoi/QoiHeader.cs
  5. 55
      src/ImageSharp/Formats/Qoi/QoiMetadata.cs
  6. BIN
      src/ImageSharp/Formats/Qoi/qoi-specification.pdf

20
src/ImageSharp/Formats/Qoi/QoiChannels.cs

@ -0,0 +1,20 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Qoi;
/// <summary>
/// Provides enumeration of available QOI color channels.
/// </summary>
public enum QoiChannels
{
/// <summary>
/// Each pixel is an R,G,B triple.
/// </summary>
Rgb = 3,
/// <summary>
/// Each pixel is an R,G,B triple, followed by an alpha sample.
/// </summary>
Rgba = 4
}

22
src/ImageSharp/Formats/Qoi/QoiColorSpace.cs

@ -0,0 +1,22 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
namespace SixLabors.ImageSharp.Formats.Qoi;
/// <summary>
/// Enum for the different QOI color spaces.
/// </summary>
public enum QoiColorSpace
{
/// <summary>
/// sRGB color space with linear alpha value
/// </summary>
SRGB_WITH_LINEAR_ALPHA,
/// <summary>
/// All the values in the color space are linear
/// </summary>
ALL_CHANNELS_LINEAR
}

26
src/ImageSharp/Formats/Qoi/QoiConstants.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Text;
namespace SixLabors.ImageSharp.Formats.Qoi;
internal static class QoiConstants
{
/// <summary>
/// Gets the bytes that indicates the image is QOI
/// </summary>
public static ReadOnlySpan<byte> Magic => Encoding.UTF8.GetBytes("qoif");
/// <summary>
/// The list of mimetypes that equate to a QOI.
/// See <seealso cref="https://github.com/phoboslab/qoi/issues/167"/>
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/qoi", "image/x-qoi", "image/vnd.qoi" };
/// <summary>
/// The list of file extensions that equate to a QOI.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "qoi" };
}

45
src/ImageSharp/Formats/Qoi/QoiHeader.cs

@ -0,0 +1,45 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Text;
namespace SixLabors.ImageSharp.Formats.Qoi;
/// <summary>
/// Represents the qoi header chunk.
/// </summary>
internal readonly struct QoiHeader
{
public QoiHeader(uint width, uint height, QoiChannels channels, QoiColorSpace colorSpace)
{
this.Width = width;
this.Height = height;
this.Channels = channels;
this.ColorSpace = colorSpace;
}
/// <summary>
/// Magic bytes "qoif"
/// </summary>
public byte[] Magic { get; } = Encoding.UTF8.GetBytes("qoif");
/// <summary>
/// Image width in pixels (BE)
/// </summary>
public uint Width { get; }
/// <summary>
/// Image height in pixels (BE)
/// </summary>
public uint Height { get; }
/// <summary>
/// Color channels of the image. 3 = RGB, 4 = RGBA.
/// </summary>
public QoiChannels Channels { get; }
/// <summary>
/// Color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear
/// </summary>
public QoiColorSpace ColorSpace { get; }
}

55
src/ImageSharp/Formats/Qoi/QoiMetadata.cs

@ -0,0 +1,55 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Text;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Qoi;
/// <summary>
/// Provides Qoi specific metadata information for the image.
/// </summary>
public class QoiMetadata : IDeepCloneable
{
/// <summary>
/// Initializes a new instance of the <see cref="QoiMetadata"/> class.
/// </summary>
public QoiMetadata()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="QoiMetadata"/> class.
/// </summary>
/// <param name="other">The metadata to create an instance from.</param>
public QoiMetadata(QoiMetadata other)
{
this.Width = other.Width;
this.Height = other.Height;
this.Channels = other.Channels;
this.ColorSpace = other.ColorSpace;
}
/// <summary>
/// Gets or sets image width in pixels (BE)
/// </summary>
public uint Width { get; set; }
/// <summary>
/// Gets or sets image height in pixels (BE)
/// </summary>
public uint Height { get; set; }
/// <summary>
/// Gets or sets color channels of the image. 3 = RGB, 4 = RGBA.
/// </summary>
public QoiChannels Channels { get; set; }
/// <summary>
/// Gets or sets color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear
/// </summary>
public QoiColorSpace ColorSpace { get; set; }
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new QoiMetadata(this);
}

BIN
src/ImageSharp/Formats/Qoi/qoi-specification.pdf

Binary file not shown.
Loading…
Cancel
Save