Magnum::DebugTools::CompareImageFile class

Image file comparator.

Similar to CompareImage, but comparing images loaded from files. Example usage:

CORRADE_COMPARE_WITH("actual.png", "expected.png",
    (DebugTools::CompareImageFile{15.5f, 5.0f}));

By default, the comparator uses a local instance of Corrade::PluginManager::Manager to load image files. This might be problematic if the code being tested also uses a plugin manager instance or if you need to use a different plugin directory, for example. For such cases it's possible to supply an external instance:

PluginManager::Manager<Trade::AbstractImporter> manager;

CORRADE_COMPARE_WITH("actual.png", "expected.png",
    (DebugTools::CompareImageFile{manager, 15.5f, 5.0f}));

The comparator uses the AnyImageImporter plugin, which in turn delegates the import to some importer plugin matching the image format(s). Both the AnyImageImporter and the concrete importer plugin(s) need to be available, otherwise the comparison fails. An alternative way is manually skipping the test if the plugins are not available:

PluginManager::Manager<Trade::AbstractImporter> manager;
if(manager.loadState("AnyImageImporter") == PluginManager::LoadState::NotFound ||
   manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
    CORRADE_SKIP("AnyImageImporter/PngImporter not found, can't compare.");

CORRADE_COMPARE_WITH("actual.png", "expected.png",
    (DebugTools::CompareImageFile{manager, 15.5f, 5.0f}));

See also CompareImageToFile and CompareFileToImage for comparing in-memory images to image files and vice versa.

Constructors, destructors, conversion operators

CompareImageFile(Float maxThreshold, Float meanThreshold) explicit
Constructor.
CompareImageFile(PluginManager::Manager<Trade::AbstractImporter>& manager, Float maxThreshold, Float meanThreshold) explicit
Construct with an explicit plugin manager instance.
CompareImageFile(PluginManager::Manager<Trade::AbstractImporter>& manager) explicit
Construct with an explicit plugin manager instance and implicit thresholds.
CompareImageFile() explicit
Construct with implicit thresholds.

Function documentation

Magnum::DebugTools::CompareImageFile::CompareImageFile(Float maxThreshold, Float meanThreshold) explicit

Constructor.

Parameters
maxThreshold Max threshold. If any pixel has delta above this value, this comparison fails
meanThreshold Mean threshold. If mean delta over all pixels is above this value, the comparison fails

Magnum::DebugTools::CompareImageFile::CompareImageFile(PluginManager::Manager<Trade::AbstractImporter>& manager, Float maxThreshold, Float meanThreshold) explicit

Construct with an explicit plugin manager instance.

Parameters
manager Image importer plugin manager instance used when comparing against images loaded from files
maxThreshold Max threshold. If any pixel has delta above this value, this comparison fails
meanThreshold Mean threshold. If mean delta over all pixels is above this value, the comparison fails

Magnum::DebugTools::CompareImageFile::CompareImageFile(PluginManager::Manager<Trade::AbstractImporter>& manager) explicit

Construct with an explicit plugin manager instance and implicit thresholds.

Equivalent to calling CompareImageFile(PluginManager::Manager<Trade::AbstractImporter>&, Float, Float) with zero values.

Magnum::DebugTools::CompareImageFile::CompareImageFile() explicit

Construct with implicit thresholds.

Equivalent to calling CompareImageFile(Float, Float) with zero values.