if (spec.isCropIfOutside()) {
elementArea = cropElementAreaIfOutside(elementArea, pageImage.getWidth(), pageImage.getHeight());
}
ImageCompareResult result = Rainbow4J.compare(pageImage, sampleImage, toRectangle(elementArea), sampleArea, options);
double difference = 0.0;
String errorMessage = null;
if (spec.getMaxPercentage() != null) {
difference = result.getPercentage() - spec.getMaxPercentage();
if (difference > 0) {
errorMessage = createErrorMessageForPercentage(msgErrorPrefix(spec.getImagePaths().get(0)), spec.getMaxPercentage(), result.getPercentage());
}
} else {
if (spec.getMaxPixels() == null) {
spec.setMaxPixels(0);
}
difference = result.getTotalPixels() - spec.getMaxPixels();
if (difference > 0) {
errorMessage = createErrorMessageForPixels(msgErrorPrefix(spec.getImagePaths().get(0)), spec.getMaxPixels(), result.getTotalPixels());
}
}
return new ImageCheck(imagePath, difference, result, errorMessage);
}