Package com.lightcrafts.media.jai.codec

Examples of com.lightcrafts.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


            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

        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

    }

    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

    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

     * Creates an image from a SeekableStream.
     */
    public RenderedImage create(ParameterBlock paramBlock,
                                RenderingHints renderHints) {
        ImagingListener listener = ImageUtil.getImagingListener(renderHints);
        SeekableStream src = (SeekableStream)paramBlock.getObjectParameter(0);
        try {
            src.seek(0L);
        } catch (IOException e) {
            listener.errorOccurred(JaiI18N.getString("StreamRIF0"),
                                   e, this, false);
//            e.printStackTrace();
            return null;
        }

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

        String[] names = ImageCodec.getDecoderNames(src);

        OperationRegistry registry =
            JAI.getDefaultInstance().getOperationRegistry();
        int bound = OpImage.OP_IO_BOUND;
        ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

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

            key = JAI.KEY_OPERATION_REGISTRY;
            if (renderHints.containsKey(key)) {
                registry = (OperationRegistry)renderHints.get(key);
            }

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

        // Try to create a JAI operation with the given name
        for (int i = 0; i < names.length; i++) {
            RenderedImageFactory rif = null;
            try {
                rif = RIFRegistry.get(registry, names[i]);
            } catch(IllegalArgumentException iae) {
                // ignore IAE.
            }
            if(rif != null) {
                RenderedImage im = RIFRegistry.create(registry, names[i],
                                                      paramBlock, renderHints);
                if (im != null) {
                    return im;
                }
            }
        }

        // 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 = src.canSeekBackwards();

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

        // Try to create an ImageDecoder directly
        for (int i = 0; i < names.length; i++) {
            ImageDecoder dec =
                ImageCodec.createImageDecoder(names[i], src, param);
            RenderedImage im = null;
            try {
                im = dec.decodeAsRenderedImage();
            } 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 = RIFUtil.getTileCacheHint(renderHints);
                    if(cache != null) {
                        cache.flush();
                    }

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

                    try {
                        // Reposition the stream before the previous decoding.
                        src.seek(streamPosition);

                        // Retry image decoding.
                        im = dec.decodeAsRenderedImage();
                    } catch (IOException ioe) {
                        listener.errorOccurred(JaiI18N.getString("StreamRIF2"),
View Full Code Here

                                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

        try {
            // Create a SeekableStream from the file name (first parameter).
            String fileName = (String)args.getObjectParameter(0);

      SeekableStream src = null;
      try {
                src = new FileSeekableStream(fileName);
            } catch (FileNotFoundException fnfe) {
    // Try to get the file as an InputStream resource. This would
    // happen when the application and image file are packaged in
View Full Code Here

TOP

Related Classes of com.lightcrafts.media.jai.codec.SeekableStream

Copyright © 2018 www.massapicom. 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.