Package net.hearthstats.util

Examples of net.hearthstats.util.Coordinate


    if (width == PixelLocation.REFERENCE_SIZE.x() && height == PixelLocation.REFERENCE_SIZE.y()) {
      // The screen size is exactly what our reference pixels are based on, so
      // we can use their coordinates directly
      result = new HashMap<>();
      for (PixelLocation pixelLocation : PixelLocation.values()) {
        Coordinate coordinate = new Coordinate(pixelLocation.x(), pixelLocation.y());
        log.debug("Stored position of {} as {}", pixelLocation, coordinate);
        result.put(pixelLocation, coordinate);
      }

    } else {
      // The screen size is different to our reference pixels, so coordinates
      // need to be adjusted
      float ratioX = (float) width / (float) PixelLocation.REFERENCE_SIZE.x();
      float ratioY = (float) height / (float) PixelLocation.REFERENCE_SIZE.y();
      // ratioY is normally the correct ratio to use, but occasionally ratioX is
      // smaller (usually during screen resizing?)
      float ratio = Math.min(ratioX, ratioY);
      float screenRatio = (float) width / (float) height;

      int xOffset;
      if (screenRatio > 1.4) {
        xOffset = (int) (((float) width - (ratio * PixelLocation.REFERENCE_SIZE.x())) / 2);
      } else {
        xOffset = 0;
      }

      log.debug("ratio={} screenRatio={}, xOffset={}", ratio, screenRatio, xOffset);

      result = new HashMap<>();
      for (PixelLocation pixelLocation : PixelLocation.values()) {
        int x = (int) (pixelLocation.x() * ratio) + xOffset;
        int y = (int) (pixelLocation.y() * ratio);
        Coordinate coordinate = new Coordinate(x, y);
        log.debug("Calculated position of {} as {}", pixelLocation, coordinate);
        result.put(pixelLocation, coordinate);
      }
    }

View Full Code Here


    if (screen.primary.size() == 0) {
      return false;
    }

    for (Pixel pixel : screen.primary) {
      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);
View Full Code Here

    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);
View Full Code Here

    if (screen.primary.size() == 0) {
      return false;
    }

    for (Pixel pixel : screen.secondary) {
      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);
View Full Code Here

    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);
View Full Code Here

    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);
View Full Code Here

    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);

        // The two bounding box pixels might have different colour ranges, so
        // test both: if either one matches than this pixel is considered to be
        // a match

        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);
        }

      }
    }

View Full Code Here

    private final static Map<UniquePixelIdentifier, Coordinate> coordinateCache = new HashMap<>();


    protected Coordinate getCachedCoordinate(UniquePixelIdentifier upi) {
        Coordinate coordinate = coordinateCache.get(upi);
        if (coordinate == null) {
            coordinate = calculatePixelCoordinate(upi);
            if (coordinateCache.size() > MAXIMUM_CACHE_ITEMS) {
                coordinateCache.clear();
            }
View Full Code Here

        if (debugLog.isDebugEnabled()) {
            debugLog.debug("Calculating pixel position {},{} for width {} height {}",
                    new Object[] { upi.x, upi.y, upi.width, upi.height });
        }

        Coordinate result;

        if (upi.width == PixelLocation.REFERENCE_SIZE.x && upi.height == PixelLocation.REFERENCE_SIZE.y) {
            // The screen size is exactly what our reference pixels are based on, so we can use their coordinates directly
            result = new Coordinate(upi.x, upi.y);
            debugLog.debug("Stored position as {}", result);

        } else {
            // The screen size is different to our reference pixels, so coordinates need to be adjusted
            float ratio = (float) upi.height / (float) PixelLocation.REFERENCE_SIZE.y;
            float screenRatio = (float) upi.width / (float) upi.height;

            int xOffset;
            if (screenRatio > 1.4) {
                xOffset = (int) (((float) upi.width - (ratio * PixelLocation.REFERENCE_SIZE.x)) / 2);
            } else {
                xOffset = 0;
            }

            int x = (int) (upi.x * ratio) + xOffset;
            int y = (int) (upi.y * ratio);
            result = new Coordinate(x, y);
            debugLog.debug("Calculated position as {}", result);
        }

        return result;
    }
View Full Code Here

                        log.debug("***** Testing Image {} *****", image.getName());

                        BufferedImage bufferedImage = ImageIO.read(image);

                        Coordinate coordinate = relativePixelAnalyser.findRelativePixel(bufferedImage, UniquePixel.VICTORY_DEFEAT_REFBOX_TL, UniquePixel.VICTORY_DEFEAT_REFBOX_BR, 8, 11);
                        coordinates.add(coordinate);

                        output.write("<td class=\"");
                        if (coordinate == null) {
                            output.write("matchzero");
                        } else {
                            output.write("matchone");
                        }
                        output.write("\">");
                        if (coordinate != null) {
                            output.write("<div>Reference Pixel = ");
              output.write(String.valueOf(coordinate.x()));
                            output.write(", ");
              output.write(String.valueOf(coordinate.y()));
                            output.write("</div>");

                            int victory1Matches = relativePixelAnalyser.countMatchingRelativePixels(bufferedImage, coordinate, new UniquePixel[] {
                                    UniquePixel.VICTORY_REL_1A, UniquePixel.VICTORY_REL_1B
                            });
View Full Code Here

TOP

Related Classes of net.hearthstats.util.Coordinate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.