diff --git a/src/ImageSharp/Formats/Qoi/QoiChannels.cs b/src/ImageSharp/Formats/Qoi/QoiChannels.cs new file mode 100644 index 000000000..a76aeef28 --- /dev/null +++ b/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; + +/// +/// Provides enumeration of available QOI color channels. +/// +public enum QoiChannels +{ + /// + /// Each pixel is an R,G,B triple. + /// + Rgb = 3, + + /// + /// Each pixel is an R,G,B triple, followed by an alpha sample. + /// + Rgba = 4 +} diff --git a/src/ImageSharp/Formats/Qoi/QoiColorSpace.cs b/src/ImageSharp/Formats/Qoi/QoiColorSpace.cs new file mode 100644 index 000000000..949e383d9 --- /dev/null +++ b/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; + +/// +/// Enum for the different QOI color spaces. +/// +public enum QoiColorSpace +{ + /// + /// sRGB color space with linear alpha value + /// + SRGB_WITH_LINEAR_ALPHA, + + /// + /// All the values in the color space are linear + /// + ALL_CHANNELS_LINEAR +} diff --git a/src/ImageSharp/Formats/Qoi/QoiConstants.cs b/src/ImageSharp/Formats/Qoi/QoiConstants.cs new file mode 100644 index 000000000..afad6d3bc --- /dev/null +++ b/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 +{ + + /// + /// Gets the bytes that indicates the image is QOI + /// + public static ReadOnlySpan Magic => Encoding.UTF8.GetBytes("qoif"); + + /// + /// The list of mimetypes that equate to a QOI. + /// See + /// + public static readonly IEnumerable MimeTypes = new[] { "image/qoi", "image/x-qoi", "image/vnd.qoi" }; + + /// + /// The list of file extensions that equate to a QOI. + /// + public static readonly IEnumerable FileExtensions = new[] { "qoi" }; +} diff --git a/src/ImageSharp/Formats/Qoi/QoiHeader.cs b/src/ImageSharp/Formats/Qoi/QoiHeader.cs new file mode 100644 index 000000000..ec23d3b74 --- /dev/null +++ b/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; + +/// +/// Represents the qoi header chunk. +/// +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; + } + + /// + /// Magic bytes "qoif" + /// + public byte[] Magic { get; } = Encoding.UTF8.GetBytes("qoif"); + + /// + /// Image width in pixels (BE) + /// + public uint Width { get; } + + /// + /// Image height in pixels (BE) + /// + public uint Height { get; } + + /// + /// Color channels of the image. 3 = RGB, 4 = RGBA. + /// + public QoiChannels Channels { get; } + + /// + /// Color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear + /// + public QoiColorSpace ColorSpace { get; } +} diff --git a/src/ImageSharp/Formats/Qoi/QoiMetadata.cs b/src/ImageSharp/Formats/Qoi/QoiMetadata.cs new file mode 100644 index 000000000..de6b0a7a6 --- /dev/null +++ b/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; + +/// +/// Provides Qoi specific metadata information for the image. +/// +public class QoiMetadata : IDeepCloneable +{ + /// + /// Initializes a new instance of the class. + /// + public QoiMetadata() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The metadata to create an instance from. + public QoiMetadata(QoiMetadata other) + { + this.Width = other.Width; + this.Height = other.Height; + this.Channels = other.Channels; + this.ColorSpace = other.ColorSpace; + } + + /// + /// Gets or sets image width in pixels (BE) + /// + public uint Width { get; set; } + + /// + /// Gets or sets image height in pixels (BE) + /// + public uint Height { get; set; } + + /// + /// Gets or sets color channels of the image. 3 = RGB, 4 = RGBA. + /// + public QoiChannels Channels { get; set; } + + /// + /// Gets or sets color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear + /// + public QoiColorSpace ColorSpace { get; set; } + + /// + public IDeepCloneable DeepClone() => new QoiMetadata(this); +} diff --git a/src/ImageSharp/Formats/Qoi/qoi-specification.pdf b/src/ImageSharp/Formats/Qoi/qoi-specification.pdf new file mode 100644 index 000000000..3ffa4bd61 Binary files /dev/null and b/src/ImageSharp/Formats/Qoi/qoi-specification.pdf differ