-
-
Notifications
You must be signed in to change notification settings - Fork 851
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
Adding QOI support #2446
Adding QOI support #2446
Conversation
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
I'm going to do some tests before the pull request and add all the functions
Now it identifies qoi images successfully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you already implemented Identify
, your next step is probably to make sure it actually works. Here's an example test, you want an equivalent for Qoi:
ImageSharp/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
Lines 338 to 355 in 7d0bbbd
[Theory] | |
[InlineData(TestImages.Png.Bpp1, 1)] | |
[InlineData(TestImages.Png.Gray4Bpp, 4)] | |
[InlineData(TestImages.Png.Palette8Bpp, 8)] | |
[InlineData(TestImages.Png.Pd, 24)] | |
[InlineData(TestImages.Png.Blur, 32)] | |
[InlineData(TestImages.Png.Rgb48Bpp, 48)] | |
[InlineData(TestImages.Png.Rgb48BppInterlaced, 48)] | |
public void Identify(string imagePath, int expectedPixelSize) | |
{ | |
TestFile testFile = TestFile.Create(imagePath); | |
using MemoryStream stream = new(testFile.Bytes, false); | |
ImageInfo imageInfo = Image.Identify(stream); | |
Assert.NotNull(imageInfo); | |
Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel); | |
} |
(I recommend to validate image size and stuff like QoiChannels
and QoiColorSpace
there.)
To make sure the format is recognized by Image.Identify
and Image.Load
and triggers your decoder, you also need to implement and register a "configuration module":
ImageSharp/src/ImageSharp/Configuration.cs
Lines 217 to 225 in 7d0bbbd
internal static Configuration CreateDefaultInstance() => new( | |
new PngConfigurationModule(), | |
new JpegConfigurationModule(), | |
new GifConfigurationModule(), | |
new BmpConfigurationModule(), | |
new PbmConfigurationModule(), | |
new TgaConfigurationModule(), | |
new TiffConfigurationModule(), | |
new WebpConfigurationModule()); |
There are some some StyleCop complaints breaking the build since we use When you will move on to the actual Decode implementation, you want to base your decoder tests on this: ImageSharp/tests/ImageSharp.Tests/Formats/Pbm/PbmDecoderTests.cs Lines 81 to 99 in 7d0bbbd
First just make sure visually that |
Thanks for the reviewing, I'll correct everything and tell when I start working on the other functions 👍 |
-Adding validation for size, channels and colorspace -Refactoring to throw general exceptions -Creating tests -Using other better data types
Hello again, I can finally work in this again 🎉 I've made the changes you told me, however, I didn't find how to run the tests, so I only added the configurations but didn't test them Soon I'll try to add the Decode and Encode options |
You can use dotnet test from the command line:
Or if you are using Visual Studio, they should appear in the Test Explorer window. |
-I had several errors about header size comparison and comparing byte arrays, but I've fixed them and tested the Identify function and it works perfect!
Hello again, I need some help with the tests When I try to test the Qoi decoder, when it tries to get the extension, qoi image format never appears: However, during debugging, it actually is correctly added: So I don't know if I must add something else on the code or tests Just in case, my qoi configuration module adds only a decoder and format detector EDIT |
I need to check phoboslab/qoi#258 because there's a bug with the decoder
See phoboslab/qoi#258 and previous commit
Hello! I'll be working on the encoder now |
-Also adding Decode method without TPixel value -Adding stream end check to decoder (we must discuss if it's necesarry or not) -formating general code
Hello again I'd like to ask for a review to see if I'm not doing something wrong |
Changing formats from 8 to 9
Also adding Modulo64 and 256 to Numerics and optimizing a little bit Encoder
Okay, I've done everything you've asked Is there anything else I should do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some optimization opportunities in QoiEncoder too, but focusing on functionality first.
I'm not sure the encoder is right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! A few more suggestions for perf.
Also removing benchmark test and fixing a typo in PngEncoderCore
Changes done |
Everything's done 🎉 |
Is there anything else I could do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to merge now. Thanks a lot for the nice work, and really appreciate the patience for the long review!
Thanks to you all for reviewing the changes so constantly and I'm sorry it took so long, I posted the idea when I was about to get back to school and I was able to do it until the semester finished xD |
Adding an entirely new image format is no small task! Really well done and thanks so much for your efforts! |
When you publish the 3.1.0 version, could I add ImageSharp it to the phoboslab/qoi repository README? Maybe on tools or implementations |
Yeah I also wanted to call out that we need to get into that hall of fame after the release. |
Prerequisites
Description
First of all, I'm sorry for being so late to add this, I've been extremely busy :(
Also I took some time to see the code to understand it and do it with the same structure
Then, I've add some files to work with qoi, at this moment it only identifies qoi images and returns the ImageInfo, but I want to make sure that I'm doing this correctly before doing the rest of functions. I've followed the Stylecop rules with Visual Studio Intellisense.
The test images were taken from the official website in the Test images in QOI and PNG format link.
This is about #2403
Could you review it please?