Skip to content

Commit 9a07ee9

Browse files
committed
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
1 parent 5283d77 commit 9a07ee9

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Formats.Qoi;
5+
6+
/// <summary>
7+
/// Provides enumeration of available QOI color channels.
8+
/// </summary>
9+
public enum QoiChannels
10+
{
11+
/// <summary>
12+
/// Each pixel is an R,G,B triple.
13+
/// </summary>
14+
Rgb = 3,
15+
16+
/// <summary>
17+
/// Each pixel is an R,G,B triple, followed by an alpha sample.
18+
/// </summary>
19+
Rgba = 4
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
// ReSharper disable InconsistentNaming
5+
// ReSharper disable IdentifierTypo
6+
namespace SixLabors.ImageSharp.Formats.Qoi;
7+
8+
/// <summary>
9+
/// Enum for the different QOI color spaces.
10+
/// </summary>
11+
public enum QoiColorSpace
12+
{
13+
/// <summary>
14+
/// sRGB color space with linear alpha value
15+
/// </summary>
16+
SRGB_WITH_LINEAR_ALPHA,
17+
18+
/// <summary>
19+
/// All the values in the color space are linear
20+
/// </summary>
21+
ALL_CHANNELS_LINEAR
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Text;
5+
6+
namespace SixLabors.ImageSharp.Formats.Qoi;
7+
8+
internal static class QoiConstants
9+
{
10+
11+
/// <summary>
12+
/// Gets the bytes that indicates the image is QOI
13+
/// </summary>
14+
public static ReadOnlySpan<byte> Magic => Encoding.UTF8.GetBytes("qoif");
15+
16+
/// <summary>
17+
/// The list of mimetypes that equate to a QOI.
18+
/// See <seealso cref="https://github.com/phoboslab/qoi/issues/167"/>
19+
/// </summary>
20+
public static readonly IEnumerable<string> MimeTypes = new[] { "image/qoi", "image/x-qoi", "image/vnd.qoi" };
21+
22+
/// <summary>
23+
/// The list of file extensions that equate to a QOI.
24+
/// </summary>
25+
public static readonly IEnumerable<string> FileExtensions = new[] { "qoi" };
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Text;
5+
6+
namespace SixLabors.ImageSharp.Formats.Qoi;
7+
8+
/// <summary>
9+
/// Represents the qoi header chunk.
10+
/// </summary>
11+
internal readonly struct QoiHeader
12+
{
13+
public QoiHeader(uint width, uint height, QoiChannels channels, QoiColorSpace colorSpace)
14+
{
15+
this.Width = width;
16+
this.Height = height;
17+
this.Channels = channels;
18+
this.ColorSpace = colorSpace;
19+
}
20+
21+
/// <summary>
22+
/// Magic bytes "qoif"
23+
/// </summary>
24+
public byte[] Magic { get; } = Encoding.UTF8.GetBytes("qoif");
25+
26+
/// <summary>
27+
/// Image width in pixels (BE)
28+
/// </summary>
29+
public uint Width { get; }
30+
31+
/// <summary>
32+
/// Image height in pixels (BE)
33+
/// </summary>
34+
public uint Height { get; }
35+
36+
/// <summary>
37+
/// Color channels of the image. 3 = RGB, 4 = RGBA.
38+
/// </summary>
39+
public QoiChannels Channels { get; }
40+
41+
/// <summary>
42+
/// Color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear
43+
/// </summary>
44+
public QoiColorSpace ColorSpace { get; }
45+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Text;
5+
using SixLabors.ImageSharp.PixelFormats;
6+
7+
namespace SixLabors.ImageSharp.Formats.Qoi;
8+
9+
/// <summary>
10+
/// Provides Qoi specific metadata information for the image.
11+
/// </summary>
12+
public class QoiMetadata : IDeepCloneable
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="QoiMetadata"/> class.
16+
/// </summary>
17+
public QoiMetadata()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="QoiMetadata"/> class.
23+
/// </summary>
24+
/// <param name="other">The metadata to create an instance from.</param>
25+
public QoiMetadata(QoiMetadata other)
26+
{
27+
this.Width = other.Width;
28+
this.Height = other.Height;
29+
this.Channels = other.Channels;
30+
this.ColorSpace = other.ColorSpace;
31+
}
32+
33+
/// <summary>
34+
/// Gets or sets image width in pixels (BE)
35+
/// </summary>
36+
public uint Width { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets image height in pixels (BE)
40+
/// </summary>
41+
public uint Height { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets color channels of the image. 3 = RGB, 4 = RGBA.
45+
/// </summary>
46+
public QoiChannels Channels { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets color space of the image. 0 = sRGB with linear alpha, 1 = All channels linear
50+
/// </summary>
51+
public QoiColorSpace ColorSpace { get; set; }
52+
53+
/// <inheritdoc/>
54+
public IDeepCloneable DeepClone() => new QoiMetadata(this);
55+
}
35.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)