//
// JAIForm.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

package visad.data.jai;

import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.rmi.RemoteException;
import visad.*;
import visad.data.*;
import visad.util.*;

/**
 * JAIForm is the VisAD data form for image formats supported by the Java
 * Advanced Imaging API: BMP, GIF, FlashPix, JPEG, PNG, PNM, and TIFF.
 */
public class JAIForm extends Form implements FormFileInformer {

  private static int num = 0;

  private static final String[] suffixes = {
    "bmp", "gif", "flashpix", "jpg", "jpeg", "jpe", "png", "pnm", "tif", "tiff"
  };

  private static boolean noJai = false;

  private static ReflectedUniverse r = createReflectedUniverse();

  private static ReflectedUniverse createReflectedUniverse() {
    ReflectedUniverse r = null;
    try {
      r = new ReflectedUniverse();
      r.exec("import javax.media.jai.JAI");
      r.exec("import javax.media.jai.PlanarImage");
    }
    catch (VisADException exc) { noJai = true; }
    return r;
  }

  private static BufferedImage createImage(String s, Object o) {
    BufferedImage bi = null;
    try {
      r.setVar("s", s);
      r.setVar("o", o);
      r.exec("pi = JAI.create(s, o)");
      bi = (BufferedImage) r.exec("pi.getAsBufferedImage()");
    }
    catch (VisADException exc) { }
    return bi;
  }

  /** Constructs a new JAI file form. */
  public JAIForm() {
    super("JAIForm" + num++);
  }

  /** Checks if the given string is a valid filename for a JAI image file. */
  public boolean isThisType(String name) {
    if (noJai) return false;
    for (int i=0; i 

Ads help maintain this website.