-
Notifications
You must be signed in to change notification settings - Fork 3
Add AVIF Decode ability #1
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
Conversation
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.
Pull Request Overview
This PR adds AVIF image format decoding capabilities to complement existing encoding support by implementing the AVIFDecoder class that uses the external avifdec tool to decode AVIF files into standard image formats.
- Implements AVIF image decoding using the external
avifdectool - Adds AVIF format detection and metadata parsing capabilities
- Provides comprehensive test coverage for the decoder functionality
Reviewed Changes
Copilot reviewed 8 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| test/AVIFDecoderTests.cs | Test suite covering AVIF file identification, decoding, and format detection |
| src/Native.cs | Adds reference to avifdec executable alongside existing avifenc |
| src/AVIFInfo.cs | Data model for storing parsed AVIF metadata information |
| src/AVIFImageFormatDetector.cs | Format detector for identifying AVIF files by header signature |
| src/AVIFFormat.cs | Updates format class to include decoder, encoder, and singleton instance |
| src/AVIFEncoder.cs | Updates to use renamed CAVIFENC constant |
| src/AVIFDecoder.cs | Core decoder implementation using external avifdec tool |
| src/AVIFConfigurationModule.cs | Configuration module registering decoder and format detector |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| [Theory] | ||
| [InlineData(AVIFTestFile, true)] | ||
| [InlineData(JPGTestFile, false)] | ||
| public void CanIdentifyAVIFFiles(string file, bool vaildAVIF) |
Copilot
AI
Sep 24, 2025
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.
Parameter name has a typo: 'vaildAVIF' should be 'validAVIF'.
| } | ||
|
|
||
|
|
||
|
|
Copilot
AI
Sep 24, 2025
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.
Remove extra blank lines to maintain consistent code formatting.
|
|
||
| public bool TryDetectFormat(ReadOnlySpan<byte> header, [NotNullWhen(true)] out IImageFormat format) | ||
| { | ||
| bool isAVIF = header.Length <= HeaderSize && IsAvif(header); |
Copilot
AI
Sep 24, 2025
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.
The condition should be >= not <=. A header with length less than HeaderSize (12) cannot contain a valid AVIF signature that requires checking bytes at positions 4-11.
| bool isAVIF = header.Length <= HeaderSize && IsAvif(header); | |
| bool isAVIF = header.Length >= HeaderSize && IsAvif(header); |
| avifInfo.Width = int.Parse(resolutionParts[0].Trim()); | ||
| avifInfo.Height = int.Parse(resolutionParts[1].Trim()); |
Copilot
AI
Sep 24, 2025
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.
Using int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully.
| } | ||
| break; | ||
| case "Bit Depth": | ||
| avifInfo.BitDepth = int.Parse(value); |
Copilot
AI
Sep 24, 2025
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.
Multiple uses of int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully for all integer parsing operations.
| avifInfo.Format = value; | ||
| break; | ||
| case "Chroma Sam. Pos": | ||
| avifInfo.ChromaSamPos = int.Parse(value); |
Copilot
AI
Sep 24, 2025
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.
Multiple uses of int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully for all integer parsing operations.
| avifInfo.Range = value; | ||
| break; | ||
| case "Color Primaries": | ||
| avifInfo.ColorPrimaries = int.Parse(value); |
Copilot
AI
Sep 24, 2025
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.
Multiple uses of int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully for all integer parsing operations.
| avifInfo.ColorPrimaries = int.Parse(value); | ||
| break; | ||
| case "Transfer Char.": | ||
| avifInfo.TransferChar = int.Parse(value); |
Copilot
AI
Sep 24, 2025
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.
Multiple uses of int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully for all integer parsing operations.
| avifInfo.TransferChar = int.Parse(value); | ||
| break; | ||
| case "Matrix Coeffs.": | ||
| avifInfo.MatrixCoeffs = int.Parse(value); |
Copilot
AI
Sep 24, 2025
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.
Multiple uses of int.Parse without validation can throw exceptions on malformed input. Consider using int.TryParse and handle parsing failures gracefully for all integer parsing operations.
| File.Delete(inputFilePath); | ||
| File.Delete(outputFilePath); |
Copilot
AI
Sep 24, 2025
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.
File deletion operations can throw exceptions if files are in use or access is denied. Wrap these calls in try-catch blocks to prevent cleanup failures from propagating.
| File.Delete(inputFilePath); | |
| File.Delete(outputFilePath); | |
| try | |
| { | |
| File.Delete(inputFilePath); | |
| } | |
| catch | |
| { | |
| // Suppress any exceptions during cleanup | |
| } | |
| try | |
| { | |
| File.Delete(outputFilePath); | |
| } | |
| catch | |
| { | |
| // Suppress any exceptions during cleanup | |
| } |
|
LGTM |
This PR completes AVIF support by adding the ability to load AVIF images, It uses the
avifdectool to load and extract data from the image file.