Package com.sun.media.jai.codec

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


    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

        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

     * 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

        {
            fract, fract,
            fract, fract,
            fract, fract
        };
        SeekableStream s = SeekableStream.wrapInputStream(stream, false);
        RenderedOp op = JAI.create("Stream", s);

        RenderingHints hints = new RenderingHints(
                RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);
View Full Code Here

/*     */   implements RenderedImageFactory
/*     */ {
/*     */   public RenderedImage create(ParameterBlock paramBlock, RenderingHints renderHints)
/*     */   {
/*  64 */     ImagingListener listener = ImageUtil.getImagingListener(renderHints);
/*  65 */     SeekableStream src = (SeekableStream)paramBlock.getObjectParameter(0);
/*     */     try {
/*  67 */       src.seek(0L);
/*     */     } catch (IOException e) {
/*  69 */       listener.errorOccurred(JaiI18N.getString("StreamRIF0"), e, this, false);
/*     */
/*  72 */       return null;
/*     */     }
/*     */
/*  75 */     ImageDecodeParam param = null;
/*  76 */     if (paramBlock.getNumParameters() > 1) {
/*  77 */       param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
/*     */     }
/*     */
/*  80 */     String[] names = ImageCodec.getDecoderNames(src);
/*     */
/*  82 */     OperationRegistry registry = JAI.getDefaultInstance().getOperationRegistry();
/*     */
/*  84 */     int bound = 2;
/*  85 */     ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
/*     */
/*  87 */     if (renderHints != null)
/*     */     {
/*  90 */       RenderingHints.Key key = JAI.KEY_OPERATION_REGISTRY;
/*  91 */       if (renderHints.containsKey(key)) {
/*  92 */         registry = (OperationRegistry)renderHints.get(key);
/*     */       }
/*     */
/*  95 */       key = JAI.KEY_OPERATION_BOUND;
/*  96 */       if (renderHints.containsKey(key)) {
/*  97 */         bound = ((Integer)renderHints.get(key)).intValue();
/*     */       }
/*     */
/*     */     }
/*     */
/* 102 */     for (int i = 0; i < names.length; i++) {
/* 103 */       RenderedImageFactory rif = null;
/*     */       try {
/* 105 */         rif = RIFRegistry.get(registry, names[i]);
/*     */       }
/*     */       catch (IllegalArgumentException iae) {
/*     */       }
/* 109 */       if (rif != null) {
/* 110 */         RenderedImage im = RIFRegistry.create(registry, names[i], paramBlock, renderHints);
/*     */
/* 112 */         if (im != null) {
/* 113 */           return im;
/*     */         }
/*     */
/*     */       }
/*     */
/*     */     }
/*     */
/* 121 */     boolean canAttemptRecovery = src.canSeekBackwards();
/*     */
/* 124 */     long streamPosition = -9223372036854775808L;
/* 125 */     if (canAttemptRecovery) {
/*     */       try {
/* 127 */         streamPosition = src.getFilePointer();
/*     */       } catch (IOException ioe) {
/* 129 */         listener.errorOccurred(JaiI18N.getString("StreamRIF1"), ioe, this, false);
/*     */
/* 133 */         canAttemptRecovery = false;
/*     */       }
/*     */
/*     */     }
/*     */
/* 138 */     for (int i = 0; i < names.length; i++) {
/* 139 */       ImageDecoder dec = ImageCodec.createImageDecoder(names[i], src, param);
/*     */
/* 141 */       RenderedImage im = null;
/*     */       try {
/* 143 */         im = dec.decodeAsRenderedImage();
/*     */       }
/*     */       catch (OutOfMemoryError memoryError)
/*     */       {
/* 148 */         if (canAttemptRecovery)
/*     */         {
/* 150 */           TileCache cache = RIFUtil.getTileCacheHint(renderHints);
/* 151 */           if (cache != null) {
/* 152 */             cache.flush();
/*     */           }
/*     */
/* 156 */           System.gc();
/*     */           try
/*     */           {
/* 160 */             src.seek(streamPosition);
/*     */
/* 163 */             im = dec.decodeAsRenderedImage();
/*     */           } catch (IOException ioe) {
/* 165 */             listener.errorOccurred(JaiI18N.getString("StreamRIF2"), ioe, this, false);
/*     */
View Full Code Here

/*     */   }
/*     */
/*     */   private void readImageContents() throws IOException {
/* 147 */     this.storage.changeDirectoryToRoot();
/* 148 */     this.storage.changeDirectory("Data Object Store 000001");
/* 149 */     SeekableStream imageContents = this.storage.getStream("\005Image Contents");
/*     */
/* 152 */     PropertySet icps = new PropertySet(imageContents);
/* 153 */     this.numResolutions = ((int)icps.getUI4(16777216));
/* 154 */     this.highestResWidth = ((int)icps.getUI4(16777218));
/* 155 */     this.highestResHeight = ((int)icps.getUI4(16777219));
View Full Code Here

/* 725 */       this.properties.put(name.toLowerCase(), new Integer((int)i));
/*     */     }
/*     */   }
/*     */
/*     */   private void getSummaryInformation() {
/* 730 */     SeekableStream summaryInformation = null;
/* 731 */     PropertySet sips = null;
/*     */     try {
/* 733 */       this.storage.changeDirectoryToRoot();
/* 734 */       summaryInformation = this.storage.getStream("\005SummaryInformation");
/* 735 */       sips = new PropertySet(summaryInformation);
View Full Code Here

/* 749 */     addLPSTRProperty("last saved by", sips, 8);
/* 750 */     addLPSTRProperty("revision number", sips, 9);
/*     */   }
/*     */
/*     */   private void getImageInfo() {
/* 754 */     SeekableStream imageInfo = null;
/* 755 */     PropertySet iips = null;
/*     */     try {
/* 757 */       this.storage.changeDirectoryToRoot();
/* 758 */       imageInfo = this.storage.getStream("\005Image Info");
/* 759 */       if (imageInfo == null) {
View Full Code Here

/*    */   {
/*    */     try
/*    */     {
/* 56 */       URL url = (URL)paramBlock.getObjectParameter(0);
/* 57 */       InputStream stream = url.openStream();
/* 58 */       SeekableStream src = SeekableStream.wrapInputStream(stream, true);
/*    */
/* 60 */       ImageDecodeParam param = null;
/* 61 */       if (paramBlock.getNumParameters() > 1) {
/* 62 */         param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
/*    */       }
View Full Code Here

TOP

Related Classes of com.sun.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.