Search in sources :

Example 1 with MultiResolutionRenderableImage

use of javax.media.jai.MultiResolutionRenderableImage in project imageio-ext by geosolutions-it.

the class ImageReadMTCRIF method createRenderable.

// XXX This implementation of renderable mode is incredibly lame
// but the architecture and implementation allow for nothing else.
// It would be better if the CRIFs had some kind of state that
// could be associated with them. As it standards getBounds2D()
// will create a new MultiResolutionRenderableImage and so will
// the second create() below. Actually what is needed is a
// RenderableImageFactory definition.
// XXX There is also a problem with multiple invocations of the
// rendered mode case. Without saving and seeking back to the
// same offset it appears to have problems. Should ImageReadOpImageMT
// save the initial position and always seek back to it?
public RenderableImage createRenderable(ParameterBlock pb, RenderingHints rh) {
    // Read the collection.
    Collection sequence = ImageReadMTCIF.createStatic(pb, rh);
    // Create a SortedMap which sorts on the basis of inverse area.
    // The keys will be Dimensions and the objects RenderedImages.
    TreeMap sourceMap = new TreeMap(new Comparator() {

        public int compare(Object o1, Object o2) {
            Dimension d1 = (Dimension) o1;
            Dimension d2 = (Dimension) o2;
            int area1 = d1.width * d1.height;
            int area2 = d2.width * d2.height;
            double inverse1 = area1 == 0 ? Double.MAX_VALUE : 1.0 / area1;
            double inverse2 = area2 == 0 ? Double.MAX_VALUE : 1.0 / area2;
            if (inverse1 < inverse2) {
                return -1;
            } else if (inverse1 > inverse2) {
                return 1;
            } else {
                return 0;
            }
        }

        public boolean equals(Object o1, Object o2) {
            return o1.equals(o2);
        }
    });
    Iterator images = sequence.iterator();
    while (images.hasNext()) {
        RenderedImage image = (RenderedImage) images.next();
        sourceMap.put(new Dimension(image.getWidth(), image.getHeight()), image);
    }
    // Create the rendered source list sorted by inverse area.
    Vector renderedSources = new Vector(sourceMap.size());
    Iterator keys = sourceMap.keySet().iterator();
    while (keys.hasNext()) {
        renderedSources.add(sourceMap.get(keys.next()));
    }
    // Create the RenderableImage from the sorted RenderedImages.
    MultiResolutionRenderableImage renderableImage = new MultiResolutionRenderableImage(renderedSources, 0.0F, 0.0F, 1.0F);
    // Set properties from those of the first rendered source.
    PropertySource firstSource = (PropertySource) renderedSources.get(0);
    copyProperty(firstSource, renderableImage, ImageReadDescriptor.PROPERTY_NAME_IMAGE_READ_PARAM);
    copyProperty(firstSource, renderableImage, ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
    copyProperty(firstSource, renderableImage, ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM);
    copyProperty(firstSource, renderableImage, ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
    // Return the RenderableImage.
    return renderableImage;
}
Also used : MultiResolutionRenderableImage(javax.media.jai.MultiResolutionRenderableImage) Iterator(java.util.Iterator) Collection(java.util.Collection) Dimension(java.awt.Dimension) TreeMap(java.util.TreeMap) RenderedImage(java.awt.image.RenderedImage) Vector(java.util.Vector) Comparator(java.util.Comparator) WritablePropertySource(javax.media.jai.WritablePropertySource) PropertySource(javax.media.jai.PropertySource)

Aggregations

Dimension (java.awt.Dimension)1 RenderedImage (java.awt.image.RenderedImage)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 TreeMap (java.util.TreeMap)1 Vector (java.util.Vector)1 MultiResolutionRenderableImage (javax.media.jai.MultiResolutionRenderableImage)1 PropertySource (javax.media.jai.PropertySource)1 WritablePropertySource (javax.media.jai.WritablePropertySource)1