Examples of SeekableStream


Examples of com.sun.media.jai.codec.SeekableStream

        StringBuffer msg = new StringBuffer();
        if (!validateParameters(paramBlock, msg)) {
            return null;
        }
        try {
            SeekableStream in = (SeekableStream) paramBlock.getObjectParameter(0);
            XTIFFImage image = new XTIFFImage(in, (TIFFDecodeParam) paramBlock.getObjectParameter(1), 0);
            return image;
        } catch (Exception e) {
            return null;
        }
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

     *                 if the image could not be manipulated correctly.
     */
    public static byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth, int pMaxHeight) throws IOException {
    InputStream imageInputStream = new ByteArrayInputStream(pImageData);
    // read in the original image from an input stream
    SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
    RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
    ((OpImage) originalImage.getRendering()).setTileCache(null);
    int origImageWidth = originalImage.getWidth();
    int origImageHeight = originalImage.getHeight();
    // now resize the image
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

     * @param input the <code>File</code> containing the image
     * @return an SWT <code>ImageData</code> version of the image data
     */
    public ImageData load(File input) throws IOException  {

        SeekableStream s = new FileSeekableStream(input);

        TIFFDecodeParam param = new TIFFDecodeParam();
        param.setDecodePaletteAsShorts( false );
        ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param); //$NON-NLS-1$
        int imageToLoad = 0;
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

     */
    public void fire() throws IllegalActionException {
        super.fire();

        InputStream inputStream = null;
        SeekableStream seekableStream = null;

        try {
            try {
                inputStream = _fileURL.openStream();

                // We use a FileCacheSeekableStream here because
                // we need to have a stream that can go backwards.
                // If we are running under the windows installer, Web Start
                // or any other jar based installation, we need to be
                // able to handle images in jar files.
                seekableStream = new FileCacheSeekableStream(inputStream);
            } catch (IOException ex) {
                throw new IllegalActionException(this, ex,
                        "Unable to load file '" + _fileURL + "'");
            }

            _outputtedImage = JAI.create("stream", seekableStream);

            /*PlanarImage dummy =*/_outputtedImage.getRendering();
        } finally {
            if (seekableStream != null) {
                try {
                    seekableStream.close();
                } catch (Throwable throwable2) {
                    throw new IllegalActionException(this, throwable2,
                            "Unable to close SeekableStream for '" + _fileURL
                                    + "'");
                }
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

    }

    public static void main(String[] args) {
        try {
            RandomAccessFile f = new RandomAccessFile(args[0], "r");
            SeekableStream sis = new FileSeekableStream(f);
            StructuredStorage ss = new StructuredStorage(sis);

            ss.changeDirectoryToRoot();

            byte[] s = ss.getStreamAsBytes("SummaryInformation");
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

    }

    private void readImageContents() throws IOException  {
        storage.changeDirectoryToRoot();
        storage.changeDirectory("Data Object Store 000001");
        SeekableStream imageContents =
            storage.getStream("Image Contents");

        PropertySet icps = new PropertySet(imageContents);
        this.numResolutions   = (int)icps.getUI4(0x01000000);
        this.highestResWidth  = (int)icps.getUI4(0x01000002);
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

            properties.put(name.toLowerCase(), new Integer((int)i));
        }
    }

    private void getSummaryInformation() {
        SeekableStream summaryInformation = null;
        PropertySet sips = null;
        try {
            storage.changeDirectoryToRoot();
            summaryInformation = storage.getStream("SummaryInformation");
            sips = new PropertySet(summaryInformation);
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

        addLPSTRProperty("last saved by", sips, 0x000000008);
        addLPSTRProperty("revision number", sips, 0x000000009);
    }

    private void getImageInfo() {
        SeekableStream imageInfo = null;
        PropertySet iips = null;
        try {
            storage.changeDirectoryToRoot();
            imageInfo = storage.getStream("Image Info");
            if (imageInfo == null) {
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

                                RenderingHints renderHints) {
        try {
            // Create a SeekableStream from the URL (first parameter).
            URL url = (URL)paramBlock.getObjectParameter(0);
            InputStream stream = url.openStream();
            SeekableStream src = SeekableStream.wrapInputStream(stream, true);

            ImageDecodeParam param = null;
            if (paramBlock.getNumParameters() > 1) {
                param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
            }
View Full Code Here

Examples of com.sun.media.jai.codec.SeekableStream

    public static RenderedImage create(String type,
                                       ParameterBlock paramBlock,
                                       RenderingHints renderHints) {
        ImagingListener listener = ImageUtil.getImagingListener(renderHints);

        SeekableStream source =
            (SeekableStream)paramBlock.getObjectParameter(0);

        ImageDecodeParam param = null;
        if (paramBlock.getNumParameters() > 1) {
            param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
        }
        int page = 0;
        if (paramBlock.getNumParameters() > 2) {
            page = paramBlock.getIntParameter(2);
        }

        ImageDecoder dec = ImageCodec.createImageDecoder(type, source, param);
        try {
            int bound = OpImage.OP_IO_BOUND;
            ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

            if (renderHints != null) {
                RenderingHints.Key key;

                key = JAI.KEY_OPERATION_BOUND;
                if (renderHints.containsKey(key)) {
                    bound = ((Integer)renderHints.get(key)).intValue();
                }
            }

            // Set flag indicating that a recovery may be attempted if
            // an OutOfMemoryError occurs during the decodeAsRenderedImage()
            // call - which is only possible if the stream can seek backwards.
            boolean canAttemptRecovery = source.canSeekBackwards();

            // Save the stream position prior to decodeAsRenderedImage().
            long streamPosition = Long.MIN_VALUE;
            if(canAttemptRecovery) {
                try {
                    streamPosition = source.getFilePointer();
                } catch(IOException ioe) {
                    listener.errorOccurred(JaiI18N.getString("StreamRIF1"),
                                           ioe, CodecRIFUtil.class, false);
                    // Unset the recovery attempt flag but otherwise
                    // ignore the exception.
                    canAttemptRecovery = false;
                }
            }

            OpImage image = null;
            try {
                // Attempt to create an OpImage from the decoder image.
                image = new DisposableNullOpImage(dec.decodeAsRenderedImage(page),
                                                  layout,
                                                  renderHints,
                                                  bound);
            } catch(OutOfMemoryError memoryError) {
                // Ran out of memory - may be due to the decoder being
                // obliged to read the entire image when it creates the
                // RenderedImage it returns.
                if(canAttemptRecovery) {
                    // First flush the cache if one is defined.
                    TileCache cache = image != null ?
                        image.getTileCache() :
                        RIFUtil.getTileCacheHint(renderHints);
                    if(cache != null) {
                        cache.flush();
                    }

                    // Force garbage collection.
                    System.gc(); //slow

                    // Reposition the stream before the previous decoding.
                    source.seek(streamPosition);

                    // Retry image decoding.
                    image = new DisposableNullOpImage(dec.decodeAsRenderedImage(page),
                                                      layout,
                                                      renderHints,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.