예제 #1
0
  /**
   * Testing TIFF capabilities.
   *
   * @throws IOException If an error occured while writting the image.
   */
  @Test
  public void testTIFFWrite() throws IOException {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    // Get the image of the world with transparency.
    final ImageWorker worker = new ImageWorker(worldImage);
    show(worker, "Input file");

    // /////////////////////////////////////////////////////////////////////
    // tiff deflated untiled
    // /////////////////////////////////////////////////////////////////////
    final File outFile = TestData.temp(this, "temp.tiff");
    worker.writeTIFF(outFile, "Deflate", 0.75f, -1, -1);
    final ImageWorker readWorker = new ImageWorker(ImageIO.read(outFile));
    show(readWorker, "Tiff untiled");

    // /////////////////////////////////////////////////////////////////////
    // tiff deflated compressed tiled
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writeTIFF(outFile, "Deflate", 0.75f, 32, 32);
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "Tiff jpeg compressed, tiled");

    outFile.delete();
  }
예제 #2
0
  /**
   * Testing JPEG capabilities.
   *
   * @throws IOException If an error occured while writting the image.
   */
  @Test
  public void testJPEGWrite() throws IOException {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    // get the image of the world with transparency
    final ImageWorker worker = new ImageWorker(getSyntheticRGB(true));
    show(worker, "Input JPEG");

    // /////////////////////////////////////////////////////////////////////
    // nativeJPEG  with compression JPEG-LS
    // ////////////////////////////////////////////////////////////////////
    final File outFile = TestData.temp(this, "temp.jpeg");
    ImageWorker readWorker;
    if (PackageUtil.isCodecLibAvailable()) {
      worker.writeJPEG(outFile, "JPEG-LS", 0.75f, true);
      readWorker = new ImageWorker(ImageIO.read(outFile));
      show(readWorker, "Native JPEG LS");
    } else {
      try {
        worker.writeJPEG(outFile, "JPEG-LS", 0.75f, true);
        assertFalse(true);
      } catch (Exception e) {
        // TODO: handle exception
      }
    }

    // /////////////////////////////////////////////////////////////////////
    // native JPEG compression
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writeJPEG(outFile, "JPEG", 0.75f, true);
    readWorker = new ImageWorker(ImageIO.read(outFile));
    show(readWorker, "native JPEG");

    // /////////////////////////////////////////////////////////////////////
    // pure java JPEG compression
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writeJPEG(outFile, "JPEG", 0.75f, false);
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "Pure Java JPEG");
    outFile.delete();
  }
예제 #3
0
  /**
   * Testing PNG capabilities.
   *
   * @throws IOException If an error occured while writting the image.
   */
  @Test
  public void testPNGWrite() throws IOException {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    // Get the image of the world with transparency.
    final ImageWorker worker = new ImageWorker(worldImage);
    show(worker, "Input file");

    // /////////////////////////////////////////////////////////////////////
    // native png filtered compression 24 bits
    // /////////////////////////////////////////////////////////////////////
    final File outFile = TestData.temp(this, "temp.png");
    worker.writePNG(outFile, "FILTERED", 0.75f, true, false);
    final ImageWorker readWorker = new ImageWorker(ImageIO.read(outFile));
    show(readWorker, "Native PNG24");

    // /////////////////////////////////////////////////////////////////////
    // native png filtered compression 8 bits
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writePNG(outFile, "FILTERED", 0.75f, true, true);
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "native PNG8");

    // /////////////////////////////////////////////////////////////////////
    // pure java png 24
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writePNG(outFile, "FILTERED", 0.75f, false, false);
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "Pure  PNG24");

    // /////////////////////////////////////////////////////////////////////
    // pure java png 8
    // /////////////////////////////////////////////////////////////////////
    worker.setImage(worldImage);
    worker.writePNG(outFile, "FILTERED", 0.75f, false, true);
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "Pure  PNG8");
    outFile.delete();

    // Check we are not expanding to RGB a paletted image
    worker.setImage(sstImage);
    assertTrue(sstImage.getColorModel() instanceof IndexColorModel);
    worker.writePNG(outFile, "FILTERED", 0.75f, false, false);
    readWorker.setImage(ImageIO.read(outFile));
    assertTrue(readWorker.getRenderedImage().getColorModel() instanceof IndexColorModel);
  }
예제 #4
0
  /**
   * Tests capability to write GIF image.
   *
   * @throws IOException If an error occured while writting the image.
   */
  @Test
  public void testGIFImageWrite() throws IOException {
    assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus());
    // Get the image of the world with transparency.
    ImageWorker worker = new ImageWorker(worldDEMImage);
    show(worker, "Input GIF");
    RenderedImage image = worker.getRenderedImage();
    ColorModel cm = image.getColorModel();
    assertTrue("wrong color model", cm instanceof IndexColorModel);
    assertEquals("wrong transparency model", Transparency.OPAQUE, cm.getTransparency());
    // Writes it out as GIF on a file using index color model with
    final File outFile = TestData.temp(this, "temp.gif");
    worker.writeGIF(outFile, "LZW", 0.75f);

    // Read it back
    final ImageWorker readWorker = new ImageWorker(ImageIO.read(outFile));
    show(readWorker, "GIF to file");
    image = readWorker.getRenderedImage();
    cm = image.getColorModel();
    assertTrue("wrong color model", cm instanceof IndexColorModel);
    assertEquals("wrong transparency model", Transparency.OPAQUE, cm.getTransparency());

    // Write on an output streams.
    final OutputStream os = new FileOutputStream(outFile);
    worker = new ImageWorker(worldImage);
    worker.forceIndexColorModelForGIF(true);
    worker.writeGIF(os, "LZW", 0.75f);

    // Read it back.
    readWorker.setImage(ImageIO.read(outFile));
    show(readWorker, "GIF to output stream");
    image = readWorker.getRenderedImage();
    cm = image.getColorModel();
    assertTrue("wrong color model", cm instanceof IndexColorModel);
    assertEquals("wrong transparency model", Transparency.BITMASK, cm.getTransparency());
    assertEquals(
        "wrong transparent color index", 255, ((IndexColorModel) cm).getTransparentPixel());
    outFile.delete();
  }