Interface TestScreenshotComparisonAlgorithm
public interface TestScreenshotComparisonAlgorithm
An algorithm for finding a template subimage (the "needle") in a screenshot (the "haystack"). Comparison algorithms
are written to find a subimage, but can also be used to compare two images of equal size (which is a special case of
finding). Custom algorithm implementations are allowed.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A thin wrapper around a raw image data array, so that algorithms can directly access the array which may be more efficient than going through aNativeImage
each time. -
Method Summary
Modifier and TypeMethodDescriptionThe default algorithm for this API, which is the Mean Squared Difference algorithm with a threshold of0.005
.exact()
An algorithm which searches for an exact match of the needle in the haystack.@Nullable org.joml.Vector2i
findColor
(TestScreenshotComparisonAlgorithm.RawImage<int[]> haystack, TestScreenshotComparisonAlgorithm.RawImage<int[]> needle) Finds a needle in a haystack, color image version.default @Nullable org.joml.Vector2i
findGrayscale
(TestScreenshotComparisonAlgorithm.RawImage<byte[]> haystack, TestScreenshotComparisonAlgorithm.RawImage<byte[]> needle) Finds a needle in a haystack, grayscale image version.meanSquaredDifference
(float maxMeanSquaredDifference) The Mean Squared Difference algorithm computes the mean of differences between the needle pixels and corresponding haystack pixels squared, and checks if the mean is less than a particular threshold.
-
Method Details
-
defaultAlgorithm
The default algorithm for this API, which is the Mean Squared Difference algorithm with a threshold of0.005
. SeemeanSquaredDifference(float)
for details.- Returns:
- The default algorithm for this API
-
meanSquaredDifference
The Mean Squared Difference algorithm computes the mean of differences between the needle pixels and corresponding haystack pixels squared, and checks if the mean is less than a particular threshold.- Parameters:
maxMeanSquaredDifference
- The maximum mean squared difference between the needle and the subimage in the haystack for a match- Returns:
- The Mean Squared Difference algorithm with the given threshold
-
exact
An algorithm which searches for an exact match of the needle in the haystack. This is simpler and faster than a fuzzy match, but is prone to failing on even the slightest inconsistency in the image.- Returns:
- An algorithm for exact matches
-
findColor
@Nullable @Nullable org.joml.Vector2i findColor(TestScreenshotComparisonAlgorithm.RawImage<int[]> haystack, TestScreenshotComparisonAlgorithm.RawImage<int[]> needle) Finds a needle in a haystack, color image version. Pixels are in RGB format (with no alpha channel).- Parameters:
haystack
- The image in which to search for the needleneedle
- The image to search for- Returns:
- The location of the match, or
null
if no match was found. In case of multiple matches, returns an arbitrary match
-
findGrayscale
@Nullable default @Nullable org.joml.Vector2i findGrayscale(TestScreenshotComparisonAlgorithm.RawImage<byte[]> haystack, TestScreenshotComparisonAlgorithm.RawImage<byte[]> needle) Finds a needle in a haystack, grayscale image version. Each pixel is a brightness value from 0-255.Note for custom algorithm implementations: the default implementation converts the images to color and then uses
findColor(net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotComparisonAlgorithm.RawImage<int[]>, net.fabricmc.fabric.api.client.gametest.v1.screenshot.TestScreenshotComparisonAlgorithm.RawImage<int[]>)
, but it is usually possible to implement this more efficiently. You should strongly consider overriding this method.- Parameters:
haystack
- The image in which to search for the needleneedle
- The image to search for- Returns:
- The location of the match, or
null
if no match was found. In case of multiple matches, returns an arbitrary match
-