예제 #1
0
  private void testAlphaRGB(boolean direct) {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(getSyntheticRGB(direct));
    worker.applyOpacity(0.5f);

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);
    assertTrue(image.getColorModel().hasAlpha());
    int sample = image.getTile(0, 0).getSample(0, 0, 3);
    assertEquals(128, sample);
  }
예제 #2
0
  @Test
  public void testOpacityGray() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(gray);
    worker.applyOpacity(0.5f);

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);
    assertTrue(image.getColorModel().hasAlpha());
    int sample = image.getTile(0, 0).getSample(0, 0, 1);
    assertEquals(128, sample);
  }
예제 #3
0
  @Test
  public void testOpacityIndexed() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    assertFalse(worldDEMImage.getColorModel().hasAlpha());
    ImageWorker worker = new ImageWorker(worldDEMImage);
    worker.applyOpacity(0.5f);

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof IndexColorModel);
    assertTrue(image.getColorModel().hasAlpha());

    // check the resulting palette
    IndexColorModel index = (IndexColorModel) image.getColorModel();
    for (int i = 0; i < index.getMapSize(); i++) {
      assertEquals(128, index.getAlpha(i));
    }
  }
예제 #4
0
  @Test
  public void testOpacityIndexedTranslucent() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    assertFalse(worldDEMImage.getColorModel().hasAlpha());
    final BufferedImage input = getSyntheticTranslucentIndexed();
    ImageWorker worker = new ImageWorker(input);
    worker.applyOpacity(0.5f);

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof IndexColorModel);
    assertTrue(image.getColorModel().hasAlpha());

    // check the resulting palette
    IndexColorModel outputCM = (IndexColorModel) image.getColorModel();
    IndexColorModel inputCM = (IndexColorModel) input.getColorModel();
    for (int i = 0; i < inputCM.getMapSize(); i++) {
      assertEquals(Math.round(inputCM.getAlpha(i) * 0.5), outputCM.getAlpha(i));
    }
  }
예제 #5
0
  @Test
  public void testOpacityGrayAlpha() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(gray);
    worker.applyOpacity(0.5f);

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);
    assertTrue(image.getColorModel().hasAlpha());
    Raster tile = gray.getTile(0, 0);
    Raster outputTile = image.getTile(0, 0);
    for (int i = 0; i < tile.getWidth(); i++) {
      for (int j = 0; j < tile.getHeight(); j++) {
        int original = tile.getSample(i, j, 1);
        int result = outputTile.getSample(i, j, 1);
        assertEquals(Math.round(original * 0.5), result);
      }
    }
  }