-
-
Notifications
You must be signed in to change notification settings - Fork 888
Adding QOI support #2446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Adding QOI support #2446
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9a07ee9
Adding QOI metadata and constants
LuisAlfredo92 6784acf
Merge branch 'main' of https://github.com/LuisAlfredo92/ImageSharp
LuisAlfredo92 c79dd77
Adding qoi identification
LuisAlfredo92 60d8763
Adding tests and fixing bugs
LuisAlfredo92 43bf27a
Merge branch 'SixLabors:main' into main
LuisAlfredo92 24e5ce6
Making changes from #2446 review
LuisAlfredo92 8b9e0a9
Merge branch 'main' of https://github.com/LuisAlfredo92/ImageSharp
LuisAlfredo92 a1342bf
Fixing Qoi detector
LuisAlfredo92 bca998d
Implementing qoi decoder
LuisAlfredo92 a87f781
Fixing edge case
LuisAlfredo92 07e6597
Finishing qoi encoder
LuisAlfredo92 4a494c7
Merge branch 'main' into main
LuisAlfredo92 c92a4ec
Adding extensions was easier than I though
LuisAlfredo92 8729fed
Fixing configuration tests
LuisAlfredo92 aed9acd
Fixing StyleCop
LuisAlfredo92 6245666
Fixing most of things of review
LuisAlfredo92 cf3271e
Update .gitattributes and deleting images to repush
LuisAlfredo92 d671006
Reuploading images
LuisAlfredo92 02212bd
Optimizing Decoder
LuisAlfredo92 88de0a6
Fixing encoder optimizations
LuisAlfredo92 383aa22
Fixing and optimizing decoder and encoder
LuisAlfredo92 bf9f1f3
Fixing and making easier to read encoder
LuisAlfredo92 f7b4f49
Fixing StyleCop
LuisAlfredo92 3f1fe69
Fixing declarations
LuisAlfredo92 ef78f98
Adding Channels and ColorSpace validations to De-/Encoder
LuisAlfredo92 dea1ee8
Optimizing avoiding casts to byte
LuisAlfredo92 472bc04
Fixing extensions, class access and StyleCop
LuisAlfredo92 1069a6d
Merge branch 'main' into main
antonfirsov eb5c6a7
private QoiMetadata(QoiMetadata other)
antonfirsov 59c4a6a
Merge branch 'main' into main
JimBobSquarePants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule shared-infrastructure
updated
2 files
| +1 −0 | .gitattributes | |
| +1 −1 | src/SharedInfrastructure/Guard.cs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using SixLabors.ImageSharp.Formats.Qoi; | ||
| using SixLabors.ImageSharp.Metadata; | ||
|
|
||
| namespace SixLabors.ImageSharp; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for the <see cref="ImageMetadata"/> type. | ||
| /// </summary> | ||
| public static partial class MetadataExtensions | ||
| { | ||
| /// <summary> | ||
| /// Gets the qoi format specific metadata for the image. | ||
| /// </summary> | ||
| /// <param name="metadata">The metadata this method extends.</param> | ||
| /// <returns>The <see cref="QoiMetadata"/>.</returns> | ||
| public static QoiMetadata GetQoiMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(QoiFormat.Instance); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Qoi; | ||
|
|
||
| /// <summary> | ||
| /// Enum that contains the operations that encoder and decoder must process, written | ||
| /// in binary to be easier to compare them in the reference | ||
| /// </summary> | ||
| internal enum QoiChunk | ||
| { | ||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_RGB where the RGB values are written | ||
| /// in one byte each one after this marker | ||
| /// </summary> | ||
| QoiOpRgb = 0b11111110, | ||
|
|
||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_RGBA where the RGBA values are written | ||
| /// in one byte each one after this marker | ||
| /// </summary> | ||
| QoiOpRgba = 0b11111111, | ||
|
|
||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_INDEX where one byte contains a 2-bit | ||
| /// marker (0b00) followed by an index on the previously seen pixels array 0..63 | ||
| /// </summary> | ||
| QoiOpIndex = 0b00000000, | ||
|
|
||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_DIFF where one byte contains a 2-bit | ||
| /// marker (0b01) followed by 2-bit differences in red, green and blue channel | ||
| /// with the previous pixel with a bias of 2 (-2..1) | ||
| /// </summary> | ||
| QoiOpDiff = 0b01000000, | ||
|
|
||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_LUMA where one byte contains a 2-bit | ||
| /// marker (0b01) followed by a 6-bits number that indicates the difference of | ||
| /// the green channel with the previous pixel. Then another byte that contains | ||
| /// a 4-bit number that indicates the difference of the red channel minus the | ||
| /// previous difference, and another 4-bit number that indicates the difference | ||
| /// of the blue channel minus the green difference | ||
| /// Example: 0b10[6-bits diff green] 0b[6-bits dr-dg][6-bits db-dg] | ||
| /// dr_dg = (cur_px.r - prev_px.r) - (cur_px.g - prev_px.g) | ||
| /// db_dg = (cur_px.b - prev_px.b) - (cur_px.g - prev_px.g) | ||
| /// </summary> | ||
| QoiOpLuma = 0b10000000, | ||
|
|
||
| /// <summary> | ||
| /// Indicates that the operation is QOI_OP_RUN where one byte contains a 2-bit | ||
| /// marker (0b11) followed by a 6-bits number that indicates the times that the | ||
| /// previous pixel is repeated | ||
| /// </summary> | ||
| QoiOpRun = 0b11000000 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> | ||
| SrgbWithLinearAlpha, | ||
|
|
||
| /// <summary> | ||
| /// All the values in the color space are linear | ||
| /// </summary> | ||
| AllChannelsLinear | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Qoi; | ||
|
|
||
| /// <summary> | ||
| /// Registers the image encoders, decoders and mime type detectors for the qoi format. | ||
| /// </summary> | ||
| public sealed class QoiConfigurationModule : IImageFormatConfigurationModule | ||
| { | ||
| /// <inheritdoc/> | ||
| public void Configure(Configuration configuration) | ||
| { | ||
| configuration.ImageFormatsManager.SetDecoder(QoiFormat.Instance, QoiDecoder.Instance); | ||
| configuration.ImageFormatsManager.SetEncoder(QoiFormat.Instance, new QoiEncoder()); | ||
| configuration.ImageFormatsManager.AddImageFormatDetector(new QoiImageFormatDetector()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using System.Text; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Qoi; | ||
|
|
||
| internal static class QoiConstants | ||
| { | ||
| private static readonly byte[] SMagic = Encoding.UTF8.GetBytes("qoif"); | ||
|
|
||
| /// <summary> | ||
| /// Gets the bytes that indicates the image is QOI | ||
| /// </summary> | ||
| public static ReadOnlySpan<byte> Magic => SMagic; | ||
|
|
||
| /// <summary> | ||
| /// Gets the list of mimetypes that equate to a QOI. | ||
| /// See https://github.com/phoboslab/qoi/issues/167 | ||
| /// </summary> | ||
| public static string[] MimeTypes { get; } = { "image/qoi", "image/x-qoi", "image/vnd.qoi" }; | ||
|
|
||
| /// <summary> | ||
| /// Gets the list of file extensions that equate to a QOI. | ||
| /// </summary> | ||
| public static string[] FileExtensions { get; } = { "qoi" }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.