Search in sources :

Example 1 with ScrollingImagePanel

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();
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel) Iterator(java.util.Iterator) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

Example 2 with ScrollingImagePanel

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;
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel) Iterator(java.util.Iterator) ImageReader(javax.imageio.ImageReader) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 3 with ScrollingImagePanel

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);
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel) JLabel(javax.swing.JLabel)

Example 4 with ScrollingImagePanel

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);
        }
    });
}
Also used : JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel)

Example 5 with ScrollingImagePanel

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);
}
Also used : JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel)

Aggregations

ScrollingImagePanel (javax.media.jai.widget.ScrollingImagePanel)5 JFrame (javax.swing.JFrame)5 File (java.io.File)2 Iterator (java.util.Iterator)2 ImageReadParam (javax.imageio.ImageReadParam)2 ImageReader (javax.imageio.ImageReader)2 BorderLayout (java.awt.BorderLayout)1 RenderingHints (java.awt.RenderingHints)1 BufferedImage (java.awt.image.BufferedImage)1 ImageLayout (javax.media.jai.ImageLayout)1 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)1 RenderedOp (javax.media.jai.RenderedOp)1 JLabel (javax.swing.JLabel)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1