use of net.hearthstats.util.Coordinate in project HearthStats.net-Uploader by HearthStats.
the class CoordinateCacheBase method getCachedCoordinate.
protected Coordinate getCachedCoordinate(UniquePixelIdentifier upi) {
Coordinate coordinate = coordinateCache.get(upi);
if (coordinate == null) {
coordinate = calculatePixelCoordinate(upi);
if (coordinateCache.size() > MAXIMUM_CACHE_ITEMS) {
coordinateCache.clear();
}
coordinateCache.put(upi, coordinate);
}
return coordinate;
}
use of net.hearthstats.util.Coordinate in project HearthStats.net-Uploader by HearthStats.
the class IndividualPixelAnalyser method testAllPixelsMatch.
public boolean testAllPixelsMatch(BufferedImage image, UniquePixel[] uniquePixels) {
for (UniquePixel uniquePixel : uniquePixels) {
UniquePixelIdentifier upi = new UniquePixelIdentifier(uniquePixel.x(), uniquePixel.y(), image.getWidth(), image.getHeight());
Coordinate coordinate = getCachedCoordinate(upi);
int x = coordinate.x();
int y = coordinate.y();
int rgb = image.getRGB(x, y);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = (rgb & 0xFF);
if (red < uniquePixel.minRed || red > uniquePixel.maxRed || green < uniquePixel.minGreen || green > uniquePixel.maxGreen || blue < uniquePixel.minBlue || blue > uniquePixel.maxBlue) {
// This pixel is outside the expected range
return false;
}
}
// No pixel texts failed, so this is a match
debugLog.debug("matched all pixels {}", (Object[]) uniquePixels);
return true;
}
use of net.hearthstats.util.Coordinate in project HearthStats.net-Uploader by HearthStats.
the class IndividualPixelAnalyser method testAnyPixelsMatch.
boolean testAnyPixelsMatch(BufferedImage image, UniquePixel[] uniquePixels) {
for (UniquePixel uniquePixel : uniquePixels) {
UniquePixelIdentifier upi = new UniquePixelIdentifier(uniquePixel.x(), uniquePixel.y(), image.getWidth(), image.getHeight());
Coordinate coordinate = getCachedCoordinate(upi);
int x = coordinate.x();
int y = coordinate.y();
int rgb = image.getRGB(x, y);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = (rgb & 0xFF);
if (red >= uniquePixel.minRed && red <= uniquePixel.maxRed && green >= uniquePixel.minGreen && green <= uniquePixel.maxGreen && blue >= uniquePixel.minBlue && blue <= uniquePixel.maxBlue) {
// This pixel is inside the expected range so it's an immediate match
debugLog.debug("matched {} any from pixel {}", uniquePixel, uniquePixels);
return true;
}
}
// All pixel text failed, so this is not a match
return false;
}
use of net.hearthstats.util.Coordinate in project HearthStats.net-Uploader by HearthStats.
the class RelativePixelAnalyser method findRelativePixel.
Coordinate findRelativePixel(BufferedImage image, UniquePixel boundingBoxTopLeft, UniquePixel boundingBoxBottomRight, int xSamples, int ySamples) {
UniquePixelIdentifier upiTopLeft = new UniquePixelIdentifier(boundingBoxTopLeft.x(), boundingBoxTopLeft.y(), image.getWidth(), image.getHeight());
UniquePixelIdentifier upiBottomRight = new UniquePixelIdentifier(boundingBoxBottomRight.x(), boundingBoxBottomRight.y(), image.getWidth(), image.getHeight());
Coordinate coordinateTopLeft = getCachedCoordinate(upiTopLeft);
Coordinate coordinateBottomRight = getCachedCoordinate(upiBottomRight);
float xStepSize = (float) (coordinateBottomRight.x() - coordinateTopLeft.x()) / (float) (xSamples - 1);
float yStepSize = (float) (coordinateBottomRight.y() - coordinateTopLeft.y()) / (float) (ySamples - 1);
debugLog.debug("relative pixel bounding box: topLeft={},{} bottomRight={},{} stepSize={},{}", coordinateTopLeft.x(), coordinateTopLeft.y(), coordinateBottomRight.x(), coordinateBottomRight.y(), xStepSize, yStepSize);
for (int yCount = 0; yCount < ySamples; yCount++) {
int y = coordinateTopLeft.y() + (int) (yCount * xStepSize);
for (int xCount = 0; xCount < xSamples; xCount++) {
int x = coordinateTopLeft.x() + (int) (xCount * xStepSize);
int rgb = image.getRGB(x, y);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = (rgb & 0xFF);
if (red >= boundingBoxTopLeft.minRed && red <= boundingBoxTopLeft.maxRed && green >= boundingBoxTopLeft.minGreen && green <= boundingBoxTopLeft.maxGreen && blue >= boundingBoxTopLeft.minBlue && blue <= boundingBoxTopLeft.maxBlue) {
// This pixel is inside the expected range so it's an immediate match
debugLog.debug("a matched reference pixel at {},{}", x, y);
return new Coordinate(x, y);
}
if (red >= boundingBoxBottomRight.minRed && red <= boundingBoxBottomRight.maxRed && green >= boundingBoxBottomRight.minGreen && green <= boundingBoxBottomRight.maxGreen && blue >= boundingBoxBottomRight.minBlue && blue <= boundingBoxBottomRight.maxBlue) {
// This pixel is inside the expected range so it's an immediate match
debugLog.debug("b matched reference pixel at {},{}", x, y);
return new Coordinate(x, y);
}
}
}
return null;
}
use of net.hearthstats.util.Coordinate in project HearthStats.net-Uploader by HearthStats.
the class ScreenAnalyser method checkForPartialMatch.
PartialResult checkForPartialMatch(BufferedImage image, Screen screen) {
// Skip screens that haven't yet been defined
if (screen.primary.size() == 0) {
return new PartialResult(0, 0);
}
int matchedCount = 0;
// Boost the unmatched count on the Starting Hand screen because it doesn't have sufficient pixels for a reliable partial match
int unmatchedCount = screen == Screen.MATCH_STARTINGHAND ? 1 : 0;
for (Pixel pixel : screen.primaryAndSecondary) {
Coordinate coordinate = pixelMap.get(pixel.pixelLocation);
int x = coordinate.x();
int y = coordinate.y();
int rgb = image.getRGB(x, y);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = (rgb & 0xFF);
if (red < pixel.minRed || red > pixel.maxRed || green < pixel.minGreen || green > pixel.maxGreen || blue < pixel.minBlue || blue > pixel.maxBlue) {
// This pixel is outside the expected range: it's not a match
unmatchedCount++;
} else {
// This pixel is inside the expected range: it's a match
matchedCount++;
}
}
return new PartialResult(matchedCount, unmatchedCount);
}
Aggregations