001: package it.geosolutions.imageio.plugins.jhdf.aps;
002:
003: import it.geosolutions.imageio.plugins.jhdf.JHDFTest;
004: import it.geosolutions.imageio.plugins.jhdf.MetadataDisplay;
005: import it.geosolutions.imageio.plugins.slices2D.SliceImageReader;
006: import it.geosolutions.resources.TestData;
007:
008: import java.io.File;
009: import java.io.IOException;
010:
011: import javax.imageio.ImageReader;
012: import javax.imageio.ImageWriter;
013: import javax.imageio.metadata.IIOMetadata;
014: import javax.imageio.metadata.IIOMetadataNode;
015: import javax.media.jai.JAI;
016: import javax.media.jai.ParameterBlockJAI;
017: import javax.media.jai.RenderedOp;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterSpi;
023: import com.sun.media.jai.operator.ImageReadDescriptor;
024:
025: public class APSReadTest extends JHDFTest {
026: public APSReadTest(String name) {
027: super (name);
028: }
029:
030: /**
031: * Simple Metadata retrieving and displaying.
032: *
033: * @throws IOException
034: */
035: public void testMetadata() throws IOException {
036: //this Test File is available at
037: //ftp://ftp.geo-solutions.it/incoming/MODPM2007027121858.L3_000_EAST_MED.zip
038: //as anonymous ftp access.
039:
040: //TODO: build an utility to auto-download and unzip this file in
041: //the setUp method.
042: final File file = TestData.file(this ,
043: "MODPM2007027121858.L3_000_EAST_MED.HDF");
044: final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI(
045: "ImageRead");
046: pbjImageRead.setParameter("Input", file);
047: final RenderedOp image = JAI.create("ImageRead", pbjImageRead);
048: ImageReader reader = (ImageReader) image
049: .getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
050:
051: final IIOMetadata metadata = reader.getImageMetadata(2);
052: IIOMetadataNode imageNode = (IIOMetadataNode) metadata
053: .getAsTree(APSImageMetadata.nativeMetadataFormatName);
054: System.out.println(MetadataDisplay
055: .buildMetadataFromNode(imageNode));
056:
057: final IIOMetadata streamMetadata = reader.getStreamMetadata();
058: IIOMetadataNode streamNode = (IIOMetadataNode) streamMetadata
059: .getAsTree(APSStreamMetadata.nativeMetadataFormatName);
060: System.out.println(MetadataDisplay
061: .buildMetadataFromNode(streamNode));
062: }
063:
064: /**
065: *
066: * @throws IOException
067: */
068: public void testJaiRead() throws IOException {
069: // this Test File is available at
070: //ftp://ftp.geo-solutions.it/incoming/MODPM2007027121858.L3_000_EAST_MED.zip
071: //as anonymous ftp access.
072:
073: //TODO: build an utility to auto-download and unzip this file in
074: //the setUp method.
075: final File file = TestData.file(this ,
076: "MODPM2007027121858.L3_000_EAST_MED.HDF");
077: for (int i = 0; i < 3; i++) {
078: ImageReader reader = new APSImageReader(
079: new APSImageReaderSpi());
080: reader.setInput(file);
081: final int imageIndex = ((SliceImageReader) reader)
082: .retrieveSlice2DIndex(i, null);
083:
084: final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI(
085: "ImageRead");
086: pbjImageRead.setParameter("Input", file);
087: pbjImageRead.setParameter("reader", reader);
088: pbjImageRead.setParameter("imageChoice", Integer
089: .valueOf(imageIndex));
090:
091: final RenderedOp image = JAI.create("ImageRead",
092: pbjImageRead);
093:
094: final File outputFile = TestData.temp(this , "WriteHDFData"
095: + i, false);
096: final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI(
097: "ImageWrite");
098: pbjImageWrite.setParameter("Transcode", false);
099: pbjImageWrite.setParameter("UseProperties", false);
100: pbjImageWrite.setParameter("Output", outputFile);
101: ImageWriter writer = new J2KImageWriterSpi()
102: .createWriterInstance();
103: pbjImageWrite.setParameter("Writer", writer);
104:
105: // Specifying image source to write
106: pbjImageWrite.addSource(image);
107:
108: // Writing
109: final RenderedOp writeOp = JAI.create("ImageWrite",
110: pbjImageWrite);
111: //USE AN EXTERNAL JP2K VIEWER TO VIEW WRITTEN IMAGE
112: //The data of this test contains negative numbers.
113: }
114: }
115:
116: public static Test suite() {
117: TestSuite suite = new TestSuite();
118:
119: suite.addTest(new APSReadTest("testJaiRead"));
120:
121: suite.addTest(new APSReadTest("testMetadata"));
122:
123: return suite;
124: }
125:
126: public static void main(java.lang.String[] args) {
127: junit.textui.TestRunner.run(suite());
128: }
129: }
|