Example #1
0
  @Test
  public void drawWithClipAndTransform() throws Exception {
    graphics.setPaint(Color.BLACK);
    graphics.fill(imageBounds);

    AffineTransform tr =
        AffineTransform.getRotateInstance(
            Math.PI / 4,
            image.getMinX() + image.getWidth() / 2,
            image.getMinY() + image.getHeight() / 2);

    graphics.transform(tr);
    graphics.clip(midRect);

    graphics.setPaint(Color.RED);
    graphics.fill(imageBounds);

    showImage("drawWithClipAndTransform");

    // Outside transformed clip region
    Rectangle outer = new Rectangle(midRect);
    outer.grow(5, 5);
    Point2D[] corners = getCorners(outer);
    Point2D[] trPoints = new Point2D[corners.length];
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.BLACK, trPoints);

    // Inside transformed clip region
    Rectangle inner = new Rectangle(midRect);
    inner.grow(-5, -5);
    corners = getCorners(inner);
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.RED, trPoints);
  }
Example #2
0
  @Before
  public void setup() {
    image = makeImage(tileWidth, xTiles, yTiles);
    graphics = image.createGraphics();

    imageBounds = image.getBounds();

    // Set up a rectangle in the middle of the image to
    // be used by tests
    midRect =
        new Rectangle(
            imageBounds.x + imageBounds.width / 4,
            imageBounds.y + imageBounds.height / 4,
            imageBounds.width / 2,
            imageBounds.height / 2);
  }
Example #3
0
  @Ignore("original test - refactor if we keep it and allow for platform differences")
  @Test
  public void test() throws Exception {
    DiskMemImage dmi = makeImage(tileWidth, xTiles, yTiles);
    BufferedImage bi = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_INT_ARGB);

    draw(dmi.createGraphics());
    draw(bi.createGraphics());

    if (!HEADLESS && SAVE_IMAGE) {
      String dmiPath = File.createTempFile("diskmem", "tif").getPath();
      JAI.create("filestore", dmi, dmiPath, "TIFF", null);

      String bmPath = File.createTempFile("buffered", "tif").getPath();
      JAI.create("filestore", bi, bmPath, "TIFF", null);

      System.out.println("Saved test image files to:");
      System.out.println(dmiPath);
      System.out.println(bmPath);
    }

    if (!HEADLESS && SHOW_IMAGE) {
      CountDownLatch latch = new CountDownLatch(1);
      WaitingImageFrame.showImage(dmi, "Close window to continue test", latch);
      latch.await();
    }

    /*
    // Test for matching pixels between image tiles and reference tile
    Raster refTile = bi.getData();
    Raster tile    = dmi.getTile(0, 0);
    assertEquals(tile.getWidth(), refTile.getWidth());
    assertEquals(tile.getHeight(), refTile.getHeight());
    assertEquals(tile.getNumBands(), refTile.getNumBands());
    for (int y = 0; y < tileHeight; y++) {
        for (int x = 0; x < tileWidth; x++) {
            for (int band = 0; band < dmi.getNumBands(); band++) {
                assertEquals(refTile.getSample(x, y, band),
                        tile.getSample(x + tile.getMinX(), y + tile.getMinY(), band));
            }
        }
    }
    */

  }
Example #4
0
  private void assertColor(Color c, Point2D... points) {
    BufferedImage bufImg = image.getAsBufferedImage();
    int expectedRGB = c.getRGB();
    for (Point2D p : points) {
      int x = (int) p.getX();
      int y = (int) p.getY();

      assertEquals(String.format("x=%d y=%d", x, y), expectedRGB, bufImg.getRGB(x, y));
    }
  }