Package com.sun.media.jai.codec

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


        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;
        RenderedImageAdapter planarImage = new RenderedImageAdapter(
                                    dec.decodeAsRenderedImage( imageToLoad ));

        return readPlanarImage( planarImage );
    }
View Full Code Here


    throws IOException, NullPointerException {

    int[] aRetVal = new int[2];

    RenderedImage oImg;
    ImageDecoder oDecoder;

    oDecoder = ImageCodec.createImageDecoder(sCodec, new ByteArrayInputStream(byImg), null);

    oImg = oDecoder.decodeAsRenderedImage();

    aRetVal[0] = oImg.getWidth();
    aRetVal[1] = oImg.getHeight();

    return aRetVal;
View Full Code Here

    RenderedImage oRenderedImg;
    PlanarImage oPlI;
    RenderedOp oScI;
    ParameterBlock oBlk;
    ImageEncoder oImgEnc;
    ImageDecoder oDecoder;

    Log.out.debug("Begin Picture.drawJAIImage("+sCodec+","+String.valueOf(iThumbWidth)+","+String.valueOf(iThumbHeight)+")");
   
    oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(sCodec, imgSrc, null);

    oRenderedImg = oDecoder.decodeAsRenderedImage();

    if (sCodec.equals("gif")) {
      // Increase color depth to 16M RGB
      try {
        javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();
View Full Code Here

        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,
                                                      bound);
                } else {
                    // Re-throw the error.
View Full Code Here

        try {
            buf.append(suffix);
            url = new URL(buf.toString());
            stream = url.openStream();
            ImageDecoder decoder =
                ImageCodec.createImageDecoder(fmt, stream, null);
            rendering = decoder.decodeAsRenderedImage();
            itWorks = true;
        } catch(Exception e) {
            itWorks = false; // redundant
        }
View Full Code Here

            }
        }

        // 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"),
                                               ioe, this, false);
                        im = null;
                    }
View Full Code Here

   * @throws FormatIOException
   */
  public BufferedImage open(String input) throws FormatIOException {
    RenderedImageAdapter aid = null;
    try {
      ImageDecoder enc = ImageCodec.createImageDecoder("PNM", new File(input), null);
      aid = new RenderedImageAdapter(enc.decodeAsRenderedImage());
    } catch (IOException e) {
      return null;
    }
    return aid.getAsBufferedImage();
  }
View Full Code Here

   * @throws FormatIOException
   */
  public BufferedImage open(InputStream input) throws FormatIOException {
    RenderedImageAdapter aid = null;
    try {
      ImageDecoder enc = ImageCodec.createImageDecoder("PNM", input, null);
      aid = new RenderedImageAdapter(enc.decodeAsRenderedImage());
    } catch (IOException e) {
      return null;
    }
    return aid.getAsBufferedImage();
  }
View Full Code Here

/*     */       }
/*     */
/*     */     }
/*     */
/* 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);
/*     */
/* 167 */             im = null;
/*     */           }
View Full Code Here

/*      */     try
/*      */     {
/*  302 */       buf.append(suffix);
/*  303 */       url = new URL(buf.toString());
/*  304 */       stream = url.openStream();
/*  305 */       ImageDecoder decoder = ImageCodec.createImageDecoder(fmt, stream, null);
/*      */
/*  307 */       rendering = decoder.decodeAsRenderedImage();
/*  308 */       itWorks = true;
/*      */     } catch (Exception e) {
/*  310 */       itWorks = false;
/*      */     }
/*      */
View Full Code Here

TOP

Related Classes of com.sun.media.jai.codec.ImageDecoder

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.