use of javax.media.jai.widget.ScrollingImagePanel in project imageio-ext by geosolutions-it.
the class JPEGReadTest method multithreadedJAIRead.
/**
* Simple test read
*
* @throws FileNotFoundException
* @throws IOException
*/
public void multithreadedJAIRead() throws FileNotFoundException, IOException {
if (!isJmagickAvailable) {
LOGGER.warning("JMagick Library is not Available; Skipping tests");
return;
}
// register the image read mt operation
ImageReadDescriptorMT.register(JAI.getDefaultInstance());
// get the file we are going to read
final String fileName = "001140.jpg";
final File file = TestData.file(this, fileName);
// acquire a reader for it but check that it is the right one
final Iterator readersIt = ImageIO.getImageReaders(file);
ImageReader reader = null;
while (readersIt.hasNext()) {
reader = (ImageReader) readersIt.next();
if (reader instanceof JpegJMagickImageReader)
break;
reader = null;
}
assertNotNull(reader);
// do an image read with jai
final ParameterBlockJAI pbjImageRead;
final ImageReadParam irp = reader.getDefaultReadParam();
irp.setSourceSubsampling(4, 4, 0, 0);
pbjImageRead = new ParameterBlockJAI("ImageReadMT");
pbjImageRead.setParameter("Input", file);
pbjImageRead.setParameter("Reader", reader);
pbjImageRead.setParameter("readParam", irp);
// set the layout so that we shrink the amount of memory needed to load
// this image
final ImageLayout l = new ImageLayout();
l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
RenderedOp image = JAI.create("ImageReadMT", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest()) {
final JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().add(new ScrollingImagePanel(image, 1024, 768));
jf.pack();
jf.show();
} else {
assertNotNull(image.getTiles());
// remember that if we do not explictly provide an Imagereader to
// the ImageReadMT operation it consistently dispose the one it
// creates once we dispose the ImageReadOpImage
image.dispose();
}
}
use of javax.media.jai.widget.ScrollingImagePanel in project imageio-ext by geosolutions-it.
the class JPEGReadTest method ImageIORead.
/**
* Simple test read
*
* @throws FileNotFoundException
* @throws IOException
*/
@org.junit.Test
public void ImageIORead() throws FileNotFoundException, IOException {
if (!isJmagickAvailable) {
LOGGER.warning("JMagick Library is not Available; Skipping tests");
return;
}
// get the file we are going to read
final String fileName = "001140.jpg";
final File file = TestData.file(this, fileName);
// acquire a reader for it but check that it is the right one
final Iterator readersIt = ImageIO.getImageReaders(file);
ImageReader reader = null;
while (readersIt.hasNext()) {
reader = (ImageReader) readersIt.next();
if (reader instanceof JpegJMagickImageReader)
break;
reader = null;
}
assertNotNull(reader);
// do an image read with jai
final ImageReadParam irp = reader.getDefaultReadParam();
irp.setSourceSubsampling(4, 4, 0, 0);
reader.setInput(ImageIO.createImageInputStream(file));
BufferedImage image = reader.read(0, irp);
if (true) {
final JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().add(new ScrollingImagePanel(image, 1024, 768));
jf.pack();
jf.show();
} else {
assertNotNull(image);
// flush resources
image.flush();
image = null;
}
}
use of javax.media.jai.widget.ScrollingImagePanel in project imageio-ext by geosolutions-it.
the class Viewer method visualizeWithTextArea.
// ///////////////////////////////////////////////////////////////////////
//
// Provides to retrieve metadata from the provided
// <code>RenderedImage</code>}
// and return the String containing properly formatted text.
//
// ///////////////////////////////////////////////////////////////////////
// TODO: Fix it since frame components are not well composed/located
private static void visualizeWithTextArea(RenderedImage ri, String title, final MetadataChoice textFields, final int index, final boolean displayImage) {
StringBuffer sb = new StringBuffer();
switch(textFields) {
case ONLY_IMAGE_METADATA:
sb.append(" Image Metadata from ").append(title);
break;
case ONLY_STREAM_METADATA:
sb.append(" Stream Metadata");
break;
case STREAM_AND_IMAGE_METADATA:
sb.append(" Metadata from ").append(title);
break;
case PROJECT_AND_GEOTRANSF:
sb.append(" CRS Information for ").append(title);
break;
case EVERYTHING:
sb.append(" Additional Information from ").append(title);
break;
}
final JFrame frame = new JFrame(title);
frame.getContentPane().setLayout(new BorderLayout());
// Sometime, we dont want to display image, only text data which
// need to be placed to the start of the area.
String textPosition = BorderLayout.PAGE_START;
if (displayImage) {
frame.getContentPane().add(new ScrollingImagePanel(ri, 640, 480));
textPosition = BorderLayout.LINE_START;
}
JLabel label = new JLabel(sb.toString());
frame.getContentPane().add(label, textPosition);
JTextArea textArea = new JTextArea();
if (textFields == MetadataChoice.PROJECT_AND_GEOTRANSF)
textArea.setText(GDALUtilities.buildCRSProperties(ri, index));
else if (textFields != MetadataChoice.EVERYTHING)
textArea.setText(GDALUtilities.buildMetadataText(ri, textFields, index));
else
textArea.setText(new StringBuffer(GDALUtilities.buildMetadataText(ri, textFields, index).toString()).append(newLine).append(GDALUtilities.buildCRSProperties(ri, index)).toString());
textArea.setEditable(false);
frame.getContentPane().add(textArea);
frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.PAGE_END);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.pack();
frame.setSize(1024, 768);
frame.setVisible(true);
}
});
}
use of javax.media.jai.widget.ScrollingImagePanel in project imageio-ext by geosolutions-it.
the class ImageIOUtilities method visualize.
/**
* base method used to simply visualize RenderedImage
*
* @param ri
* RenderedImage to visualize
* @param title
* title for the frame (usually the image filename)
*/
public static void visualize(final RenderedImage ri, String title) {
final JFrame frame = new JFrame(title);
frame.getContentPane().add(new ScrollingImagePanel(ri, 1024, 768));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.pack();
frame.setSize(1024, 768);
frame.setVisible(true);
}
});
}
use of javax.media.jai.widget.ScrollingImagePanel in project imageio-ext by geosolutions-it.
the class TestImageInputStream method visualize.
/**
* @param image
* @param string
* @throws HeadlessException
*/
private void visualize(final RenderedOp image, String string) throws HeadlessException {
final JFrame f = new JFrame();
f.setTitle(string);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new ScrollingImagePanel(image, 800, 800));
f.pack();
f.setVisible(true);
}
Aggregations