Skip to content

Commit 900e9d0

Browse files
Merge pull request #2446 from LuisAlfredo92/main
Adding QOI support
2 parents b2ac9bb + 59c4a6a commit 900e9d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1409
-63
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
*.bmp filter=lfs diff=lfs merge=lfs -text
119119
*.gif filter=lfs diff=lfs merge=lfs -text
120120
*.png filter=lfs diff=lfs merge=lfs -text
121+
*.qoi filter=lfs diff=lfs merge=lfs -text
121122
*.tif filter=lfs diff=lfs merge=lfs -text
122123
*.tiff filter=lfs diff=lfs merge=lfs -text
123124
*.tga filter=lfs diff=lfs merge=lfs -text

ImageSharp.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tga", "Tga", "{5DFC394F-136
646646
tests\Images\Input\Tga\targa_8bit_rle.tga = tests\Images\Input\Tga\targa_8bit_rle.tga
647647
EndProjectSection
648648
EndProject
649+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Qoi", "Qoi", "{E801B508-4935-41CD-BA85-CF11BFF55A45}"
650+
ProjectSection(SolutionItems) = preProject
651+
tests\Images\Input\Qoi\dice.qoi = tests\Images\Input\Qoi\dice.qoi
652+
tests\Images\Input\Qoi\edgecase.qoi = tests\Images\Input\Qoi\edgecase.qoi
653+
tests\Images\Input\Qoi\kodim10.qoi = tests\Images\Input\Qoi\kodim10.qoi
654+
tests\Images\Input\Qoi\kodim23.qoi = tests\Images\Input\Qoi\kodim23.qoi
655+
tests\Images\Input\Qoi\qoi_logo.qoi = tests\Images\Input\Qoi\qoi_logo.qoi
656+
tests\Images\Input\Qoi\testcard.qoi = tests\Images\Input\Qoi\testcard.qoi
657+
tests\Images\Input\Qoi\testcard_rgba.qoi = tests\Images\Input\Qoi\testcard_rgba.qoi
658+
tests\Images\Input\Qoi\wikipedia_008.qoi = tests\Images\Input\Qoi\wikipedia_008.qoi
659+
EndProjectSection
660+
EndProject
649661
Global
650662
GlobalSection(SolutionConfigurationPlatforms) = preSolution
651663
Debug|Any CPU = Debug|Any CPU
@@ -698,6 +710,7 @@ Global
698710
{FC527290-2F22-432C-B77B-6E815726B02C} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
699711
{670DD46C-82E9-499A-B2D2-00A802ED0141} = {E1C42A6F-913B-4A7B-B1A8-2BB62843B254}
700712
{5DFC394F-136F-4B76-9BCA-3BA786515EFC} = {9DA226A1-8656-49A8-A58A-A8B5C081AD66}
713+
{E801B508-4935-41CD-BA85-CF11BFF55A45} = {9DA226A1-8656-49A8-A58A-A8B5C081AD66}
701714
EndGlobalSection
702715
GlobalSection(ExtensibilityGlobals) = postSolution
703716
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}

src/ImageSharp/Common/Helpers/Numerics.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ public static int LeastCommonMultiple(int a, int b)
7373
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7474
public static nint Modulo8(nint x) => x & 7;
7575

76+
/// <summary>
77+
/// Calculates <paramref name="x"/> % 64
78+
/// </summary>
79+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
80+
public static int Modulo64(int x) => x & 63;
81+
82+
/// <summary>
83+
/// Calculates <paramref name="x"/> % 64
84+
/// </summary>
85+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
86+
public static nint Modulo64(nint x) => x & 63;
87+
88+
/// <summary>
89+
/// Calculates <paramref name="x"/> % 256
90+
/// </summary>
91+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
92+
public static int Modulo256(int x) => x & 255;
93+
94+
/// <summary>
95+
/// Calculates <paramref name="x"/> % 256
96+
/// </summary>
97+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
98+
public static nint Modulo256(nint x) => x & 255;
99+
76100
/// <summary>
77101
/// Fast (x mod m) calculator, with the restriction that
78102
/// <paramref name="m"/> should be power of 2.

src/ImageSharp/Configuration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using SixLabors.ImageSharp.Formats.Jpeg;
99
using SixLabors.ImageSharp.Formats.Pbm;
1010
using SixLabors.ImageSharp.Formats.Png;
11+
using SixLabors.ImageSharp.Formats.Qoi;
1112
using SixLabors.ImageSharp.Formats.Tga;
1213
using SixLabors.ImageSharp.Formats.Tiff;
1314
using SixLabors.ImageSharp.Formats.Webp;
@@ -212,6 +213,7 @@ public void Configure(IImageFormatConfigurationModule configuration)
212213
/// <see cref="TgaConfigurationModule"/>.
213214
/// <see cref="TiffConfigurationModule"/>.
214215
/// <see cref="WebpConfigurationModule"/>.
216+
/// <see cref="QoiConfigurationModule"/>.
215217
/// </summary>
216218
/// <returns>The default configuration of <see cref="Configuration"/>.</returns>
217219
internal static Configuration CreateDefaultInstance() => new(
@@ -222,5 +224,6 @@ public void Configure(IImageFormatConfigurationModule configuration)
222224
new PbmConfigurationModule(),
223225
new TgaConfigurationModule(),
224226
new TiffConfigurationModule(),
225-
new WebpConfigurationModule());
227+
new WebpConfigurationModule(),
228+
new QoiConfigurationModule());
226229
}

src/ImageSharp/Formats/ImageExtensions.Save.cs

Lines changed: 154 additions & 51 deletions
Large diffs are not rendered by default.

src/ImageSharp/Formats/ImageExtensions.Save.tt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ using SixLabors.ImageSharp.Advanced;
1414
"Jpeg",
1515
"Pbm",
1616
"Png",
17+
"Qoi",
1718
"Tga",
18-
"Webp",
1919
"Tiff",
20+
"Webp",
2021
};
2122

2223
foreach (string fmt in formats)

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
3434
private readonly MemoryAllocator memoryAllocator;
3535

3636
/// <summary>
37-
/// The configuration instance for the decoding operation.
37+
/// The configuration instance for the encoding operation.
3838
/// </summary>
3939
private readonly Configuration configuration;
4040

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+
using SixLabors.ImageSharp.Formats.Qoi;
5+
using SixLabors.ImageSharp.Metadata;
6+
7+
namespace SixLabors.ImageSharp;
8+
9+
/// <summary>
10+
/// Extension methods for the <see cref="ImageMetadata"/> type.
11+
/// </summary>
12+
public static partial class MetadataExtensions
13+
{
14+
/// <summary>
15+
/// Gets the qoi format specific metadata for the image.
16+
/// </summary>
17+
/// <param name="metadata">The metadata this method extends.</param>
18+
/// <returns>The <see cref="QoiMetadata"/>.</returns>
19+
public static QoiMetadata GetQoiMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(QoiFormat.Instance);
20+
}
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+
}

0 commit comments

Comments
 (0)