Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Parameter name has a typo: 'vaildAVIF' should be 'validAVIF'.
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.