Repository navigation
Conversation
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prerequisites
Description
Fixes #1129. Implements the API direction agreed in discussion #1358.
New public namespace
SixLabors.ImageSharp.Comparison:ImageComparer- abstract comparer withExact,Tolerant(...)andTolerantPercentage(...)factories. Non-generic entry points:CompareImagesOrFrames(Image, Image),CompareImagesOrFrames(int, ImageFrame, ImageFrame),CompareImages(Image, Image)andVerifySimilarity(Image, Image).TolerantImageComparer- configurable thresholds with the same semantics as the internal test comparers: manhattan metric in sixteen-bit units, same normalization, NaN-safe comparisons.ImageSimilarityReport- non-generic report: frame index, compared frames,TotalNormalizedDifference,DifferencePercentageString,IsEmpty, andCreateDifferenceImage().ImagesSimilarityException,ImageDimensionsMismatchException,ImageFramesMismatchException,ImageDifferenceIsOverThresholdException.Design notes (from discussion #1358):
Image/ImageFrame. A pair of nestedIImageFrameVisitorimplementations double-dispatches into the pixel-specific comparison.PixelDifferenceis not public. The report carries aggregates and frames only; the difference image shows where and how pixels differ. This also fixes the nullableTotalNormalizedDifferenceTODO from the test utilities.CreateDifferenceImage()also works for matching frames and renders uniform mid-gray.Implementation notes:
ImageComparer.ExactisTolerantImageComparer(0, 0), matching the internalImageComparer.Exact.ImageComparisonEngine, so both paths use one row conversion and one metric.Seed<TPixel>()seeds the comparison for same-type pairs through a newAotCompileImageComparison<TPixel>(), following the compile-only seeding pattern used by the encoders. Cross-type pairs follow the same discovery limits as other cross-type generic APIs.Test coverage:
tests/ImageSharp.Tests/Comparison/ImageComparerTests.cs- 15 tests covering exact and tolerant thresholds, per-pixel threshold behavior, percentage semantics, dimension and frame-count mismatches,VerifySimilarity, multi-frame indices, difference-image rendering, the non-generic double-dispatch path, and mixed pixel formats (Rgba32vsRgb24).The internal test comparers are unchanged (104 test files use them). Re-pointing them to the public API can be a follow-up.