Skip to content
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

Perform fast memcmp comparison before making deep pixel-by-pixel comparison #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions FBSnapshotTestCase/Categories/UIImage+Compare.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ - (BOOL)fb_compareWithImage:(UIImage *)image perPixelTolerance:(CGFloat)perPixel
CGContextRelease(referenceImageContext);
CGContextRelease(imageContext);

BOOL imageEqual = YES;
FBComparePixel *p1 = referenceImagePixels;
FBComparePixel *p2 = imagePixels;

BOOL imageEqual = (memcmp(referenceImagePixels, imagePixels, referenceImageSizeBytes) == 0);
// Do a fast compare if we can
if (overallTolerance == 0 && perPixelTolerance == 0) {
imageEqual = (memcmp(referenceImagePixels, imagePixels, referenceImageSizeBytes) == 0);
} else {
const NSUInteger pixelCount = referenceImageSize.width * referenceImageSize.height;
// Go through each pixel in turn and see if it is different
imageEqual = [self _compareAllPixelsWithPerPixelTolerance:perPixelTolerance
overallTolerance:overallTolerance
pixelCount:pixelCount
referencePixels:p1
imagePixels:p2];
if (!imageEqual) {
if (overallTolerance != 0 || perPixelTolerance != 0) {
const NSUInteger pixelCount = referenceImageSize.width * referenceImageSize.height;
// Go through each pixel in turn and see if it is different
imageEqual = [self _compareAllPixelsWithPerPixelTolerance:perPixelTolerance
overallTolerance:overallTolerance
pixelCount:pixelCount
referencePixels:p1
imagePixels:p2];
}
}

free(referenceImagePixels);
Expand Down