001: package it.geosolutions.imageio.plugins.jhdf;
002:
003: import java.awt.image.DataBuffer;
004: import java.awt.image.RenderedImage;
005: import java.awt.image.renderable.ParameterBlock;
006:
007: import javax.media.jai.JAI;
008: import javax.media.jai.PlanarImage;
009: import javax.media.jai.ROI;
010: import javax.media.jai.RenderedOp;
011: import javax.media.jai.widget.ScrollingImagePanel;
012: import javax.swing.JFrame;
013: import javax.swing.SwingUtilities;
014:
015: import junit.framework.TestCase;
016:
017: public class JHDFTest extends TestCase {
018: public JHDFTest(String name) {
019: super (name);
020: }
021:
022: protected void setUp() throws Exception {
023: super .setUp();
024: JAI.getDefaultInstance().getTileCache().setMemoryCapacity(
025: 64 * 1024 * 1024);
026: JAI.getDefaultInstance().getTileCache()
027: .setMemoryThreshold(1.0f);
028:
029: }
030:
031: //
032: // public void testJaiMultithreadingRead() throws IOException {
033: // // SETS JHDFImageReaderSpi as SPI in
034: // // META-INF/services/javax.imageio.spi.ImageReaderSpi
035: //
036: // final File file = TestData.file(this,
037: // "MODPM2007027122358.L3_000_EAST_MED");
038: // ImageReadParam irp = new ImageReadParam();
039: // irp.setSourceSubsampling(1, 1, 0, 0);
040: // // irp.setSourceRegion(new Rectangle(0, 512, 1024, 1024));
041: // int i = 2;
042: // final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI(
043: // "ImageRead");
044: //
045: // pbjImageRead.setParameter("Input", file);
046: // pbjImageRead.setParameter("readParam", irp);
047: // pbjImageRead.setParameter("imageChoice", Integer.valueOf(i));
048: // final RenderedOp image = JAI.create("ImageRead", pbjImageRead);
049: // visualize(image, "");
050: // }
051:
052: /**
053: * Visualization Methods
054: */
055: protected static void visualize(final RenderedImage bi, String test) {
056: visualize(bi, test, false);
057: }
058:
059: /**
060: * Visualization Methods
061: */
062: protected static void visualize(final RenderedImage bi,
063: String test, boolean rescaleImage) {
064: final JFrame frame = new JFrame(test);
065:
066: if (rescaleImage) {
067: ROI roi = new ROI(bi, -999);
068:
069: ParameterBlock pb = new ParameterBlock();
070: pb.addSource(bi); // The source image
071: pb.add(roi); // The region of the image to scan
072:
073: // Perform the extrema operation on the source image
074: RenderedOp op = JAI.create("extrema", pb);
075:
076: // Retrieve both the maximum and minimum pixel value
077: double[][] extrema = (double[][]) op.getProperty("extrema");
078:
079: final double[] scale = new double[] { (255) / (extrema[1][0] - extrema[0][0]) };
080: final double[] offset = new double[] { ((255) * extrema[0][0])
081: / (extrema[0][0] - extrema[1][0]) };
082:
083: ParameterBlock pbRescale = new ParameterBlock();
084: pbRescale.add(scale);
085: pbRescale.add(offset);
086: pbRescale.addSource(bi);
087: PlanarImage rescaledImage = (PlanarImage) JAI.create(
088: "Rescale", pbRescale);
089:
090: ParameterBlock pbConvert = new ParameterBlock();
091: pbConvert.addSource(rescaledImage);
092: pbConvert.add(DataBuffer.TYPE_BYTE);
093: PlanarImage convertedImage = JAI
094: .create("format", pbConvert);
095: frame.getContentPane().add(
096: new ScrollingImagePanel(convertedImage, 800, 600));
097: } else
098: frame.getContentPane().add(
099: new ScrollingImagePanel(bi, 800, 600));
100:
101: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
102: frame.setTitle(test);
103: SwingUtilities.invokeLater(new Runnable() {
104:
105: public void run() {
106: frame.pack();
107: frame.show();
108: }
109: });
110: }
111:
112: }
|