コード例 #1
0
  @Test
  public void testBitmask() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(sstImage);

    worker.forceBitmaskIndexColorModel();
    assertEquals(1, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());

    final BufferedImage directRGB = getSyntheticRGB(true);
    worker = new ImageWorker(directRGB);
    worker.forceBitmaskIndexColorModel();
    assertEquals(1, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());

    final BufferedImage componentRGB = getSyntheticRGB(false);
    worker = new ImageWorker(componentRGB);
    worker.forceBitmaskIndexColorModel();
    assertEquals(1, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());

    final BufferedImage translucentIndexed = getSyntheticTranslucentIndexed();
    worker = new ImageWorker(translucentIndexed);
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertTrue(worker.isTranslucent());

    worker.forceIndexColorModelForGIF(true);
    assertEquals(1, worker.getNumBands());
    assertEquals(0, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isTranslucent());
  }
コード例 #2
0
  @Test
  public void testYCbCr() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    // check the presence of the PYCC.pf file that contains the profile for the YCbCr color space
    if (ImageWorker.CS_PYCC == null) {
      System.out.println(
          "testYCbCr disabled since we are unable to locate the YCbCr color profile");
      return;
    }
    // RGB component color model
    ImageWorker worker = new ImageWorker(getSyntheticRGB(false));

    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);
    assertTrue(!image.getColorModel().hasAlpha());
    int sample = image.getTile(0, 0).getSample(0, 0, 2);
    assertEquals(0, sample);

    assertFalse(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceYCbCr();
    assertTrue(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceRGB();
    assertFalse(worker.isColorSpaceYCbCr());
    assertTrue(worker.isColorSpaceRGB());

    // RGB Palette
    worker.forceBitmaskIndexColorModel();
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof IndexColorModel);
    assertTrue(!image.getColorModel().hasAlpha());

    assertFalse(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceYCbCr();
    assertTrue(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceRGB();
    assertFalse(worker.isColorSpaceYCbCr());
    assertTrue(worker.isColorSpaceRGB());

    // RGB DirectColorModel
    worker = new ImageWorker(getSyntheticRGB(true));
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof DirectColorModel);
    assertTrue(!image.getColorModel().hasAlpha());
    sample = image.getTile(0, 0).getSample(0, 0, 2);
    assertEquals(0, sample);

    assertFalse(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceYCbCr();
    assertTrue(worker.isColorSpaceYCbCr());
    worker.forceColorSpaceRGB();
    assertFalse(worker.isColorSpaceYCbCr());
    assertTrue(worker.isColorSpaceRGB());
  }
コード例 #3
0
  /** Tests the {@link ImageWorker#tile()} methods. Some trivial tests are performed before. */
  @Test
  public void testReTile() {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(worldImage);

    assertSame(worldImage, worker.getRenderedImage());
    assertEquals(4, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertFalse(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertTrue(worker.isTranslucent());

    assertSame("Expected no operation.", worldImage, worker.rescaleToBytes().getRenderedImage());
    assertSame(
        "Expected no operation.", worldImage, worker.forceComponentColorModel().getRenderedImage());
    assertSame(
        "Expected no operation.", worldImage, worker.forceColorSpaceRGB().getRenderedImage());
    assertSame("Expected no operation.", worldImage, worker.retainBands(4).getRenderedImage());

    // Following will change image, so we need to test after the above assertions.
    worker.setRenderingHint(
        JAI.KEY_IMAGE_LAYOUT,
        new ImageLayout()
            .setTileGridXOffset(0)
            .setTileGridYOffset(0)
            .setTileHeight(64)
            .setTileWidth(64));
    worker.tile();
    assertSame("Expected 64.", 64, worker.getRenderedImage().getTileWidth());
    assertSame("Expected 64.", 64, worker.getRenderedImage().getTileHeight());
  }
コード例 #4
0
  /**
   * Tests the {@link ImageWorker#makeColorTransparent} methods. Some trivial tests are performed
   * before.
   *
   * @throws IOException
   * @throws FileNotFoundException
   * @throws IllegalStateException
   */
  @Test
  public void testMakeColorTransparent()
      throws IllegalStateException, FileNotFoundException, IOException {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    ImageWorker worker = new ImageWorker(sstImage);

    assertSame(sstImage, worker.getRenderedImage());
    assertEquals(1, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isBinary());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());

    assertSame(
        "Expected no operation.", sstImage, worker.forceIndexColorModel(false).getRenderedImage());
    assertSame(
        "Expected no operation.", sstImage, worker.forceIndexColorModel(true).getRenderedImage());
    assertSame("Expected no operation.", sstImage, worker.forceColorSpaceRGB().getRenderedImage());
    assertSame("Expected no operation.", sstImage, worker.retainFirstBand().getRenderedImage());
    assertSame("Expected no operation.", sstImage, worker.retainLastBand().getRenderedImage());

    // Following will change image, so we need to test after the above assertions.
    assertEquals(0, worker.getMinimums()[0], 0);
    assertEquals(255, worker.getMaximums()[0], 0);
    assertNotSame(sstImage, worker.getRenderedImage());
    assertSame(
        "Expected same databuffer, i.e. pixels should not be duplicated.",
        sstImage.getTile(0, 0).getDataBuffer(),
        worker.getRenderedImage().getTile(0, 0).getDataBuffer());

    assertSame(worker, worker.makeColorTransparent(Color.WHITE));
    assertEquals(255, worker.getTransparentPixel());
    assertFalse(worker.isTranslucent());
    assertSame(
        "Expected same databuffer, i.e. pixels should not be duplicated.",
        sstImage.getTile(0, 0).getDataBuffer(),
        worker.getRenderedImage().getTile(0, 0).getDataBuffer());

    // INDEX TO INDEX-ALPHA
    worker = new ImageWorker(chlImage).makeColorTransparent(Color.black);
    show(worker, "CHL01195.png");
    assertEquals(1, worker.getNumBands());
    assertEquals(0, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());
    RenderedImage image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof IndexColorModel);
    IndexColorModel iColorModel = (IndexColorModel) image.getColorModel();
    int transparentColor = iColorModel.getRGB(worker.getTransparentPixel()) & 0x00ffffff;
    assertTrue(transparentColor == 0);

    // INDEX TO INDEX-ALPHA
    worker = new ImageWorker(bathy).makeColorTransparent(Color.WHITE);
    show(worker, "BATHY.png");
    assertEquals(1, worker.getNumBands());
    assertEquals(206, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertTrue(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertFalse(worker.isTranslucent());
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof IndexColorModel);
    iColorModel = (IndexColorModel) image.getColorModel();
    transparentColor = iColorModel.getRGB(worker.getTransparentPixel()) & 0x00ffffff;
    assertTrue(transparentColor == (Color.WHITE.getRGB() & 0x00ffffff));

    // RGB TO RGBA
    worker = new ImageWorker(smallWorld).makeColorTransparent(new Color(11, 10, 50));
    show(worker, "small_world.png");
    assertEquals(4, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertTrue(worker.isTranslucent());
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);

    // RGBA to RGBA
    worker = new ImageWorker(worldImage).makeColorTransparent(Color.white);
    show(worker, "world.png");
    assertEquals(4, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isIndexed());
    assertTrue(worker.isColorSpaceRGB());
    assertFalse(worker.isColorSpaceGRAYScale());
    assertTrue(worker.isTranslucent());
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);

    // GRAY TO GRAY-ALPHA
    worker = new ImageWorker(gray).makeColorTransparent(Color.black);
    show(worker, "gray.png");
    assertEquals(2, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isIndexed());
    assertFalse(worker.isColorSpaceRGB());
    assertTrue(worker.isColorSpaceGRAYScale());
    assertTrue(worker.isTranslucent());
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);

    // GRAY-ALPHA TO GRAY-ALPHA.
    worker = new ImageWorker(grayAlpha).makeColorTransparent(Color.black);
    show(worker, "gray-alpha.png");
    assertEquals(2, worker.getNumBands());
    assertEquals(-1, worker.getTransparentPixel());
    assertTrue(worker.isBytes());
    assertFalse(worker.isIndexed());
    assertFalse(worker.isColorSpaceRGB());
    assertTrue(worker.isColorSpaceGRAYScale());
    assertTrue(worker.isTranslucent());
    image = worker.getRenderedImage();
    assertTrue(image.getColorModel() instanceof ComponentColorModel);
  }